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