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-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2012 Regents of the University of California
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This file was copied from include/asm-generic/uaccess.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #ifndef _ASM_RISCV_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define _ASM_RISCV_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <asm/pgtable.h>		/* for TASK_SIZE */
^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) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/thread_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/byteorder.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) #include <asm/asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define __enable_user_access()							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	__asm__ __volatile__ ("csrs sstatus, %0" : : "r" (SR_SUM) : "memory")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define __disable_user_access()							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	__asm__ __volatile__ ("csrc sstatus, %0" : : "r" (SR_SUM) : "memory")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * access_ok: - Checks if a user space pointer is valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * @addr: User space pointer to start of block to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * @size: Size of block to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * Context: User context only.  This function may sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * Checks if a pointer to a block of memory in user space is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * Returns true (nonzero) if the memory block may be valid, false (zero)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * if it is definitely invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * Note that, depending on architecture, this function probably just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * checks that the pointer is in the user space range - after calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * this function, memory access functions may still return -EFAULT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define access_ok(addr, size) ({					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	__chk_user_ptr(addr);						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	likely(__access_ok((unsigned long __force)(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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * Ensure that the range [addr, addr+size) is within the process's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * address space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static inline int __access_ok(unsigned long addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return size <= TASK_SIZE && addr <= TASK_SIZE - size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * The exception table consists of pairs of addresses: the first is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * address of an instruction that is allowed to fault, and the second is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * the address at which the program should continue.  No registers are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * modified, so it is entirely up to the continuation code to figure out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * what to do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * All the routines below use bits of fixup code that are out of line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * with the main instruction path.  This means when everything is well,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * we don't even have to jump over them.  Further, they do not intrude
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * on our cache or tlb entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define __LSW	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define __MSW	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * The "__xxx" versions of the user access functions do not verify the address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * space - it must have been done previously with a separate "access_ok()"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #define __get_user_asm(insn, x, ptr, err)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	uintptr_t __tmp;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	__typeof__(x) __x;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	__asm__ __volatile__ (					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		"1:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		"	" insn " %1, %3\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		"2:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		"	.section .fixup,\"ax\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		"	.balign 4\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		"3:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		"	li %0, %4\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		"	li %1, 0\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		"	jump 2b, %2\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		"	.previous\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		"	.section __ex_table,\"a\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		"	.balign " RISCV_SZPTR "\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		"	" RISCV_PTR " 1b, 3b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		"	.previous"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		: "+r" (err), "=&r" (__x), "=r" (__tmp)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		: "m" (*(ptr)), "i" (-EFAULT));			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	(x) = __x;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define __get_user_8(x, ptr, err) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	__get_user_asm("ld", x, ptr, err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #else /* !CONFIG_64BIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define __get_user_8(x, ptr, err)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	u32 __user *__ptr = (u32 __user *)(ptr);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	u32 __lo, __hi;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	uintptr_t __tmp;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	__asm__ __volatile__ (					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		"1:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		"	lw %1, %4\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		"2:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		"	lw %2, %5\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		"3:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		"	.section .fixup,\"ax\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		"	.balign 4\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		"4:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		"	li %0, %6\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		"	li %1, 0\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		"	li %2, 0\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		"	jump 3b, %3\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		"	.previous\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		"	.section __ex_table,\"a\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		"	.balign " RISCV_SZPTR "\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		"	" RISCV_PTR " 1b, 4b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		"	" RISCV_PTR " 2b, 4b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		"	.previous"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		: "+r" (err), "=&r" (__lo), "=r" (__hi),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			"=r" (__tmp)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		: "m" (__ptr[__LSW]), "m" (__ptr[__MSW]),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			"i" (-EFAULT));				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	(x) = (__typeof__(x))((__typeof__((x)-(x)))(		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		(((u64)__hi << 32) | __lo)));			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #endif /* CONFIG_64BIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define __get_user_nocheck(x, __gu_ptr, __gu_err)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	switch (sizeof(*__gu_ptr)) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	case 1:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		__get_user_asm("lb", (x), __gu_ptr, __gu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	case 2:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		__get_user_asm("lh", (x), __gu_ptr, __gu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	case 4:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		__get_user_asm("lw", (x), __gu_ptr, __gu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	case 8:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		__get_user_8((x), __gu_ptr, __gu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	default:						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		BUILD_BUG();					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) } while (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)  * __get_user: - Get a simple variable from user space, with less checking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  * @x:   Variable to store result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * @ptr: Source address, in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * Context: User context only.  This function may sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  * This macro copies a single simple variable from user space to kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  * space.  It supports simple types like char and int, but not larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * data types like structures or arrays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * @ptr must have pointer-to-simple-variable type, and the result of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * dereferencing @ptr must be assignable to @x without a cast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * Caller must check the pointer with access_ok() before calling this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * Returns zero on success, or -EFAULT on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * On error, the variable @x is set to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #define __get_user(x, ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	const __typeof__(*(ptr)) __user *__gu_ptr = (ptr);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	long __gu_err = 0;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	__chk_user_ptr(__gu_ptr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	__enable_user_access();					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	__get_user_nocheck(x, __gu_ptr, __gu_err);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	__disable_user_access();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	__gu_err;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * get_user: - Get a simple variable from user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * @x:   Variable to store result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * @ptr: Source address, in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * Context: User context only.  This function may sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * This macro copies a single simple variable from user space to kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * space.  It supports simple types like char and int, but not larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * data types like structures or arrays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * @ptr must have pointer-to-simple-variable type, and the result of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * dereferencing @ptr must be assignable to @x without a cast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * Returns zero on success, or -EFAULT on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * On error, the variable @x is set to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define get_user(x, ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	const __typeof__(*(ptr)) __user *__p = (ptr);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	might_fault();						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	access_ok(__p, sizeof(*__p)) ?		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		__get_user((x), __p) :				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		((x) = 0, -EFAULT);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define __put_user_asm(insn, x, ptr, err)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	uintptr_t __tmp;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	__typeof__(*(ptr)) __x = x;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	__asm__ __volatile__ (					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		"1:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		"	" insn " %z3, %2\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		"2:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		"	.section .fixup,\"ax\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		"	.balign 4\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		"3:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		"	li %0, %4\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		"	jump 2b, %1\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		"	.previous\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		"	.section __ex_table,\"a\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		"	.balign " RISCV_SZPTR "\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		"	" RISCV_PTR " 1b, 3b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		"	.previous"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		: "+r" (err), "=r" (__tmp), "=m" (*(ptr))	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		: "rJ" (__x), "i" (-EFAULT));			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #define __put_user_8(x, ptr, err) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	__put_user_asm("sd", x, ptr, err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #else /* !CONFIG_64BIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #define __put_user_8(x, ptr, err)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	u32 __user *__ptr = (u32 __user *)(ptr);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	u64 __x = (__typeof__((x)-(x)))(x);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	uintptr_t __tmp;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	__asm__ __volatile__ (					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		"1:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		"	sw %z4, %2\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		"2:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		"	sw %z5, %3\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		"3:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		"	.section .fixup,\"ax\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		"	.balign 4\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		"4:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		"	li %0, %6\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		"	jump 3b, %1\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		"	.previous\n"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		"	.section __ex_table,\"a\"\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		"	.balign " RISCV_SZPTR "\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		"	" RISCV_PTR " 1b, 4b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		"	" RISCV_PTR " 2b, 4b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		"	.previous"				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		: "+r" (err), "=r" (__tmp),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			"=m" (__ptr[__LSW]),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			"=m" (__ptr[__MSW])			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		: "rJ" (__x), "rJ" (__x >> 32), "i" (-EFAULT));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #endif /* CONFIG_64BIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #define __put_user_nocheck(x, __gu_ptr, __pu_err)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	switch (sizeof(*__gu_ptr)) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	case 1:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		__put_user_asm("sb", (x), __gu_ptr, __pu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	case 2:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		__put_user_asm("sh", (x), __gu_ptr, __pu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	case 4:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		__put_user_asm("sw", (x), __gu_ptr, __pu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	case 8:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		__put_user_8((x), __gu_ptr, __pu_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	default:						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		BUILD_BUG();					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * __put_user: - Write a simple value into user space, with less checking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * @x:   Value to copy to user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * @ptr: Destination address, in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * Context: User context only.  This function may sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * This macro copies a single simple value from kernel space to user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * space.  It supports simple types like char and int, but not larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * data types like structures or arrays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  * @ptr must have pointer-to-simple-variable type, and @x must be assignable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  * to the result of dereferencing @ptr. The value of @x is copied to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * re-ordering where @x is evaluated inside the block that enables user-space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  * access (thus bypassing user space protection if @x is a function).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  * Caller must check the pointer with access_ok() before calling this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  * function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  * Returns zero on success, or -EFAULT on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) #define __put_user(x, ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	__typeof__(*(ptr)) __user *__gu_ptr = (ptr);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	__typeof__(*__gu_ptr) __val = (x);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	long __pu_err = 0;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	__chk_user_ptr(__gu_ptr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	__enable_user_access();					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	__put_user_nocheck(__val, __gu_ptr, __pu_err);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	__disable_user_access();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	__pu_err;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * put_user: - Write a simple value into user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * @x:   Value to copy to user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * @ptr: Destination address, in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  * Context: User context only.  This function may sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  * This macro copies a single simple value from kernel space to user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  * space.  It supports simple types like char and int, but not larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  * data types like structures or arrays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)  * @ptr must have pointer-to-simple-variable type, and @x must be assignable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)  * to the result of dereferencing @ptr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  * Returns zero on success, or -EFAULT on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) #define put_user(x, ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	__typeof__(*(ptr)) __user *__p = (ptr);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	might_fault();						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	access_ok(__p, sizeof(*__p)) ?		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		__put_user((x), __p) :				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		-EFAULT;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) unsigned long __must_check __asm_copy_to_user(void __user *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	const void *from, unsigned long n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) unsigned long __must_check __asm_copy_from_user(void *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	const void __user *from, unsigned long n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) raw_copy_from_user(void *to, const void __user *from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return __asm_copy_from_user(to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) raw_copy_to_user(void __user *to, const void *from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	return __asm_copy_to_user(to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) extern long strncpy_from_user(char *dest, const char __user *src, long count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) extern long __must_check strlen_user(const char __user *str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) extern long __must_check strnlen_user(const char __user *str, long n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) extern
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) unsigned long __must_check clear_user(void __user *to, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	might_fault();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	return access_ok(to, n) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		__clear_user(to, n) : n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  * Atomic compare-and-exchange, but with a fixup for userspace faults.  Faults
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  * will set "err" to -EFAULT, while successful accesses return the previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  * value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) #define __cmpxchg_user(ptr, old, new, err, size, lrb, scb)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	__typeof__(ptr) __ptr = (ptr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	__typeof__(*(ptr)) __old = (old);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	__typeof__(*(ptr)) __new = (new);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	__typeof__(*(ptr)) __ret;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	__typeof__(err) __err = 0;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	register unsigned int __rc;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	__enable_user_access();					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	switch (size) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	case 4:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		__asm__ __volatile__ (				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		"0:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		"	lr.w" #scb " %[ret], %[ptr]\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		"	bne          %[ret], %z[old], 1f\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		"	sc.w" #lrb " %[rc], %z[new], %[ptr]\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		"	bnez         %[rc], 0b\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		"1:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		".section .fixup,\"ax\"\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		".balign 4\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		"2:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		"	li %[err], %[efault]\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		"	jump 1b, %[rc]\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		".previous\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		".section __ex_table,\"a\"\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		".balign " RISCV_SZPTR "\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		"	" RISCV_PTR " 1b, 2b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		".previous\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			: [ret] "=&r" (__ret),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			  [rc]  "=&r" (__rc),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 			  [ptr] "+A" (*__ptr),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			  [err] "=&r" (__err)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			: [old] "rJ" (__old),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			  [new] "rJ" (__new),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			  [efault] "i" (-EFAULT));		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	case 8:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		__asm__ __volatile__ (				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		"0:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		"	lr.d" #scb " %[ret], %[ptr]\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		"	bne          %[ret], %z[old], 1f\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		"	sc.d" #lrb " %[rc], %z[new], %[ptr]\n"	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		"	bnez         %[rc], 0b\n"		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		"1:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		".section .fixup,\"ax\"\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		".balign 4\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		"2:\n"						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		"	li %[err], %[efault]\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		"	jump 1b, %[rc]\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		".previous\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		".section __ex_table,\"a\"\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		".balign " RISCV_SZPTR "\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		"	" RISCV_PTR " 1b, 2b\n"			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		".previous\n"					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			: [ret] "=&r" (__ret),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			  [rc]  "=&r" (__rc),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			  [ptr] "+A" (*__ptr),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			  [err] "=&r" (__err)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 			: [old] "rJ" (__old),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			  [new] "rJ" (__new),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			  [efault] "i" (-EFAULT));		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	default:						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		BUILD_BUG();					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	__disable_user_access();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	(err) = __err;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	__ret;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) #define HAVE_GET_KERNEL_NOFAULT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) #define __get_kernel_nofault(dst, src, type, err_label)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	long __kr_err;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	__get_user_nocheck(*((type *)(dst)), (type *)(src), __kr_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	if (unlikely(__kr_err))						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		goto err_label;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) #define __put_kernel_nofault(dst, src, type, err_label)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	long __kr_err;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	__put_user_nocheck(*((type *)(src)), (type *)(dst), __kr_err);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	if (unlikely(__kr_err))						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		goto err_label;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) #else /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) #include <asm-generic/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) #endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) #endif /* _ASM_RISCV_UACCESS_H */