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/export.h>
30 #include <linux/linkage.h>
31 #include <asm/page_types.h>
32 #include <asm/errno.h>
33 #include <asm/asm-offsets.h>
34 #include <asm/thread_info.h>
38 #define ASM_BARRIER_NOSPEC ALTERNATIVE "", "lfence", X86_FEATURE_LFENCE_RDTSC
40 .macro check_range size:req
41 .if IS_ENABLED(CONFIG_X86_64)
42 movq $0x0123456789abcdef,%rdx
44 .pushsection runtime_ptr_USER_PTR_MAX,"a"
51 cmp $TASK_SIZE_MAX-\size+1, %eax
53 sbb %edx, %edx /* array_index_mask_nospec() */
58 .macro UACCESS op src dst
60 _ASM_EXTABLE_UA(1b, __get_user_handle_exception)
65 SYM_FUNC_START(__get_user_1)
68 UACCESS movzbl (%_ASM_AX),%edx
72 SYM_FUNC_END(__get_user_1)
73 EXPORT_SYMBOL(__get_user_1)
75 SYM_FUNC_START(__get_user_2)
78 UACCESS movzwl (%_ASM_AX),%edx
82 SYM_FUNC_END(__get_user_2)
83 EXPORT_SYMBOL(__get_user_2)
85 SYM_FUNC_START(__get_user_4)
88 UACCESS movl (%_ASM_AX),%edx
92 SYM_FUNC_END(__get_user_4)
93 EXPORT_SYMBOL(__get_user_4)
95 SYM_FUNC_START(__get_user_8)
102 UACCESS movq (%_ASM_AX),%rdx
104 UACCESS movl (%_ASM_AX),%edx
105 UACCESS movl 4(%_ASM_AX),%ecx
110 SYM_FUNC_END(__get_user_8)
111 EXPORT_SYMBOL(__get_user_8)
113 /* .. and the same for __get_user, just without the range checks */
114 SYM_FUNC_START(__get_user_nocheck_1)
117 UACCESS movzbl (%_ASM_AX),%edx
121 SYM_FUNC_END(__get_user_nocheck_1)
122 EXPORT_SYMBOL(__get_user_nocheck_1)
124 SYM_FUNC_START(__get_user_nocheck_2)
127 UACCESS movzwl (%_ASM_AX),%edx
131 SYM_FUNC_END(__get_user_nocheck_2)
132 EXPORT_SYMBOL(__get_user_nocheck_2)
134 SYM_FUNC_START(__get_user_nocheck_4)
137 UACCESS movl (%_ASM_AX),%edx
141 SYM_FUNC_END(__get_user_nocheck_4)
142 EXPORT_SYMBOL(__get_user_nocheck_4)
144 SYM_FUNC_START(__get_user_nocheck_8)
148 UACCESS movq (%_ASM_AX),%rdx
151 UACCESS movl (%_ASM_AX),%edx
152 UACCESS movl 4(%_ASM_AX),%ecx
157 SYM_FUNC_END(__get_user_nocheck_8)
158 EXPORT_SYMBOL(__get_user_nocheck_8)
161 SYM_CODE_START_LOCAL(__get_user_handle_exception)
165 mov $(-EFAULT),%_ASM_AX
167 SYM_CODE_END(__get_user_handle_exception)