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);
31 #endif /*CONFIG_DEBUG_ENTRY */
33 static unsigned long raw_copy_from_user_key(void *to, const void __user *from,
34 unsigned long size, unsigned long key)
39 .oac2.as = PSW_BITS_AS_SECONDARY,
46 "0: mvcos 0(%[to]),0(%[from]),%[size]\n"
48 " algr %[size],%[val]\n"
49 " slgr %[from],%[val]\n"
50 " slgr %[to],%[val]\n"
52 "2: la %[rem],4095(%[from])\n" /* rem = from + 4095 */
53 " nr %[rem],%[val]\n" /* rem = (from + 4095) & -4096 */
54 " slgr %[rem],%[from]\n"
55 " clgr %[size],%[rem]\n" /* copy crosses next page boundary? */
57 "3: mvcos 0(%[to]),0(%[from]),%[rem]\n"
58 "4: slgr %[size],%[rem]\n"
60 "5: slgr %[size],%[size]\n"
66 : [size] "+&a" (size), [from] "+&a" (from), [to] "+&a" (to), [rem] "=&a" (rem)
67 : [val] "a" (-4096UL), [spec] "d" (spec.val)
68 : "cc", "memory", "0");
72 unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n)
74 return raw_copy_from_user_key(to, from, n, 0);
76 EXPORT_SYMBOL(raw_copy_from_user);
78 unsigned long _copy_from_user_key(void *to, const void __user *from,
79 unsigned long n, unsigned long key)
81 unsigned long res = n;
84 if (!should_fail_usercopy()) {
85 instrument_copy_from_user_before(to, from, n);
86 res = raw_copy_from_user_key(to, from, n, key);
87 instrument_copy_from_user_after(to, from, n, res);
90 memset(to + (n - res), 0, res);
93 EXPORT_SYMBOL(_copy_from_user_key);
95 static unsigned long raw_copy_to_user_key(void __user *to, const void *from,
96 unsigned long size, unsigned long key)
101 .oac1.as = PSW_BITS_AS_SECONDARY,
108 "0: mvcos 0(%[to]),0(%[from]),%[size]\n"
110 " algr %[size],%[val]\n"
111 " slgr %[to],%[val]\n"
112 " slgr %[from],%[val]\n"
114 "2: la %[rem],4095(%[to])\n" /* rem = to + 4095 */
115 " nr %[rem],%[val]\n" /* rem = (to + 4095) & -4096 */
116 " slgr %[rem],%[to]\n"
117 " clgr %[size],%[rem]\n" /* copy crosses next page boundary? */
119 "3: mvcos 0(%[to]),0(%[from]),%[rem]\n"
120 "4: slgr %[size],%[rem]\n"
122 "5: slgr %[size],%[size]\n"
128 : [size] "+&a" (size), [to] "+&a" (to), [from] "+&a" (from), [rem] "=&a" (rem)
129 : [val] "a" (-4096UL), [spec] "d" (spec.val)
130 : "cc", "memory", "0");
134 unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n)
136 return raw_copy_to_user_key(to, from, n, 0);
138 EXPORT_SYMBOL(raw_copy_to_user);
140 unsigned long _copy_to_user_key(void __user *to, const void *from,
141 unsigned long n, unsigned long key)
144 if (should_fail_usercopy())
146 instrument_copy_to_user(to, from, n);
147 return raw_copy_to_user_key(to, from, n, key);
149 EXPORT_SYMBOL(_copy_to_user_key);
151 unsigned long __clear_user(void __user *to, unsigned long size)
155 .oac1.as = PSW_BITS_AS_SECONDARY,
161 "0: mvcos 0(%[to]),0(%[zeropg]),%[size]\n"
163 " algr %[size],%[val]\n"
164 " slgr %[to],%[val]\n"
166 "2: la %[rem],4095(%[to])\n" /* rem = to + 4095 */
167 " nr %[rem],%[val]\n" /* rem = (to + 4095) & -4096 */
168 " slgr %[rem],%[to]\n"
169 " clgr %[size],%[rem]\n" /* copy crosses next page boundary? */
171 "3: mvcos 0(%[to]),0(%[zeropg]),%[rem]\n"
172 "4: slgr %[size],%[rem]\n"
174 "5: slgr %[size],%[size]\n"
180 : [size] "+&a" (size), [to] "+&a" (to), [rem] "=&a" (rem)
181 : [val] "a" (-4096UL), [zeropg] "a" (empty_zero_page), [spec] "d" (spec.val)
182 : "cc", "memory", "0");
185 EXPORT_SYMBOL(__clear_user);