Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1 | #include <linux/linkage.h> |
Borislav Petkov | cd4d09e | 2016-01-26 22:12:04 +0100 | [diff] [blame] | 2 | #include <asm/cpufeatures.h> |
Fenghua Yu | e365c9d | 2011-05-17 15:29:14 -0700 | [diff] [blame] | 3 | #include <asm/alternative-asm.h> |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 4 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | /* |
Borislav Petkov | 6620ef2 | 2015-01-18 12:57:41 +0100 | [diff] [blame] | 6 | * Most CPUs support enhanced REP MOVSB/STOSB instructions. It is |
| 7 | * recommended to use this when possible and we do use them by default. |
| 8 | * If enhanced REP MOVSB/STOSB is not available, try to use fast string. |
| 9 | * Otherwise, use original. |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * Zero a page. |
| 14 | * %rdi - page |
| 15 | */ |
| 16 | ENTRY(clear_page) |
Borislav Petkov | 6620ef2 | 2015-01-18 12:57:41 +0100 | [diff] [blame] | 17 | |
| 18 | ALTERNATIVE_2 "jmp clear_page_orig", "", X86_FEATURE_REP_GOOD, \ |
| 19 | "jmp clear_page_c_e", X86_FEATURE_ERMS |
| 20 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 21 | movl $4096/8,%ecx |
| 22 | xorl %eax,%eax |
| 23 | rep stosq |
| 24 | ret |
Borislav Petkov | 6620ef2 | 2015-01-18 12:57:41 +0100 | [diff] [blame] | 25 | ENDPROC(clear_page) |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 26 | |
Borislav Petkov | 6620ef2 | 2015-01-18 12:57:41 +0100 | [diff] [blame] | 27 | ENTRY(clear_page_orig) |
Fenghua Yu | e365c9d | 2011-05-17 15:29:14 -0700 | [diff] [blame] | 28 | |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 29 | xorl %eax,%eax |
| 30 | movl $4096/64,%ecx |
| 31 | .p2align 4 |
| 32 | .Lloop: |
| 33 | decl %ecx |
| 34 | #define PUT(x) movq %rax,x*8(%rdi) |
| 35 | movq %rax,(%rdi) |
| 36 | PUT(1) |
| 37 | PUT(2) |
| 38 | PUT(3) |
| 39 | PUT(4) |
| 40 | PUT(5) |
| 41 | PUT(6) |
| 42 | PUT(7) |
| 43 | leaq 64(%rdi),%rdi |
| 44 | jnz .Lloop |
| 45 | nop |
| 46 | ret |
Borislav Petkov | 6620ef2 | 2015-01-18 12:57:41 +0100 | [diff] [blame] | 47 | ENDPROC(clear_page_orig) |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 48 | |
Borislav Petkov | 6620ef2 | 2015-01-18 12:57:41 +0100 | [diff] [blame] | 49 | ENTRY(clear_page_c_e) |
Borislav Petkov | 6620ef2 | 2015-01-18 12:57:41 +0100 | [diff] [blame] | 50 | movl $4096,%ecx |
| 51 | xorl %eax,%eax |
| 52 | rep stosb |
| 53 | ret |
Borislav Petkov | 6620ef2 | 2015-01-18 12:57:41 +0100 | [diff] [blame] | 54 | ENDPROC(clear_page_c_e) |