1 /* SPDX-License-Identifier: GPL-2.0 */
3 * __get_user functions.
5 * (C) Copyright 1998 Linus Torvalds
6 * (C) Copyright 2005 Andi Kleen
7 * (C) Copyright 2008 Glauber Costa
9 * These functions have a non-standard call interface
10 * to make them more efficient, especially as they
11 * return an error value in addition to the "real"
18 * Inputs: %[r|e]ax contains the address.
20 * Outputs: %[r|e]ax is error code (0 or -EFAULT)
21 * %[r|e]dx contains zero-extended value
22 * %ecx contains the high half for 32-bit __get_user_8
25 * These functions should not modify any other registers,
26 * as they get called from within inline assembly.
29 #include <linux/linkage.h>
30 #include <asm/page_types.h>
31 #include <asm/errno.h>
32 #include <asm/asm-offsets.h>
33 #include <asm/thread_info.h>
36 #include <asm/export.h>
38 #ifdef CONFIG_X86_5LEVEL
39 #define LOAD_TASK_SIZE_MINUS_N(n) \
40 ALTERNATIVE __stringify(mov $((1 << 47) - 4096 - (n)),%rdx), \
41 __stringify(mov $((1 << 56) - 4096 - (n)),%rdx), X86_FEATURE_LA57
43 #define LOAD_TASK_SIZE_MINUS_N(n) \
44 mov $(TASK_SIZE_MAX - (n)),%_ASM_DX
48 SYM_FUNC_START(__get_user_1)
49 LOAD_TASK_SIZE_MINUS_N(0)
52 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
53 and %_ASM_DX, %_ASM_AX
55 1: movzbl (%_ASM_AX),%edx
59 SYM_FUNC_END(__get_user_1)
60 EXPORT_SYMBOL(__get_user_1)
62 SYM_FUNC_START(__get_user_2)
63 LOAD_TASK_SIZE_MINUS_N(1)
66 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
67 and %_ASM_DX, %_ASM_AX
69 2: movzwl (%_ASM_AX),%edx
73 SYM_FUNC_END(__get_user_2)
74 EXPORT_SYMBOL(__get_user_2)
76 SYM_FUNC_START(__get_user_4)
77 LOAD_TASK_SIZE_MINUS_N(3)
80 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
81 and %_ASM_DX, %_ASM_AX
83 3: movl (%_ASM_AX),%edx
87 SYM_FUNC_END(__get_user_4)
88 EXPORT_SYMBOL(__get_user_4)
90 SYM_FUNC_START(__get_user_8)
92 LOAD_TASK_SIZE_MINUS_N(7)
95 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
96 and %_ASM_DX, %_ASM_AX
98 4: movq (%_ASM_AX),%rdx
103 LOAD_TASK_SIZE_MINUS_N(7)
104 cmp %_ASM_DX,%_ASM_AX
106 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
107 and %_ASM_DX, %_ASM_AX
109 4: movl (%_ASM_AX),%edx
110 5: movl 4(%_ASM_AX),%ecx
115 SYM_FUNC_END(__get_user_8)
116 EXPORT_SYMBOL(__get_user_8)
119 SYM_CODE_START_LOCAL(.Lbad_get_user_clac)
123 mov $(-EFAULT),%_ASM_AX
125 SYM_CODE_END(.Lbad_get_user_clac)
128 SYM_CODE_START_LOCAL(.Lbad_get_user_8_clac)
133 mov $(-EFAULT),%_ASM_AX
135 SYM_CODE_END(.Lbad_get_user_8_clac)
138 _ASM_EXTABLE_UA(1b, .Lbad_get_user_clac)
139 _ASM_EXTABLE_UA(2b, .Lbad_get_user_clac)
140 _ASM_EXTABLE_UA(3b, .Lbad_get_user_clac)
142 _ASM_EXTABLE_UA(4b, .Lbad_get_user_clac)
144 _ASM_EXTABLE_UA(4b, .Lbad_get_user_8_clac)
145 _ASM_EXTABLE_UA(5b, .Lbad_get_user_8_clac)