H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_UACCESS_64_H |
| 2 | #define _ASM_X86_UACCESS_64_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
| 4 | /* |
| 5 | * User space memory access functions |
| 6 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/compiler.h> |
| 8 | #include <linux/errno.h> |
Nick Piggin | 16dbc6c | 2008-10-02 14:50:12 -0700 | [diff] [blame] | 9 | #include <linux/lockdep.h> |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 10 | #include <linux/kasan-checks.h> |
Jan Beulich | 1b1d925 | 2009-12-18 16:12:56 +0000 | [diff] [blame] | 11 | #include <asm/alternative.h> |
Borislav Petkov | cd4d09e | 2016-01-26 22:12:04 +0100 | [diff] [blame] | 12 | #include <asm/cpufeatures.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/page.h> |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | /* |
| 16 | * Copy To/From Userspace |
| 17 | */ |
| 18 | |
| 19 | /* Handles exceptions in both to and from, but doesn't do access_ok */ |
Andi Kleen | 9591200 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 20 | __must_check unsigned long |
Fenghua Yu | 954e482 | 2012-05-24 18:19:45 -0700 | [diff] [blame] | 21 | copy_user_enhanced_fast_string(void *to, const void *from, unsigned len); |
| 22 | __must_check unsigned long |
Jan Beulich | 1b1d925 | 2009-12-18 16:12:56 +0000 | [diff] [blame] | 23 | copy_user_generic_string(void *to, const void *from, unsigned len); |
| 24 | __must_check unsigned long |
| 25 | copy_user_generic_unrolled(void *to, const void *from, unsigned len); |
| 26 | |
| 27 | static __always_inline __must_check unsigned long |
| 28 | copy_user_generic(void *to, const void *from, unsigned len) |
| 29 | { |
| 30 | unsigned ret; |
| 31 | |
Fenghua Yu | 954e482 | 2012-05-24 18:19:45 -0700 | [diff] [blame] | 32 | /* |
| 33 | * If CPU has ERMS feature, use copy_user_enhanced_fast_string. |
| 34 | * Otherwise, if CPU has rep_good feature, use copy_user_generic_string. |
| 35 | * Otherwise, use copy_user_generic_unrolled. |
| 36 | */ |
| 37 | alternative_call_2(copy_user_generic_unrolled, |
Jan Beulich | 1b1d925 | 2009-12-18 16:12:56 +0000 | [diff] [blame] | 38 | copy_user_generic_string, |
| 39 | X86_FEATURE_REP_GOOD, |
Fenghua Yu | 954e482 | 2012-05-24 18:19:45 -0700 | [diff] [blame] | 40 | copy_user_enhanced_fast_string, |
| 41 | X86_FEATURE_ERMS, |
Jan Beulich | 1b1d925 | 2009-12-18 16:12:56 +0000 | [diff] [blame] | 42 | ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from), |
| 43 | "=d" (len)), |
| 44 | "1" (to), "2" (from), "3" (len) |
| 45 | : "memory", "rcx", "r8", "r9", "r10", "r11"); |
| 46 | return ret; |
| 47 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Andi Kleen | 9591200 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 49 | __must_check unsigned long |
Andi Kleen | 9591200 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 50 | copy_in_user(void __user *to, const void __user *from, unsigned len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Frederic Weisbecker | 3c93ca0 | 2009-11-16 15:42:18 +0100 | [diff] [blame] | 52 | static __always_inline __must_check |
Andi Kleen | ff47ab4f | 2013-08-16 14:17:19 -0700 | [diff] [blame] | 53 | int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 54 | { |
Andi Kleen | 383d079 | 2006-09-26 10:52:40 +0200 | [diff] [blame] | 55 | int ret = 0; |
Ingo Molnar | d1a7618 | 2008-10-28 16:54:49 +0100 | [diff] [blame] | 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | if (!__builtin_constant_p(size)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 58 | return copy_user_generic(dst, (__force void *)src, size); |
| 59 | switch (size) { |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 60 | case 1: |
| 61 | __uaccess_begin(); |
| 62 | __get_user_asm(*(u8 *)dst, (u8 __user *)src, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 63 | ret, "b", "b", "=q", 1); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 64 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 66 | case 2: |
| 67 | __uaccess_begin(); |
| 68 | __get_user_asm(*(u16 *)dst, (u16 __user *)src, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 69 | ret, "w", "w", "=r", 2); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 70 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 72 | case 4: |
| 73 | __uaccess_begin(); |
| 74 | __get_user_asm(*(u32 *)dst, (u32 __user *)src, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 75 | ret, "l", "k", "=r", 4); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 76 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 78 | case 8: |
| 79 | __uaccess_begin(); |
| 80 | __get_user_asm(*(u64 *)dst, (u64 __user *)src, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 81 | ret, "q", "", "=r", 8); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 82 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 83 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | case 10: |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 85 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 86 | __get_user_asm(*(u64 *)dst, (u64 __user *)src, |
Hiroshi Shimamoto | 20a4a23 | 2008-11-13 18:06:04 -0800 | [diff] [blame] | 87 | ret, "q", "", "=r", 10); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 88 | if (likely(!ret)) |
| 89 | __get_user_asm(*(u16 *)(8 + (char *)dst), |
| 90 | (u16 __user *)(8 + (char __user *)src), |
| 91 | ret, "w", "w", "=r", 2); |
| 92 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 93 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | case 16: |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 95 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 96 | __get_user_asm(*(u64 *)dst, (u64 __user *)src, |
| 97 | ret, "q", "", "=r", 16); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 98 | if (likely(!ret)) |
| 99 | __get_user_asm(*(u64 *)(8 + (char *)dst), |
| 100 | (u64 __user *)(8 + (char __user *)src), |
| 101 | ret, "q", "", "=r", 8); |
| 102 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 103 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | default: |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 105 | return copy_user_generic(dst, (__force void *)src, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Andi Kleen | 9591200 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 109 | static __always_inline __must_check |
Andi Kleen | ff47ab4f | 2013-08-16 14:17:19 -0700 | [diff] [blame] | 110 | int __copy_from_user(void *dst, const void __user *src, unsigned size) |
| 111 | { |
| 112 | might_fault(); |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 113 | kasan_check_write(dst, size); |
Andi Kleen | ff47ab4f | 2013-08-16 14:17:19 -0700 | [diff] [blame] | 114 | return __copy_from_user_nocheck(dst, src, size); |
| 115 | } |
| 116 | |
| 117 | static __always_inline __must_check |
| 118 | int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 119 | { |
Andi Kleen | 383d079 | 2006-09-26 10:52:40 +0200 | [diff] [blame] | 120 | int ret = 0; |
Ingo Molnar | d1a7618 | 2008-10-28 16:54:49 +0100 | [diff] [blame] | 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | if (!__builtin_constant_p(size)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 123 | return copy_user_generic((__force void *)dst, src, size); |
| 124 | switch (size) { |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 125 | case 1: |
| 126 | __uaccess_begin(); |
| 127 | __put_user_asm(*(u8 *)src, (u8 __user *)dst, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 128 | ret, "b", "b", "iq", 1); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 129 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 131 | case 2: |
| 132 | __uaccess_begin(); |
| 133 | __put_user_asm(*(u16 *)src, (u16 __user *)dst, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 134 | ret, "w", "w", "ir", 2); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 135 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 137 | case 4: |
| 138 | __uaccess_begin(); |
| 139 | __put_user_asm(*(u32 *)src, (u32 __user *)dst, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 140 | ret, "l", "k", "ir", 4); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 141 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 143 | case 8: |
| 144 | __uaccess_begin(); |
| 145 | __put_user_asm(*(u64 *)src, (u64 __user *)dst, |
Uros Bizjak | 155b735 | 2009-07-19 18:06:35 +0200 | [diff] [blame] | 146 | ret, "q", "", "er", 8); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 147 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 148 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | case 10: |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 150 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 151 | __put_user_asm(*(u64 *)src, (u64 __user *)dst, |
Uros Bizjak | 155b735 | 2009-07-19 18:06:35 +0200 | [diff] [blame] | 152 | ret, "q", "", "er", 10); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 153 | if (likely(!ret)) { |
| 154 | asm("":::"memory"); |
| 155 | __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst, |
| 156 | ret, "w", "w", "ir", 2); |
| 157 | } |
| 158 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 159 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | case 16: |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 161 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 162 | __put_user_asm(*(u64 *)src, (u64 __user *)dst, |
Uros Bizjak | 155b735 | 2009-07-19 18:06:35 +0200 | [diff] [blame] | 163 | ret, "q", "", "er", 16); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 164 | if (likely(!ret)) { |
| 165 | asm("":::"memory"); |
| 166 | __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst, |
| 167 | ret, "q", "", "er", 8); |
| 168 | } |
| 169 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 170 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | default: |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 172 | return copy_user_generic((__force void *)dst, src, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Andi Kleen | 9591200 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 176 | static __always_inline __must_check |
Andi Kleen | ff47ab4f | 2013-08-16 14:17:19 -0700 | [diff] [blame] | 177 | int __copy_to_user(void __user *dst, const void *src, unsigned size) |
| 178 | { |
| 179 | might_fault(); |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 180 | kasan_check_read(src, size); |
Andi Kleen | ff47ab4f | 2013-08-16 14:17:19 -0700 | [diff] [blame] | 181 | return __copy_to_user_nocheck(dst, src, size); |
| 182 | } |
| 183 | |
| 184 | static __always_inline __must_check |
Andi Kleen | 9591200 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 185 | int __copy_in_user(void __user *dst, const void __user *src, unsigned size) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 186 | { |
Andi Kleen | 383d079 | 2006-09-26 10:52:40 +0200 | [diff] [blame] | 187 | int ret = 0; |
Ingo Molnar | d1a7618 | 2008-10-28 16:54:49 +0100 | [diff] [blame] | 188 | |
| 189 | might_fault(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | if (!__builtin_constant_p(size)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 191 | return copy_user_generic((__force void *)dst, |
| 192 | (__force void *)src, size); |
| 193 | switch (size) { |
| 194 | case 1: { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | u8 tmp; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 196 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 197 | __get_user_asm(tmp, (u8 __user *)src, |
| 198 | ret, "b", "b", "=q", 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (likely(!ret)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 200 | __put_user_asm(tmp, (u8 __user *)dst, |
| 201 | ret, "b", "b", "iq", 1); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 202 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | return ret; |
| 204 | } |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 205 | case 2: { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | u16 tmp; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 207 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 208 | __get_user_asm(tmp, (u16 __user *)src, |
| 209 | ret, "w", "w", "=r", 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | if (likely(!ret)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 211 | __put_user_asm(tmp, (u16 __user *)dst, |
| 212 | ret, "w", "w", "ir", 2); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 213 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | return ret; |
| 215 | } |
| 216 | |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 217 | case 4: { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | u32 tmp; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 219 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 220 | __get_user_asm(tmp, (u32 __user *)src, |
| 221 | ret, "l", "k", "=r", 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | if (likely(!ret)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 223 | __put_user_asm(tmp, (u32 __user *)dst, |
| 224 | ret, "l", "k", "ir", 4); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 225 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | return ret; |
| 227 | } |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 228 | case 8: { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | u64 tmp; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 230 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 231 | __get_user_asm(tmp, (u64 __user *)src, |
| 232 | ret, "q", "", "=r", 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | if (likely(!ret)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 234 | __put_user_asm(tmp, (u64 __user *)dst, |
Uros Bizjak | 155b735 | 2009-07-19 18:06:35 +0200 | [diff] [blame] | 235 | ret, "q", "", "er", 8); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 236 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | return ret; |
| 238 | } |
| 239 | default: |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 240 | return copy_user_generic((__force void *)dst, |
| 241 | (__force void *)src, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Jan Beulich | 1472248 | 2009-11-13 11:56:24 +0000 | [diff] [blame] | 245 | static __must_check __always_inline int |
| 246 | __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size) |
| 247 | { |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 248 | kasan_check_write(dst, size); |
Steven Rostedt | df90ca96 | 2014-01-03 16:45:00 -0500 | [diff] [blame] | 249 | return __copy_from_user_nocheck(dst, src, size); |
Jan Beulich | 1472248 | 2009-11-13 11:56:24 +0000 | [diff] [blame] | 250 | } |
Andi Kleen | b885808 | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 251 | |
| 252 | static __must_check __always_inline int |
| 253 | __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size) |
| 254 | { |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 255 | kasan_check_read(src, size); |
Steven Rostedt | df90ca96 | 2014-01-03 16:45:00 -0500 | [diff] [blame] | 256 | return __copy_to_user_nocheck(dst, src, size); |
Andi Kleen | b885808 | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 259 | extern long __copy_user_nocache(void *dst, const void __user *src, |
| 260 | unsigned size, int zerorest); |
Andi Kleen | 0812a57 | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 261 | |
Ingo Molnar | f180053 | 2009-03-02 11:00:57 +0100 | [diff] [blame] | 262 | static inline int |
| 263 | __copy_from_user_nocache(void *dst, const void __user *src, unsigned size) |
Andi Kleen | 0812a57 | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 264 | { |
Michael S. Tsirkin | 016be2e | 2013-05-26 17:31:55 +0300 | [diff] [blame] | 265 | might_fault(); |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 266 | kasan_check_write(dst, size); |
Ingo Molnar | f180053 | 2009-03-02 11:00:57 +0100 | [diff] [blame] | 267 | return __copy_user_nocache(dst, src, size, 1); |
Andi Kleen | 0812a57 | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 268 | } |
| 269 | |
Ingo Molnar | f180053 | 2009-03-02 11:00:57 +0100 | [diff] [blame] | 270 | static inline int |
| 271 | __copy_from_user_inatomic_nocache(void *dst, const void __user *src, |
| 272 | unsigned size) |
Andi Kleen | 0812a57 | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 273 | { |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 274 | kasan_check_write(dst, size); |
Ingo Molnar | f180053 | 2009-03-02 11:00:57 +0100 | [diff] [blame] | 275 | return __copy_user_nocache(dst, src, size, 0); |
Andi Kleen | 0812a57 | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 276 | } |
| 277 | |
Vitaly Mayatskikh | 1129585 | 2008-07-02 15:48:21 +0200 | [diff] [blame] | 278 | unsigned long |
Linus Torvalds | cae2a17 | 2015-04-06 10:26:17 -0700 | [diff] [blame] | 279 | copy_user_handle_tail(char *to, char *from, unsigned len); |
Vitaly Mayatskikh | 1129585 | 2008-07-02 15:48:21 +0200 | [diff] [blame] | 280 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 281 | #endif /* _ASM_X86_UACCESS_64_H */ |