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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * include/asm-xtensa/uaccess.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * User space memory access functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * These routines provide basic accessing functions to the user memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * space for the kernel. This header file provides functions such as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * Copyright (C) 2001 - 2005 Tensilica Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #ifndef _XTENSA_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define _XTENSA_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/prefetch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/extable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * The fs value determines whether argument validity checking should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * be performed or not.  If get_fs() == USER_DS, checking is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * performed, with get_fs() == KERNEL_DS, checking is bypassed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * For historical reasons (Data Segment Register?), these macros are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * grossly misnamed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define KERNEL_DS	((mm_segment_t) { 0 })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define USER_DS		((mm_segment_t) { 1 })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define get_fs()	(current->thread.current_ds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define set_fs(val)	(current->thread.current_ds = (val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define uaccess_kernel() (get_fs().seg == KERNEL_DS.seg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define __kernel_ok (uaccess_kernel())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define __user_ok(addr, size) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		(((size) <= TASK_SIZE)&&((addr) <= TASK_SIZE-(size)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define __access_ok(addr, size) (__kernel_ok || __user_ok((addr), (size)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define access_ok(addr, size) __access_ok((unsigned long)(addr), (size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define user_addr_max() (uaccess_kernel() ? ~0UL : TASK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * These are the main single-value transfer routines.  They
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * automatically use the right size if we just have the right pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * This gets kind of ugly. We want to return _two_ values in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * "get_user()" and yet we don't want to do any pointers, because that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * is too much of a performance impact. Thus we have a few rather ugly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * macros here, and hide all the uglyness from the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * Careful to not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * (a) re-use the arguments for side effects (sizeof is ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * (b) require any knowledge of processes at this stage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define put_user(x, ptr)	__put_user_check((x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define get_user(x, ptr) __get_user_check((x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * The "__xxx" versions of the user access functions are versions that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * do not verify the address space, that must have been done previously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * with a separate "access_ok()" call (this is used when we do multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * accesses to the same area of user memory).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #define __put_user(x, ptr) __put_user_nocheck((x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define __get_user(x, ptr) __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) extern long __put_user_bad(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define __put_user_nocheck(x, ptr, size)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) ({							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	long __pu_err;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	__put_user_size((x), (ptr), (size), __pu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	__pu_err;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define __put_user_check(x, ptr, size)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	long __pu_err = -EFAULT;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	__typeof__(*(ptr)) __user *__pu_addr = (ptr);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (access_ok(__pu_addr, size))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		__put_user_size((x), __pu_addr, (size), __pu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	__pu_err;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #define __put_user_size(x, ptr, size, retval)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int __cb;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	retval = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	switch (size) {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	case 1: __put_user_asm(x, ptr, retval, 1, "s8i", __cb);  break;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	case 2: __put_user_asm(x, ptr, retval, 2, "s16i", __cb); break;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	case 4: __put_user_asm(x, ptr, retval, 4, "s32i", __cb); break;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	case 8: {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		     __typeof__(*ptr) __v64 = x;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		     retval = __copy_to_user(ptr, &__v64, 8) ? -EFAULT : 0;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		     break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	        }							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	default: __put_user_bad();					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * Consider a case of a user single load/store would cause both an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * unaligned exception and an MMU-related exception (unaligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * exceptions happen first):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * User code passes a bad variable ptr to a system call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * Kernel tries to access the variable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * Unaligned exception occurs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * Unaligned exception handler tries to make aligned accesses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * Double exception occurs for MMU-related cause (e.g., page not mapped).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * do_page_fault() thinks the fault address belongs to the kernel, not the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * user, and panics.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * The kernel currently prohibits user unaligned accesses.  We use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * __check_align_* macros to check for unaligned addresses before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * accessing user space so we don't crash the kernel.  Both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * __put_user_asm and __get_user_asm use these alignment macros, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * macro-specific labels such as 0f, 1f, %0, %2, and %3 must stay in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * sync.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define __check_align_1  ""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define __check_align_2				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	"   _bbci.l %[mem] * 0, 1f	\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	"   movi    %[err], %[efault]	\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	"   _j      2f			\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define __check_align_4				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	"   _bbsi.l %[mem] * 0, 0f	\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	"   _bbci.l %[mem] * 0 + 1, 1f	\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	"0: movi    %[err], %[efault]	\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	"   _j      2f			\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * We don't tell gcc that we are accessing memory, but this is OK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * because we do not write to any memory gcc knows about, so there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * are no aliasing issues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * WARNING: If you modify this macro at all, verify that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * __check_align_* macros still work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define __put_user_asm(x_, addr_, err_, align, insn, cb)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) __asm__ __volatile__(					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	__check_align_##align				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	"1: "insn"  %[x], %[mem]	\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	"2:				\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	"   .section  .fixup,\"ax\"	\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	"   .align 4			\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	"   .literal_position		\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	"5:				\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	"   movi   %[tmp], 2b		\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	"   movi   %[err], %[efault]	\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	"   jx     %[tmp]		\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	"   .previous			\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	"   .section  __ex_table,\"a\"	\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	"   .long	1b, 5b		\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	"   .previous"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	:[err] "+r"(err_), [tmp] "=r"(cb), [mem] "=m"(*(addr_))		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	:[x] "r"(x_), [efault] "i"(-EFAULT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define __get_user_nocheck(x, ptr, size)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	long __gu_err;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	__get_user_size((x), (ptr), (size), __gu_err);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	__gu_err;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #define __get_user_check(x, ptr, size)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	long __gu_err = -EFAULT;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	const __typeof__(*(ptr)) __user *__gu_addr = (ptr);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (access_ok(__gu_addr, size))					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		__get_user_size((x), __gu_addr, (size), __gu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	else								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		(x) = (__typeof__(*(ptr)))0;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	__gu_err;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) extern long __get_user_bad(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define __get_user_size(x, ptr, size, retval)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int __cb;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	retval = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	switch (size) {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	case 1: __get_user_asm(x, ptr, retval, 1, "l8ui", __cb);  break;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	case 2: __get_user_asm(x, ptr, retval, 2, "l16ui", __cb); break;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	case 4: __get_user_asm(x, ptr, retval, 4, "l32i", __cb);  break;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	case 8: {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		u64 __x;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		if (unlikely(__copy_from_user(&__x, ptr, 8))) {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			retval = -EFAULT;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			(x) = (__typeof__(*(ptr)))0;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		} else {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			(x) = *(__force __typeof__(*(ptr)) *)&__x;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		break;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	default:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		(x) = (__typeof__(*(ptr)))0;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		__get_user_bad();					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * WARNING: If you modify this macro at all, verify that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * __check_align_* macros still work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define __get_user_asm(x_, addr_, err_, align, insn, cb) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) do {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	u32 __x = 0;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	__asm__ __volatile__(				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		__check_align_##align			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		"1: "insn"  %[x], %[mem]	\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		"2:				\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		"   .section  .fixup,\"ax\"	\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		"   .align 4			\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		"   .literal_position		\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		"5:				\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		"   movi   %[tmp], 2b		\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		"   movi   %[err], %[efault]	\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		"   jx     %[tmp]		\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		"   .previous			\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		"   .section  __ex_table,\"a\"	\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		"   .long	1b, 5b		\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		"   .previous"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		:[err] "+r"(err_), [tmp] "=r"(cb), [x] "+r"(__x) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		:[mem] "m"(*(addr_)), [efault] "i"(-EFAULT)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	(x_) = (__force __typeof__(*(addr_)))__x;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * Copy to/from user space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) extern unsigned __xtensa_copy_user(void *to, const void *from, unsigned n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) raw_copy_from_user(void *to, const void __user *from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	prefetchw(to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return __xtensa_copy_user(to, (__force const void *)from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) raw_copy_to_user(void __user *to, const void *from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	prefetch(from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return __xtensa_copy_user((__force void *)to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #define INLINE_COPY_FROM_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #define INLINE_COPY_TO_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * We need to return the number of bytes not cleared.  Our memset()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * returns zero if a problem occurs while accessing user-space memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * In that event, return no memory cleared.  Otherwise, zero for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  * success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) __xtensa_clear_user(void __user *addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (!__memset((void __force *)addr, 0, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) clear_user(void __user *addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (access_ok(addr, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		return __xtensa_clear_user(addr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	return size ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #define __clear_user  __xtensa_clear_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #ifndef CONFIG_GENERIC_STRNCPY_FROM_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) extern long __strncpy_user(char *dst, const char __user *src, long count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static inline long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) strncpy_from_user(char *dst, const char __user *src, long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (access_ok(src, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		return __strncpy_user(dst, src, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) long strncpy_from_user(char *dst, const char __user *src, long count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #endif
^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)  * Return the size of a string (including the ending 0!)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) extern long __strnlen_user(const char __user *str, long len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static inline long strnlen_user(const char __user *str, long len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	if (!access_ok(str, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	return __strnlen_user(str, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #endif	/* _XTENSA_UACCESS_H */