aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Rothwell <sfr@canb.auug.org.au>2005-10-29 03:51:31 -0400
committerStephen Rothwell <sfr@canb.auug.org.au>2005-10-31 22:34:03 -0500
commit2df5e8bcca53e528a78ee0e3b114d0d21dd6d043 (patch)
tree2234ea07e58a21ff7385dc24ad649ce8ec0273be
parente2f2e58e7968f8446b1078a20a18bf8ea12b4fbc (diff)
powerpc: merge uaccess.h
There is still a bug to be fixed and more merging to be done. Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
-rw-r--r--include/asm-powerpc/uaccess.h504
-rw-r--r--include/asm-ppc/uaccess.h393
-rw-r--r--include/asm-ppc64/uaccess.h341
3 files changed, 504 insertions, 734 deletions
diff --git a/include/asm-powerpc/uaccess.h b/include/asm-powerpc/uaccess.h
new file mode 100644
index 000000000000..2ecc3e16e49e
--- /dev/null
+++ b/include/asm-powerpc/uaccess.h
@@ -0,0 +1,504 @@
1#ifndef _ARCH_POWERPC_UACCESS_H
2#define _ARCH_POWERPC_UACCESS_H
3
4#ifdef __KERNEL__
5#ifndef __ASSEMBLY__
6
7#include <linux/sched.h>
8#include <linux/errno.h>
9#include <asm/processor.h>
10
11#define VERIFY_READ 0
12#define VERIFY_WRITE 1
13
14/*
15 * The fs value determines whether argument validity checking should be
16 * performed or not. If get_fs() == USER_DS, checking is performed, with
17 * get_fs() == KERNEL_DS, checking is bypassed.
18 *
19 * For historical reasons, these macros are grossly misnamed.
20 *
21 * The fs/ds values are now the highest legal address in the "segment".
22 * This simplifies the checking in the routines below.
23 */
24
25#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
26
27#ifdef __powerpc64__
28#define KERNEL_DS MAKE_MM_SEG(0UL)
29#define USER_DS MAKE_MM_SEG(0xf000000000000000UL)
30#else
31#define KERNEL_DS MAKE_MM_SEG(~0UL)
32#define USER_DS MAKE_MM_SEG(TASK_SIZE - 1)
33#endif
34
35#define get_ds() (KERNEL_DS)
36#define get_fs() (current->thread.fs)
37#define set_fs(val) (current->thread.fs = (val))
38
39#define segment_eq(a, b) ((a).seg == (b).seg)
40
41#ifdef __powerpc64__
42/*
43 * Use the alpha trick for checking ranges:
44 *
45 * Is a address valid? This does a straightforward calculation rather
46 * than tests.
47 *
48 * Address valid if:
49 * - "addr" doesn't have any high-bits set
50 * - AND "size" doesn't have any high-bits set
51 * - OR we are in kernel mode.
52 *
53 * We dont have to check for high bits in (addr+size) because the first
54 * two checks force the maximum result to be below the start of the
55 * kernel region.
56 */
57#define __access_ok(addr, size, segment) \
58 (((segment).seg & (addr | size )) == 0)
59
60#else
61
62#define __access_ok(addr, size, segment) \
63 (((addr) <= (segment).seg) && \
64 (((size) == 0) || (((size) - 1) <= ((segment).seg - (addr)))))
65
66#endif
67
68#define access_ok(type, addr, size) \
69 (__chk_user_ptr(addr), \
70 __access_ok((__force unsigned long)(addr), (size), get_fs()))
71
72/*
73 * The exception table consists of pairs of addresses: the first is the
74 * address of an instruction that is allowed to fault, and the second is
75 * the address at which the program should continue. No registers are
76 * modified, so it is entirely up to the continuation code to figure out
77 * what to do.
78 *
79 * All the routines below use bits of fixup code that are out of line
80 * with the main instruction path. This means when everything is well,
81 * we don't even have to jump over them. Further, they do not intrude
82 * on our cache or tlb entries.
83 */
84
85struct exception_table_entry {
86 unsigned long insn;
87 unsigned long fixup;
88};
89
90/*
91 * These are the main single-value transfer routines. They automatically
92 * use the right size if we just have the right pointer type.
93 *
94 * This gets kind of ugly. We want to return _two_ values in "get_user()"
95 * and yet we don't want to do any pointers, because that is too much
96 * of a performance impact. Thus we have a few rather ugly macros here,
97 * and hide all the ugliness from the user.
98 *
99 * The "__xxx" versions of the user access functions are versions that
100 * do not verify the address space, that must have been done previously
101 * with a separate "access_ok()" call (this is used when we do multiple
102 * accesses to the same area of user memory).
103 *
104 * As we use the same address space for kernel and user data on the
105 * PowerPC, we can just do these as direct assignments. (Of course, the
106 * exception handling means that it's no longer "just"...)
107 *
108 * The "user64" versions of the user access functions are versions that
109 * allow access of 64-bit data. The "get_user" functions do not
110 * properly handle 64-bit data because the value gets down cast to a long.
111 * The "put_user" functions already handle 64-bit data properly but we add
112 * "user64" versions for completeness
113 */
114#define get_user(x, ptr) \
115 __get_user_check((x), (ptr), sizeof(*(ptr)))
116#define put_user(x, ptr) \
117 __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
118
119#define __get_user(x, ptr) \
120 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
121#define __put_user(x, ptr) \
122 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
123#ifndef __powerpc64__
124#define __get_user64(x, ptr) \
125 __get_user64_nocheck((x), (ptr), sizeof(*(ptr)))
126#define __put_user64(x, ptr) __put_user(x, ptr)
127#endif
128
129#ifdef __powerpc64__
130#define __get_user_unaligned __get_user
131#define __put_user_unaligned __put_user
132#endif
133
134extern long __put_user_bad(void);
135
136#ifdef __powerpc64__
137#define __EX_TABLE_ALIGN "3"
138#define __EX_TABLE_TYPE "llong"
139#else
140#define __EX_TABLE_ALIGN "2"
141#define __EX_TABLE_TYPE "long"
142#endif
143
144/*
145 * We don't tell gcc that we are accessing memory, but this is OK
146 * because we do not write to any memory gcc knows about, so there
147 * are no aliasing issues.
148 */
149#define __put_user_asm(x, addr, err, op) \
150 __asm__ __volatile__( \
151 "1: " op " %1,0(%2) # put_user\n" \
152 "2:\n" \
153 ".section .fixup,\"ax\"\n" \
154 "3: li %0,%3\n" \
155 " b 2b\n" \
156 ".previous\n" \
157 ".section __ex_table,\"a\"\n" \
158 " .align " __EX_TABLE_ALIGN "\n" \
159 " ."__EX_TABLE_TYPE" 1b,3b\n" \
160 ".previous" \
161 : "=r" (err) \
162 : "r" (x), "b" (addr), "i" (-EFAULT), "0" (err))
163
164#ifndef __powerpc64__
165#define __put_user_asm2(x, addr, err) \
166 __asm__ __volatile__( \
167 "1: stw %1,0(%2)\n" \
168 "2: stw %1+1,4(%2)\n" \
169 "3:\n" \
170 ".section .fixup,\"ax\"\n" \
171 "4: li %0,%3\n" \
172 " b 3b\n" \
173 ".previous\n" \
174 ".section __ex_table,\"a\"\n" \
175 " .align " __EX_TABLE_ALIGN "\n" \
176 " ." __EX_TABLE_TYPE " 1b,4b\n" \
177 " ." __EX_TABLE_TYPE " 2b,4b\n" \
178 ".previous" \
179 : "=r" (err) \
180 : "r" (x), "b" (addr), "i" (-EFAULT), "0" (err))
181#else /* __powerpc64__ */
182#define __put_user_asm2(x, ptr, retval) \
183 __put_user_asm(x, ptr, retval, "std")
184#endif /* __powerpc64__ */
185
186#define __put_user_size(x, ptr, size, retval) \
187do { \
188 retval = 0; \
189 switch (size) { \
190 case 1: __put_user_asm(x, ptr, retval, "stb"); break; \
191 case 2: __put_user_asm(x, ptr, retval, "sth"); break; \
192 case 4: __put_user_asm(x, ptr, retval, "stw"); break; \
193 case 8: __put_user_asm2(x, ptr, retval); break; \
194 default: __put_user_bad(); \
195 } \
196} while (0)
197
198#define __put_user_nocheck(x, ptr, size) \
199({ \
200 long __pu_err; \
201 might_sleep(); \
202 __chk_user_ptr(ptr); \
203 __put_user_size((x), (ptr), (size), __pu_err); \
204 __pu_err; \
205})
206
207#define __put_user_check(x, ptr, size) \
208({ \
209 long __pu_err = -EFAULT; \
210 __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
211 might_sleep(); \
212 if (access_ok(VERIFY_WRITE, __pu_addr, size)) \
213 __put_user_size((x), __pu_addr, (size), __pu_err); \
214 __pu_err; \
215})
216
217extern long __get_user_bad(void);
218
219#define __get_user_asm(x, addr, err, op) \
220 __asm__ __volatile__( \
221 "1: "op" %1,0(%2) # get_user\n" \
222 "2:\n" \
223 ".section .fixup,\"ax\"\n" \
224 "3: li %0,%3\n" \
225 " li %1,0\n" \
226 " b 2b\n" \
227 ".previous\n" \
228 ".section __ex_table,\"a\"\n" \
229 " .align "__EX_TABLE_ALIGN "\n" \
230 " ." __EX_TABLE_TYPE " 1b,3b\n" \
231 ".previous" \
232 : "=r" (err), "=r" (x) \
233 : "b" (addr), "i" (-EFAULT), "0" (err))
234
235#ifndef __powerpc64__
236#define __get_user_asm2(x, addr, err) \
237 __asm__ __volatile__( \
238 "1: lwz %1,0(%2)\n" \
239 "2: lwz %1+1,4(%2)\n" \
240 "3:\n" \
241 ".section .fixup,\"ax\"\n" \
242 "4: li %0,%3\n" \
243 " li %1,0\n" \
244 " li %1+1,0\n" \
245 " b 3b\n" \
246 ".previous\n" \
247 ".section __ex_table,\"a\"\n" \
248 " .align " __EX_TABLE_ALIGN "\n" \
249 " ." __EX_TABLE_TYPE " 1b,4b\n" \
250 " ." __EX_TABLE_TYPE " 2b,4b\n" \
251 ".previous" \
252 : "=r" (err), "=&r" (x) \
253 : "b" (addr), "i" (-EFAULT), "0" (err))
254#else
255#define __get_user_asm2(x, addr, err) \
256 __get_user_asm(x, addr, err, "ld")
257#endif /* __powerpc64__ */
258
259#define __get_user_size(x, ptr, size, retval) \
260do { \
261 retval = 0; \
262 __chk_user_ptr(ptr); \
263 if (size > sizeof(x)) \
264 (x) = __get_user_bad(); \
265 switch (size) { \
266 case 1: __get_user_asm(x, ptr, retval, "lbz"); break; \
267 case 2: __get_user_asm(x, ptr, retval, "lhz"); break; \
268 case 4: __get_user_asm(x, ptr, retval, "lwz"); break; \
269 case 8: __get_user_asm2(x, ptr, retval); break; \
270 default: (x) = __get_user_bad(); \
271 } \
272} while (0)
273
274#define __get_user_nocheck(x, ptr, size) \
275({ \
276 long __gu_err; \
277 unsigned long __gu_val; \
278 __chk_user_ptr(ptr); \
279 might_sleep(); \
280 __get_user_size(__gu_val, (ptr), (size), __gu_err); \
281 (x) = (__typeof__(*(ptr)))__gu_val; \
282 __gu_err; \
283})
284
285#ifndef __powerpc64__
286#define __get_user64_nocheck(x, ptr, size) \
287({ \
288 long __gu_err; \
289 long long __gu_val; \
290 __chk_user_ptr(ptr); \
291 might_sleep(); \
292 __get_user_size(__gu_val, (ptr), (size), __gu_err); \
293 (x) = (__typeof__(*(ptr)))__gu_val; \
294 __gu_err; \
295})
296#endif /* __powerpc64__ */
297
298#define __get_user_check(x, ptr, size) \
299({ \
300 long __gu_err = -EFAULT; \
301 unsigned long __gu_val = 0; \
302 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
303 might_sleep(); \
304 if (access_ok(VERIFY_READ, __gu_addr, (size))) \
305 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
306 (x) = (__typeof__(*(ptr)))__gu_val; \
307 __gu_err; \
308})
309
310/* more complex routines */
311
312extern unsigned long __copy_tofrom_user(void __user *to,
313 const void __user *from, unsigned long size);
314
315#ifndef __powerpc64__
316extern inline unsigned long
317copy_from_user(void *to, const void __user *from, unsigned long n)
318{
319 unsigned long over;
320
321 if (access_ok(VERIFY_READ, from, n))
322 return __copy_tofrom_user((__force void __user *)to, from, n);
323 if ((unsigned long)from < TASK_SIZE) {
324 over = (unsigned long)from + n - TASK_SIZE;
325 return __copy_tofrom_user((__force void __user *)to, from,
326 n - over) + over;
327 }
328 return n;
329}
330
331extern inline unsigned long
332copy_to_user(void __user *to, const void *from, unsigned long n)
333{
334 unsigned long over;
335
336 if (access_ok(VERIFY_WRITE, to, n))
337 return __copy_tofrom_user(to, (__force void __user *)from, n);
338 if ((unsigned long)to < TASK_SIZE) {
339 over = (unsigned long)to + n - TASK_SIZE;
340 return __copy_tofrom_user(to, (__force void __user *)from,
341 n - over) + over;
342 }
343 return n;
344}
345
346#else /* __powerpc64__ */
347
348static inline unsigned long
349__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
350{
351 if (__builtin_constant_p(n) && (n <= 8)) {
352 unsigned long ret;
353
354 switch (n) {
355 case 1:
356 __get_user_size(*(u8 *)to, from, 1, ret);
357 break;
358 case 2:
359 __get_user_size(*(u16 *)to, from, 2, ret);
360 break;
361 case 4:
362 __get_user_size(*(u32 *)to, from, 4, ret);
363 break;
364 case 8:
365 __get_user_size(*(u64 *)to, from, 8, ret);
366 break;
367 }
368 return (ret == -EFAULT) ? n : 0;
369 }
370 return __copy_tofrom_user((__force void __user *) to, from, n);
371}
372
373static inline unsigned long
374__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
375{
376 if (__builtin_constant_p(n) && (n <= 8)) {
377 unsigned long ret;
378
379 switch (n) {
380 case 1:
381 __put_user_size(*(u8 *)from, (u8 __user *)to, 1, ret);
382 break;
383 case 2:
384 __put_user_size(*(u16 *)from, (u16 __user *)to, 2, ret);
385 break;
386 case 4:
387 __put_user_size(*(u32 *)from, (u32 __user *)to, 4, ret);
388 break;
389 case 8:
390 __put_user_size(*(u64 *)from, (u64 __user *)to, 8, ret);
391 break;
392 }
393 return (ret == -EFAULT) ? n : 0;
394 }
395 return __copy_tofrom_user(to, (__force const void __user *) from, n);
396}
397
398#endif /* __powerpc64__ */
399
400static inline unsigned long
401__copy_from_user(void *to, const void __user *from, unsigned long size)
402{
403 might_sleep();
404#ifndef __powerpc64__
405 return __copy_tofrom_user((__force void __user *)to, from, size);
406#else /* __powerpc64__ */
407 return __copy_from_user_inatomic(to, from, size);
408#endif /* __powerpc64__ */
409}
410
411static inline unsigned long
412__copy_to_user(void __user *to, const void *from, unsigned long size)
413{
414 might_sleep();
415#ifndef __powerpc64__
416 return __copy_tofrom_user(to, (__force void __user *)from, size);
417#else /* __powerpc64__ */
418 return __copy_to_user_inatomic(to, from, size);
419#endif /* __powerpc64__ */
420}
421
422#ifndef __powerpc64__
423#define __copy_to_user_inatomic __copy_to_user
424#define __copy_from_user_inatomic __copy_from_user
425#else /* __powerpc64__ */
426#define __copy_in_user(to, from, size) \
427 __copy_tofrom_user((to), (from), (size))
428
429extern unsigned long copy_from_user(void *to, const void __user *from,
430 unsigned long n);
431extern unsigned long copy_to_user(void __user *to, const void *from,
432 unsigned long n);
433extern unsigned long copy_in_user(void __user *to, const void __user *from,
434 unsigned long n);
435#endif /* __powerpc64__ */
436
437extern unsigned long __clear_user(void __user *addr, unsigned long size);
438
439static inline unsigned long clear_user(void __user *addr, unsigned long size)
440{
441 might_sleep();
442 if (likely(access_ok(VERIFY_WRITE, addr, size)))
443 return __clear_user(addr, size);
444#ifndef __powerpc64__
445 if ((unsigned long)addr < TASK_SIZE) {
446 unsigned long over = (unsigned long)addr + size - TASK_SIZE;
447 return __clear_user(addr, size - over) + over;
448 }
449#endif /* __powerpc64__ */
450 return size;
451}
452
453extern int __strncpy_from_user(char *dst, const char __user *src, long count);
454
455static inline long strncpy_from_user(char *dst, const char __user *src,
456 long count)
457{
458 might_sleep();
459 if (likely(access_ok(VERIFY_READ, src, 1)))
460 return __strncpy_from_user(dst, src, count);
461 return -EFAULT;
462}
463
464/*
465 * Return the size of a string (including the ending 0)
466 *
467 * Return 0 for error
468 */
469#ifndef __powerpc64__
470extern int __strnlen_user(const char __user *str, long len, unsigned long top);
471#else /* __powerpc64__ */
472extern int __strnlen_user(const char __user *str, long len);
473#endif /* __powerpc64__ */
474
475/*
476 * Returns the length of the string at str (including the null byte),
477 * or 0 if we hit a page we can't access,
478 * or something > len if we didn't find a null byte.
479 *
480 * The `top' parameter to __strnlen_user is to make sure that
481 * we can never overflow from the user area into kernel space.
482 */
483static inline int strnlen_user(const char __user *str, long len)
484{
485#ifndef __powerpc64__
486 unsigned long top = current->thread.fs.seg;
487
488 if ((unsigned long)str > top)
489 return 0;
490 return __strnlen_user(str, len, top);
491#else /* __powerpc64__ */
492 might_sleep();
493 if (likely(access_ok(VERIFY_READ, str, 1)))
494 return __strnlen_user(str, len);
495 return 0;
496#endif /* __powerpc64__ */
497}
498
499#define strlen_user(str) strnlen_user((str), 0x7ffffffe)
500
501#endif /* __ASSEMBLY__ */
502#endif /* __KERNEL__ */
503
504#endif /* _ARCH_POWERPC_UACCESS_H */
diff --git a/include/asm-ppc/uaccess.h b/include/asm-ppc/uaccess.h
deleted file mode 100644
index 63f56224da8c..000000000000
--- a/include/asm-ppc/uaccess.h
+++ /dev/null
@@ -1,393 +0,0 @@
1#ifdef __KERNEL__
2#ifndef _PPC_UACCESS_H
3#define _PPC_UACCESS_H
4
5#ifndef __ASSEMBLY__
6#include <linux/sched.h>
7#include <linux/errno.h>
8#include <asm/processor.h>
9
10#define VERIFY_READ 0
11#define VERIFY_WRITE 1
12
13/*
14 * The fs value determines whether argument validity checking should be
15 * performed or not. If get_fs() == USER_DS, checking is performed, with
16 * get_fs() == KERNEL_DS, checking is bypassed.
17 *
18 * For historical reasons, these macros are grossly misnamed.
19 *
20 * The fs/ds values are now the highest legal address in the "segment".
21 * This simplifies the checking in the routines below.
22 */
23
24#define KERNEL_DS ((mm_segment_t) { ~0UL })
25#define USER_DS ((mm_segment_t) { TASK_SIZE - 1 })
26
27#define get_ds() (KERNEL_DS)
28#define get_fs() (current->thread.fs)
29#define set_fs(val) (current->thread.fs = (val))
30
31#define segment_eq(a,b) ((a).seg == (b).seg)
32
33#define __access_ok(addr,size) \
34 ((addr) <= current->thread.fs.seg \
35 && ((size) == 0 || (size) - 1 <= current->thread.fs.seg - (addr)))
36
37#define access_ok(type, addr, size) \
38 (__chk_user_ptr(addr),__access_ok((unsigned long)(addr),(size)))
39
40/*
41 * The exception table consists of pairs of addresses: the first is the
42 * address of an instruction that is allowed to fault, and the second is
43 * the address at which the program should continue. No registers are
44 * modified, so it is entirely up to the continuation code to figure out
45 * what to do.
46 *
47 * All the routines below use bits of fixup code that are out of line
48 * with the main instruction path. This means when everything is well,
49 * we don't even have to jump over them. Further, they do not intrude
50 * on our cache or tlb entries.
51 */
52
53struct exception_table_entry
54{
55 unsigned long insn, fixup;
56};
57
58/*
59 * These are the main single-value transfer routines. They automatically
60 * use the right size if we just have the right pointer type.
61 *
62 * This gets kind of ugly. We want to return _two_ values in "get_user()"
63 * and yet we don't want to do any pointers, because that is too much
64 * of a performance impact. Thus we have a few rather ugly macros here,
65 * and hide all the ugliness from the user.
66 *
67 * The "__xxx" versions of the user access functions are versions that
68 * do not verify the address space, that must have been done previously
69 * with a separate "access_ok()" call (this is used when we do multiple
70 * accesses to the same area of user memory).
71 *
72 * As we use the same address space for kernel and user data on the
73 * PowerPC, we can just do these as direct assignments. (Of course, the
74 * exception handling means that it's no longer "just"...)
75 *
76 * The "user64" versions of the user access functions are versions that
77 * allow access of 64-bit data. The "get_user" functions do not
78 * properly handle 64-bit data because the value gets down cast to a long.
79 * The "put_user" functions already handle 64-bit data properly but we add
80 * "user64" versions for completeness
81 */
82#define get_user(x,ptr) \
83 __get_user_check((x),(ptr),sizeof(*(ptr)))
84#define get_user64(x,ptr) \
85 __get_user64_check((x),(ptr),sizeof(*(ptr)))
86#define put_user(x,ptr) \
87 __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
88#define put_user64(x,ptr) put_user(x,ptr)
89
90#define __get_user(x,ptr) \
91 __get_user_nocheck((x),(ptr),sizeof(*(ptr)))
92#define __get_user64(x,ptr) \
93 __get_user64_nocheck((x),(ptr),sizeof(*(ptr)))
94#define __put_user(x,ptr) \
95 __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
96#define __put_user64(x,ptr) __put_user(x,ptr)
97
98extern long __put_user_bad(void);
99
100#define __put_user_nocheck(x,ptr,size) \
101({ \
102 long __pu_err; \
103 __chk_user_ptr(ptr); \
104 __put_user_size((x),(ptr),(size),__pu_err); \
105 __pu_err; \
106})
107
108#define __put_user_check(x,ptr,size) \
109({ \
110 long __pu_err = -EFAULT; \
111 __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
112 if (access_ok(VERIFY_WRITE,__pu_addr,size)) \
113 __put_user_size((x),__pu_addr,(size),__pu_err); \
114 __pu_err; \
115})
116
117#define __put_user_size(x,ptr,size,retval) \
118do { \
119 retval = 0; \
120 switch (size) { \
121 case 1: \
122 __put_user_asm(x, ptr, retval, "stb"); \
123 break; \
124 case 2: \
125 __put_user_asm(x, ptr, retval, "sth"); \
126 break; \
127 case 4: \
128 __put_user_asm(x, ptr, retval, "stw"); \
129 break; \
130 case 8: \
131 __put_user_asm2(x, ptr, retval); \
132 break; \
133 default: \
134 __put_user_bad(); \
135 } \
136} while (0)
137
138/*
139 * We don't tell gcc that we are accessing memory, but this is OK
140 * because we do not write to any memory gcc knows about, so there
141 * are no aliasing issues.
142 */
143#define __put_user_asm(x, addr, err, op) \
144 __asm__ __volatile__( \
145 "1: "op" %1,0(%2)\n" \
146 "2:\n" \
147 ".section .fixup,\"ax\"\n" \
148 "3: li %0,%3\n" \
149 " b 2b\n" \
150 ".previous\n" \
151 ".section __ex_table,\"a\"\n" \
152 " .align 2\n" \
153 " .long 1b,3b\n" \
154 ".previous" \
155 : "=r" (err) \
156 : "r" (x), "b" (addr), "i" (-EFAULT), "0" (err))
157
158#define __put_user_asm2(x, addr, err) \
159 __asm__ __volatile__( \
160 "1: stw %1,0(%2)\n" \
161 "2: stw %1+1,4(%2)\n" \
162 "3:\n" \
163 ".section .fixup,\"ax\"\n" \
164 "4: li %0,%3\n" \
165 " b 3b\n" \
166 ".previous\n" \
167 ".section __ex_table,\"a\"\n" \
168 " .align 2\n" \
169 " .long 1b,4b\n" \
170 " .long 2b,4b\n" \
171 ".previous" \
172 : "=r" (err) \
173 : "r" (x), "b" (addr), "i" (-EFAULT), "0" (err))
174
175#define __get_user_nocheck(x, ptr, size) \
176({ \
177 long __gu_err; \
178 unsigned long __gu_val; \
179 __chk_user_ptr(ptr); \
180 __get_user_size(__gu_val, (ptr), (size), __gu_err); \
181 (x) = (__typeof__(*(ptr)))__gu_val; \
182 __gu_err; \
183})
184
185#define __get_user64_nocheck(x, ptr, size) \
186({ \
187 long __gu_err; \
188 long long __gu_val; \
189 __chk_user_ptr(ptr); \
190 __get_user_size64(__gu_val, (ptr), (size), __gu_err); \
191 (x) = (__typeof__(*(ptr)))__gu_val; \
192 __gu_err; \
193})
194
195#define __get_user_check(x, ptr, size) \
196({ \
197 long __gu_err = -EFAULT; \
198 unsigned long __gu_val = 0; \
199 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
200 if (access_ok(VERIFY_READ, __gu_addr, (size))) \
201 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
202 (x) = (__typeof__(*(ptr)))__gu_val; \
203 __gu_err; \
204})
205
206#define __get_user64_check(x, ptr, size) \
207({ \
208 long __gu_err = -EFAULT; \
209 long long __gu_val = 0; \
210 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
211 if (access_ok(VERIFY_READ, __gu_addr, (size))) \
212 __get_user_size64(__gu_val, __gu_addr, (size), __gu_err); \
213 (x) = (__typeof__(*(ptr)))__gu_val; \
214 __gu_err; \
215})
216
217extern long __get_user_bad(void);
218
219#define __get_user_size(x, ptr, size, retval) \
220do { \
221 retval = 0; \
222 switch (size) { \
223 case 1: \
224 __get_user_asm(x, ptr, retval, "lbz"); \
225 break; \
226 case 2: \
227 __get_user_asm(x, ptr, retval, "lhz"); \
228 break; \
229 case 4: \
230 __get_user_asm(x, ptr, retval, "lwz"); \
231 break; \
232 default: \
233 x = __get_user_bad(); \
234 } \
235} while (0)
236
237#define __get_user_size64(x, ptr, size, retval) \
238do { \
239 retval = 0; \
240 switch (size) { \
241 case 1: \
242 __get_user_asm(x, ptr, retval, "lbz"); \
243 break; \
244 case 2: \
245 __get_user_asm(x, ptr, retval, "lhz"); \
246 break; \
247 case 4: \
248 __get_user_asm(x, ptr, retval, "lwz"); \
249 break; \
250 case 8: \
251 __get_user_asm2(x, ptr, retval); \
252 break; \
253 default: \
254 x = __get_user_bad(); \
255 } \
256} while (0)
257
258#define __get_user_asm(x, addr, err, op) \
259 __asm__ __volatile__( \
260 "1: "op" %1,0(%2)\n" \
261 "2:\n" \
262 ".section .fixup,\"ax\"\n" \
263 "3: li %0,%3\n" \
264 " li %1,0\n" \
265 " b 2b\n" \
266 ".previous\n" \
267 ".section __ex_table,\"a\"\n" \
268 " .align 2\n" \
269 " .long 1b,3b\n" \
270 ".previous" \
271 : "=r"(err), "=r"(x) \
272 : "b"(addr), "i"(-EFAULT), "0"(err))
273
274#define __get_user_asm2(x, addr, err) \
275 __asm__ __volatile__( \
276 "1: lwz %1,0(%2)\n" \
277 "2: lwz %1+1,4(%2)\n" \
278 "3:\n" \
279 ".section .fixup,\"ax\"\n" \
280 "4: li %0,%3\n" \
281 " li %1,0\n" \
282 " li %1+1,0\n" \
283 " b 3b\n" \
284 ".previous\n" \
285 ".section __ex_table,\"a\"\n" \
286 " .align 2\n" \
287 " .long 1b,4b\n" \
288 " .long 2b,4b\n" \
289 ".previous" \
290 : "=r"(err), "=&r"(x) \
291 : "b"(addr), "i"(-EFAULT), "0"(err))
292
293/* more complex routines */
294
295extern int __copy_tofrom_user(void __user *to, const void __user *from,
296 unsigned long size);
297
298extern inline unsigned long
299copy_from_user(void *to, const void __user *from, unsigned long n)
300{
301 unsigned long over;
302
303 if (access_ok(VERIFY_READ, from, n))
304 return __copy_tofrom_user((__force void __user *)to, from, n);
305 if ((unsigned long)from < TASK_SIZE) {
306 over = (unsigned long)from + n - TASK_SIZE;
307 return __copy_tofrom_user((__force void __user *)to, from, n - over) + over;
308 }
309 return n;
310}
311
312extern inline unsigned long
313copy_to_user(void __user *to, const void *from, unsigned long n)
314{
315 unsigned long over;
316
317 if (access_ok(VERIFY_WRITE, to, n))
318 return __copy_tofrom_user(to, (__force void __user *) from, n);
319 if ((unsigned long)to < TASK_SIZE) {
320 over = (unsigned long)to + n - TASK_SIZE;
321 return __copy_tofrom_user(to, (__force void __user *) from, n - over) + over;
322 }
323 return n;
324}
325
326static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long size)
327{
328 return __copy_tofrom_user((__force void __user *)to, from, size);
329}
330
331static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long size)
332{
333 return __copy_tofrom_user(to, (__force void __user *)from, size);
334}
335
336#define __copy_to_user_inatomic __copy_to_user
337#define __copy_from_user_inatomic __copy_from_user
338
339extern unsigned long __clear_user(void __user *addr, unsigned long size);
340
341extern inline unsigned long
342clear_user(void __user *addr, unsigned long size)
343{
344 if (access_ok(VERIFY_WRITE, addr, size))
345 return __clear_user(addr, size);
346 if ((unsigned long)addr < TASK_SIZE) {
347 unsigned long over = (unsigned long)addr + size - TASK_SIZE;
348 return __clear_user(addr, size - over) + over;
349 }
350 return size;
351}
352
353extern int __strncpy_from_user(char *dst, const char __user *src, long count);
354
355extern inline long
356strncpy_from_user(char *dst, const char __user *src, long count)
357{
358 if (access_ok(VERIFY_READ, src, 1))
359 return __strncpy_from_user(dst, src, count);
360 return -EFAULT;
361}
362
363/*
364 * Return the size of a string (including the ending 0)
365 *
366 * Return 0 for error
367 */
368
369extern int __strnlen_user(const char __user *str, long len, unsigned long top);
370
371/*
372 * Returns the length of the string at str (including the null byte),
373 * or 0 if we hit a page we can't access,
374 * or something > len if we didn't find a null byte.
375 *
376 * The `top' parameter to __strnlen_user is to make sure that
377 * we can never overflow from the user area into kernel space.
378 */
379extern __inline__ int strnlen_user(const char __user *str, long len)
380{
381 unsigned long top = current->thread.fs.seg;
382
383 if ((unsigned long)str > top)
384 return 0;
385 return __strnlen_user(str, len, top);
386}
387
388#define strlen_user(str) strnlen_user((str), 0x7ffffffe)
389
390#endif /* __ASSEMBLY__ */
391
392#endif /* _PPC_UACCESS_H */
393#endif /* __KERNEL__ */
diff --git a/include/asm-ppc64/uaccess.h b/include/asm-ppc64/uaccess.h
deleted file mode 100644
index 132c1276547b..000000000000
--- a/include/asm-ppc64/uaccess.h
+++ /dev/null
@@ -1,341 +0,0 @@
1#ifndef _PPC64_UACCESS_H
2#define _PPC64_UACCESS_H
3
4/*
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
9 */
10
11#ifndef __ASSEMBLY__
12#include <linux/sched.h>
13#include <linux/errno.h>
14#include <asm/processor.h>
15
16#define VERIFY_READ 0
17#define VERIFY_WRITE 1
18
19/*
20 * The fs value determines whether argument validity checking should be
21 * performed or not. If get_fs() == USER_DS, checking is performed, with
22 * get_fs() == KERNEL_DS, checking is bypassed.
23 *
24 * For historical reasons, these macros are grossly misnamed.
25 */
26
27#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
28
29#define KERNEL_DS MAKE_MM_SEG(0UL)
30#define USER_DS MAKE_MM_SEG(0xf000000000000000UL)
31
32#define get_ds() (KERNEL_DS)
33#define get_fs() (current->thread.fs)
34#define set_fs(val) (current->thread.fs = (val))
35
36#define segment_eq(a,b) ((a).seg == (b).seg)
37
38/*
39 * Use the alpha trick for checking ranges:
40 *
41 * Is a address valid? This does a straightforward calculation rather
42 * than tests.
43 *
44 * Address valid if:
45 * - "addr" doesn't have any high-bits set
46 * - AND "size" doesn't have any high-bits set
47 * - OR we are in kernel mode.
48 *
49 * We dont have to check for high bits in (addr+size) because the first
50 * two checks force the maximum result to be below the start of the
51 * kernel region.
52 */
53#define __access_ok(addr,size,segment) \
54 (((segment).seg & (addr | size )) == 0)
55
56#define access_ok(type,addr,size) \
57 __access_ok(((__force unsigned long)(addr)),(size),get_fs())
58
59/*
60 * The exception table consists of pairs of addresses: the first is the
61 * address of an instruction that is allowed to fault, and the second is
62 * the address at which the program should continue. No registers are
63 * modified, so it is entirely up to the continuation code to figure out
64 * what to do.
65 *
66 * All the routines below use bits of fixup code that are out of line
67 * with the main instruction path. This means when everything is well,
68 * we don't even have to jump over them. Further, they do not intrude
69 * on our cache or tlb entries.
70 */
71
72struct exception_table_entry
73{
74 unsigned long insn, fixup;
75};
76
77/* Returns 0 if exception not found and fixup otherwise. */
78extern unsigned long search_exception_table(unsigned long);
79
80/*
81 * These are the main single-value transfer routines. They automatically
82 * use the right size if we just have the right pointer type.
83 *
84 * This gets kind of ugly. We want to return _two_ values in "get_user()"
85 * and yet we don't want to do any pointers, because that is too much
86 * of a performance impact. Thus we have a few rather ugly macros here,
87 * and hide all the ugliness from the user.
88 *
89 * The "__xxx" versions of the user access functions are versions that
90 * do not verify the address space, that must have been done previously
91 * with a separate "access_ok()" call (this is used when we do multiple
92 * accesses to the same area of user memory).
93 *
94 * As we use the same address space for kernel and user data on the
95 * PowerPC, we can just do these as direct assignments. (Of course, the
96 * exception handling means that it's no longer "just"...)
97 */
98#define get_user(x,ptr) \
99 __get_user_check((x),(ptr),sizeof(*(ptr)))
100#define put_user(x,ptr) \
101 __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
102
103#define __get_user(x,ptr) \
104 __get_user_nocheck((x),(ptr),sizeof(*(ptr)))
105#define __put_user(x,ptr) \
106 __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
107
108#define __get_user_unaligned __get_user
109#define __put_user_unaligned __put_user
110
111extern long __put_user_bad(void);
112
113#define __put_user_nocheck(x,ptr,size) \
114({ \
115 long __pu_err; \
116 might_sleep(); \
117 __chk_user_ptr(ptr); \
118 __put_user_size((x),(ptr),(size),__pu_err,-EFAULT); \
119 __pu_err; \
120})
121
122#define __put_user_check(x,ptr,size) \
123({ \
124 long __pu_err = -EFAULT; \
125 void __user *__pu_addr = (ptr); \
126 might_sleep(); \
127 if (access_ok(VERIFY_WRITE,__pu_addr,size)) \
128 __put_user_size((x),__pu_addr,(size),__pu_err,-EFAULT); \
129 __pu_err; \
130})
131
132#define __put_user_size(x,ptr,size,retval,errret) \
133do { \
134 retval = 0; \
135 switch (size) { \
136 case 1: __put_user_asm(x,ptr,retval,"stb",errret); break; \
137 case 2: __put_user_asm(x,ptr,retval,"sth",errret); break; \
138 case 4: __put_user_asm(x,ptr,retval,"stw",errret); break; \
139 case 8: __put_user_asm(x,ptr,retval,"std",errret); break; \
140 default: __put_user_bad(); \
141 } \
142} while (0)
143
144/*
145 * We don't tell gcc that we are accessing memory, but this is OK
146 * because we do not write to any memory gcc knows about, so there
147 * are no aliasing issues.
148 */
149#define __put_user_asm(x, addr, err, op, errret) \
150 __asm__ __volatile__( \
151 "1: "op" %1,0(%2) # put_user\n" \
152 "2:\n" \
153 ".section .fixup,\"ax\"\n" \
154 "3: li %0,%3\n" \
155 " b 2b\n" \
156 ".previous\n" \
157 ".section __ex_table,\"a\"\n" \
158 " .align 3\n" \
159 " .llong 1b,3b\n" \
160 ".previous" \
161 : "=r"(err) \
162 : "r"(x), "b"(addr), "i"(errret), "0"(err))
163
164
165#define __get_user_nocheck(x,ptr,size) \
166({ \
167 long __gu_err; \
168 unsigned long __gu_val; \
169 might_sleep(); \
170 __get_user_size(__gu_val,(ptr),(size),__gu_err,-EFAULT);\
171 (x) = (__typeof__(*(ptr)))__gu_val; \
172 __gu_err; \
173})
174
175#define __get_user_check(x,ptr,size) \
176({ \
177 long __gu_err = -EFAULT; \
178 unsigned long __gu_val = 0; \
179 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
180 might_sleep(); \
181 if (access_ok(VERIFY_READ,__gu_addr,size)) \
182 __get_user_size(__gu_val,__gu_addr,(size),__gu_err,-EFAULT);\
183 (x) = (__typeof__(*(ptr)))__gu_val; \
184 __gu_err; \
185})
186
187extern long __get_user_bad(void);
188
189#define __get_user_size(x,ptr,size,retval,errret) \
190do { \
191 retval = 0; \
192 __chk_user_ptr(ptr); \
193 switch (size) { \
194 case 1: __get_user_asm(x,ptr,retval,"lbz",errret); break; \
195 case 2: __get_user_asm(x,ptr,retval,"lhz",errret); break; \
196 case 4: __get_user_asm(x,ptr,retval,"lwz",errret); break; \
197 case 8: __get_user_asm(x,ptr,retval,"ld",errret); break; \
198 default: (x) = __get_user_bad(); \
199 } \
200} while (0)
201
202#define __get_user_asm(x, addr, err, op, errret) \
203 __asm__ __volatile__( \
204 "1: "op" %1,0(%2) # get_user\n" \
205 "2:\n" \
206 ".section .fixup,\"ax\"\n" \
207 "3: li %0,%3\n" \
208 " li %1,0\n" \
209 " b 2b\n" \
210 ".previous\n" \
211 ".section __ex_table,\"a\"\n" \
212 " .align 3\n" \
213 " .llong 1b,3b\n" \
214 ".previous" \
215 : "=r"(err), "=r"(x) \
216 : "b"(addr), "i"(errret), "0"(err))
217
218/* more complex routines */
219
220extern unsigned long __copy_tofrom_user(void __user *to, const void __user *from,
221 unsigned long size);
222
223static inline unsigned long
224__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
225{
226 if (__builtin_constant_p(n)) {
227 unsigned long ret;
228
229 switch (n) {
230 case 1:
231 __get_user_size(*(u8 *)to, from, 1, ret, 1);
232 return ret;
233 case 2:
234 __get_user_size(*(u16 *)to, from, 2, ret, 2);
235 return ret;
236 case 4:
237 __get_user_size(*(u32 *)to, from, 4, ret, 4);
238 return ret;
239 case 8:
240 __get_user_size(*(u64 *)to, from, 8, ret, 8);
241 return ret;
242 }
243 }
244 return __copy_tofrom_user((__force void __user *) to, from, n);
245}
246
247static inline unsigned long
248__copy_from_user(void *to, const void __user *from, unsigned long n)
249{
250 might_sleep();
251 return __copy_from_user_inatomic(to, from, n);
252}
253
254static inline unsigned long
255__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
256{
257 if (__builtin_constant_p(n)) {
258 unsigned long ret;
259
260 switch (n) {
261 case 1:
262 __put_user_size(*(u8 *)from, (u8 __user *)to, 1, ret, 1);
263 return ret;
264 case 2:
265 __put_user_size(*(u16 *)from, (u16 __user *)to, 2, ret, 2);
266 return ret;
267 case 4:
268 __put_user_size(*(u32 *)from, (u32 __user *)to, 4, ret, 4);
269 return ret;
270 case 8:
271 __put_user_size(*(u64 *)from, (u64 __user *)to, 8, ret, 8);
272 return ret;
273 }
274 }
275 return __copy_tofrom_user(to, (__force const void __user *) from, n);
276}
277
278static inline unsigned long
279__copy_to_user(void __user *to, const void *from, unsigned long n)
280{
281 might_sleep();
282 return __copy_to_user_inatomic(to, from, n);
283}
284
285#define __copy_in_user(to, from, size) \
286 __copy_tofrom_user((to), (from), (size))
287
288extern unsigned long copy_from_user(void *to, const void __user *from,
289 unsigned long n);
290extern unsigned long copy_to_user(void __user *to, const void *from,
291 unsigned long n);
292extern unsigned long copy_in_user(void __user *to, const void __user *from,
293 unsigned long n);
294
295extern unsigned long __clear_user(void __user *addr, unsigned long size);
296
297static inline unsigned long
298clear_user(void __user *addr, unsigned long size)
299{
300 might_sleep();
301 if (likely(access_ok(VERIFY_WRITE, addr, size)))
302 size = __clear_user(addr, size);
303 return size;
304}
305
306extern int __strncpy_from_user(char *dst, const char __user *src, long count);
307
308static inline long
309strncpy_from_user(char *dst, const char __user *src, long count)
310{
311 might_sleep();
312 if (likely(access_ok(VERIFY_READ, src, 1)))
313 return __strncpy_from_user(dst, src, count);
314 return -EFAULT;
315}
316
317/*
318 * Return the size of a string (including the ending 0)
319 *
320 * Return 0 for error
321 */
322extern int __strnlen_user(const char __user *str, long len);
323
324/*
325 * Returns the length of the string at str (including the null byte),
326 * or 0 if we hit a page we can't access,
327 * or something > len if we didn't find a null byte.
328 */
329static inline int strnlen_user(const char __user *str, long len)
330{
331 might_sleep();
332 if (likely(access_ok(VERIFY_READ, str, 1)))
333 return __strnlen_user(str, len);
334 return 0;
335}
336
337#define strlen_user(str) strnlen_user((str), 0x7ffffffe)
338
339#endif /* __ASSEMBLY__ */
340
341#endif /* _PPC64_UACCESS_H */