FROMLIST: arm64: Factor out PAN enabling/disabling into separate uaccess_* macros
[firefly-linux-kernel-4.4.55.git] / arch / arm64 / lib / clear_user.S
1 /*
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>
19
20 #include <asm/assembler.h>
21 #include <asm/cpufeature.h>
22 #include <asm/sysreg.h>
23 #include <asm/uaccess.h>
24
25         .text
26
27 /* Prototype: int __clear_user(void *addr, size_t sz)
28  * Purpose  : clear some user memory
29  * Params   : addr - user memory address to clear
30  *          : sz   - number of bytes to clear
31  * Returns  : number of bytes NOT cleared
32  *
33  * Alignment fixed up by hardware.
34  */
35 ENTRY(__clear_user)
36         uaccess_enable_not_uao x2, x3
37         mov     x2, x1                  // save the size for fixup return
38         subs    x1, x1, #8
39         b.mi    2f
40 1:
41 uao_user_alternative 9f, str, sttr, xzr, x0, 8
42         subs    x1, x1, #8
43         b.pl    1b
44 2:      adds    x1, x1, #4
45         b.mi    3f
46 uao_user_alternative 9f, str, sttr, wzr, x0, 4
47         sub     x1, x1, #4
48 3:      adds    x1, x1, #2
49         b.mi    4f
50 uao_user_alternative 9f, strh, sttrh, wzr, x0, 2
51         sub     x1, x1, #2
52 4:      adds    x1, x1, #1
53         b.mi    5f
54 uao_user_alternative 9f, strb, sttrb, wzr, x0, 0
55 5:      mov     x0, #0
56         uaccess_disable_not_uao x2
57         ret
58 ENDPROC(__clear_user)
59
60         .section .fixup,"ax"
61         .align  2
62 9:      mov     x0, x2                  // return the original size
63         ret
64         .previous