Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Vitaly Mayatskikh <vmayatsk@redhat.com> |
| 3 | * Copyright 2002 Andi Kleen, SuSE Labs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Subject to the GNU Public License v2. |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 5 | * |
| 6 | * Functions to copy from and to user space. |
| 7 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 9 | #include <linux/linkage.h> |
Andi Kleen | 3022d73 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 10 | #include <asm/current.h> |
| 11 | #include <asm/asm-offsets.h> |
| 12 | #include <asm/thread_info.h> |
| 13 | #include <asm/cpufeature.h> |
Fenghua Yu | 4307bec | 2011-05-17 15:29:15 -0700 | [diff] [blame] | 14 | #include <asm/alternative-asm.h> |
H. Peter Anvin | 9732da8 | 2012-04-20 12:19:51 -0700 | [diff] [blame] | 15 | #include <asm/asm.h> |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 16 | #include <asm/smap.h> |
Andi Kleen | 3022d73 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 17 | |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 18 | /* Standard copy_to_user with segment limit checking */ |
Frederic Weisbecker | 3c93ca0 | 2009-11-16 15:42:18 +0100 | [diff] [blame] | 19 | ENTRY(_copy_to_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | GET_THREAD_INFO(%rax) |
| 21 | movq %rdi,%rcx |
| 22 | addq %rdx,%rcx |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 23 | jc bad_to_user |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 24 | cmpq TI_addr_limit(%rax),%rcx |
Jiri Olsa | 26afb7c | 2011-05-12 16:30:30 +0200 | [diff] [blame] | 25 | ja bad_to_user |
Borislav Petkov | de2ff88 | 2015-01-13 01:38:17 +0100 | [diff] [blame] | 26 | ALTERNATIVE_2 "jmp copy_user_generic_unrolled", \ |
| 27 | "jmp copy_user_generic_string", \ |
| 28 | X86_FEATURE_REP_GOOD, \ |
| 29 | "jmp copy_user_enhanced_fast_string", \ |
| 30 | X86_FEATURE_ERMS |
Frederic Weisbecker | 3c93ca0 | 2009-11-16 15:42:18 +0100 | [diff] [blame] | 31 | ENDPROC(_copy_to_user) |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 32 | |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 33 | /* Standard copy_from_user with segment limit checking */ |
Arjan van de Ven | 9f0cf4a | 2009-09-26 14:33:01 +0200 | [diff] [blame] | 34 | ENTRY(_copy_from_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | GET_THREAD_INFO(%rax) |
| 36 | movq %rsi,%rcx |
| 37 | addq %rdx,%rcx |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 38 | jc bad_from_user |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 39 | cmpq TI_addr_limit(%rax),%rcx |
Jiri Olsa | 26afb7c | 2011-05-12 16:30:30 +0200 | [diff] [blame] | 40 | ja bad_from_user |
Borislav Petkov | de2ff88 | 2015-01-13 01:38:17 +0100 | [diff] [blame] | 41 | ALTERNATIVE_2 "jmp copy_user_generic_unrolled", \ |
| 42 | "jmp copy_user_generic_string", \ |
| 43 | X86_FEATURE_REP_GOOD, \ |
| 44 | "jmp copy_user_enhanced_fast_string", \ |
| 45 | X86_FEATURE_ERMS |
Arjan van de Ven | 9f0cf4a | 2009-09-26 14:33:01 +0200 | [diff] [blame] | 46 | ENDPROC(_copy_from_user) |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | .section .fixup,"ax" |
| 49 | /* must zero dest */ |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 50 | ENTRY(bad_from_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | bad_from_user: |
| 52 | movl %edx,%ecx |
| 53 | xorl %eax,%eax |
| 54 | rep |
| 55 | stosb |
| 56 | bad_to_user: |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 57 | movl %edx,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | ret |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 59 | ENDPROC(bad_from_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | .previous |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* |
Andi Kleen | 3022d73 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 63 | * copy_user_generic_unrolled - memory copy with exception handling. |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 64 | * This version is for CPUs like P4 that don't have efficient micro |
| 65 | * code for rep movsq |
| 66 | * |
| 67 | * Input: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | * rdi destination |
| 69 | * rsi source |
| 70 | * rdx count |
| 71 | * |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 72 | * Output: |
Lucas De Marchi | 0d2eb44 | 2011-03-17 16:24:16 -0300 | [diff] [blame] | 73 | * eax uncopied bytes or 0 if successful. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | */ |
Andi Kleen | 3022d73 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 75 | ENTRY(copy_user_generic_unrolled) |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 76 | ASM_STAC |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 77 | cmpl $8,%edx |
| 78 | jb 20f /* less then 8 bytes, go to byte copy loop */ |
| 79 | ALIGN_DESTINATION |
| 80 | movl %edx,%ecx |
| 81 | andl $63,%edx |
| 82 | shrl $6,%ecx |
| 83 | jz 17f |
| 84 | 1: movq (%rsi),%r8 |
| 85 | 2: movq 1*8(%rsi),%r9 |
| 86 | 3: movq 2*8(%rsi),%r10 |
| 87 | 4: movq 3*8(%rsi),%r11 |
| 88 | 5: movq %r8,(%rdi) |
| 89 | 6: movq %r9,1*8(%rdi) |
| 90 | 7: movq %r10,2*8(%rdi) |
| 91 | 8: movq %r11,3*8(%rdi) |
| 92 | 9: movq 4*8(%rsi),%r8 |
| 93 | 10: movq 5*8(%rsi),%r9 |
| 94 | 11: movq 6*8(%rsi),%r10 |
| 95 | 12: movq 7*8(%rsi),%r11 |
| 96 | 13: movq %r8,4*8(%rdi) |
| 97 | 14: movq %r9,5*8(%rdi) |
| 98 | 15: movq %r10,6*8(%rdi) |
| 99 | 16: movq %r11,7*8(%rdi) |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 100 | leaq 64(%rsi),%rsi |
| 101 | leaq 64(%rdi),%rdi |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 102 | decl %ecx |
| 103 | jnz 1b |
| 104 | 17: movl %edx,%ecx |
| 105 | andl $7,%edx |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 106 | shrl $3,%ecx |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 107 | jz 20f |
| 108 | 18: movq (%rsi),%r8 |
| 109 | 19: movq %r8,(%rdi) |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 110 | leaq 8(%rsi),%rsi |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 111 | leaq 8(%rdi),%rdi |
| 112 | decl %ecx |
| 113 | jnz 18b |
| 114 | 20: andl %edx,%edx |
| 115 | jz 23f |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 116 | movl %edx,%ecx |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 117 | 21: movb (%rsi),%al |
| 118 | 22: movb %al,(%rdi) |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 119 | incq %rsi |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 120 | incq %rdi |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 121 | decl %ecx |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 122 | jnz 21b |
| 123 | 23: xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 124 | ASM_CLAC |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 125 | ret |
| 126 | |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 127 | .section .fixup,"ax" |
| 128 | 30: shll $6,%ecx |
| 129 | addl %ecx,%edx |
| 130 | jmp 60f |
H. Peter Anvin | 661c801 | 2013-11-20 12:50:51 -0800 | [diff] [blame] | 131 | 40: leal (%rdx,%rcx,8),%edx |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 132 | jmp 60f |
| 133 | 50: movl %ecx,%edx |
| 134 | 60: jmp copy_user_handle_tail /* ecx is zerorest also */ |
| 135 | .previous |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 136 | |
H. Peter Anvin | 9732da8 | 2012-04-20 12:19:51 -0700 | [diff] [blame] | 137 | _ASM_EXTABLE(1b,30b) |
| 138 | _ASM_EXTABLE(2b,30b) |
| 139 | _ASM_EXTABLE(3b,30b) |
| 140 | _ASM_EXTABLE(4b,30b) |
| 141 | _ASM_EXTABLE(5b,30b) |
| 142 | _ASM_EXTABLE(6b,30b) |
| 143 | _ASM_EXTABLE(7b,30b) |
| 144 | _ASM_EXTABLE(8b,30b) |
| 145 | _ASM_EXTABLE(9b,30b) |
| 146 | _ASM_EXTABLE(10b,30b) |
| 147 | _ASM_EXTABLE(11b,30b) |
| 148 | _ASM_EXTABLE(12b,30b) |
| 149 | _ASM_EXTABLE(13b,30b) |
| 150 | _ASM_EXTABLE(14b,30b) |
| 151 | _ASM_EXTABLE(15b,30b) |
| 152 | _ASM_EXTABLE(16b,30b) |
| 153 | _ASM_EXTABLE(18b,40b) |
| 154 | _ASM_EXTABLE(19b,40b) |
| 155 | _ASM_EXTABLE(21b,50b) |
| 156 | _ASM_EXTABLE(22b,50b) |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 157 | ENDPROC(copy_user_generic_unrolled) |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 158 | |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 159 | /* Some CPUs run faster using the string copy instructions. |
| 160 | * This is also a lot simpler. Use them when possible. |
| 161 | * |
| 162 | * Only 4GB of copy is supported. This shouldn't be a problem |
| 163 | * because the kernel normally only writes from/to page sized chunks |
| 164 | * even if user space passed a longer buffer. |
| 165 | * And more would be dangerous because both Intel and AMD have |
| 166 | * errata with rep movsq > 4GB. If someone feels the need to fix |
| 167 | * this please consider this. |
| 168 | * |
| 169 | * Input: |
| 170 | * rdi destination |
| 171 | * rsi source |
| 172 | * rdx count |
| 173 | * |
| 174 | * Output: |
| 175 | * eax uncopied bytes or 0 if successful. |
| 176 | */ |
Andi Kleen | 3022d73 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 177 | ENTRY(copy_user_generic_string) |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 178 | ASM_STAC |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 179 | cmpl $8,%edx |
| 180 | jb 2f /* less than 8 bytes, go to byte copy loop */ |
| 181 | ALIGN_DESTINATION |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | movl %edx,%ecx |
| 183 | shrl $3,%ecx |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 184 | andl $7,%edx |
| 185 | 1: rep |
Andi Kleen | 3022d73 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 186 | movsq |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 187 | 2: movl %edx,%ecx |
| 188 | 3: rep |
| 189 | movsb |
Fenghua Yu | f4cb1cc | 2013-11-16 12:37:01 -0800 | [diff] [blame] | 190 | xorl %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 191 | ASM_CLAC |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 192 | ret |
Andi Kleen | 3022d73 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 193 | |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 194 | .section .fixup,"ax" |
H. Peter Anvin | 661c801 | 2013-11-20 12:50:51 -0800 | [diff] [blame] | 195 | 11: leal (%rdx,%rcx,8),%ecx |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 196 | 12: movl %ecx,%edx /* ecx is zerorest also */ |
| 197 | jmp copy_user_handle_tail |
| 198 | .previous |
Andi Kleen | 2cbc9ee | 2006-01-11 22:44:45 +0100 | [diff] [blame] | 199 | |
H. Peter Anvin | 9732da8 | 2012-04-20 12:19:51 -0700 | [diff] [blame] | 200 | _ASM_EXTABLE(1b,11b) |
| 201 | _ASM_EXTABLE(3b,12b) |
Vitaly Mayatskikh | ad2fc2c | 2008-07-02 15:53:13 +0200 | [diff] [blame] | 202 | ENDPROC(copy_user_generic_string) |
Fenghua Yu | 4307bec | 2011-05-17 15:29:15 -0700 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * Some CPUs are adding enhanced REP MOVSB/STOSB instructions. |
| 206 | * It's recommended to use enhanced REP MOVSB/STOSB if it's enabled. |
| 207 | * |
| 208 | * Input: |
| 209 | * rdi destination |
| 210 | * rsi source |
| 211 | * rdx count |
| 212 | * |
| 213 | * Output: |
| 214 | * eax uncopied bytes or 0 if successful. |
| 215 | */ |
| 216 | ENTRY(copy_user_enhanced_fast_string) |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 217 | ASM_STAC |
Fenghua Yu | 4307bec | 2011-05-17 15:29:15 -0700 | [diff] [blame] | 218 | movl %edx,%ecx |
| 219 | 1: rep |
| 220 | movsb |
Fenghua Yu | f4cb1cc | 2013-11-16 12:37:01 -0800 | [diff] [blame] | 221 | xorl %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 222 | ASM_CLAC |
Fenghua Yu | 4307bec | 2011-05-17 15:29:15 -0700 | [diff] [blame] | 223 | ret |
| 224 | |
| 225 | .section .fixup,"ax" |
| 226 | 12: movl %ecx,%edx /* ecx is zerorest also */ |
| 227 | jmp copy_user_handle_tail |
| 228 | .previous |
| 229 | |
H. Peter Anvin | 9732da8 | 2012-04-20 12:19:51 -0700 | [diff] [blame] | 230 | _ASM_EXTABLE(1b,12b) |
Fenghua Yu | 4307bec | 2011-05-17 15:29:15 -0700 | [diff] [blame] | 231 | ENDPROC(copy_user_enhanced_fast_string) |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * copy_user_nocache - Uncached memory copy with exception handling |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 235 | * This will force destination out of cache for more performance. |
| 236 | * |
| 237 | * Note: Cached memory copy is used when destination or size is not |
| 238 | * naturally aligned. That is: |
| 239 | * - Require 8-byte alignment when size is 8 bytes or larger. |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 240 | */ |
| 241 | ENTRY(__copy_user_nocache) |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 242 | ASM_STAC |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 243 | |
| 244 | /* If size is less than 8 bytes, go to byte copy */ |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 245 | cmpl $8,%edx |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 246 | jb .L_1b_cache_copy_entry |
| 247 | |
| 248 | /* If destination is not 8-byte aligned, "cache" copy to align it */ |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 249 | ALIGN_DESTINATION |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 250 | |
| 251 | /* Set 4x8-byte copy count and remainder */ |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 252 | movl %edx,%ecx |
| 253 | andl $63,%edx |
| 254 | shrl $6,%ecx |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 255 | jz .L_8b_nocache_copy_entry /* jump if count is 0 */ |
| 256 | |
| 257 | /* Perform 4x8-byte nocache loop-copy */ |
| 258 | .L_4x8b_nocache_copy_loop: |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 259 | 1: movq (%rsi),%r8 |
| 260 | 2: movq 1*8(%rsi),%r9 |
| 261 | 3: movq 2*8(%rsi),%r10 |
| 262 | 4: movq 3*8(%rsi),%r11 |
| 263 | 5: movnti %r8,(%rdi) |
| 264 | 6: movnti %r9,1*8(%rdi) |
| 265 | 7: movnti %r10,2*8(%rdi) |
| 266 | 8: movnti %r11,3*8(%rdi) |
| 267 | 9: movq 4*8(%rsi),%r8 |
| 268 | 10: movq 5*8(%rsi),%r9 |
| 269 | 11: movq 6*8(%rsi),%r10 |
| 270 | 12: movq 7*8(%rsi),%r11 |
| 271 | 13: movnti %r8,4*8(%rdi) |
| 272 | 14: movnti %r9,5*8(%rdi) |
| 273 | 15: movnti %r10,6*8(%rdi) |
| 274 | 16: movnti %r11,7*8(%rdi) |
| 275 | leaq 64(%rsi),%rsi |
| 276 | leaq 64(%rdi),%rdi |
| 277 | decl %ecx |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 278 | jnz .L_4x8b_nocache_copy_loop |
| 279 | |
| 280 | /* Set 8-byte copy count and remainder */ |
| 281 | .L_8b_nocache_copy_entry: |
| 282 | movl %edx,%ecx |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 283 | andl $7,%edx |
| 284 | shrl $3,%ecx |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 285 | jz .L_1b_cache_copy_entry /* jump if count is 0 */ |
| 286 | |
| 287 | /* Perform 8-byte nocache loop-copy */ |
| 288 | .L_8b_nocache_copy_loop: |
| 289 | 20: movq (%rsi),%r8 |
| 290 | 21: movnti %r8,(%rdi) |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 291 | leaq 8(%rsi),%rsi |
| 292 | leaq 8(%rdi),%rdi |
| 293 | decl %ecx |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 294 | jnz .L_8b_nocache_copy_loop |
| 295 | |
| 296 | /* If no byte left, we're done */ |
| 297 | .L_1b_cache_copy_entry: |
| 298 | andl %edx,%edx |
| 299 | jz .L_finish_copy |
| 300 | |
| 301 | /* Perform byte "cache" loop-copy for the remainder */ |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 302 | movl %edx,%ecx |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 303 | .L_1b_cache_copy_loop: |
| 304 | 40: movb (%rsi),%al |
| 305 | 41: movb %al,(%rdi) |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 306 | incq %rsi |
| 307 | incq %rdi |
| 308 | decl %ecx |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 309 | jnz .L_1b_cache_copy_loop |
| 310 | |
| 311 | /* Finished copying; fence the prior stores */ |
| 312 | .L_finish_copy: |
| 313 | xorl %eax,%eax |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 314 | ASM_CLAC |
| 315 | sfence |
| 316 | ret |
| 317 | |
| 318 | .section .fixup,"ax" |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 319 | .L_fixup_4x8b_copy: |
| 320 | shll $6,%ecx |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 321 | addl %ecx,%edx |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 322 | jmp .L_fixup_handle_tail |
| 323 | .L_fixup_8b_copy: |
| 324 | lea (%rdx,%rcx,8),%rdx |
| 325 | jmp .L_fixup_handle_tail |
| 326 | .L_fixup_1b_copy: |
| 327 | movl %ecx,%edx |
| 328 | .L_fixup_handle_tail: |
| 329 | sfence |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 330 | jmp copy_user_handle_tail |
| 331 | .previous |
| 332 | |
Toshi Kani | ee9737c | 2016-02-11 14:24:16 -0700 | [diff] [blame^] | 333 | _ASM_EXTABLE(1b,.L_fixup_4x8b_copy) |
| 334 | _ASM_EXTABLE(2b,.L_fixup_4x8b_copy) |
| 335 | _ASM_EXTABLE(3b,.L_fixup_4x8b_copy) |
| 336 | _ASM_EXTABLE(4b,.L_fixup_4x8b_copy) |
| 337 | _ASM_EXTABLE(5b,.L_fixup_4x8b_copy) |
| 338 | _ASM_EXTABLE(6b,.L_fixup_4x8b_copy) |
| 339 | _ASM_EXTABLE(7b,.L_fixup_4x8b_copy) |
| 340 | _ASM_EXTABLE(8b,.L_fixup_4x8b_copy) |
| 341 | _ASM_EXTABLE(9b,.L_fixup_4x8b_copy) |
| 342 | _ASM_EXTABLE(10b,.L_fixup_4x8b_copy) |
| 343 | _ASM_EXTABLE(11b,.L_fixup_4x8b_copy) |
| 344 | _ASM_EXTABLE(12b,.L_fixup_4x8b_copy) |
| 345 | _ASM_EXTABLE(13b,.L_fixup_4x8b_copy) |
| 346 | _ASM_EXTABLE(14b,.L_fixup_4x8b_copy) |
| 347 | _ASM_EXTABLE(15b,.L_fixup_4x8b_copy) |
| 348 | _ASM_EXTABLE(16b,.L_fixup_4x8b_copy) |
| 349 | _ASM_EXTABLE(20b,.L_fixup_8b_copy) |
| 350 | _ASM_EXTABLE(21b,.L_fixup_8b_copy) |
| 351 | _ASM_EXTABLE(40b,.L_fixup_1b_copy) |
| 352 | _ASM_EXTABLE(41b,.L_fixup_1b_copy) |
Borislav Petkov | b41e6ec | 2015-05-13 19:42:24 +0200 | [diff] [blame] | 353 | ENDPROC(__copy_user_nocache) |