Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  S390 version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *    Copyright IBM Corp. 1999, 2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *    Author(s): Hartmut Penner (hp@de.ibm.com),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Derived from "include/asm-i386/uaccess.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #ifndef __S390_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define __S390_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * User space memory access functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/ctl_reg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/extable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/facility.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * The fs value determines whether argument validity checking should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * performed or not.  If get_fs() == USER_DS, checking is performed, with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * get_fs() == KERNEL_DS, checking is bypassed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * For historical reasons, these macros are grossly misnamed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define KERNEL_DS	(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define KERNEL_DS_SACF	(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define USER_DS		(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define USER_DS_SACF	(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define get_fs()        (current->thread.mm_segment)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define uaccess_kernel() ((get_fs() & 2) == KERNEL_DS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) void set_fs(mm_segment_t fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static inline int __range_ok(unsigned long addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define __access_ok(addr, size)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) ({							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	__chk_user_ptr(addr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	__range_ok((unsigned long)(addr), (size));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define access_ok(addr, size) __access_ok(addr, size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) unsigned long __must_check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) raw_copy_from_user(void *to, const void __user *from, unsigned long n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) unsigned long __must_check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) raw_copy_to_user(void __user *to, const void *from, unsigned long n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #ifndef CONFIG_KASAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define INLINE_COPY_FROM_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define INLINE_COPY_TO_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) int __put_user_bad(void) __attribute__((noreturn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) int __get_user_bad(void) __attribute__((noreturn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define __put_get_user_asm(to, from, size, spec)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	register unsigned long __reg0 asm("0") = spec;		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int __rc;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	asm volatile(						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		"0:	mvcos	%1,%3,%2\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		"1:	xr	%0,%0\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		"2:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		".pushsection .fixup, \"ax\"\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		"3:	lhi	%0,%5\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		"	jg	2b\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		".popsection\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		EX_TABLE(0b,3b) EX_TABLE(1b,3b)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		: "=d" (__rc), "+Q" (*(to))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		: "d" (size), "Q" (*(from)),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		  "d" (__reg0), "K" (-EFAULT)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		: "cc");					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	__rc;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static __always_inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	unsigned long spec = 0x010000UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	switch (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		rc = __put_get_user_asm((unsigned char __user *)ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 					(unsigned char *)x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 					size, spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		rc = __put_get_user_asm((unsigned short __user *)ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 					(unsigned short *)x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 					size, spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		rc = __put_get_user_asm((unsigned int __user *)ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 					(unsigned int *)x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 					size, spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		rc = __put_get_user_asm((unsigned long __user *)ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 					(unsigned long *)x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 					size, spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		__put_user_bad();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static __always_inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	unsigned long spec = 0x01UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	switch (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		rc = __put_get_user_asm((unsigned char *)x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 					(unsigned char __user *)ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 					size, spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		rc = __put_get_user_asm((unsigned short *)x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 					(unsigned short __user *)ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 					size, spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		rc = __put_get_user_asm((unsigned int *)x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 					(unsigned int __user *)ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 					size, spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		rc = __put_get_user_asm((unsigned long *)x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 					(unsigned long __user *)ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 					size, spec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		__get_user_bad();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #else /* CONFIG_HAVE_MARCH_Z10_FEATURES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	size = raw_copy_to_user(ptr, x, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return size ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	size = raw_copy_from_user(x, ptr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return size ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #endif /* CONFIG_HAVE_MARCH_Z10_FEATURES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * These are the main single-value transfer routines.  They automatically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * use the right size if we just have the right pointer type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #define __put_user(x, ptr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	__typeof__(*(ptr)) __x = (x);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	int __pu_err = -EFAULT;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)         __chk_user_ptr(ptr);                                    \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	switch (sizeof (*(ptr))) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	case 1:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	case 2:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	case 4:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	case 8:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		__pu_err = __put_user_fn(&__x, ptr,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 					 sizeof(*(ptr)));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	default:						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		__put_user_bad();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	__builtin_expect(__pu_err, 0);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #define put_user(x, ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	might_fault();						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	__put_user(x, ptr);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define __get_user(x, ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	int __gu_err = -EFAULT;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	__chk_user_ptr(ptr);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	switch (sizeof(*(ptr))) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	case 1: {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		unsigned char __x = 0;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		__gu_err = __get_user_fn(&__x, ptr,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 					 sizeof(*(ptr)));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		(x) = *(__force __typeof__(*(ptr)) *) &__x;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	};							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	case 2: {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		unsigned short __x = 0;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		__gu_err = __get_user_fn(&__x, ptr,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 					 sizeof(*(ptr)));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		(x) = *(__force __typeof__(*(ptr)) *) &__x;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	};							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	case 4: {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		unsigned int __x = 0;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		__gu_err = __get_user_fn(&__x, ptr,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 					 sizeof(*(ptr)));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		(x) = *(__force __typeof__(*(ptr)) *) &__x;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	};							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	case 8: {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		unsigned long long __x = 0;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		__gu_err = __get_user_fn(&__x, ptr,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 					 sizeof(*(ptr)));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		(x) = *(__force __typeof__(*(ptr)) *) &__x;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	};							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	default:						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		__get_user_bad();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	__builtin_expect(__gu_err, 0);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #define get_user(x, ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	might_fault();						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	__get_user(x, ptr);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) unsigned long __must_check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) raw_copy_in_user(void __user *to, const void __user *from, unsigned long n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * Copy a null terminated string from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) long __strncpy_from_user(char *dst, const char __user *src, long count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static inline long __must_check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) strncpy_from_user(char *dst, const char __user *src, long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	might_fault();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	return __strncpy_from_user(dst, src, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) unsigned long __must_check __strnlen_user(const char __user *src, unsigned long count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static inline unsigned long strnlen_user(const char __user *src, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	might_fault();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return __strnlen_user(src, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  * Zero Userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) unsigned long __must_check __clear_user(void __user *to, unsigned long size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	might_fault();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	return __clear_user(to, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int copy_to_user_real(void __user *dest, void *src, unsigned long count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) void *s390_kernel_write(void *dst, const void *src, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #define HAVE_GET_KERNEL_NOFAULT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int __noreturn __put_kernel_bad(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #define __put_kernel_asm(val, to, insn)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	int __rc;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	asm volatile(							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		"0:   " insn "  %2,%1\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		"1:	xr	%0,%0\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		"2:\n"							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		".pushsection .fixup, \"ax\"\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		"3:	lhi	%0,%3\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		"	jg	2b\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		".popsection\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		EX_TABLE(0b,3b) EX_TABLE(1b,3b)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		: "=d" (__rc), "+Q" (*(to))				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		: "d" (val), "K" (-EFAULT)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		: "cc");						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	__rc;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #define __put_kernel_nofault(dst, src, type, err_label)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	u64 __x = (u64)(*((type *)(src)));				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	int __pk_err;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	switch (sizeof(type)) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	case 1:								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		__pk_err = __put_kernel_asm(__x, (type *)(dst), "stc"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	case 2:								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		__pk_err = __put_kernel_asm(__x, (type *)(dst), "sth"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	case 4:								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		__pk_err = __put_kernel_asm(__x, (type *)(dst), "st");	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	case 8:								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		__pk_err = __put_kernel_asm(__x, (type *)(dst), "stg"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	default:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		__pk_err = __put_kernel_bad();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (unlikely(__pk_err))						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		goto err_label;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) int __noreturn __get_kernel_bad(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) #define __get_kernel_asm(val, from, insn)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	int __rc;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	asm volatile(							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		"0:   " insn "  %1,%2\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		"1:	xr	%0,%0\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		"2:\n"							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		".pushsection .fixup, \"ax\"\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		"3:	lhi	%0,%3\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		"	jg	2b\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		".popsection\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		EX_TABLE(0b,3b) EX_TABLE(1b,3b)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		: "=d" (__rc), "+d" (val)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		: "Q" (*(from)), "K" (-EFAULT)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		: "cc");						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	__rc;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) #define __get_kernel_nofault(dst, src, type, err_label)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	int __gk_err;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	switch (sizeof(type)) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	case 1: {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		u8 __x = 0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		__gk_err = __get_kernel_asm(__x, (type *)(src), "ic");	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		*((type *)(dst)) = (type)__x;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	};								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	case 2: {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		u16 __x = 0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		__gk_err = __get_kernel_asm(__x, (type *)(src), "lh");	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		*((type *)(dst)) = (type)__x;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	};								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	case 4: {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		u32 __x = 0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		__gk_err = __get_kernel_asm(__x, (type *)(src), "l");	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		*((type *)(dst)) = (type)__x;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	};								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	case 8: {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		u64 __x = 0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		__gk_err = __get_kernel_asm(__x, (type *)(src), "lg");	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		*((type *)(dst)) = (type)__x;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	};								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	default:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		__gk_err = __get_kernel_bad();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (unlikely(__gk_err))						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		goto err_label;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) #endif /* __S390_UACCESS_H */