blob: 296afafde120bca3100e39bbcf365fee7ddf8bd6 [file] [log] [blame]
Catalin Marinas0aea86a2012-03-05 11:49:32 +00001/*
2 * Based on arch/arm/lib/clear_user.S
3 *
4 * Copyright (C) 2012 ARM Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include <linux/linkage.h>
James Morse338d4f42015-07-22 19:05:54 +010019
Catalin Marinas2962f1d2016-07-01 14:58:21 +010020#include <asm/uaccess.h>
Catalin Marinas0aea86a2012-03-05 11:49:32 +000021
22 .text
23
Mark Rutland4504c5c2018-04-12 12:11:05 +010024/* Prototype: int __arch_clear_user(void *addr, size_t sz)
Catalin Marinas0aea86a2012-03-05 11:49:32 +000025 * Purpose : clear some user memory
26 * Params : addr - user memory address to clear
27 * : sz - number of bytes to clear
28 * Returns : number of bytes NOT cleared
29 *
30 * Alignment fixed up by hardware.
31 */
Mark Rutland4504c5c2018-04-12 12:11:05 +010032ENTRY(__arch_clear_user)
Will Deacon599c71f2017-08-10 13:58:16 +010033 uaccess_enable_not_uao x2, x3, x4
Catalin Marinas0aea86a2012-03-05 11:49:32 +000034 mov x2, x1 // save the size for fixup return
35 subs x1, x1, #8
36 b.mi 2f
371:
James Morse57f49592016-02-05 14:58:48 +000038uao_user_alternative 9f, str, sttr, xzr, x0, 8
Catalin Marinas0aea86a2012-03-05 11:49:32 +000039 subs x1, x1, #8
40 b.pl 1b
412: adds x1, x1, #4
42 b.mi 3f
James Morse57f49592016-02-05 14:58:48 +000043uao_user_alternative 9f, str, sttr, wzr, x0, 4
Catalin Marinas0aea86a2012-03-05 11:49:32 +000044 sub x1, x1, #4
453: adds x1, x1, #2
46 b.mi 4f
James Morse57f49592016-02-05 14:58:48 +000047uao_user_alternative 9f, strh, sttrh, wzr, x0, 2
Catalin Marinas0aea86a2012-03-05 11:49:32 +000048 sub x1, x1, #2
494: adds x1, x1, #1
50 b.mi 5f
James Morse57f49592016-02-05 14:58:48 +000051uao_user_alternative 9f, strb, sttrb, wzr, x0, 0
Catalin Marinas0aea86a2012-03-05 11:49:32 +0000525: mov x0, #0
Catalin Marinas87883132018-01-10 13:18:30 +000053 uaccess_disable_not_uao x2, x3
Catalin Marinas0aea86a2012-03-05 11:49:32 +000054 ret
Mark Rutland4504c5c2018-04-12 12:11:05 +010055ENDPROC(__arch_clear_user)
Catalin Marinas0aea86a2012-03-05 11:49:32 +000056
57 .section .fixup,"ax"
58 .align 2
599: mov x0, x2 // return the original size
Pavel Tatashin9f03d162019-11-19 17:10:06 -050060ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_ALT_PAN_NOT_UAO, \
61 CONFIG_ARM64_PAN)
Catalin Marinas0aea86a2012-03-05 11:49:32 +000062 ret
63 .previous