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 | |
Kees Cook | 5b710f3 | 2016-06-23 15:04:01 -0700 | [diff] [blame] | 57 | check_object_size(dst, size, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | if (!__builtin_constant_p(size)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 59 | return copy_user_generic(dst, (__force void *)src, size); |
| 60 | switch (size) { |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 61 | case 1: |
Dan Williams | 065eae4 | 2018-01-29 17:02:49 -0800 | [diff] [blame] | 62 | __uaccess_begin_nospec(); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 63 | __get_user_asm(*(u8 *)dst, (u8 __user *)src, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 64 | ret, "b", "b", "=q", 1); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 65 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 67 | case 2: |
Dan Williams | 065eae4 | 2018-01-29 17:02:49 -0800 | [diff] [blame] | 68 | __uaccess_begin_nospec(); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 69 | __get_user_asm(*(u16 *)dst, (u16 __user *)src, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 70 | ret, "w", "w", "=r", 2); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 71 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 73 | case 4: |
Dan Williams | 065eae4 | 2018-01-29 17:02:49 -0800 | [diff] [blame] | 74 | __uaccess_begin_nospec(); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 75 | __get_user_asm(*(u32 *)dst, (u32 __user *)src, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 76 | ret, "l", "k", "=r", 4); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 77 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 79 | case 8: |
Dan Williams | 065eae4 | 2018-01-29 17:02:49 -0800 | [diff] [blame] | 80 | __uaccess_begin_nospec(); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 81 | __get_user_asm(*(u64 *)dst, (u64 __user *)src, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 82 | ret, "q", "", "=r", 8); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 83 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 84 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | case 10: |
Dan Williams | 065eae4 | 2018-01-29 17:02:49 -0800 | [diff] [blame] | 86 | __uaccess_begin_nospec(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 87 | __get_user_asm(*(u64 *)dst, (u64 __user *)src, |
Hiroshi Shimamoto | 20a4a23 | 2008-11-13 18:06:04 -0800 | [diff] [blame] | 88 | ret, "q", "", "=r", 10); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 89 | if (likely(!ret)) |
| 90 | __get_user_asm(*(u16 *)(8 + (char *)dst), |
| 91 | (u16 __user *)(8 + (char __user *)src), |
| 92 | ret, "w", "w", "=r", 2); |
| 93 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 94 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | case 16: |
Dan Williams | 065eae4 | 2018-01-29 17:02:49 -0800 | [diff] [blame] | 96 | __uaccess_begin_nospec(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 97 | __get_user_asm(*(u64 *)dst, (u64 __user *)src, |
| 98 | ret, "q", "", "=r", 16); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 99 | if (likely(!ret)) |
| 100 | __get_user_asm(*(u64 *)(8 + (char *)dst), |
| 101 | (u64 __user *)(8 + (char __user *)src), |
| 102 | ret, "q", "", "=r", 8); |
| 103 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 104 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | default: |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 106 | return copy_user_generic(dst, (__force void *)src, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 108 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Andi Kleen | 9591200 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 110 | static __always_inline __must_check |
Andi Kleen | ff47ab4f | 2013-08-16 14:17:19 -0700 | [diff] [blame] | 111 | int __copy_from_user(void *dst, const void __user *src, unsigned size) |
| 112 | { |
| 113 | might_fault(); |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 114 | kasan_check_write(dst, size); |
Andi Kleen | ff47ab4f | 2013-08-16 14:17:19 -0700 | [diff] [blame] | 115 | return __copy_from_user_nocheck(dst, src, size); |
| 116 | } |
| 117 | |
| 118 | static __always_inline __must_check |
| 119 | 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] | 120 | { |
Andi Kleen | 383d079 | 2006-09-26 10:52:40 +0200 | [diff] [blame] | 121 | int ret = 0; |
Ingo Molnar | d1a7618 | 2008-10-28 16:54:49 +0100 | [diff] [blame] | 122 | |
Kees Cook | 5b710f3 | 2016-06-23 15:04:01 -0700 | [diff] [blame] | 123 | check_object_size(src, size, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | if (!__builtin_constant_p(size)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 125 | return copy_user_generic((__force void *)dst, src, size); |
| 126 | switch (size) { |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 127 | case 1: |
| 128 | __uaccess_begin(); |
| 129 | __put_user_asm(*(u8 *)src, (u8 __user *)dst, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 130 | ret, "b", "b", "iq", 1); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 131 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 133 | case 2: |
| 134 | __uaccess_begin(); |
| 135 | __put_user_asm(*(u16 *)src, (u16 __user *)dst, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 136 | ret, "w", "w", "ir", 2); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 137 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 139 | case 4: |
| 140 | __uaccess_begin(); |
| 141 | __put_user_asm(*(u32 *)src, (u32 __user *)dst, |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 142 | ret, "l", "k", "ir", 4); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 143 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return ret; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 145 | case 8: |
| 146 | __uaccess_begin(); |
| 147 | __put_user_asm(*(u64 *)src, (u64 __user *)dst, |
Uros Bizjak | 155b735 | 2009-07-19 18:06:35 +0200 | [diff] [blame] | 148 | ret, "q", "", "er", 8); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 149 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 150 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | case 10: |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 152 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 153 | __put_user_asm(*(u64 *)src, (u64 __user *)dst, |
Uros Bizjak | 155b735 | 2009-07-19 18:06:35 +0200 | [diff] [blame] | 154 | ret, "q", "", "er", 10); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 155 | if (likely(!ret)) { |
| 156 | asm("":::"memory"); |
| 157 | __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst, |
| 158 | ret, "w", "w", "ir", 2); |
| 159 | } |
| 160 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 161 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | case 16: |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 163 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 164 | __put_user_asm(*(u64 *)src, (u64 __user *)dst, |
Uros Bizjak | 155b735 | 2009-07-19 18:06:35 +0200 | [diff] [blame] | 165 | ret, "q", "", "er", 16); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 166 | if (likely(!ret)) { |
| 167 | asm("":::"memory"); |
| 168 | __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst, |
| 169 | ret, "q", "", "er", 8); |
| 170 | } |
| 171 | __uaccess_end(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 172 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | default: |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 174 | return copy_user_generic((__force void *)dst, src, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Andi Kleen | 9591200 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 178 | static __always_inline __must_check |
Andi Kleen | ff47ab4f | 2013-08-16 14:17:19 -0700 | [diff] [blame] | 179 | int __copy_to_user(void __user *dst, const void *src, unsigned size) |
| 180 | { |
| 181 | might_fault(); |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 182 | kasan_check_read(src, size); |
Andi Kleen | ff47ab4f | 2013-08-16 14:17:19 -0700 | [diff] [blame] | 183 | return __copy_to_user_nocheck(dst, src, size); |
| 184 | } |
| 185 | |
| 186 | static __always_inline __must_check |
Andi Kleen | 9591200 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 187 | 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] | 188 | { |
Andi Kleen | 383d079 | 2006-09-26 10:52:40 +0200 | [diff] [blame] | 189 | int ret = 0; |
Ingo Molnar | d1a7618 | 2008-10-28 16:54:49 +0100 | [diff] [blame] | 190 | |
| 191 | might_fault(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | if (!__builtin_constant_p(size)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 193 | return copy_user_generic((__force void *)dst, |
| 194 | (__force void *)src, size); |
| 195 | switch (size) { |
| 196 | case 1: { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | u8 tmp; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 198 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 199 | __get_user_asm(tmp, (u8 __user *)src, |
| 200 | ret, "b", "b", "=q", 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | if (likely(!ret)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 202 | __put_user_asm(tmp, (u8 __user *)dst, |
| 203 | ret, "b", "b", "iq", 1); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 204 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return ret; |
| 206 | } |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 207 | case 2: { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | u16 tmp; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 209 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 210 | __get_user_asm(tmp, (u16 __user *)src, |
| 211 | ret, "w", "w", "=r", 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | if (likely(!ret)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 213 | __put_user_asm(tmp, (u16 __user *)dst, |
| 214 | ret, "w", "w", "ir", 2); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 215 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | return ret; |
| 217 | } |
| 218 | |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 219 | case 4: { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | u32 tmp; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 221 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 222 | __get_user_asm(tmp, (u32 __user *)src, |
| 223 | ret, "l", "k", "=r", 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | if (likely(!ret)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 225 | __put_user_asm(tmp, (u32 __user *)dst, |
| 226 | ret, "l", "k", "ir", 4); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 227 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | return ret; |
| 229 | } |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 230 | case 8: { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | u64 tmp; |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 232 | __uaccess_begin(); |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 233 | __get_user_asm(tmp, (u64 __user *)src, |
| 234 | ret, "q", "", "=r", 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | if (likely(!ret)) |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 236 | __put_user_asm(tmp, (u64 __user *)dst, |
Uros Bizjak | 155b735 | 2009-07-19 18:06:35 +0200 | [diff] [blame] | 237 | ret, "q", "", "er", 8); |
Linus Torvalds | 11f1a4b | 2015-12-17 09:45:09 -0800 | [diff] [blame] | 238 | __uaccess_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return ret; |
| 240 | } |
| 241 | default: |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 242 | return copy_user_generic((__force void *)dst, |
| 243 | (__force void *)src, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Jan Beulich | 1472248 | 2009-11-13 11:56:24 +0000 | [diff] [blame] | 247 | static __must_check __always_inline int |
| 248 | __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size) |
| 249 | { |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 250 | kasan_check_write(dst, size); |
Steven Rostedt | df90ca96 | 2014-01-03 16:45:00 -0500 | [diff] [blame] | 251 | return __copy_from_user_nocheck(dst, src, size); |
Jan Beulich | 1472248 | 2009-11-13 11:56:24 +0000 | [diff] [blame] | 252 | } |
Andi Kleen | b885808 | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 253 | |
| 254 | static __must_check __always_inline int |
| 255 | __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size) |
| 256 | { |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 257 | kasan_check_read(src, size); |
Steven Rostedt | df90ca96 | 2014-01-03 16:45:00 -0500 | [diff] [blame] | 258 | return __copy_to_user_nocheck(dst, src, size); |
Andi Kleen | b885808 | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 259 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Joe Perches | b896313 | 2008-03-23 01:03:49 -0700 | [diff] [blame] | 261 | extern long __copy_user_nocache(void *dst, const void __user *src, |
| 262 | unsigned size, int zerorest); |
Andi Kleen | 0812a57 | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 263 | |
Ingo Molnar | f180053 | 2009-03-02 11:00:57 +0100 | [diff] [blame] | 264 | static inline int |
| 265 | __copy_from_user_nocache(void *dst, const void __user *src, unsigned size) |
Andi Kleen | 0812a57 | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 266 | { |
Michael S. Tsirkin | 016be2e | 2013-05-26 17:31:55 +0300 | [diff] [blame] | 267 | might_fault(); |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 268 | kasan_check_write(dst, size); |
Ingo Molnar | f180053 | 2009-03-02 11:00:57 +0100 | [diff] [blame] | 269 | return __copy_user_nocache(dst, src, size, 1); |
Andi Kleen | 0812a57 | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 270 | } |
| 271 | |
Ingo Molnar | f180053 | 2009-03-02 11:00:57 +0100 | [diff] [blame] | 272 | static inline int |
| 273 | __copy_from_user_inatomic_nocache(void *dst, const void __user *src, |
| 274 | unsigned size) |
Andi Kleen | 0812a57 | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 275 | { |
Andrey Ryabinin | 1771c6e | 2016-05-20 16:59:31 -0700 | [diff] [blame] | 276 | kasan_check_write(dst, size); |
Ingo Molnar | f180053 | 2009-03-02 11:00:57 +0100 | [diff] [blame] | 277 | return __copy_user_nocache(dst, src, size, 0); |
Andi Kleen | 0812a57 | 2007-02-13 13:26:19 +0100 | [diff] [blame] | 278 | } |
| 279 | |
Vitaly Mayatskikh | 1129585 | 2008-07-02 15:48:21 +0200 | [diff] [blame] | 280 | unsigned long |
Linus Torvalds | cae2a17 | 2015-04-06 10:26:17 -0700 | [diff] [blame] | 281 | copy_user_handle_tail(char *to, char *from, unsigned len); |
Vitaly Mayatskikh | 1129585 | 2008-07-02 15:48:21 +0200 | [diff] [blame] | 282 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 283 | #endif /* _ASM_X86_UACCESS_64_H */ |