1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Copyright IBM Corp. 1999, 2000
5 * Author(s): Hartmut Penner (hp@de.ibm.com),
6 * Martin Schwidefsky (schwidefsky@de.ibm.com)
8 * Derived from "include/asm-i386/uaccess.h"
10 #ifndef __S390_UACCESS_H
11 #define __S390_UACCESS_H
14 * User space memory access functions
16 #include <asm/processor.h>
17 #include <asm/ctl_reg.h>
18 #include <asm/extable.h>
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.
26 * For historical reasons, these macros are grossly misnamed.
29 #define MAKE_MM_SEG(a) ((mm_segment_t) { (a) })
32 #define KERNEL_DS MAKE_MM_SEG(0)
33 #define USER_DS MAKE_MM_SEG(1)
35 #define get_ds() (KERNEL_DS)
36 #define get_fs() (current->thread.mm_segment)
37 #define segment_eq(a,b) ((a).ar4 == (b).ar4)
39 static inline void set_fs(mm_segment_t fs
)
41 current
->thread
.mm_segment
= fs
;
42 if (uaccess_kernel()) {
43 set_cpu_flag(CIF_ASCE_SECONDARY
);
44 __ctl_load(S390_lowcore
.kernel_asce
, 7, 7);
46 clear_cpu_flag(CIF_ASCE_SECONDARY
);
47 __ctl_load(S390_lowcore
.user_asce
, 7, 7);
51 static inline int __range_ok(unsigned long addr
, unsigned long size
)
56 #define __access_ok(addr, size) \
58 __chk_user_ptr(addr); \
59 __range_ok((unsigned long)(addr), (size)); \
62 #define access_ok(type, addr, size) __access_ok(addr, size)
64 unsigned long __must_check
65 raw_copy_from_user(void *to
, const void __user
*from
, unsigned long n
);
67 unsigned long __must_check
68 raw_copy_to_user(void __user
*to
, const void *from
, unsigned long n
);
70 #define INLINE_COPY_FROM_USER
71 #define INLINE_COPY_TO_USER
73 #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
75 #define __put_get_user_asm(to, from, size, spec) \
77 register unsigned long __reg0 asm("0") = spec; \
81 "0: mvcos %1,%3,%2\n" \
84 ".pushsection .fixup, \"ax\"\n" \
88 EX_TABLE(0b,3b) EX_TABLE(1b,3b) \
89 : "=d" (__rc), "+Q" (*(to)) \
90 : "d" (size), "Q" (*(from)), \
91 "d" (__reg0), "K" (-EFAULT) \
96 static inline int __put_user_fn(void *x
, void __user
*ptr
, unsigned long size
)
98 unsigned long spec
= 0x810000UL
;
103 rc
= __put_get_user_asm((unsigned char __user
*)ptr
,
108 rc
= __put_get_user_asm((unsigned short __user
*)ptr
,
113 rc
= __put_get_user_asm((unsigned int __user
*)ptr
,
118 rc
= __put_get_user_asm((unsigned long __user
*)ptr
,
126 static inline int __get_user_fn(void *x
, const void __user
*ptr
, unsigned long size
)
128 unsigned long spec
= 0x81UL
;
133 rc
= __put_get_user_asm((unsigned char *)x
,
134 (unsigned char __user
*)ptr
,
138 rc
= __put_get_user_asm((unsigned short *)x
,
139 (unsigned short __user
*)ptr
,
143 rc
= __put_get_user_asm((unsigned int *)x
,
144 (unsigned int __user
*)ptr
,
148 rc
= __put_get_user_asm((unsigned long *)x
,
149 (unsigned long __user
*)ptr
,
156 #else /* CONFIG_HAVE_MARCH_Z10_FEATURES */
158 static inline int __put_user_fn(void *x
, void __user
*ptr
, unsigned long size
)
160 size
= raw_copy_to_user(ptr
, x
, size
);
161 return size
? -EFAULT
: 0;
164 static inline int __get_user_fn(void *x
, const void __user
*ptr
, unsigned long size
)
166 size
= raw_copy_from_user(x
, ptr
, size
);
167 return size
? -EFAULT
: 0;
170 #endif /* CONFIG_HAVE_MARCH_Z10_FEATURES */
173 * These are the main single-value transfer routines. They automatically
174 * use the right size if we just have the right pointer type.
176 #define __put_user(x, ptr) \
178 __typeof__(*(ptr)) __x = (x); \
179 int __pu_err = -EFAULT; \
180 __chk_user_ptr(ptr); \
181 switch (sizeof (*(ptr))) { \
186 __pu_err = __put_user_fn(&__x, ptr, \
193 __builtin_expect(__pu_err, 0); \
196 #define put_user(x, ptr) \
199 __put_user(x, ptr); \
203 int __put_user_bad(void) __attribute__((noreturn
));
205 #define __get_user(x, ptr) \
207 int __gu_err = -EFAULT; \
208 __chk_user_ptr(ptr); \
209 switch (sizeof(*(ptr))) { \
211 unsigned char __x = 0; \
212 __gu_err = __get_user_fn(&__x, ptr, \
214 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
218 unsigned short __x = 0; \
219 __gu_err = __get_user_fn(&__x, ptr, \
221 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
225 unsigned int __x = 0; \
226 __gu_err = __get_user_fn(&__x, ptr, \
228 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
232 unsigned long long __x = 0; \
233 __gu_err = __get_user_fn(&__x, ptr, \
235 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
242 __builtin_expect(__gu_err, 0); \
245 #define get_user(x, ptr) \
248 __get_user(x, ptr); \
251 int __get_user_bad(void) __attribute__((noreturn
));
253 unsigned long __must_check
254 raw_copy_in_user(void __user
*to
, const void __user
*from
, unsigned long n
);
257 * Copy a null terminated string from userspace.
260 long __strncpy_from_user(char *dst
, const char __user
*src
, long count
);
262 static inline long __must_check
263 strncpy_from_user(char *dst
, const char __user
*src
, long count
)
266 return __strncpy_from_user(dst
, src
, count
);
269 unsigned long __must_check
__strnlen_user(const char __user
*src
, unsigned long count
);
271 static inline unsigned long strnlen_user(const char __user
*src
, unsigned long n
)
274 return __strnlen_user(src
, n
);
280 unsigned long __must_check
__clear_user(void __user
*to
, unsigned long size
);
282 static inline unsigned long __must_check
clear_user(void __user
*to
, unsigned long n
)
285 return __clear_user(to
, n
);
288 int copy_to_user_real(void __user
*dest
, void *src
, unsigned long count
);
289 void s390_kernel_write(void *dst
, const void *src
, size_t size
);
291 #endif /* __S390_UACCESS_H */