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> 10*fa69a806SHelge Deller #include <asm/extable.h> 11deae26bfSKyle McMartin 128dd95c68SHelge Deller #include <linux/bug.h> 13aace880fSAl Viro #include <linux/string.h> 14deae26bfSKyle McMartin 1512700c17SArnd Bergmann #define TASK_SIZE_MAX DEFAULT_TASK_SIZE 1612700c17SArnd Bergmann #include <asm/pgtable.h> 1712700c17SArnd Bergmann #include <asm-generic/access_ok.h> 18deae26bfSKyle McMartin 19deae26bfSKyle McMartin #define put_user __put_user 20deae26bfSKyle McMartin #define get_user __get_user 21deae26bfSKyle McMartin 22deae26bfSKyle McMartin #if !defined(CONFIG_64BIT) 2367102872SHelge Deller #define LDD_USER(sr, val, ptr) __get_user_asm64(sr, val, ptr) 2467102872SHelge Deller #define STD_USER(sr, x, ptr) __put_user_asm64(sr, x, ptr) 25deae26bfSKyle McMartin #else 2667102872SHelge Deller #define LDD_USER(sr, val, ptr) __get_user_asm(sr, val, "ldd", ptr) 2767102872SHelge Deller #define STD_USER(sr, x, ptr) __put_user_asm(sr, "std", x, ptr) 28deae26bfSKyle McMartin #endif 29deae26bfSKyle McMartin 3067102872SHelge Deller #define __get_user_internal(sr, val, ptr) \ 31deae26bfSKyle McMartin ({ \ 324b9d2a73SHelge Deller ASM_EXCEPTIONTABLE_VAR(__gu_err); \ 33deae26bfSKyle McMartin \ 34deae26bfSKyle McMartin switch (sizeof(*(ptr))) { \ 3567102872SHelge Deller case 1: __get_user_asm(sr, val, "ldb", ptr); break; \ 3667102872SHelge Deller case 2: __get_user_asm(sr, val, "ldh", ptr); break; \ 3767102872SHelge Deller case 4: __get_user_asm(sr, val, "ldw", ptr); break; \ 3867102872SHelge Deller case 8: LDD_USER(sr, val, ptr); break; \ 393f795cefSHelge Deller default: BUILD_BUG(); \ 40deae26bfSKyle McMartin } \ 41deae26bfSKyle McMartin \ 42deae26bfSKyle McMartin __gu_err; \ 43deae26bfSKyle McMartin }) 44deae26bfSKyle McMartin 453f795cefSHelge Deller #define __get_user(val, ptr) \ 463f795cefSHelge Deller ({ \ 475613a930SHelge Deller __get_user_internal(SR_USER, val, ptr); \ 483f795cefSHelge Deller }) 493f795cefSHelge Deller 5067102872SHelge Deller #define __get_user_asm(sr, val, ldx, ptr) \ 513f795cefSHelge Deller { \ 523f795cefSHelge Deller register long __gu_val; \ 533f795cefSHelge Deller \ 545613a930SHelge Deller __asm__("1: " ldx " 0(%%sr%2,%3),%0\n" \ 55d19f5e41SHelge Deller "9:\n" \ 56*fa69a806SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b, "%1") \ 57dbd0b423SHelge Deller : "=r"(__gu_val), "+r"(__gu_err) \ 585613a930SHelge Deller : "i"(sr), "r"(ptr)); \ 593f795cefSHelge Deller \ 603f795cefSHelge Deller (val) = (__force __typeof__(*(ptr))) __gu_val; \ 613f795cefSHelge Deller } 62deae26bfSKyle McMartin 6367102872SHelge Deller #define __get_kernel_nofault(dst, src, type, err_label) \ 6467102872SHelge Deller { \ 6567102872SHelge Deller type __z; \ 6667102872SHelge Deller long __err; \ 675613a930SHelge Deller __err = __get_user_internal(SR_KERNEL, __z, (type *)(src)); \ 6867102872SHelge Deller if (unlikely(__err)) \ 6967102872SHelge Deller goto err_label; \ 7067102872SHelge Deller else \ 7167102872SHelge Deller *(type *)(dst) = __z; \ 7267102872SHelge Deller } 7367102872SHelge Deller 7467102872SHelge Deller 75d2ad824fSHelge Deller #if !defined(CONFIG_64BIT) 76d2ad824fSHelge Deller 7767102872SHelge Deller #define __get_user_asm64(sr, val, ptr) \ 783f795cefSHelge Deller { \ 793f795cefSHelge Deller union { \ 803f795cefSHelge Deller unsigned long long l; \ 813f795cefSHelge Deller __typeof__(*(ptr)) t; \ 823f795cefSHelge Deller } __gu_tmp; \ 833f795cefSHelge Deller \ 84d19f5e41SHelge Deller __asm__(" copy %%r0,%R0\n" \ 855613a930SHelge Deller "1: ldw 0(%%sr%2,%3),%0\n" \ 865613a930SHelge Deller "2: ldw 4(%%sr%2,%3),%R0\n" \ 87d19f5e41SHelge Deller "9:\n" \ 88*fa69a806SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b, "%1") \ 89*fa69a806SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b, "%1") \ 90dbd0b423SHelge Deller : "=&r"(__gu_tmp.l), "+r"(__gu_err) \ 915613a930SHelge Deller : "i"(sr), "r"(ptr)); \ 923f795cefSHelge Deller \ 933f795cefSHelge Deller (val) = __gu_tmp.t; \ 943f795cefSHelge Deller } 95d2ad824fSHelge Deller 96d2ad824fSHelge Deller #endif /* !defined(CONFIG_64BIT) */ 97d2ad824fSHelge Deller 98d2ad824fSHelge Deller 9967102872SHelge Deller #define __put_user_internal(sr, x, ptr) \ 100deae26bfSKyle McMartin ({ \ 1014b9d2a73SHelge Deller ASM_EXCEPTIONTABLE_VAR(__pu_err); \ 102deae26bfSKyle McMartin \ 103deae26bfSKyle McMartin switch (sizeof(*(ptr))) { \ 104dbd0b423SHelge Deller case 1: __put_user_asm(sr, "stb", x, ptr); break; \ 105dbd0b423SHelge Deller case 2: __put_user_asm(sr, "sth", x, ptr); break; \ 106dbd0b423SHelge Deller case 4: __put_user_asm(sr, "stw", x, ptr); break; \ 107dbd0b423SHelge Deller case 8: STD_USER(sr, x, ptr); break; \ 1083f795cefSHelge Deller default: BUILD_BUG(); \ 109deae26bfSKyle McMartin } \ 110deae26bfSKyle McMartin \ 111deae26bfSKyle McMartin __pu_err; \ 112deae26bfSKyle McMartin }) 113deae26bfSKyle McMartin 1143f795cefSHelge Deller #define __put_user(x, ptr) \ 1153f795cefSHelge Deller ({ \ 116dbd0b423SHelge Deller __typeof__(&*(ptr)) __ptr = ptr; \ 117dbd0b423SHelge Deller __typeof__(*(__ptr)) __x = (__typeof__(*(__ptr)))(x); \ 1185613a930SHelge Deller __put_user_internal(SR_USER, __x, __ptr); \ 1193f795cefSHelge Deller }) 1203f795cefSHelge Deller 12167102872SHelge Deller #define __put_kernel_nofault(dst, src, type, err_label) \ 12267102872SHelge Deller { \ 12367102872SHelge Deller type __z = *(type *)(src); \ 12467102872SHelge Deller long __err; \ 1255613a930SHelge Deller __err = __put_user_internal(SR_KERNEL, __z, (type *)(dst)); \ 12667102872SHelge Deller if (unlikely(__err)) \ 12767102872SHelge Deller goto err_label; \ 12867102872SHelge Deller } 12967102872SHelge Deller 13067102872SHelge Deller 13167102872SHelge Deller 1323f795cefSHelge Deller 133deae26bfSKyle McMartin /* 134deae26bfSKyle McMartin * The "__put_user/kernel_asm()" macros tell gcc they read from memory 135deae26bfSKyle McMartin * instead of writing. This is because they do not write to any memory 136deae26bfSKyle McMartin * gcc knows about, so there are no aliasing issues. These macros must 137d19f5e41SHelge Deller * also be aware that fixups are executed in the context of the fault, 138d19f5e41SHelge Deller * and any registers used there must be listed as clobbers. 1394b9d2a73SHelge Deller * The register holding the possible EFAULT error (ASM_EXCEPTIONTABLE_REG) 1404b9d2a73SHelge Deller * is already listed as input and output register. 141deae26bfSKyle McMartin */ 142deae26bfSKyle McMartin 14367102872SHelge Deller #define __put_user_asm(sr, stx, x, ptr) \ 144deae26bfSKyle McMartin __asm__ __volatile__ ( \ 1455613a930SHelge Deller "1: " stx " %1,0(%%sr%2,%3)\n" \ 146d19f5e41SHelge Deller "9:\n" \ 147*fa69a806SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b, "%0") \ 148dbd0b423SHelge Deller : "+r"(__pu_err) \ 1495613a930SHelge Deller : "r"(x), "i"(sr), "r"(ptr)) 150deae26bfSKyle McMartin 151deae26bfSKyle McMartin 152deae26bfSKyle McMartin #if !defined(CONFIG_64BIT) 153deae26bfSKyle McMartin 15467102872SHelge Deller #define __put_user_asm64(sr, __val, ptr) do { \ 155deae26bfSKyle McMartin __asm__ __volatile__ ( \ 1565613a930SHelge Deller "1: stw %1,0(%%sr%2,%3)\n" \ 1575613a930SHelge Deller "2: stw %R1,4(%%sr%2,%3)\n" \ 158d19f5e41SHelge Deller "9:\n" \ 159*fa69a806SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b, "%0") \ 160*fa69a806SHelge Deller ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b, "%0") \ 161dbd0b423SHelge Deller : "+r"(__pu_err) \ 1625613a930SHelge Deller : "r"(__val), "i"(sr), "r"(ptr)); \ 163deae26bfSKyle McMartin } while (0) 164deae26bfSKyle McMartin 165deae26bfSKyle McMartin #endif /* !defined(CONFIG_64BIT) */ 166deae26bfSKyle McMartin 167deae26bfSKyle McMartin /* 168deae26bfSKyle McMartin * Complex access routines -- external declarations 169deae26bfSKyle McMartin */ 170deae26bfSKyle McMartin 171b1195c0eSJames Bottomley extern long strncpy_from_user(char *, const char __user *, long); 17267102872SHelge Deller extern __must_check unsigned lclear_user(void __user *, unsigned long); 1731260dea6SHelge Deller extern __must_check long strnlen_user(const char __user *src, long n); 174deae26bfSKyle McMartin /* 175deae26bfSKyle McMartin * Complex access routines -- macros 176deae26bfSKyle McMartin */ 177deae26bfSKyle McMartin 178deae26bfSKyle McMartin #define clear_user lclear_user 179deae26bfSKyle McMartin #define __clear_user lclear_user 180deae26bfSKyle McMartin 181f64fd180SAl Viro unsigned long __must_check raw_copy_to_user(void __user *dst, const void *src, 1829e91db6bSHelge Deller unsigned long len); 183f64fd180SAl Viro unsigned long __must_check raw_copy_from_user(void *dst, const void __user *src, 1849e91db6bSHelge Deller unsigned long len); 185f64fd180SAl Viro #define INLINE_COPY_TO_USER 186f64fd180SAl Viro #define INLINE_COPY_FROM_USER 1879e91db6bSHelge Deller 188deae26bfSKyle McMartin #endif /* __PARISC_UACCESS_H */ 189