]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - arch/s390/include/asm/uaccess.h
Merge branch 'efi-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-focal-kernel.git] / arch / s390 / include / asm / uaccess.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4 2/*
1da177e4 3 * S390 version
a53c8fab 4 * Copyright IBM Corp. 1999, 2000
1da177e4
LT
5 * Author(s): Hartmut Penner (hp@de.ibm.com),
6 * Martin Schwidefsky (schwidefsky@de.ibm.com)
7 *
8 * Derived from "include/asm-i386/uaccess.h"
9 */
10#ifndef __S390_UACCESS_H
11#define __S390_UACCESS_H
12
13/*
14 * User space memory access functions
15 */
b5a882fc 16#include <asm/processor.h>
a0616cde 17#include <asm/ctl_reg.h>
e70f1d59 18#include <asm/extable.h>
0aaba41b 19#include <asm/facility.h>
1da177e4
LT
20
21/*
22 * The fs value determines whether argument validity checking should be
23 * performed or not. If get_fs() == USER_DS, checking is performed, with
24 * get_fs() == KERNEL_DS, checking is bypassed.
25 *
26 * For historical reasons, these macros are grossly misnamed.
27 */
28
0aaba41b
MS
29#define KERNEL_DS (0)
30#define KERNEL_DS_SACF (1)
31#define USER_DS (2)
32#define USER_DS_SACF (3)
1da177e4 33
1da177e4 34#define get_fs() (current->thread.mm_segment)
0aaba41b 35#define segment_eq(a,b) (((a) & 2) == ((b) & 2))
1da177e4 36
0aaba41b 37void set_fs(mm_segment_t fs);
b5a882fc 38
491af990
HC
39static inline int __range_ok(unsigned long addr, unsigned long size)
40{
41 return 1;
42}
43
44#define __access_ok(addr, size) \
45({ \
46 __chk_user_ptr(addr); \
47 __range_ok((unsigned long)(addr), (size)); \
7683f744 48})
1da177e4 49
96d4f267 50#define access_ok(addr, size) __access_ok(addr, size)
1da177e4 51
37096003
AV
52unsigned long __must_check
53raw_copy_from_user(void *to, const void __user *from, unsigned long n);
eb608fb3 54
37096003
AV
55unsigned long __must_check
56raw_copy_to_user(void __user *to, const void *from, unsigned long n);
d02765d1 57
01eb42af 58#ifndef CONFIG_KASAN
37096003
AV
59#define INLINE_COPY_FROM_USER
60#define INLINE_COPY_TO_USER
01eb42af 61#endif
6c1e3e79 62
c9ca7841
HC
63#ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
64
65#define __put_get_user_asm(to, from, size, spec) \
66({ \
67 register unsigned long __reg0 asm("0") = spec; \
68 int __rc; \
69 \
70 asm volatile( \
71 "0: mvcos %1,%3,%2\n" \
72 "1: xr %0,%0\n" \
73 "2:\n" \
74 ".pushsection .fixup, \"ax\"\n" \
75 "3: lhi %0,%5\n" \
76 " jg 2b\n" \
77 ".popsection\n" \
78 EX_TABLE(0b,3b) EX_TABLE(1b,3b) \
d09c5373 79 : "=d" (__rc), "+Q" (*(to)) \
c9ca7841
HC
80 : "d" (size), "Q" (*(from)), \
81 "d" (__reg0), "K" (-EFAULT) \
82 : "cc"); \
83 __rc; \
84})
85
062795fc 86static __always_inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
dc4aace1 87{
0aaba41b 88 unsigned long spec = 0x010000UL;
dc4aace1
HC
89 int rc;
90
91 switch (size) {
92 case 1:
93 rc = __put_get_user_asm((unsigned char __user *)ptr,
94 (unsigned char *)x,
95 size, spec);
96 break;
97 case 2:
98 rc = __put_get_user_asm((unsigned short __user *)ptr,
99 (unsigned short *)x,
100 size, spec);
101 break;
102 case 4:
103 rc = __put_get_user_asm((unsigned int __user *)ptr,
104 (unsigned int *)x,
105 size, spec);
106 break;
107 case 8:
108 rc = __put_get_user_asm((unsigned long __user *)ptr,
109 (unsigned long *)x,
110 size, spec);
111 break;
0b925159 112 }
dc4aace1
HC
113 return rc;
114}
115
062795fc 116static __always_inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size)
dc4aace1 117{
0aaba41b 118 unsigned long spec = 0x01UL;
dc4aace1
HC
119 int rc;
120
121 switch (size) {
122 case 1:
123 rc = __put_get_user_asm((unsigned char *)x,
124 (unsigned char __user *)ptr,
125 size, spec);
126 break;
127 case 2:
128 rc = __put_get_user_asm((unsigned short *)x,
129 (unsigned short __user *)ptr,
130 size, spec);
131 break;
132 case 4:
133 rc = __put_get_user_asm((unsigned int *)x,
134 (unsigned int __user *)ptr,
135 size, spec);
136 break;
137 case 8:
138 rc = __put_get_user_asm((unsigned long *)x,
139 (unsigned long __user *)ptr,
140 size, spec);
141 break;
0b925159 142 }
dc4aace1
HC
143 return rc;
144}
c9ca7841
HC
145
146#else /* CONFIG_HAVE_MARCH_Z10_FEATURES */
147
211deca6 148static inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
d02765d1 149{
37096003 150 size = raw_copy_to_user(ptr, x, size);
4f41c2b4 151 return size ? -EFAULT : 0;
d02765d1
GS
152}
153
211deca6 154static inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size)
d02765d1 155{
37096003 156 size = raw_copy_from_user(x, ptr, size);
4f41c2b4 157 return size ? -EFAULT : 0;
d02765d1 158}
1da177e4 159
c9ca7841
HC
160#endif /* CONFIG_HAVE_MARCH_Z10_FEATURES */
161
1da177e4
LT
162/*
163 * These are the main single-value transfer routines. They automatically
164 * use the right size if we just have the right pointer type.
165 */
1da177e4
LT
166#define __put_user(x, ptr) \
167({ \
168 __typeof__(*(ptr)) __x = (x); \
d02765d1 169 int __pu_err = -EFAULT; \
17566c3c 170 __chk_user_ptr(ptr); \
1da177e4
LT
171 switch (sizeof (*(ptr))) { \
172 case 1: \
173 case 2: \
174 case 4: \
175 case 8: \
cfa785e6
HC
176 __pu_err = __put_user_fn(&__x, ptr, \
177 sizeof(*(ptr))); \
1da177e4
LT
178 break; \
179 default: \
180 __put_user_bad(); \
181 break; \
182 } \
ee64baf4 183 __builtin_expect(__pu_err, 0); \
1da177e4 184})
1da177e4
LT
185
186#define put_user(x, ptr) \
187({ \
dab4079d 188 might_fault(); \
1da177e4
LT
189 __put_user(x, ptr); \
190})
191
192
4f41c2b4 193int __put_user_bad(void) __attribute__((noreturn));
1da177e4 194
1da177e4
LT
195#define __get_user(x, ptr) \
196({ \
d02765d1
GS
197 int __gu_err = -EFAULT; \
198 __chk_user_ptr(ptr); \
1da177e4 199 switch (sizeof(*(ptr))) { \
1047aa77 200 case 1: { \
fd2d2b19 201 unsigned char __x = 0; \
cfa785e6
HC
202 __gu_err = __get_user_fn(&__x, ptr, \
203 sizeof(*(ptr))); \
97fa5a66 204 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
1047aa77
MS
205 break; \
206 }; \
207 case 2: { \
fd2d2b19 208 unsigned short __x = 0; \
cfa785e6
HC
209 __gu_err = __get_user_fn(&__x, ptr, \
210 sizeof(*(ptr))); \
97fa5a66 211 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
1047aa77
MS
212 break; \
213 }; \
214 case 4: { \
fd2d2b19 215 unsigned int __x = 0; \
cfa785e6
HC
216 __gu_err = __get_user_fn(&__x, ptr, \
217 sizeof(*(ptr))); \
97fa5a66 218 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
1047aa77
MS
219 break; \
220 }; \
221 case 8: { \
fd2d2b19 222 unsigned long long __x = 0; \
cfa785e6
HC
223 __gu_err = __get_user_fn(&__x, ptr, \
224 sizeof(*(ptr))); \
97fa5a66 225 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
1da177e4 226 break; \
1047aa77 227 }; \
1da177e4
LT
228 default: \
229 __get_user_bad(); \
230 break; \
231 } \
ee64baf4 232 __builtin_expect(__gu_err, 0); \
1da177e4 233})
1da177e4
LT
234
235#define get_user(x, ptr) \
236({ \
dab4079d 237 might_fault(); \
1da177e4
LT
238 __get_user(x, ptr); \
239})
240
4f41c2b4 241int __get_user_bad(void) __attribute__((noreturn));
1da177e4 242
4f41c2b4 243unsigned long __must_check
37096003 244raw_copy_in_user(void __user *to, const void __user *from, unsigned long n);
1da177e4
LT
245
246/*
247 * Copy a null terminated string from userspace.
248 */
4f41c2b4
HC
249
250long __strncpy_from_user(char *dst, const char __user *src, long count);
251
f7675ad7 252static inline long __must_check
1da177e4
LT
253strncpy_from_user(char *dst, const char __user *src, long count)
254{
dab4079d 255 might_fault();
4f41c2b4 256 return __strncpy_from_user(dst, src, count);
1da177e4
LT
257}
258
211deca6 259unsigned long __must_check __strnlen_user(const char __user *src, unsigned long count);
4f41c2b4 260
211deca6 261static inline unsigned long strnlen_user(const char __user *src, unsigned long n)
1da177e4 262{
dab4079d 263 might_fault();
4f41c2b4 264 return __strnlen_user(src, n);
1da177e4
LT
265}
266
1da177e4
LT
267/*
268 * Zero Userspace
269 */
211deca6 270unsigned long __must_check __clear_user(void __user *to, unsigned long size);
1da177e4 271
211deca6 272static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
1da177e4 273{
dab4079d 274 might_fault();
4f41c2b4 275 return __clear_user(to, n);
1da177e4
LT
276}
277
211deca6 278int copy_to_user_real(void __user *dest, void *src, unsigned long count);
8a5d8473 279void s390_kernel_write(void *dst, const void *src, size_t size);
a0616cde 280
1da177e4 281#endif /* __S390_UACCESS_H */