2 * arch/s390/lib/uaccess_std.c
4 * Standard user space access functions based on mvcp/mvcs and doing
5 * interesting things in the secondary space mode.
7 * Copyright (C) IBM Corp. 2006
8 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
9 * Gerald Schaefer (gerald.schaefer@de.ibm.com)
12 #include <linux/errno.h>
14 #include <linux/uaccess.h>
15 #include <asm/futex.h>
31 extern size_t copy_from_user_pt(size_t n, const void __user *from, void *to);
32 extern size_t copy_to_user_pt(size_t n, void __user *to, const void *from);
34 size_t copy_from_user_std(size_t size, const void __user *ptr, void *x)
36 unsigned long tmp1, tmp2;
40 "0: mvcp 0(%0,%2),0(%1),%3\n"
45 "2: mvcp 0(%0,%2),0(%1),%3\n"
48 "3: la %4,255(%1)\n" /* %4 = ptr + 255 */
50 " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */
52 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
54 "4: mvcp 0(%4,%2),0(%1),%3\n"
58 " "ALR" %4,%0\n" /* copy remaining size, subtract 1 */
59 " bras %3,7f\n" /* memset loop */
61 "6: xc 0(256,%2),0(%2)\n"
69 EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,5b)
70 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
75 size_t copy_from_user_std_check(size_t size, const void __user *ptr, void *x)
78 return copy_from_user_std(size, ptr, x);
79 return copy_from_user_pt(size, ptr, x);
82 size_t copy_to_user_std(size_t size, void __user *ptr, const void *x)
84 unsigned long tmp1, tmp2;
88 "0: mvcs 0(%0,%1),0(%2),%3\n"
93 "2: mvcs 0(%0,%1),0(%2),%3\n"
96 "3: la %4,255(%1)\n" /* %4 = ptr + 255 */
98 " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */
100 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
102 "4: mvcs 0(%4,%1),0(%2),%3\n"
107 EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,6b)
108 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
113 size_t copy_to_user_std_check(size_t size, void __user *ptr, const void *x)
116 return copy_to_user_std(size, ptr, x);
117 return copy_to_user_pt(size, ptr, x);
120 size_t copy_in_user_std(size_t size, void __user *to, const void __user *from)
130 "1: mvc 0(1,%1),0(%2)\n"
136 "2: mvc 0(256,%1),0(%2)\n"
141 "4: ex %0,1b-0b(%3)\n"
145 EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b)
146 : "+a" (size), "+a" (to), "+a" (from), "=a" (tmp1)
151 size_t clear_user_std(size_t size, void __user *to)
153 unsigned long tmp1, tmp2;
160 " xc 0(1,%1),0(%1)\n"
162 " la %2,255(%1)\n" /* %2 = ptr + 255 */
164 " sll %2,12\n" /* %2 = (ptr + 255) & -4096 */
166 " "CLR" %0,%2\n" /* clear crosses next page boundary? */
173 "2: xc 0(256,%1),0(%1)\n"
181 EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b)
182 : "+a" (size), "+a" (to), "=a" (tmp1), "=a" (tmp2)
187 size_t strnlen_user_std(size_t size, const char __user *src)
189 register unsigned long reg0 asm("0") = 0UL;
190 unsigned long tmp1, tmp2;
199 " la %0,1(%3)\n" /* strnlen_user results includes \0 */
203 : "+a" (size), "+a" (src), "=a" (tmp1), "=a" (tmp2)
204 : "d" (reg0) : "cc", "memory");
208 size_t strncpy_from_user_std(size_t size, const char __user *src, char *dst)
210 register unsigned long reg0 asm("0") = 0UL;
211 unsigned long tmp1, tmp2;
221 " jh 1f\n" /* found \0 in string ? */
222 " "AHI" %4,1\n" /* include \0 in copy */
223 "1:"SLR" %0,%1\n" /* %0 = return length (without \0) */
224 " "SLR" %4,%1\n" /* %4 = copy length (including \0) */
225 "2: mvcp 0(%4,%2),0(%1),%5\n"
230 "4: mvcp 0(%4,%2),0(%1),%5\n"
236 EX_TABLE(0b,7b) EX_TABLE(2b,8b) EX_TABLE(4b,8b)
237 : "+a" (size), "+a" (src), "+d" (dst), "=a" (tmp1), "=a" (tmp2)
238 : "d" (reg0), "K" (-EFAULT) : "cc", "memory");
242 #define __futex_atomic_op(insn, ret, oldval, newval, uaddr, oparg) \
247 "2: cs %1,%2,0(%6)\n" \
251 EX_TABLE(0b,4b) EX_TABLE(2b,4b) EX_TABLE(3b,4b) \
252 : "=d" (ret), "=&d" (oldval), "=&d" (newval), \
254 : "0" (-EFAULT), "d" (oparg), "a" (uaddr), \
255 "m" (*uaddr) : "cc");
257 int futex_atomic_op(int op, int __user *uaddr, int oparg, int *old)
259 int oldval = 0, newval, ret;
265 __futex_atomic_op("lr %2,%5\n",
266 ret, oldval, newval, uaddr, oparg);
269 __futex_atomic_op("lr %2,%1\nar %2,%5\n",
270 ret, oldval, newval, uaddr, oparg);
273 __futex_atomic_op("lr %2,%1\nor %2,%5\n",
274 ret, oldval, newval, uaddr, oparg);
277 __futex_atomic_op("lr %2,%1\nnr %2,%5\n",
278 ret, oldval, newval, uaddr, oparg);
281 __futex_atomic_op("lr %2,%1\nxr %2,%5\n",
282 ret, oldval, newval, uaddr, oparg);
292 int futex_atomic_cmpxchg(int __user *uaddr, int oldval, int newval)
302 : "=d" (ret), "+d" (oldval), "=m" (*uaddr)
303 : "0" (-EFAULT), "d" (newval), "a" (uaddr), "m" (*uaddr)
308 struct uaccess_ops uaccess_std = {
309 .copy_from_user = copy_from_user_std_check,
310 .copy_from_user_small = copy_from_user_std,
311 .copy_to_user = copy_to_user_std_check,
312 .copy_to_user_small = copy_to_user_std,
313 .copy_in_user = copy_in_user_std,
314 .clear_user = clear_user_std,
315 .strnlen_user = strnlen_user_std,
316 .strncpy_from_user = strncpy_from_user_std,
317 .futex_atomic_op = futex_atomic_op,
318 .futex_atomic_cmpxchg = futex_atomic_cmpxchg,