]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/x86/include/asm/uaccess_64.h
Merge branch 'slab/urgent' into slab/for-linus
[mirror_ubuntu-artful-kernel.git] / arch / x86 / include / asm / uaccess_64.h
CommitLineData
1965aae3
PA
1#ifndef _ASM_X86_UACCESS_64_H
2#define _ASM_X86_UACCESS_64_H
1da177e4
LT
3
4/*
5 * User space memory access functions
6 */
1da177e4
LT
7#include <linux/compiler.h>
8#include <linux/errno.h>
16dbc6c9 9#include <linux/lockdep.h>
1b1d9258
JB
10#include <asm/alternative.h>
11#include <asm/cpufeature.h>
1da177e4
LT
12#include <asm/page.h>
13
1da177e4
LT
14/*
15 * Copy To/From Userspace
16 */
17
18/* Handles exceptions in both to and from, but doesn't do access_ok */
95912008 19__must_check unsigned long
1b1d9258
JB
20copy_user_generic_string(void *to, const void *from, unsigned len);
21__must_check unsigned long
22copy_user_generic_unrolled(void *to, const void *from, unsigned len);
23
24static __always_inline __must_check unsigned long
25copy_user_generic(void *to, const void *from, unsigned len)
26{
27 unsigned ret;
28
29 alternative_call(copy_user_generic_unrolled,
30 copy_user_generic_string,
31 X86_FEATURE_REP_GOOD,
32 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
33 "=d" (len)),
34 "1" (to), "2" (from), "3" (len)
35 : "memory", "rcx", "r8", "r9", "r10", "r11");
36 return ret;
37}
95912008
AK
38
39__must_check unsigned long
3c93ca00 40_copy_to_user(void __user *to, const void *from, unsigned len);
95912008 41__must_check unsigned long
9f0cf4ad 42_copy_from_user(void *to, const void __user *from, unsigned len);
95912008
AK
43__must_check unsigned long
44copy_in_user(void __user *to, const void __user *from, unsigned len);
45
9f0cf4ad
AV
46static inline unsigned long __must_check copy_from_user(void *to,
47 const void __user *from,
48 unsigned long n)
49{
50 int sz = __compiletime_object_size(to);
9f0cf4ad 51
3c93ca00 52 might_fault();
9f0cf4ad 53 if (likely(sz == -1 || sz >= n))
409d02ef 54 n = _copy_from_user(to, from, n);
9f0cf4ad
AV
55#ifdef CONFIG_DEBUG_VM
56 else
57 WARN(1, "Buffer overflow detected!\n");
58#endif
409d02ef 59 return n;
9f0cf4ad
AV
60}
61
3c93ca00
FW
62static __always_inline __must_check
63int copy_to_user(void __user *dst, const void *src, unsigned size)
64{
65 might_fault();
66
67 return _copy_to_user(dst, src, size);
68}
9f0cf4ad 69
95912008
AK
70static __always_inline __must_check
71int __copy_from_user(void *dst, const void __user *src, unsigned size)
b896313e 72{
383d079b 73 int ret = 0;
c10d38dd 74
3ee1afa3 75 might_fault();
1da177e4 76 if (!__builtin_constant_p(size))
b896313e
JP
77 return copy_user_generic(dst, (__force void *)src, size);
78 switch (size) {
79 case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
80 ret, "b", "b", "=q", 1);
1da177e4 81 return ret;
b896313e
JP
82 case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
83 ret, "w", "w", "=r", 2);
1da177e4 84 return ret;
b896313e
JP
85 case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
86 ret, "l", "k", "=r", 4);
87 return ret;
88 case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
89 ret, "q", "", "=r", 8);
1da177e4 90 return ret;
1da177e4 91 case 10:
b896313e 92 __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20a4a236 93 ret, "q", "", "=r", 10);
b896313e
JP
94 if (unlikely(ret))
95 return ret;
96 __get_user_asm(*(u16 *)(8 + (char *)dst),
97 (u16 __user *)(8 + (char __user *)src),
98 ret, "w", "w", "=r", 2);
99 return ret;
1da177e4 100 case 16:
b896313e
JP
101 __get_user_asm(*(u64 *)dst, (u64 __user *)src,
102 ret, "q", "", "=r", 16);
103 if (unlikely(ret))
104 return ret;
105 __get_user_asm(*(u64 *)(8 + (char *)dst),
106 (u64 __user *)(8 + (char __user *)src),
107 ret, "q", "", "=r", 8);
108 return ret;
1da177e4 109 default:
b896313e 110 return copy_user_generic(dst, (__force void *)src, size);
1da177e4 111 }
b896313e 112}
1da177e4 113
95912008
AK
114static __always_inline __must_check
115int __copy_to_user(void __user *dst, const void *src, unsigned size)
b896313e 116{
383d079b 117 int ret = 0;
c10d38dd 118
3ee1afa3 119 might_fault();
1da177e4 120 if (!__builtin_constant_p(size))
b896313e
JP
121 return copy_user_generic((__force void *)dst, src, size);
122 switch (size) {
123 case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
124 ret, "b", "b", "iq", 1);
1da177e4 125 return ret;
b896313e
JP
126 case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
127 ret, "w", "w", "ir", 2);
1da177e4 128 return ret;
b896313e
JP
129 case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
130 ret, "l", "k", "ir", 4);
131 return ret;
132 case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
155b7352 133 ret, "q", "", "er", 8);
1da177e4 134 return ret;
1da177e4 135 case 10:
b896313e 136 __put_user_asm(*(u64 *)src, (u64 __user *)dst,
155b7352 137 ret, "q", "", "er", 10);
b896313e
JP
138 if (unlikely(ret))
139 return ret;
1da177e4 140 asm("":::"memory");
b896313e
JP
141 __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
142 ret, "w", "w", "ir", 2);
143 return ret;
1da177e4 144 case 16:
b896313e 145 __put_user_asm(*(u64 *)src, (u64 __user *)dst,
155b7352 146 ret, "q", "", "er", 16);
b896313e
JP
147 if (unlikely(ret))
148 return ret;
1da177e4 149 asm("":::"memory");
b896313e 150 __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
155b7352 151 ret, "q", "", "er", 8);
b896313e 152 return ret;
1da177e4 153 default:
b896313e 154 return copy_user_generic((__force void *)dst, src, size);
1da177e4 155 }
b896313e 156}
1da177e4 157
95912008
AK
158static __always_inline __must_check
159int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
b896313e 160{
383d079b 161 int ret = 0;
c10d38dd 162
3ee1afa3 163 might_fault();
1da177e4 164 if (!__builtin_constant_p(size))
b896313e
JP
165 return copy_user_generic((__force void *)dst,
166 (__force void *)src, size);
167 switch (size) {
168 case 1: {
1da177e4 169 u8 tmp;
b896313e
JP
170 __get_user_asm(tmp, (u8 __user *)src,
171 ret, "b", "b", "=q", 1);
1da177e4 172 if (likely(!ret))
b896313e
JP
173 __put_user_asm(tmp, (u8 __user *)dst,
174 ret, "b", "b", "iq", 1);
1da177e4
LT
175 return ret;
176 }
b896313e 177 case 2: {
1da177e4 178 u16 tmp;
b896313e
JP
179 __get_user_asm(tmp, (u16 __user *)src,
180 ret, "w", "w", "=r", 2);
1da177e4 181 if (likely(!ret))
b896313e
JP
182 __put_user_asm(tmp, (u16 __user *)dst,
183 ret, "w", "w", "ir", 2);
1da177e4
LT
184 return ret;
185 }
186
b896313e 187 case 4: {
1da177e4 188 u32 tmp;
b896313e
JP
189 __get_user_asm(tmp, (u32 __user *)src,
190 ret, "l", "k", "=r", 4);
1da177e4 191 if (likely(!ret))
b896313e
JP
192 __put_user_asm(tmp, (u32 __user *)dst,
193 ret, "l", "k", "ir", 4);
1da177e4
LT
194 return ret;
195 }
b896313e 196 case 8: {
1da177e4 197 u64 tmp;
b896313e
JP
198 __get_user_asm(tmp, (u64 __user *)src,
199 ret, "q", "", "=r", 8);
1da177e4 200 if (likely(!ret))
b896313e 201 __put_user_asm(tmp, (u64 __user *)dst,
155b7352 202 ret, "q", "", "er", 8);
1da177e4
LT
203 return ret;
204 }
205 default:
b896313e
JP
206 return copy_user_generic((__force void *)dst,
207 (__force void *)src, size);
1da177e4 208 }
b896313e 209}
1da177e4 210
b896313e 211__must_check long
95912008 212strncpy_from_user(char *dst, const char __user *src, long count);
b896313e 213__must_check long
95912008
AK
214__strncpy_from_user(char *dst, const char __user *src, long count);
215__must_check long strnlen_user(const char __user *str, long n);
216__must_check long __strnlen_user(const char __user *str, long n);
217__must_check long strlen_user(const char __user *str);
218__must_check unsigned long clear_user(void __user *mem, unsigned long len);
219__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
220
14722485
JB
221static __must_check __always_inline int
222__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
223{
224 return copy_user_generic(dst, (__force const void *)src, size);
225}
b885808e
AK
226
227static __must_check __always_inline int
228__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
229{
230 return copy_user_generic((__force void *)dst, src, size);
231}
1da177e4 232
b896313e
JP
233extern long __copy_user_nocache(void *dst, const void __user *src,
234 unsigned size, int zerorest);
0812a579 235
f1800536
IM
236static inline int
237__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
0812a579
AK
238{
239 might_sleep();
f1800536 240 return __copy_user_nocache(dst, src, size, 1);
0812a579
AK
241}
242
f1800536
IM
243static inline int
244__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
245 unsigned size)
0812a579 246{
f1800536 247 return __copy_user_nocache(dst, src, size, 0);
0812a579
AK
248}
249
1129585a
VM
250unsigned long
251copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
252
1965aae3 253#endif /* _ASM_X86_UACCESS_64_H */