Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef __PARISC_UACCESS_H |
| 3 | #define __PARISC_UACCESS_H |
| 4 | |
| 5 | /* |
| 6 | * User space memory access functions |
| 7 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <asm/page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <asm/cache.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Helge Deller | 8dd95c6 | 2014-10-21 21:29:09 +0200 | [diff] [blame] | 11 | #include <linux/bug.h> |
Al Viro | aace880 | 2016-08-20 19:03:37 -0400 | [diff] [blame] | 12 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | /* |
| 15 | * Note that since kernel addresses are in a separate address space on |
Jesper Juhl | e49332b | 2005-05-01 08:59:08 -0700 | [diff] [blame] | 16 | * parisc, we don't need to do anything for access_ok(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * We just let the page fault handler do the right thing. This also means |
| 18 | * that put_user is the same as __put_user, etc. |
| 19 | */ |
| 20 | |
Linus Torvalds | 96d4f26 | 2019-01-03 18:57:57 -0800 | [diff] [blame] | 21 | #define access_ok(uaddr, size) \ |
Helge Deller | 186ecf1 | 2017-03-15 21:48:42 +0100 | [diff] [blame] | 22 | ( (uaddr) == (uaddr) ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #define put_user __put_user |
| 25 | #define get_user __get_user |
| 26 | |
Helge Deller | ca72a22 | 2006-12-20 00:35:57 +0100 | [diff] [blame] | 27 | #if !defined(CONFIG_64BIT) |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 28 | #define LDD_USER(sr, val, ptr) __get_user_asm64(sr, val, ptr) |
| 29 | #define STD_USER(sr, x, ptr) __put_user_asm64(sr, x, ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #else |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 31 | #define LDD_USER(sr, val, ptr) __get_user_asm(sr, val, "ldd", ptr) |
| 32 | #define STD_USER(sr, x, ptr) __put_user_asm(sr, "std", x, ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #endif |
| 34 | |
| 35 | /* |
Helge Deller | cb910c1 | 2016-04-08 21:36:06 +0200 | [diff] [blame] | 36 | * The exception table contains two values: the first is the relative offset to |
| 37 | * the address of the instruction that is allowed to fault, and the second is |
| 38 | * the relative offset to the address of the fixup routine. Since relative |
| 39 | * addresses are used, 32bit values are sufficient even on 64bit kernel. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | */ |
| 41 | |
Helge Deller | 0de7985 | 2016-03-23 16:00:46 +0100 | [diff] [blame] | 42 | #define ARCH_HAS_RELATIVE_EXTABLE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | struct exception_table_entry { |
Helge Deller | 0de7985 | 2016-03-23 16:00:46 +0100 | [diff] [blame] | 44 | int insn; /* relative address of insn that is allowed to fault. */ |
| 45 | int fixup; /* relative address of fixup routine */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
Helge Deller | 0b3d643 | 2007-01-28 14:52:57 +0100 | [diff] [blame] | 48 | #define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr )\ |
| 49 | ".section __ex_table,\"aw\"\n" \ |
Helge Deller | 0de7985 | 2016-03-23 16:00:46 +0100 | [diff] [blame] | 50 | ".word (" #fault_addr " - .), (" #except_addr " - .)\n\t" \ |
Helge Deller | 0b3d643 | 2007-01-28 14:52:57 +0100 | [diff] [blame] | 51 | ".previous\n" |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* |
Helge Deller | d19f5e4 | 2017-03-25 11:59:15 +0100 | [diff] [blame] | 54 | * ASM_EXCEPTIONTABLE_ENTRY_EFAULT() creates a special exception table entry |
| 55 | * (with lowest bit set) for which the fault handler in fixup_exception() will |
Helge Deller | 4b9d2a7 | 2021-12-23 21:46:35 +0100 | [diff] [blame] | 56 | * load -EFAULT into %r29 for a read or write fault, and zeroes the target |
Helge Deller | d19f5e4 | 2017-03-25 11:59:15 +0100 | [diff] [blame] | 57 | * register in case of a read fault in get_user(). |
| 58 | */ |
Helge Deller | 4b9d2a7 | 2021-12-23 21:46:35 +0100 | [diff] [blame] | 59 | #define ASM_EXCEPTIONTABLE_REG 29 |
| 60 | #define ASM_EXCEPTIONTABLE_VAR(__variable) \ |
| 61 | register long __variable __asm__ ("r29") = 0 |
Helge Deller | d19f5e4 | 2017-03-25 11:59:15 +0100 | [diff] [blame] | 62 | #define ASM_EXCEPTIONTABLE_ENTRY_EFAULT( fault_addr, except_addr )\ |
| 63 | ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr + 1) |
| 64 | |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 65 | #define __get_user_internal(sr, val, ptr) \ |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 66 | ({ \ |
Helge Deller | 4b9d2a7 | 2021-12-23 21:46:35 +0100 | [diff] [blame] | 67 | ASM_EXCEPTIONTABLE_VAR(__gu_err); \ |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 68 | \ |
| 69 | switch (sizeof(*(ptr))) { \ |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 70 | case 1: __get_user_asm(sr, val, "ldb", ptr); break; \ |
| 71 | case 2: __get_user_asm(sr, val, "ldh", ptr); break; \ |
| 72 | case 4: __get_user_asm(sr, val, "ldw", ptr); break; \ |
| 73 | case 8: LDD_USER(sr, val, ptr); break; \ |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 74 | default: BUILD_BUG(); \ |
| 75 | } \ |
| 76 | \ |
| 77 | __gu_err; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | }) |
| 79 | |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 80 | #define __get_user(val, ptr) \ |
| 81 | ({ \ |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 82 | __get_user_internal("%%sr3,", val, ptr); \ |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 83 | }) |
| 84 | |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 85 | #define __get_user_asm(sr, val, ldx, ptr) \ |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 86 | { \ |
| 87 | register long __gu_val; \ |
| 88 | \ |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 89 | __asm__("1: " ldx " 0(" sr "%2),%0\n" \ |
Helge Deller | d19f5e4 | 2017-03-25 11:59:15 +0100 | [diff] [blame] | 90 | "9:\n" \ |
| 91 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ |
Helge Deller | dbd0b42 | 2022-02-13 22:52:11 +0100 | [diff] [blame] | 92 | : "=r"(__gu_val), "+r"(__gu_err) \ |
| 93 | : "r"(ptr)); \ |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 94 | \ |
| 95 | (val) = (__force __typeof__(*(ptr))) __gu_val; \ |
| 96 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 98 | #define HAVE_GET_KERNEL_NOFAULT |
| 99 | #define __get_kernel_nofault(dst, src, type, err_label) \ |
| 100 | { \ |
| 101 | type __z; \ |
| 102 | long __err; \ |
| 103 | __err = __get_user_internal("%%sr0,", __z, (type *)(src)); \ |
| 104 | if (unlikely(__err)) \ |
| 105 | goto err_label; \ |
| 106 | else \ |
| 107 | *(type *)(dst) = __z; \ |
| 108 | } |
| 109 | |
| 110 | |
Helge Deller | d2ad824 | 2016-04-09 08:27:08 +0200 | [diff] [blame] | 111 | #if !defined(CONFIG_64BIT) |
| 112 | |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 113 | #define __get_user_asm64(sr, val, ptr) \ |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 114 | { \ |
| 115 | union { \ |
| 116 | unsigned long long l; \ |
| 117 | __typeof__(*(ptr)) t; \ |
| 118 | } __gu_tmp; \ |
| 119 | \ |
Helge Deller | d19f5e4 | 2017-03-25 11:59:15 +0100 | [diff] [blame] | 120 | __asm__(" copy %%r0,%R0\n" \ |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 121 | "1: ldw 0(" sr "%2),%0\n" \ |
| 122 | "2: ldw 4(" sr "%2),%R0\n" \ |
Helge Deller | d19f5e4 | 2017-03-25 11:59:15 +0100 | [diff] [blame] | 123 | "9:\n" \ |
| 124 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ |
| 125 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \ |
Helge Deller | dbd0b42 | 2022-02-13 22:52:11 +0100 | [diff] [blame] | 126 | : "=&r"(__gu_tmp.l), "+r"(__gu_err) \ |
| 127 | : "r"(ptr)); \ |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 128 | \ |
| 129 | (val) = __gu_tmp.t; \ |
| 130 | } |
Helge Deller | d2ad824 | 2016-04-09 08:27:08 +0200 | [diff] [blame] | 131 | |
| 132 | #endif /* !defined(CONFIG_64BIT) */ |
| 133 | |
| 134 | |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 135 | #define __put_user_internal(sr, x, ptr) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | ({ \ |
Helge Deller | 4b9d2a7 | 2021-12-23 21:46:35 +0100 | [diff] [blame] | 137 | ASM_EXCEPTIONTABLE_VAR(__pu_err); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | \ |
Helge Deller | 06bff6b | 2016-04-09 08:26:14 +0200 | [diff] [blame] | 139 | switch (sizeof(*(ptr))) { \ |
Helge Deller | dbd0b42 | 2022-02-13 22:52:11 +0100 | [diff] [blame] | 140 | case 1: __put_user_asm(sr, "stb", x, ptr); break; \ |
| 141 | case 2: __put_user_asm(sr, "sth", x, ptr); break; \ |
| 142 | case 4: __put_user_asm(sr, "stw", x, ptr); break; \ |
| 143 | case 8: STD_USER(sr, x, ptr); break; \ |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 144 | default: BUILD_BUG(); \ |
| 145 | } \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | \ |
| 147 | __pu_err; \ |
| 148 | }) |
| 149 | |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 150 | #define __put_user(x, ptr) \ |
| 151 | ({ \ |
Helge Deller | dbd0b42 | 2022-02-13 22:52:11 +0100 | [diff] [blame] | 152 | __typeof__(&*(ptr)) __ptr = ptr; \ |
| 153 | __typeof__(*(__ptr)) __x = (__typeof__(*(__ptr)))(x); \ |
| 154 | __put_user_internal("%%sr3,", __x, __ptr); \ |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 155 | }) |
| 156 | |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 157 | #define __put_kernel_nofault(dst, src, type, err_label) \ |
| 158 | { \ |
| 159 | type __z = *(type *)(src); \ |
| 160 | long __err; \ |
| 161 | __err = __put_user_internal("%%sr0,", __z, (type *)(dst)); \ |
| 162 | if (unlikely(__err)) \ |
| 163 | goto err_label; \ |
| 164 | } |
| 165 | |
| 166 | |
| 167 | |
Helge Deller | 3f795ce | 2017-04-16 10:00:14 +0200 | [diff] [blame] | 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | /* |
| 170 | * The "__put_user/kernel_asm()" macros tell gcc they read from memory |
| 171 | * instead of writing. This is because they do not write to any memory |
Carlos O'Donell | 3fd3a74 | 2006-04-22 14:47:21 -0600 | [diff] [blame] | 172 | * gcc knows about, so there are no aliasing issues. These macros must |
Helge Deller | d19f5e4 | 2017-03-25 11:59:15 +0100 | [diff] [blame] | 173 | * also be aware that fixups are executed in the context of the fault, |
| 174 | * and any registers used there must be listed as clobbers. |
Helge Deller | 4b9d2a7 | 2021-12-23 21:46:35 +0100 | [diff] [blame] | 175 | * The register holding the possible EFAULT error (ASM_EXCEPTIONTABLE_REG) |
| 176 | * is already listed as input and output register. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | */ |
| 178 | |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 179 | #define __put_user_asm(sr, stx, x, ptr) \ |
| 180 | __asm__ __volatile__ ( \ |
| 181 | "1: " stx " %2,0(" sr "%1)\n" \ |
| 182 | "9:\n" \ |
| 183 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ |
Helge Deller | dbd0b42 | 2022-02-13 22:52:11 +0100 | [diff] [blame] | 184 | : "+r"(__pu_err) \ |
| 185 | : "r"(ptr), "r"(x)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Helge Deller | ca72a22 | 2006-12-20 00:35:57 +0100 | [diff] [blame] | 188 | #if !defined(CONFIG_64BIT) |
Helge Deller | 94a1981 | 2006-12-19 22:33:58 +0100 | [diff] [blame] | 189 | |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 190 | #define __put_user_asm64(sr, __val, ptr) do { \ |
| 191 | __asm__ __volatile__ ( \ |
| 192 | "1: stw %2,0(" sr "%1)\n" \ |
| 193 | "2: stw %R2,4(" sr "%1)\n" \ |
| 194 | "9:\n" \ |
| 195 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ |
| 196 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \ |
Helge Deller | dbd0b42 | 2022-02-13 22:52:11 +0100 | [diff] [blame] | 197 | : "+r"(__pu_err) \ |
| 198 | : "r"(ptr), "r"(__val)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } while (0) |
| 200 | |
Helge Deller | ca72a22 | 2006-12-20 00:35:57 +0100 | [diff] [blame] | 201 | #endif /* !defined(CONFIG_64BIT) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | |
| 204 | /* |
| 205 | * Complex access routines -- external declarations |
| 206 | */ |
| 207 | |
James Bottomley | b1195c0 | 2012-05-26 09:48:19 +0100 | [diff] [blame] | 208 | extern long strncpy_from_user(char *, const char __user *, long); |
Helge Deller | 6710287 | 2021-09-09 12:47:00 +0200 | [diff] [blame] | 209 | extern __must_check unsigned lclear_user(void __user *, unsigned long); |
Helge Deller | 1260dea | 2021-09-04 23:49:26 +0200 | [diff] [blame] | 210 | extern __must_check long strnlen_user(const char __user *src, long n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /* |
| 212 | * Complex access routines -- macros |
| 213 | */ |
| 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | #define clear_user lclear_user |
| 216 | #define __clear_user lclear_user |
| 217 | |
Al Viro | f64fd18 | 2017-03-24 23:11:26 -0400 | [diff] [blame] | 218 | unsigned long __must_check raw_copy_to_user(void __user *dst, const void *src, |
| 219 | unsigned long len); |
| 220 | unsigned long __must_check raw_copy_from_user(void *dst, const void __user *src, |
| 221 | unsigned long len); |
Al Viro | f64fd18 | 2017-03-24 23:11:26 -0400 | [diff] [blame] | 222 | #define INLINE_COPY_TO_USER |
| 223 | #define INLINE_COPY_FROM_USER |
Helge Deller | 888c31f | 2010-02-01 19:56:33 +0000 | [diff] [blame] | 224 | |
Helge Deller | e448372 | 2009-01-13 20:52:46 +0100 | [diff] [blame] | 225 | struct pt_regs; |
Kyle McMartin | c61c25e | 2008-12-20 02:29:06 +0000 | [diff] [blame] | 226 | int fixup_exception(struct pt_regs *regs); |
| 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | #endif /* __PARISC_UACCESS_H */ |