1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2deae26bfSKyle McMartin #ifndef __PARISC_UACCESS_H 3deae26bfSKyle McMartin #define __PARISC_UACCESS_H 4deae26bfSKyle McMartin 5deae26bfSKyle McMartin /* 6deae26bfSKyle McMartin * User space memory access functions 7deae26bfSKyle McMartin */ 8deae26bfSKyle McMartin #include <asm/page.h> 9deae26bfSKyle McMartin #include <asm/cache.h> 10deae26bfSKyle McMartin 118dd95c68SHelge Deller #include <linux/bug.h> 12aace880fSAl Viro #include <linux/string.h> 13deae26bfSKyle McMartin 14deae26bfSKyle McMartin /* 15deae26bfSKyle McMartin * Note that since kernel addresses are in a separate address space on 16deae26bfSKyle McMartin * parisc, we don't need to do anything for access_ok(). 17deae26bfSKyle McMartin * We just let the page fault handler do the right thing. This also means 18deae26bfSKyle McMartin * that put_user is the same as __put_user, etc. 19deae26bfSKyle McMartin */ 20deae26bfSKyle McMartin 2196d4f267SLinus Torvalds #define access_ok(uaddr, size) \ 22186ecf14SHelge Deller ( (uaddr) == (uaddr) ) 23deae26bfSKyle McMartin 24deae26bfSKyle McMartin #define put_user __put_user 25deae26bfSKyle McMartin #define get_user __get_user 26deae26bfSKyle McMartin 27deae26bfSKyle McMartin #if !defined(CONFIG_64BIT) 28*67102872SHelge Deller #define LDD_USER(sr, val, ptr) __get_user_asm64(sr, val, ptr) 29*67102872SHelge Deller #define STD_USER(sr, x, ptr) __put_user_asm64(sr, x, ptr) 30deae26bfSKyle McMartin #else 31*67102872SHelge Deller #define LDD_USER(sr, val, ptr) __get_user_asm(sr, val, "ldd", ptr) 32*67102872SHelge Deller #define STD_USER(sr, x, ptr) __put_user_asm(sr, "std", x, ptr) 33deae26bfSKyle McMartin #endif 34deae26bfSKyle McMartin 35deae26bfSKyle McMartin /* 36cb910c17SHelge Deller * The exception table contains two values: the first is the relative offset to 37cb910c17SHelge Deller * the address of the instruction that is allowed to fault, and the second is 38cb910c17SHelge Deller * the relative offset to the address of the fixup routine. Since relative 39cb910c17SHelge Deller * addresses are used, 32bit values are sufficient even on 64bit kernel. 40deae26bfSKyle McMartin */ 41deae26bfSKyle McMartin 420de79858SHelge Deller #define ARCH_HAS_RELATIVE_EXTABLE 43deae26bfSKyle McMartin struct exception_table_entry { 440de79858SHelge Deller int insn; /* relative address of insn that is allowed to fault. */ 450de79858SHelge Deller int fixup; /* relative address of fixup routine */ 46deae26bfSKyle McMartin }; 47deae26bfSKyle McMartin 48deae26bfSKyle McMartin #define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr )\ 49deae26bfSKyle McMartin ".section __ex_table,\"aw\"\n" \ 500de79858SHelge Deller ".word (" #fault_addr " - .), (" #except_addr " - .)\n\t" \ 51deae26bfSKyle McMartin ".previous\n" 52deae26bfSKyle McMartin 53deae26bfSKyle McMartin /* 54d19f5e41SHelge Deller * ASM_EXCEPTIONTABLE_ENTRY_EFAULT() creates a special exception table entry 55d19f5e41SHelge Deller * (with lowest bit set) for which the fault handler in fixup_exception() will 56d19f5e41SHelge Deller * load -EFAULT into %r8 for a read or write fault, and zeroes the target 57d19f5e41SHelge Deller * register in case of a read fault in get_user(). 58d19f5e41SHelge Deller */ 59d19f5e41SHelge Deller #define ASM_EXCEPTIONTABLE_ENTRY_EFAULT( fault_addr, except_addr )\ 60d19f5e41SHelge Deller ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr + 1) 61d19f5e41SHelge Deller 62*67102872SHelge Deller #define __get_user_internal(sr, val, ptr) \ 63deae26bfSKyle McMartin ({ \ 64deae26bfSKyle McMartin register long __gu_err __asm__ ("r8") = 0; \ 65deae26bfSKyle McMartin \ 66deae26bfSKyle McMartin switch (sizeof(*(ptr))) { \ 67*67102872SHelge Deller case 1: __get_user_asm(sr, val, "ldb", ptr); break; \ 68*67102872SHelge Deller case 2: __get_user_asm(sr, val, "ldh", ptr); break; \ 69*67102872SHelge Deller case 4: __get_user_asm(sr, val, "ldw", ptr); break; \ 70*67102872SHelge Deller case 8: LDD_USER(sr, val, ptr); break; \ 713f795cefSHelge Deller default: BUILD_BUG(); \ 72deae26bfSKyle McMartin } \ 73deae26bfSKyle McMartin \ 74deae26bfSKyle McMartin __gu_err; \ 75deae26bfSKyle McMartin }) 76deae26bfSKyle McMartin 773f795cefSHelge Deller #define __get_user(val, ptr) \ 783f795cefSHelge Deller ({ \ 79*67102872SHelge Deller __get_user_internal("%%sr3,", val, ptr); \ 803f795cefSHelge Deller }) 813f795cefSHelge Deller 82*67102872SHelge Deller #define __get_user_asm(sr, val, ldx, ptr) \ 833f795cefSHelge Deller { \ 843f795cefSHelge Deller register long __gu_val; \ 853f795cefSHelge Deller \ 86*67102872SHelge Deller __asm__("1: " ldx " 0(" sr "%2),%0\n" \ 87d19f5e41SHelge Deller "9:\n" \ 88d19f5e41SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ 89deae26bfSKyle McMartin : "=r"(__gu_val), "=r"(__gu_err) \ 903f795cefSHelge Deller : "r"(ptr), "1"(__gu_err)); \ 913f795cefSHelge Deller \ 923f795cefSHelge Deller (val) = (__force __typeof__(*(ptr))) __gu_val; \ 933f795cefSHelge Deller } 94deae26bfSKyle McMartin 95*67102872SHelge Deller #define HAVE_GET_KERNEL_NOFAULT 96*67102872SHelge Deller #define __get_kernel_nofault(dst, src, type, err_label) \ 97*67102872SHelge Deller { \ 98*67102872SHelge Deller type __z; \ 99*67102872SHelge Deller long __err; \ 100*67102872SHelge Deller __err = __get_user_internal("%%sr0,", __z, (type *)(src)); \ 101*67102872SHelge Deller if (unlikely(__err)) \ 102*67102872SHelge Deller goto err_label; \ 103*67102872SHelge Deller else \ 104*67102872SHelge Deller *(type *)(dst) = __z; \ 105*67102872SHelge Deller } 106*67102872SHelge Deller 107*67102872SHelge Deller 108d2ad824fSHelge Deller #if !defined(CONFIG_64BIT) 109d2ad824fSHelge Deller 110*67102872SHelge Deller #define __get_user_asm64(sr, val, ptr) \ 1113f795cefSHelge Deller { \ 1123f795cefSHelge Deller union { \ 1133f795cefSHelge Deller unsigned long long l; \ 1143f795cefSHelge Deller __typeof__(*(ptr)) t; \ 1153f795cefSHelge Deller } __gu_tmp; \ 1163f795cefSHelge Deller \ 117d19f5e41SHelge Deller __asm__(" copy %%r0,%R0\n" \ 118*67102872SHelge Deller "1: ldw 0(" sr "%2),%0\n" \ 119*67102872SHelge Deller "2: ldw 4(" sr "%2),%R0\n" \ 120d19f5e41SHelge Deller "9:\n" \ 121d19f5e41SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ 122d19f5e41SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \ 1233f795cefSHelge Deller : "=&r"(__gu_tmp.l), "=r"(__gu_err) \ 1243f795cefSHelge Deller : "r"(ptr), "1"(__gu_err)); \ 1253f795cefSHelge Deller \ 1263f795cefSHelge Deller (val) = __gu_tmp.t; \ 1273f795cefSHelge Deller } 128d2ad824fSHelge Deller 129d2ad824fSHelge Deller #endif /* !defined(CONFIG_64BIT) */ 130d2ad824fSHelge Deller 131d2ad824fSHelge Deller 132*67102872SHelge Deller #define __put_user_internal(sr, x, ptr) \ 133deae26bfSKyle McMartin ({ \ 134deae26bfSKyle McMartin register long __pu_err __asm__ ("r8") = 0; \ 135deae26bfSKyle McMartin __typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x); \ 136deae26bfSKyle McMartin \ 137deae26bfSKyle McMartin switch (sizeof(*(ptr))) { \ 138*67102872SHelge Deller case 1: __put_user_asm(sr, "stb", __x, ptr); break; \ 139*67102872SHelge Deller case 2: __put_user_asm(sr, "sth", __x, ptr); break; \ 140*67102872SHelge Deller case 4: __put_user_asm(sr, "stw", __x, ptr); break; \ 141*67102872SHelge Deller case 8: STD_USER(sr, __x, ptr); break; \ 1423f795cefSHelge Deller default: BUILD_BUG(); \ 143deae26bfSKyle McMartin } \ 144deae26bfSKyle McMartin \ 145deae26bfSKyle McMartin __pu_err; \ 146deae26bfSKyle McMartin }) 147deae26bfSKyle McMartin 1483f795cefSHelge Deller #define __put_user(x, ptr) \ 1493f795cefSHelge Deller ({ \ 150*67102872SHelge Deller __put_user_internal("%%sr3,", x, ptr); \ 1513f795cefSHelge Deller }) 1523f795cefSHelge Deller 153*67102872SHelge Deller #define __put_kernel_nofault(dst, src, type, err_label) \ 154*67102872SHelge Deller { \ 155*67102872SHelge Deller type __z = *(type *)(src); \ 156*67102872SHelge Deller long __err; \ 157*67102872SHelge Deller __err = __put_user_internal("%%sr0,", __z, (type *)(dst)); \ 158*67102872SHelge Deller if (unlikely(__err)) \ 159*67102872SHelge Deller goto err_label; \ 160*67102872SHelge Deller } 161*67102872SHelge Deller 162*67102872SHelge Deller 163*67102872SHelge Deller 1643f795cefSHelge Deller 165deae26bfSKyle McMartin /* 166deae26bfSKyle McMartin * The "__put_user/kernel_asm()" macros tell gcc they read from memory 167deae26bfSKyle McMartin * instead of writing. This is because they do not write to any memory 168deae26bfSKyle McMartin * gcc knows about, so there are no aliasing issues. These macros must 169d19f5e41SHelge Deller * also be aware that fixups are executed in the context of the fault, 170d19f5e41SHelge Deller * and any registers used there must be listed as clobbers. 171d19f5e41SHelge Deller * r8 is already listed as err. 172deae26bfSKyle McMartin */ 173deae26bfSKyle McMartin 174*67102872SHelge Deller #define __put_user_asm(sr, stx, x, ptr) \ 175deae26bfSKyle McMartin __asm__ __volatile__ ( \ 176*67102872SHelge Deller "1: " stx " %2,0(" sr "%1)\n" \ 177d19f5e41SHelge Deller "9:\n" \ 178d19f5e41SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ 179deae26bfSKyle McMartin : "=r"(__pu_err) \ 180d19f5e41SHelge Deller : "r"(ptr), "r"(x), "0"(__pu_err)) 181deae26bfSKyle McMartin 182deae26bfSKyle McMartin 183deae26bfSKyle McMartin #if !defined(CONFIG_64BIT) 184deae26bfSKyle McMartin 185*67102872SHelge Deller #define __put_user_asm64(sr, __val, ptr) do { \ 186deae26bfSKyle McMartin __asm__ __volatile__ ( \ 187*67102872SHelge Deller "1: stw %2,0(" sr "%1)\n" \ 188*67102872SHelge Deller "2: stw %R2,4(" sr "%1)\n" \ 189d19f5e41SHelge Deller "9:\n" \ 190d19f5e41SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ 191d19f5e41SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \ 192deae26bfSKyle McMartin : "=r"(__pu_err) \ 193d19f5e41SHelge Deller : "r"(ptr), "r"(__val), "0"(__pu_err)); \ 194deae26bfSKyle McMartin } while (0) 195deae26bfSKyle McMartin 196deae26bfSKyle McMartin #endif /* !defined(CONFIG_64BIT) */ 197deae26bfSKyle McMartin 198deae26bfSKyle McMartin 199deae26bfSKyle McMartin /* 200deae26bfSKyle McMartin * Complex access routines -- external declarations 201deae26bfSKyle McMartin */ 202deae26bfSKyle McMartin 203b1195c0eSJames Bottomley extern long strncpy_from_user(char *, const char __user *, long); 204*67102872SHelge Deller extern __must_check unsigned lclear_user(void __user *, unsigned long); 2051260dea6SHelge Deller extern __must_check long strnlen_user(const char __user *src, long n); 206deae26bfSKyle McMartin /* 207deae26bfSKyle McMartin * Complex access routines -- macros 208deae26bfSKyle McMartin */ 209deae26bfSKyle McMartin 210deae26bfSKyle McMartin #define clear_user lclear_user 211deae26bfSKyle McMartin #define __clear_user lclear_user 212deae26bfSKyle McMartin 213f64fd180SAl Viro unsigned long __must_check raw_copy_to_user(void __user *dst, const void *src, 2149e91db6bSHelge Deller unsigned long len); 215f64fd180SAl Viro unsigned long __must_check raw_copy_from_user(void *dst, const void __user *src, 2169e91db6bSHelge Deller unsigned long len); 217f64fd180SAl Viro #define INLINE_COPY_TO_USER 218f64fd180SAl Viro #define INLINE_COPY_FROM_USER 2199e91db6bSHelge Deller 220e448372cSHelge Deller struct pt_regs; 221c61c25ebSKyle McMartin int fixup_exception(struct pt_regs *regs); 222c61c25ebSKyle McMartin 223deae26bfSKyle McMartin #endif /* __PARISC_UACCESS_H */ 224