GNU Linux-libre 4.4.288-gnu1
[releases.git] / arch / x86 / lib / getuser.S
1 /*
2  * __get_user functions.
3  *
4  * (C) Copyright 1998 Linus Torvalds
5  * (C) Copyright 2005 Andi Kleen
6  * (C) Copyright 2008 Glauber Costa
7  *
8  * These functions have a non-standard call interface
9  * to make them more efficient, especially as they
10  * return an error value in addition to the "real"
11  * return value.
12  */
13
14 /*
15  * __get_user_X
16  *
17  * Inputs:      %[r|e]ax contains the address.
18  *
19  * Outputs:     %[r|e]ax is error code (0 or -EFAULT)
20  *              %[r|e]dx contains zero-extended value
21  *              %ecx contains the high half for 32-bit __get_user_8
22  *
23  *
24  * These functions should not modify any other registers,
25  * as they get called from within inline assembly.
26  */
27
28 #include <linux/linkage.h>
29 #include <asm/page_types.h>
30 #include <asm/errno.h>
31 #include <asm/asm-offsets.h>
32 #include <asm/thread_info.h>
33 #include <asm/asm.h>
34 #include <asm/smap.h>
35
36         .text
37 ENTRY(__get_user_1)
38         GET_THREAD_INFO(%_ASM_DX)
39         cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
40         jae bad_get_user
41         sbb %_ASM_DX, %_ASM_DX          /* array_index_mask_nospec() */
42         and %_ASM_DX, %_ASM_AX
43         ASM_STAC
44 1:      movzbl (%_ASM_AX),%edx
45         xor %eax,%eax
46         ASM_CLAC
47         ret
48 ENDPROC(__get_user_1)
49
50 ENTRY(__get_user_2)
51         add $1,%_ASM_AX
52         jc bad_get_user
53         GET_THREAD_INFO(%_ASM_DX)
54         cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
55         jae bad_get_user
56         sbb %_ASM_DX, %_ASM_DX          /* array_index_mask_nospec() */
57         and %_ASM_DX, %_ASM_AX
58         ASM_STAC
59 2:      movzwl -1(%_ASM_AX),%edx
60         xor %eax,%eax
61         ASM_CLAC
62         ret
63 ENDPROC(__get_user_2)
64
65 ENTRY(__get_user_4)
66         add $3,%_ASM_AX
67         jc bad_get_user
68         GET_THREAD_INFO(%_ASM_DX)
69         cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
70         jae bad_get_user
71         sbb %_ASM_DX, %_ASM_DX          /* array_index_mask_nospec() */
72         and %_ASM_DX, %_ASM_AX
73         ASM_STAC
74 3:      movl -3(%_ASM_AX),%edx
75         xor %eax,%eax
76         ASM_CLAC
77         ret
78 ENDPROC(__get_user_4)
79
80 ENTRY(__get_user_8)
81 #ifdef CONFIG_X86_64
82         add $7,%_ASM_AX
83         jc bad_get_user
84         GET_THREAD_INFO(%_ASM_DX)
85         cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
86         jae bad_get_user
87         sbb %_ASM_DX, %_ASM_DX          /* array_index_mask_nospec() */
88         and %_ASM_DX, %_ASM_AX
89         ASM_STAC
90 4:      movq -7(%_ASM_AX),%rdx
91         xor %eax,%eax
92         ASM_CLAC
93         ret
94 #else
95         add $7,%_ASM_AX
96         jc bad_get_user_8
97         GET_THREAD_INFO(%_ASM_DX)
98         cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
99         jae bad_get_user_8
100         sbb %_ASM_DX, %_ASM_DX          /* array_index_mask_nospec() */
101         and %_ASM_DX, %_ASM_AX
102         ASM_STAC
103 4:      movl -7(%_ASM_AX),%edx
104 5:      movl -3(%_ASM_AX),%ecx
105         xor %eax,%eax
106         ASM_CLAC
107         ret
108 #endif
109 ENDPROC(__get_user_8)
110
111
112 bad_get_user:
113         xor %edx,%edx
114         mov $(-EFAULT),%_ASM_AX
115         ASM_CLAC
116         ret
117 END(bad_get_user)
118
119 #ifdef CONFIG_X86_32
120 bad_get_user_8:
121         xor %edx,%edx
122         xor %ecx,%ecx
123         mov $(-EFAULT),%_ASM_AX
124         ASM_CLAC
125         ret
126 END(bad_get_user_8)
127 #endif
128
129         _ASM_EXTABLE(1b,bad_get_user)
130         _ASM_EXTABLE(2b,bad_get_user)
131         _ASM_EXTABLE(3b,bad_get_user)
132 #ifdef CONFIG_X86_64
133         _ASM_EXTABLE(4b,bad_get_user)
134 #else
135         _ASM_EXTABLE(4b,bad_get_user_8)
136         _ASM_EXTABLE(5b,bad_get_user_8)
137 #endif