2 * Standard user space access functions based on mvcp/mvcs and doing
3 * interesting things in the secondary space mode.
5 * Copyright IBM Corp. 2006
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7 * Gerald Schaefer (gerald.schaefer@de.ibm.com)
10 #include <linux/errno.h>
12 #include <linux/uaccess.h>
13 #include <asm/futex.h>
30 size_t copy_from_user_std(size_t size
, const void __user
*ptr
, void *x
)
32 unsigned long tmp1
, tmp2
;
36 "0: mvcp 0(%0,%2),0(%1),%3\n"
41 "2: mvcp 0(%0,%2),0(%1),%3\n"
44 "3: la %4,255(%1)\n" /* %4 = ptr + 255 */
46 " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */
48 " "CLR
" %0,%4\n" /* copy crosses next page boundary? */
50 "4: mvcp 0(%4,%2),0(%1),%3\n"
54 " "ALR
" %4,%0\n" /* copy remaining size, subtract 1 */
55 " bras %3,7f\n" /* memset loop */
57 "6: xc 0(256,%2),0(%2)\n"
65 EX_TABLE(0b
,3b
) EX_TABLE(2b
,3b
) EX_TABLE(4b
,5b
)
66 EX_TABLE(10b
,3b
) EX_TABLE(11b
,3b
) EX_TABLE(12b
,5b
)
67 : "+a" (size
), "+a" (ptr
), "+a" (x
), "+a" (tmp1
), "=a" (tmp2
)
72 static size_t copy_from_user_std_check(size_t size
, const void __user
*ptr
,
76 return copy_from_user_std(size
, ptr
, x
);
77 return copy_from_user_pt(size
, ptr
, x
);
80 size_t copy_to_user_std(size_t size
, void __user
*ptr
, const void *x
)
82 unsigned long tmp1
, tmp2
;
86 "0: mvcs 0(%0,%1),0(%2),%3\n"
91 "2: mvcs 0(%0,%1),0(%2),%3\n"
94 "3: la %4,255(%1)\n" /* %4 = ptr + 255 */
96 " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */
98 " "CLR
" %0,%4\n" /* copy crosses next page boundary? */
100 "4: mvcs 0(%4,%1),0(%2),%3\n"
105 EX_TABLE(0b
,3b
) EX_TABLE(2b
,3b
) EX_TABLE(4b
,6b
)
106 EX_TABLE(7b
,3b
) EX_TABLE(8b
,3b
) EX_TABLE(9b
,6b
)
107 : "+a" (size
), "+a" (ptr
), "+a" (x
), "+a" (tmp1
), "=a" (tmp2
)
112 static size_t copy_to_user_std_check(size_t size
, void __user
*ptr
,
116 return copy_to_user_std(size
, ptr
, x
);
117 return copy_to_user_pt(size
, ptr
, x
);
120 static size_t copy_in_user_std(size_t size
, void __user
*to
,
121 const void __user
*from
)
131 "1: mvc 0(1,%1),0(%2)\n"
137 "2: mvc 0(256,%1),0(%2)\n"
142 "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 static 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"
180 EX_TABLE(1b
,6b
) EX_TABLE(2b
,0b
) EX_TABLE(4b
,0b
)
181 : "+a" (size
), "+a" (to
), "=a" (tmp1
), "=a" (tmp2
)
186 size_t strnlen_user_std(size_t size
, const char __user
*src
)
188 register unsigned long reg0
asm("0") = 0UL;
189 unsigned long tmp1
, tmp2
;
200 " la %0,1(%3)\n" /* strnlen_user results includes \0 */
204 : "+a" (size
), "+a" (src
), "=a" (tmp1
), "=a" (tmp2
)
205 : "d" (reg0
) : "cc", "memory");
209 size_t strncpy_from_user_std(size_t count
, const char __user
*src
, char *dst
)
211 size_t done
, len
, offset
, len_str
;
213 if (unlikely(!count
))
217 offset
= (size_t)src
& ~PAGE_MASK
;
218 len
= min(count
- done
, PAGE_SIZE
- offset
);
219 if (copy_from_user_std(len
, src
, dst
))
221 len_str
= strnlen(dst
, len
);
225 } while ((len_str
== len
) && (done
< count
));
229 #define __futex_atomic_op(insn, ret, oldval, newval, uaddr, oparg) \
234 "2: cs %1,%2,0(%6)\n" \
238 EX_TABLE(0b,4b) EX_TABLE(2b,4b) EX_TABLE(3b,4b) \
239 : "=d" (ret), "=&d" (oldval), "=&d" (newval), \
241 : "0" (-EFAULT), "d" (oparg), "a" (uaddr), \
242 "m" (*uaddr) : "cc");
244 int futex_atomic_op_std(int op
, u32 __user
*uaddr
, int oparg
, int *old
)
246 int oldval
= 0, newval
, ret
;
250 __futex_atomic_op("lr %2,%5\n",
251 ret
, oldval
, newval
, uaddr
, oparg
);
254 __futex_atomic_op("lr %2,%1\nar %2,%5\n",
255 ret
, oldval
, newval
, uaddr
, oparg
);
258 __futex_atomic_op("lr %2,%1\nor %2,%5\n",
259 ret
, oldval
, newval
, uaddr
, oparg
);
262 __futex_atomic_op("lr %2,%1\nnr %2,%5\n",
263 ret
, oldval
, newval
, uaddr
, oparg
);
266 __futex_atomic_op("lr %2,%1\nxr %2,%5\n",
267 ret
, oldval
, newval
, uaddr
, oparg
);
276 int futex_atomic_cmpxchg_std(u32
*uval
, u32 __user
*uaddr
,
277 u32 oldval
, u32 newval
)
283 "0: cs %1,%4,0(%5)\n"
286 EX_TABLE(0b
,2b
) EX_TABLE(1b
,2b
)
287 : "=d" (ret
), "+d" (oldval
), "=m" (*uaddr
)
288 : "0" (-EFAULT
), "d" (newval
), "a" (uaddr
), "m" (*uaddr
)
294 struct uaccess_ops uaccess_std
= {
295 .copy_from_user
= copy_from_user_std_check
,
296 .copy_from_user_small
= copy_from_user_std
,
297 .copy_to_user
= copy_to_user_std_check
,
298 .copy_to_user_small
= copy_to_user_std
,
299 .copy_in_user
= copy_in_user_std
,
300 .clear_user
= clear_user_std
,
301 .strnlen_user
= strnlen_user_std
,
302 .strncpy_from_user
= strncpy_from_user_std
,
303 .futex_atomic_op
= futex_atomic_op_std
,
304 .futex_atomic_cmpxchg
= futex_atomic_cmpxchg_std
,