2 * arch/s390/lib/uaccess_mvcos.c
4 * Optimized user space space access functions based on mvcos.
6 * Copyright (C) IBM Corp. 2006
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
8 * Gerald Schaefer (gerald.schaefer@de.ibm.com)
11 #include <linux/errno.h>
13 #include <asm/uaccess.h>
14 #include <asm/futex.h>
31 static size_t copy_from_user_mvcos(size_t size
, const void __user
*ptr
, void *x
)
33 register unsigned long reg0
asm("0") = 0x81UL
;
34 unsigned long tmp1
, tmp2
;
38 "0: .insn ss,0xc80000000000,0(%0,%2),0(%1),0\n"
44 "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
45 " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
47 " "CLR
" %0,%4\n" /* copy crosses next page boundary? */
49 "3: .insn ss,0xc80000000000,0(%4,%2),0(%1),0\n"
53 " "ALR
" %4,%0\n" /* copy remaining size, subtract 1 */
54 " bras %3,6f\n" /* memset loop */
56 "5: xc 0(256,%2),0(%2)\n"
64 EX_TABLE(0b
,2b
) EX_TABLE(3b
,4b
) EX_TABLE(9b
,2b
) EX_TABLE(10b
,4b
)
65 : "+a" (size
), "+a" (ptr
), "+a" (x
), "+a" (tmp1
), "=a" (tmp2
)
66 : "d" (reg0
) : "cc", "memory");
70 static size_t copy_from_user_mvcos_check(size_t size
, const void __user
*ptr
, void *x
)
73 return copy_from_user_std(size
, ptr
, x
);
74 return copy_from_user_mvcos(size
, ptr
, x
);
77 static size_t copy_to_user_mvcos(size_t size
, void __user
*ptr
, const void *x
)
79 register unsigned long reg0
asm("0") = 0x810000UL
;
80 unsigned long tmp1
, tmp2
;
84 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
90 "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
91 " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
93 " "CLR
" %0,%4\n" /* copy crosses next page boundary? */
95 "3: .insn ss,0xc80000000000,0(%4,%1),0(%2),0\n"
100 EX_TABLE(0b
,2b
) EX_TABLE(3b
,5b
) EX_TABLE(6b
,2b
) EX_TABLE(7b
,5b
)
101 : "+a" (size
), "+a" (ptr
), "+a" (x
), "+a" (tmp1
), "=a" (tmp2
)
102 : "d" (reg0
) : "cc", "memory");
106 static size_t copy_to_user_mvcos_check(size_t size
, void __user
*ptr
,
110 return copy_to_user_std(size
, ptr
, x
);
111 return copy_to_user_mvcos(size
, ptr
, x
);
114 static size_t copy_in_user_mvcos(size_t size
, void __user
*to
,
115 const void __user
*from
)
117 register unsigned long reg0
asm("0") = 0x810081UL
;
118 unsigned long tmp1
, tmp2
;
121 /* FIXME: copy with reduced length. */
123 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
132 : "+a" (size
), "+a" (to
), "+a" (from
), "+a" (tmp1
), "=a" (tmp2
)
133 : "d" (reg0
) : "cc", "memory");
137 static size_t clear_user_mvcos(size_t size
, void __user
*to
)
139 register unsigned long reg0
asm("0") = 0x810000UL
;
140 unsigned long tmp1
, tmp2
;
144 "0: .insn ss,0xc80000000000,0(%0,%1),0(%4),0\n"
149 "2: la %3,4095(%1)\n"/* %4 = to + 4095 */
150 " nr %3,%2\n" /* %4 = (to + 4095) & -4096 */
152 " "CLR
" %0,%3\n" /* copy crosses next page boundary? */
154 "3: .insn ss,0xc80000000000,0(%3,%1),0(%4),0\n"
159 EX_TABLE(0b
,2b
) EX_TABLE(3b
,5b
)
160 : "+a" (size
), "+a" (to
), "+a" (tmp1
), "=a" (tmp2
)
161 : "a" (empty_zero_page
), "d" (reg0
) : "cc", "memory");
165 static size_t strnlen_user_mvcos(size_t count
, const char __user
*src
)
169 size_t done
, len
, len_str
;
173 len
= min(count
- done
, (size_t) 256);
174 rc
= uaccess
.copy_from_user(len
, src
+ done
, buf
);
175 if (unlikely(rc
== len
))
178 len_str
= strnlen(buf
, len
);
180 } while ((len_str
== len
) && (done
< count
));
184 static size_t strncpy_from_user_mvcos(size_t count
, const char __user
*src
,
188 size_t done
, len
, len_str
;
192 len
= min(count
- done
, (size_t) 4096);
193 rc
= uaccess
.copy_from_user(len
, src
+ done
, dst
);
194 if (unlikely(rc
== len
))
197 len_str
= strnlen(dst
, len
);
199 } while ((len_str
== len
) && (done
< count
));
203 struct uaccess_ops uaccess_mvcos
= {
204 .copy_from_user
= copy_from_user_mvcos_check
,
205 .copy_from_user_small
= copy_from_user_std
,
206 .copy_to_user
= copy_to_user_mvcos_check
,
207 .copy_to_user_small
= copy_to_user_std
,
208 .copy_in_user
= copy_in_user_mvcos
,
209 .clear_user
= clear_user_mvcos
,
210 .strnlen_user
= strnlen_user_std
,
211 .strncpy_from_user
= strncpy_from_user_std
,
212 .futex_atomic_op
= futex_atomic_op_std
,
213 .futex_atomic_cmpxchg
= futex_atomic_cmpxchg_std
,
216 struct uaccess_ops uaccess_mvcos_switch
= {
217 .copy_from_user
= copy_from_user_mvcos
,
218 .copy_from_user_small
= copy_from_user_mvcos
,
219 .copy_to_user
= copy_to_user_mvcos
,
220 .copy_to_user_small
= copy_to_user_mvcos
,
221 .copy_in_user
= copy_in_user_mvcos
,
222 .clear_user
= clear_user_mvcos
,
223 .strnlen_user
= strnlen_user_mvcos
,
224 .strncpy_from_user
= strncpy_from_user_mvcos
,
225 .futex_atomic_op
= futex_atomic_op_pt
,
226 .futex_atomic_cmpxchg
= futex_atomic_cmpxchg_pt
,