mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-05-24 10:39:52 +00:00
x86/lib/clear_page_64.S: Convert to ALTERNATIVE_2 macro
Move clear_page() up so that we can get 2-byte forward JMPs when patching: apply_alternatives: feat: 3*32+16, old: (ffffffff8130adb0, len: 5), repl: (ffffffff81d0b859, len: 5) ffffffff8130adb0: alt_insn: 90 90 90 90 90 recompute_jump: new_displ: 0x0000003e ffffffff81d0b859: rpl_insn: eb 3e 66 66 90 even though the compiler generated 5-byte JMPs which we padded with 5 NOPs. Also, make the REP_GOOD version be the default as the majority of machines set REP_GOOD. This way we get to save ourselves the JMP: old insn VA: 0xffffffff813038b0, CPU feat: X86_FEATURE_REP_GOOD, size: 5, padlen: 0 clear_page: ffffffff813038b0 <clear_page>: ffffffff813038b0: e9 0b 00 00 00 jmpq ffffffff813038c0 repl insn: 0xffffffff81cf0e92, size: 0 old insn VA: 0xffffffff813038b0, CPU feat: X86_FEATURE_ERMS, size: 5, padlen: 0 clear_page: ffffffff813038b0 <clear_page>: ffffffff813038b0: e9 0b 00 00 00 jmpq ffffffff813038c0 repl insn: 0xffffffff81cf0e92, size: 5 ffffffff81cf0e92: e9 69 2a 61 ff jmpq ffffffff81303900 ffffffff813038b0 <clear_page>: ffffffff813038b0: e9 69 2a 61 ff jmpq ffffffff8091631e Signed-off-by: Borislav Petkov <bp@suse.de>
This commit is contained in:
parent
8e65f6e03a
commit
6620ef28c8
1 changed files with 27 additions and 39 deletions
|
@ -1,31 +1,35 @@
|
||||||
#include <linux/linkage.h>
|
#include <linux/linkage.h>
|
||||||
#include <asm/dwarf2.h>
|
#include <asm/dwarf2.h>
|
||||||
|
#include <asm/cpufeature.h>
|
||||||
#include <asm/alternative-asm.h>
|
#include <asm/alternative-asm.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Zero a page.
|
* Most CPUs support enhanced REP MOVSB/STOSB instructions. It is
|
||||||
* rdi page
|
* recommended to use this when possible and we do use them by default.
|
||||||
|
* If enhanced REP MOVSB/STOSB is not available, try to use fast string.
|
||||||
|
* Otherwise, use original.
|
||||||
*/
|
*/
|
||||||
ENTRY(clear_page_c)
|
|
||||||
|
/*
|
||||||
|
* Zero a page.
|
||||||
|
* %rdi - page
|
||||||
|
*/
|
||||||
|
ENTRY(clear_page)
|
||||||
CFI_STARTPROC
|
CFI_STARTPROC
|
||||||
|
|
||||||
|
ALTERNATIVE_2 "jmp clear_page_orig", "", X86_FEATURE_REP_GOOD, \
|
||||||
|
"jmp clear_page_c_e", X86_FEATURE_ERMS
|
||||||
|
|
||||||
movl $4096/8,%ecx
|
movl $4096/8,%ecx
|
||||||
xorl %eax,%eax
|
xorl %eax,%eax
|
||||||
rep stosq
|
rep stosq
|
||||||
ret
|
ret
|
||||||
CFI_ENDPROC
|
CFI_ENDPROC
|
||||||
ENDPROC(clear_page_c)
|
ENDPROC(clear_page)
|
||||||
|
|
||||||
ENTRY(clear_page_c_e)
|
ENTRY(clear_page_orig)
|
||||||
CFI_STARTPROC
|
CFI_STARTPROC
|
||||||
movl $4096,%ecx
|
|
||||||
xorl %eax,%eax
|
|
||||||
rep stosb
|
|
||||||
ret
|
|
||||||
CFI_ENDPROC
|
|
||||||
ENDPROC(clear_page_c_e)
|
|
||||||
|
|
||||||
ENTRY(clear_page)
|
|
||||||
CFI_STARTPROC
|
|
||||||
xorl %eax,%eax
|
xorl %eax,%eax
|
||||||
movl $4096/64,%ecx
|
movl $4096/64,%ecx
|
||||||
.p2align 4
|
.p2align 4
|
||||||
|
@ -45,29 +49,13 @@ ENTRY(clear_page)
|
||||||
nop
|
nop
|
||||||
ret
|
ret
|
||||||
CFI_ENDPROC
|
CFI_ENDPROC
|
||||||
.Lclear_page_end:
|
ENDPROC(clear_page_orig)
|
||||||
ENDPROC(clear_page)
|
|
||||||
|
|
||||||
/*
|
ENTRY(clear_page_c_e)
|
||||||
* Some CPUs support enhanced REP MOVSB/STOSB instructions.
|
CFI_STARTPROC
|
||||||
* It is recommended to use this when possible.
|
movl $4096,%ecx
|
||||||
* If enhanced REP MOVSB/STOSB is not available, try to use fast string.
|
xorl %eax,%eax
|
||||||
* Otherwise, use original function.
|
rep stosb
|
||||||
*
|
ret
|
||||||
*/
|
CFI_ENDPROC
|
||||||
|
ENDPROC(clear_page_c_e)
|
||||||
#include <asm/cpufeature.h>
|
|
||||||
|
|
||||||
.section .altinstr_replacement,"ax"
|
|
||||||
1: .byte 0xeb /* jmp <disp8> */
|
|
||||||
.byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
|
|
||||||
2: .byte 0xeb /* jmp <disp8> */
|
|
||||||
.byte (clear_page_c_e - clear_page) - (3f - 2b) /* offset */
|
|
||||||
3:
|
|
||||||
.previous
|
|
||||||
.section .altinstructions,"a"
|
|
||||||
altinstruction_entry clear_page,1b,X86_FEATURE_REP_GOOD,\
|
|
||||||
.Lclear_page_end-clear_page, 2b-1b, 0
|
|
||||||
altinstruction_entry clear_page,2b,X86_FEATURE_ERMS, \
|
|
||||||
.Lclear_page_end-clear_page,3b-2b, 0
|
|
||||||
.previous
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue