1 #ifndef _ASM_X86_UACCESS_64_H
2 #define _ASM_X86_UACCESS_64_H
5 * User space memory access functions
7 #include <linux/compiler.h>
8 #include <linux/lockdep.h>
9 #include <linux/kasan-checks.h>
10 #include <asm/alternative.h>
11 #include <asm/cpufeatures.h>
15 * Copy To/From Userspace
18 /* Handles exceptions in both to and from, but doesn't do access_ok */
19 __must_check
unsigned long
20 copy_user_enhanced_fast_string(void *to
, const void *from
, unsigned len
);
21 __must_check
unsigned long
22 copy_user_generic_string(void *to
, const void *from
, unsigned len
);
23 __must_check
unsigned long
24 copy_user_generic_unrolled(void *to
, const void *from
, unsigned len
);
26 static __always_inline __must_check
unsigned long
27 copy_user_generic(void *to
, const void *from
, unsigned len
)
32 * If CPU has ERMS feature, use copy_user_enhanced_fast_string.
33 * Otherwise, if CPU has rep_good feature, use copy_user_generic_string.
34 * Otherwise, use copy_user_generic_unrolled.
36 alternative_call_2(copy_user_generic_unrolled
,
37 copy_user_generic_string
,
39 copy_user_enhanced_fast_string
,
41 ASM_OUTPUT2("=a" (ret
), "=D" (to
), "=S" (from
),
43 "1" (to
), "2" (from
), "3" (len
)
44 : "memory", "rcx", "r8", "r9", "r10", "r11");
48 static __always_inline __must_check
unsigned long
49 raw_copy_from_user(void *dst
, const void __user
*src
, unsigned long size
)
53 if (!__builtin_constant_p(size
))
54 return copy_user_generic(dst
, (__force
void *)src
, size
);
58 __get_user_asm_nozero(*(u8
*)dst
, (u8 __user
*)src
,
59 ret
, "b", "b", "=q", 1);
64 __get_user_asm_nozero(*(u16
*)dst
, (u16 __user
*)src
,
65 ret
, "w", "w", "=r", 2);
70 __get_user_asm_nozero(*(u32
*)dst
, (u32 __user
*)src
,
71 ret
, "l", "k", "=r", 4);
76 __get_user_asm_nozero(*(u64
*)dst
, (u64 __user
*)src
,
77 ret
, "q", "", "=r", 8);
82 __get_user_asm_nozero(*(u64
*)dst
, (u64 __user
*)src
,
83 ret
, "q", "", "=r", 10);
85 __get_user_asm_nozero(*(u16
*)(8 + (char *)dst
),
86 (u16 __user
*)(8 + (char __user
*)src
),
87 ret
, "w", "w", "=r", 2);
92 __get_user_asm_nozero(*(u64
*)dst
, (u64 __user
*)src
,
93 ret
, "q", "", "=r", 16);
95 __get_user_asm_nozero(*(u64
*)(8 + (char *)dst
),
96 (u64 __user
*)(8 + (char __user
*)src
),
97 ret
, "q", "", "=r", 8);
101 return copy_user_generic(dst
, (__force
void *)src
, size
);
105 static __always_inline __must_check
unsigned long
106 raw_copy_to_user(void __user
*dst
, const void *src
, unsigned long size
)
110 if (!__builtin_constant_p(size
))
111 return copy_user_generic((__force
void *)dst
, src
, size
);
115 __put_user_asm(*(u8
*)src
, (u8 __user
*)dst
,
116 ret
, "b", "b", "iq", 1);
121 __put_user_asm(*(u16
*)src
, (u16 __user
*)dst
,
122 ret
, "w", "w", "ir", 2);
127 __put_user_asm(*(u32
*)src
, (u32 __user
*)dst
,
128 ret
, "l", "k", "ir", 4);
133 __put_user_asm(*(u64
*)src
, (u64 __user
*)dst
,
134 ret
, "q", "", "er", 8);
139 __put_user_asm(*(u64
*)src
, (u64 __user
*)dst
,
140 ret
, "q", "", "er", 10);
143 __put_user_asm(4[(u16
*)src
], 4 + (u16 __user
*)dst
,
144 ret
, "w", "w", "ir", 2);
150 __put_user_asm(*(u64
*)src
, (u64 __user
*)dst
,
151 ret
, "q", "", "er", 16);
154 __put_user_asm(1[(u64
*)src
], 1 + (u64 __user
*)dst
,
155 ret
, "q", "", "er", 8);
160 return copy_user_generic((__force
void *)dst
, src
, size
);
164 static __always_inline __must_check
165 unsigned long raw_copy_in_user(void __user
*dst
, const void __user
*src
, unsigned long size
)
167 return copy_user_generic((__force
void *)dst
,
168 (__force
void *)src
, size
);
171 extern long __copy_user_nocache(void *dst
, const void __user
*src
,
172 unsigned size
, int zerorest
);
174 extern long __copy_user_flushcache(void *dst
, const void __user
*src
, unsigned size
);
175 extern void memcpy_page_flushcache(char *to
, struct page
*page
, size_t offset
,
179 __copy_from_user_inatomic_nocache(void *dst
, const void __user
*src
,
182 kasan_check_write(dst
, size
);
183 return __copy_user_nocache(dst
, src
, size
, 0);
187 __copy_from_user_flushcache(void *dst
, const void __user
*src
, unsigned size
)
189 kasan_check_write(dst
, size
);
190 return __copy_user_flushcache(dst
, src
, size
);
194 copy_user_handle_tail(char *to
, char *from
, unsigned len
);
196 #endif /* _ASM_X86_UACCESS_64_H */