1 // SPDX-License-Identifier: GPL-2.0
3 * Standard user space access functions based on mvcp/mvcs and doing
4 * interesting things in the secondary space mode.
6 * Copyright IBM Corp. 2006,2014
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
8 * Gerald Schaefer (gerald.schaefer@de.ibm.com)
11 #include <linux/uaccess.h>
12 #include <linux/export.h>
14 #include <asm/asm-extable.h>
16 #ifdef CONFIG_DEBUG_ENTRY
17 void debug_user_asce(int exit)
19 unsigned long cr1, cr7;
21 __ctl_store(cr1, 1, 1);
22 __ctl_store(cr7, 7, 7);
23 if (cr1 == S390_lowcore.kernel_asce && cr7 == S390_lowcore.user_asce)
25 panic("incorrect ASCE on kernel %s\n"
26 "cr1: %016lx cr7: %016lx\n"
27 "kernel: %016llx user: %016llx\n",
28 exit ? "exit" : "entry", cr1, cr7,
29 S390_lowcore.kernel_asce, S390_lowcore.user_asce);
32 #endif /*CONFIG_DEBUG_ENTRY */
34 static unsigned long raw_copy_from_user_key(void *to, const void __user *from,
35 unsigned long size, unsigned long key)
37 unsigned long tmp1, tmp2;
40 .oac2.as = PSW_BITS_AS_SECONDARY,
48 "0: mvcos 0(%2),0(%1),%0\n"
54 "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
55 " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
57 " clgr %0,%4\n" /* copy crosses next page boundary? */
59 "3: mvcos 0(%2),0(%1),%4\n"
64 EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
65 : "+a" (size), "+a" (from), "+a" (to), "+a" (tmp1), "=a" (tmp2)
66 : [spec] "d" (spec.val)
67 : "cc", "memory", "0");
71 unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n)
73 return raw_copy_from_user_key(to, from, n, 0);
75 EXPORT_SYMBOL(raw_copy_from_user);
77 unsigned long _copy_from_user_key(void *to, const void __user *from,
78 unsigned long n, unsigned long key)
80 unsigned long res = n;
83 if (!should_fail_usercopy()) {
84 instrument_copy_from_user_before(to, from, n);
85 res = raw_copy_from_user_key(to, from, n, key);
86 instrument_copy_from_user_after(to, from, n, res);
89 memset(to + (n - res), 0, res);
92 EXPORT_SYMBOL(_copy_from_user_key);
94 static unsigned long raw_copy_to_user_key(void __user *to, const void *from,
95 unsigned long size, unsigned long key)
97 unsigned long tmp1, tmp2;
100 .oac1.as = PSW_BITS_AS_SECONDARY,
108 "0: mvcos 0(%1),0(%2),%0\n"
114 "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
115 " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
117 " clgr %0,%4\n" /* copy crosses next page boundary? */
119 "3: mvcos 0(%1),0(%2),%4\n"
124 EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
125 : "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2)
126 : [spec] "d" (spec.val)
127 : "cc", "memory", "0");
131 unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n)
133 return raw_copy_to_user_key(to, from, n, 0);
135 EXPORT_SYMBOL(raw_copy_to_user);
137 unsigned long _copy_to_user_key(void __user *to, const void *from,
138 unsigned long n, unsigned long key)
141 if (should_fail_usercopy())
143 instrument_copy_to_user(to, from, n);
144 return raw_copy_to_user_key(to, from, n, key);
146 EXPORT_SYMBOL(_copy_to_user_key);
148 unsigned long __clear_user(void __user *to, unsigned long size)
150 unsigned long tmp1, tmp2;
152 .oac1.as = PSW_BITS_AS_SECONDARY,
159 "0: mvcos 0(%1),0(%4),%0\n"
164 "2: la %3,4095(%1)\n"/* %4 = to + 4095 */
165 " nr %3,%2\n" /* %4 = (to + 4095) & -4096 */
167 " clgr %0,%3\n" /* copy crosses next page boundary? */
169 "3: mvcos 0(%1),0(%4),%3\n"
174 EX_TABLE(0b,2b) EX_TABLE(6b,2b) EX_TABLE(3b,5b) EX_TABLE(7b,5b)
175 : "+&a" (size), "+&a" (to), "+a" (tmp1), "=&a" (tmp2)
176 : "a" (empty_zero_page), [spec] "d" (spec.val)
177 : "cc", "memory", "0");
180 EXPORT_SYMBOL(__clear_user);