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 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * S390 version |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999, 2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Hartmut Penner (hp@de.ibm.com), |
| 6 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 7 | * |
| 8 | * Derived from "include/asm-i386/uaccess.h" |
| 9 | */ |
| 10 | #ifndef __S390_UACCESS_H |
| 11 | #define __S390_UACCESS_H |
| 12 | |
| 13 | /* |
| 14 | * User space memory access functions |
| 15 | */ |
Heiko Carstens | b5a882f | 2017-02-17 08:13:28 +0100 | [diff] [blame] | 16 | #include <asm/processor.h> |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 17 | #include <asm/ctl_reg.h> |
Al Viro | e70f1d5 | 2016-12-26 00:48:37 -0500 | [diff] [blame] | 18 | #include <asm/extable.h> |
Martin Schwidefsky | 0aaba41 | 2017-08-22 12:08:22 +0200 | [diff] [blame] | 19 | #include <asm/facility.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Sven Schnelle | 56e62a7 | 2020-11-21 11:14:56 +0100 | [diff] [blame] | 21 | void debug_user_asce(int exit); |
Heiko Carstens | 062e527 | 2020-11-16 08:06:41 +0100 | [diff] [blame] | 22 | |
Heiko Carstens | 491af99 | 2012-05-29 07:33:59 +0200 | [diff] [blame] | 23 | static inline int __range_ok(unsigned long addr, unsigned long size) |
| 24 | { |
| 25 | return 1; |
| 26 | } |
| 27 | |
| 28 | #define __access_ok(addr, size) \ |
| 29 | ({ \ |
| 30 | __chk_user_ptr(addr); \ |
| 31 | __range_ok((unsigned long)(addr), (size)); \ |
Heiko Carstens | 7683f74 | 2011-05-26 09:48:25 +0200 | [diff] [blame] | 32 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 96d4f26 | 2019-01-03 18:57:57 -0800 | [diff] [blame] | 34 | #define access_ok(addr, size) __access_ok(addr, size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Al Viro | 3709600 | 2017-03-28 15:06:24 -0400 | [diff] [blame] | 36 | unsigned long __must_check |
| 37 | raw_copy_from_user(void *to, const void __user *from, unsigned long n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Al Viro | 3709600 | 2017-03-28 15:06:24 -0400 | [diff] [blame] | 39 | unsigned long __must_check |
| 40 | raw_copy_to_user(void __user *to, const void *from, unsigned long n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Vasily Gorbik | 01eb42a | 2019-04-23 15:36:36 +0200 | [diff] [blame] | 42 | #ifndef CONFIG_KASAN |
Al Viro | 3709600 | 2017-03-28 15:06:24 -0400 | [diff] [blame] | 43 | #define INLINE_COPY_FROM_USER |
| 44 | #define INLINE_COPY_TO_USER |
Vasily Gorbik | 01eb42a | 2019-04-23 15:36:36 +0200 | [diff] [blame] | 45 | #endif |
Gerald Schaefer | 6c1e3e7 | 2009-12-07 12:51:47 +0100 | [diff] [blame] | 46 | |
Heiko Carstens | db52739 | 2020-10-08 16:28:15 +0200 | [diff] [blame] | 47 | int __put_user_bad(void) __attribute__((noreturn)); |
| 48 | int __get_user_bad(void) __attribute__((noreturn)); |
| 49 | |
Heiko Carstens | c9ca784 | 2014-04-17 14:16:03 +0200 | [diff] [blame] | 50 | #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES |
| 51 | |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 52 | #define __put_get_user_asm(to, from, size, insn) \ |
Heiko Carstens | c9ca784 | 2014-04-17 14:16:03 +0200 | [diff] [blame] | 53 | ({ \ |
Heiko Carstens | c9ca784 | 2014-04-17 14:16:03 +0200 | [diff] [blame] | 54 | int __rc; \ |
| 55 | \ |
| 56 | asm volatile( \ |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 57 | insn " 0,%[spec]\n" \ |
| 58 | "0: mvcos %[_to],%[_from],%[_size]\n" \ |
| 59 | "1: xr %[rc],%[rc]\n" \ |
Heiko Carstens | c9ca784 | 2014-04-17 14:16:03 +0200 | [diff] [blame] | 60 | "2:\n" \ |
| 61 | ".pushsection .fixup, \"ax\"\n" \ |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 62 | "3: lhi %[rc],%[retval]\n" \ |
Heiko Carstens | c9ca784 | 2014-04-17 14:16:03 +0200 | [diff] [blame] | 63 | " jg 2b\n" \ |
| 64 | ".popsection\n" \ |
| 65 | EX_TABLE(0b,3b) EX_TABLE(1b,3b) \ |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 66 | : [rc] "=&d" (__rc), [_to] "+Q" (*(to)) \ |
| 67 | : [_size] "d" (size), [_from] "Q" (*(from)), \ |
| 68 | [retval] "K" (-EFAULT), [spec] "K" (0x81UL) \ |
| 69 | : "cc", "0"); \ |
Heiko Carstens | c9ca784 | 2014-04-17 14:16:03 +0200 | [diff] [blame] | 70 | __rc; \ |
| 71 | }) |
| 72 | |
Christian Borntraeger | 062795f | 2019-10-08 17:02:32 +0200 | [diff] [blame] | 73 | static __always_inline int __put_user_fn(void *x, void __user *ptr, unsigned long size) |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 74 | { |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 75 | int rc; |
| 76 | |
| 77 | switch (size) { |
| 78 | case 1: |
| 79 | rc = __put_get_user_asm((unsigned char __user *)ptr, |
| 80 | (unsigned char *)x, |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 81 | size, "llilh"); |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 82 | break; |
| 83 | case 2: |
| 84 | rc = __put_get_user_asm((unsigned short __user *)ptr, |
| 85 | (unsigned short *)x, |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 86 | size, "llilh"); |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 87 | break; |
| 88 | case 4: |
| 89 | rc = __put_get_user_asm((unsigned int __user *)ptr, |
| 90 | (unsigned int *)x, |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 91 | size, "llilh"); |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 92 | break; |
| 93 | case 8: |
| 94 | rc = __put_get_user_asm((unsigned long __user *)ptr, |
| 95 | (unsigned long *)x, |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 96 | size, "llilh"); |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 97 | break; |
Heiko Carstens | db52739 | 2020-10-08 16:28:15 +0200 | [diff] [blame] | 98 | default: |
| 99 | __put_user_bad(); |
| 100 | break; |
Heiko Carstens | 0b92515 | 2017-01-02 08:51:02 +0100 | [diff] [blame] | 101 | } |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 102 | return rc; |
| 103 | } |
| 104 | |
Christian Borntraeger | 062795f | 2019-10-08 17:02:32 +0200 | [diff] [blame] | 105 | static __always_inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size) |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 106 | { |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 107 | int rc; |
| 108 | |
| 109 | switch (size) { |
| 110 | case 1: |
| 111 | rc = __put_get_user_asm((unsigned char *)x, |
| 112 | (unsigned char __user *)ptr, |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 113 | size, "lghi"); |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 114 | break; |
| 115 | case 2: |
| 116 | rc = __put_get_user_asm((unsigned short *)x, |
| 117 | (unsigned short __user *)ptr, |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 118 | size, "lghi"); |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 119 | break; |
| 120 | case 4: |
| 121 | rc = __put_get_user_asm((unsigned int *)x, |
| 122 | (unsigned int __user *)ptr, |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 123 | size, "lghi"); |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 124 | break; |
| 125 | case 8: |
| 126 | rc = __put_get_user_asm((unsigned long *)x, |
| 127 | (unsigned long __user *)ptr, |
Heiko Carstens | dbb8864 | 2021-06-14 21:07:37 +0200 | [diff] [blame] | 128 | size, "lghi"); |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 129 | break; |
Heiko Carstens | db52739 | 2020-10-08 16:28:15 +0200 | [diff] [blame] | 130 | default: |
| 131 | __get_user_bad(); |
| 132 | break; |
Heiko Carstens | 0b92515 | 2017-01-02 08:51:02 +0100 | [diff] [blame] | 133 | } |
Heiko Carstens | dc4aace | 2016-06-20 10:35:20 +0200 | [diff] [blame] | 134 | return rc; |
| 135 | } |
Heiko Carstens | c9ca784 | 2014-04-17 14:16:03 +0200 | [diff] [blame] | 136 | |
| 137 | #else /* CONFIG_HAVE_MARCH_Z10_FEATURES */ |
| 138 | |
Heiko Carstens | 211deca | 2014-01-24 12:51:27 +0100 | [diff] [blame] | 139 | static inline int __put_user_fn(void *x, void __user *ptr, unsigned long size) |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 140 | { |
Al Viro | 3709600 | 2017-03-28 15:06:24 -0400 | [diff] [blame] | 141 | size = raw_copy_to_user(ptr, x, size); |
Heiko Carstens | 4f41c2b | 2014-01-23 11:18:36 +0100 | [diff] [blame] | 142 | return size ? -EFAULT : 0; |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 143 | } |
| 144 | |
Heiko Carstens | 211deca | 2014-01-24 12:51:27 +0100 | [diff] [blame] | 145 | static inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size) |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 146 | { |
Al Viro | 3709600 | 2017-03-28 15:06:24 -0400 | [diff] [blame] | 147 | size = raw_copy_from_user(x, ptr, size); |
Heiko Carstens | 4f41c2b | 2014-01-23 11:18:36 +0100 | [diff] [blame] | 148 | return size ? -EFAULT : 0; |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Heiko Carstens | c9ca784 | 2014-04-17 14:16:03 +0200 | [diff] [blame] | 151 | #endif /* CONFIG_HAVE_MARCH_Z10_FEATURES */ |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* |
| 154 | * These are the main single-value transfer routines. They automatically |
| 155 | * use the right size if we just have the right pointer type. |
| 156 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | #define __put_user(x, ptr) \ |
| 158 | ({ \ |
| 159 | __typeof__(*(ptr)) __x = (x); \ |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 160 | int __pu_err = -EFAULT; \ |
Al Viro | 17566c3 | 2005-08-23 22:48:22 +0100 | [diff] [blame] | 161 | __chk_user_ptr(ptr); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | switch (sizeof (*(ptr))) { \ |
| 163 | case 1: \ |
| 164 | case 2: \ |
| 165 | case 4: \ |
| 166 | case 8: \ |
Heiko Carstens | cfa785e | 2014-01-22 14:49:30 +0100 | [diff] [blame] | 167 | __pu_err = __put_user_fn(&__x, ptr, \ |
| 168 | sizeof(*(ptr))); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | break; \ |
| 170 | default: \ |
| 171 | __put_user_bad(); \ |
| 172 | break; \ |
Heiko Carstens | 10e5afb | 2020-10-08 16:43:17 +0200 | [diff] [blame] | 173 | } \ |
Heiko Carstens | ee64baf | 2016-06-13 10:17:20 +0200 | [diff] [blame] | 174 | __builtin_expect(__pu_err, 0); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | #define put_user(x, ptr) \ |
| 178 | ({ \ |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 179 | might_fault(); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | __put_user(x, ptr); \ |
| 181 | }) |
| 182 | |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | #define __get_user(x, ptr) \ |
| 185 | ({ \ |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 186 | int __gu_err = -EFAULT; \ |
| 187 | __chk_user_ptr(ptr); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | switch (sizeof(*(ptr))) { \ |
Martin Schwidefsky | 1047aa7 | 2005-11-07 00:59:11 -0800 | [diff] [blame] | 189 | case 1: { \ |
Al Viro | fd2d2b1 | 2016-08-21 22:00:54 -0400 | [diff] [blame] | 190 | unsigned char __x = 0; \ |
Heiko Carstens | cfa785e | 2014-01-22 14:49:30 +0100 | [diff] [blame] | 191 | __gu_err = __get_user_fn(&__x, ptr, \ |
| 192 | sizeof(*(ptr))); \ |
Al Viro | 97fa5a6 | 2006-02-03 20:11:52 -0500 | [diff] [blame] | 193 | (x) = *(__force __typeof__(*(ptr)) *) &__x; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | break; \ |
Martin Schwidefsky | 1047aa7 | 2005-11-07 00:59:11 -0800 | [diff] [blame] | 195 | }; \ |
| 196 | case 2: { \ |
Al Viro | fd2d2b1 | 2016-08-21 22:00:54 -0400 | [diff] [blame] | 197 | unsigned short __x = 0; \ |
Heiko Carstens | cfa785e | 2014-01-22 14:49:30 +0100 | [diff] [blame] | 198 | __gu_err = __get_user_fn(&__x, ptr, \ |
| 199 | sizeof(*(ptr))); \ |
Al Viro | 97fa5a6 | 2006-02-03 20:11:52 -0500 | [diff] [blame] | 200 | (x) = *(__force __typeof__(*(ptr)) *) &__x; \ |
Martin Schwidefsky | 1047aa7 | 2005-11-07 00:59:11 -0800 | [diff] [blame] | 201 | break; \ |
| 202 | }; \ |
| 203 | case 4: { \ |
Al Viro | fd2d2b1 | 2016-08-21 22:00:54 -0400 | [diff] [blame] | 204 | unsigned int __x = 0; \ |
Heiko Carstens | cfa785e | 2014-01-22 14:49:30 +0100 | [diff] [blame] | 205 | __gu_err = __get_user_fn(&__x, ptr, \ |
| 206 | sizeof(*(ptr))); \ |
Al Viro | 97fa5a6 | 2006-02-03 20:11:52 -0500 | [diff] [blame] | 207 | (x) = *(__force __typeof__(*(ptr)) *) &__x; \ |
Martin Schwidefsky | 1047aa7 | 2005-11-07 00:59:11 -0800 | [diff] [blame] | 208 | break; \ |
| 209 | }; \ |
| 210 | case 8: { \ |
Al Viro | fd2d2b1 | 2016-08-21 22:00:54 -0400 | [diff] [blame] | 211 | unsigned long long __x = 0; \ |
Heiko Carstens | cfa785e | 2014-01-22 14:49:30 +0100 | [diff] [blame] | 212 | __gu_err = __get_user_fn(&__x, ptr, \ |
| 213 | sizeof(*(ptr))); \ |
Al Viro | 97fa5a6 | 2006-02-03 20:11:52 -0500 | [diff] [blame] | 214 | (x) = *(__force __typeof__(*(ptr)) *) &__x; \ |
Martin Schwidefsky | 1047aa7 | 2005-11-07 00:59:11 -0800 | [diff] [blame] | 215 | break; \ |
| 216 | }; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | default: \ |
| 218 | __get_user_bad(); \ |
| 219 | break; \ |
| 220 | } \ |
Heiko Carstens | ee64baf | 2016-06-13 10:17:20 +0200 | [diff] [blame] | 221 | __builtin_expect(__gu_err, 0); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | #define get_user(x, ptr) \ |
| 225 | ({ \ |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 226 | might_fault(); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | __get_user(x, ptr); \ |
| 228 | }) |
| 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | /* |
| 231 | * Copy a null terminated string from userspace. |
| 232 | */ |
Heiko Carstens | e93a1cb | 2021-07-22 22:07:30 +0200 | [diff] [blame] | 233 | long __must_check strncpy_from_user(char *dst, const char __user *src, long count); |
Heiko Carstens | 4f41c2b | 2014-01-23 11:18:36 +0100 | [diff] [blame] | 234 | |
Heiko Carstens | e93a1cb | 2021-07-22 22:07:30 +0200 | [diff] [blame] | 235 | long __must_check strnlen_user(const char __user *src, long count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /* |
| 238 | * Zero Userspace |
| 239 | */ |
Heiko Carstens | 211deca | 2014-01-24 12:51:27 +0100 | [diff] [blame] | 240 | unsigned long __must_check __clear_user(void __user *to, unsigned long size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Heiko Carstens | 211deca | 2014-01-24 12:51:27 +0100 | [diff] [blame] | 242 | static inline unsigned long __must_check clear_user(void __user *to, unsigned long n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 244 | might_fault(); |
Heiko Carstens | 4f41c2b | 2014-01-23 11:18:36 +0100 | [diff] [blame] | 245 | return __clear_user(to, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Heiko Carstens | 211deca | 2014-01-24 12:51:27 +0100 | [diff] [blame] | 248 | int copy_to_user_real(void __user *dest, void *src, unsigned long count); |
Josh Poimboeuf | cb2ccea | 2020-04-29 10:24:47 -0500 | [diff] [blame] | 249 | void *s390_kernel_write(void *dst, const void *src, size_t size); |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 250 | |
Heiko Carstens | 110a6db | 2020-09-14 13:42:25 +0200 | [diff] [blame] | 251 | #define HAVE_GET_KERNEL_NOFAULT |
| 252 | |
| 253 | int __noreturn __put_kernel_bad(void); |
| 254 | |
| 255 | #define __put_kernel_asm(val, to, insn) \ |
| 256 | ({ \ |
| 257 | int __rc; \ |
| 258 | \ |
| 259 | asm volatile( \ |
| 260 | "0: " insn " %2,%1\n" \ |
| 261 | "1: xr %0,%0\n" \ |
| 262 | "2:\n" \ |
| 263 | ".pushsection .fixup, \"ax\"\n" \ |
| 264 | "3: lhi %0,%3\n" \ |
| 265 | " jg 2b\n" \ |
| 266 | ".popsection\n" \ |
| 267 | EX_TABLE(0b,3b) EX_TABLE(1b,3b) \ |
| 268 | : "=d" (__rc), "+Q" (*(to)) \ |
| 269 | : "d" (val), "K" (-EFAULT) \ |
| 270 | : "cc"); \ |
| 271 | __rc; \ |
| 272 | }) |
| 273 | |
| 274 | #define __put_kernel_nofault(dst, src, type, err_label) \ |
| 275 | do { \ |
| 276 | u64 __x = (u64)(*((type *)(src))); \ |
| 277 | int __pk_err; \ |
| 278 | \ |
| 279 | switch (sizeof(type)) { \ |
| 280 | case 1: \ |
| 281 | __pk_err = __put_kernel_asm(__x, (type *)(dst), "stc"); \ |
| 282 | break; \ |
| 283 | case 2: \ |
| 284 | __pk_err = __put_kernel_asm(__x, (type *)(dst), "sth"); \ |
| 285 | break; \ |
| 286 | case 4: \ |
| 287 | __pk_err = __put_kernel_asm(__x, (type *)(dst), "st"); \ |
| 288 | break; \ |
| 289 | case 8: \ |
| 290 | __pk_err = __put_kernel_asm(__x, (type *)(dst), "stg"); \ |
| 291 | break; \ |
| 292 | default: \ |
| 293 | __pk_err = __put_kernel_bad(); \ |
| 294 | break; \ |
| 295 | } \ |
| 296 | if (unlikely(__pk_err)) \ |
| 297 | goto err_label; \ |
| 298 | } while (0) |
| 299 | |
| 300 | int __noreturn __get_kernel_bad(void); |
| 301 | |
| 302 | #define __get_kernel_asm(val, from, insn) \ |
| 303 | ({ \ |
| 304 | int __rc; \ |
| 305 | \ |
| 306 | asm volatile( \ |
| 307 | "0: " insn " %1,%2\n" \ |
| 308 | "1: xr %0,%0\n" \ |
| 309 | "2:\n" \ |
| 310 | ".pushsection .fixup, \"ax\"\n" \ |
| 311 | "3: lhi %0,%3\n" \ |
| 312 | " jg 2b\n" \ |
| 313 | ".popsection\n" \ |
| 314 | EX_TABLE(0b,3b) EX_TABLE(1b,3b) \ |
| 315 | : "=d" (__rc), "+d" (val) \ |
| 316 | : "Q" (*(from)), "K" (-EFAULT) \ |
| 317 | : "cc"); \ |
| 318 | __rc; \ |
| 319 | }) |
| 320 | |
| 321 | #define __get_kernel_nofault(dst, src, type, err_label) \ |
| 322 | do { \ |
| 323 | int __gk_err; \ |
| 324 | \ |
| 325 | switch (sizeof(type)) { \ |
| 326 | case 1: { \ |
| 327 | u8 __x = 0; \ |
| 328 | \ |
| 329 | __gk_err = __get_kernel_asm(__x, (type *)(src), "ic"); \ |
| 330 | *((type *)(dst)) = (type)__x; \ |
| 331 | break; \ |
| 332 | }; \ |
| 333 | case 2: { \ |
| 334 | u16 __x = 0; \ |
| 335 | \ |
| 336 | __gk_err = __get_kernel_asm(__x, (type *)(src), "lh"); \ |
| 337 | *((type *)(dst)) = (type)__x; \ |
| 338 | break; \ |
| 339 | }; \ |
| 340 | case 4: { \ |
| 341 | u32 __x = 0; \ |
| 342 | \ |
| 343 | __gk_err = __get_kernel_asm(__x, (type *)(src), "l"); \ |
| 344 | *((type *)(dst)) = (type)__x; \ |
| 345 | break; \ |
| 346 | }; \ |
| 347 | case 8: { \ |
| 348 | u64 __x = 0; \ |
| 349 | \ |
| 350 | __gk_err = __get_kernel_asm(__x, (type *)(src), "lg"); \ |
| 351 | *((type *)(dst)) = (type)__x; \ |
| 352 | break; \ |
| 353 | }; \ |
| 354 | default: \ |
| 355 | __gk_err = __get_kernel_bad(); \ |
| 356 | break; \ |
| 357 | } \ |
| 358 | if (unlikely(__gk_err)) \ |
| 359 | goto err_label; \ |
| 360 | } while (0) |
| 361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | #endif /* __S390_UACCESS_H */ |