x86/entry: GPR handling improvements
cover x86/entry: GPR handling improvements
Finish the conversion to PUSH/POP_GPRS, and remove SAVE/RESTORE_ALL.
Slightly RFC; testing still ongoing, but I dont anticipate any issues.
Andrew Cooper (3):
x86/hvm: Use PUSH_AND_CLEAR_GPRS in preference to SAVE_ALL x86/entry: Use POP_GPRS and remove RESTORE_ALL x86/entry: Use PUSH_AND_CLEAR_GPRS and drop SAVE_ALL
xen/arch/x86/hvm/svm/entry.S | 2 +- xen/arch/x86/hvm/vmx/entry.S | 4 +- xen/arch/x86/include/asm/asm_defns.h | 95 +--------------------------- xen/arch/x86/x86_64/compat/entry.S | 12 ++-- xen/arch/x86/x86_64/entry.S | 37 ++++++----- 5 files changed, 31 insertions(+), 119 deletions(-)
base-commit: eca5f92e6b6b6135092ec179647a9349dfe8f907
Signature · 1 line
2.39.5
PATCH 1/3 x86/hvm: Use PUSH_AND_CLEAR_GPRS in preference to SAVE_ALL
SAVE_ALL hides a CLD instruction which is not needed anywhere here.
* VMX VMExit always clears flags. VMX VMentry failure never switched away from the host flags, so they're still good.
* SVM VMRUN always saves and restores the host flags.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
Bloat-o-meter reports:
add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-168 (-168)
Function old new delta svm_asm_do_resume 416 360 -56 vmx_asm_vmexit_handler 576 464 -112 --- xen/arch/x86/hvm/svm/entry.S | 2 +- xen/arch/x86/hvm/vmx/entry.S | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/svm/entry.S +1 -1
@@ -89,7 +89,7 @@ __UNLIKELY_END(nsvm_hap) vmrun - SAVE_ALL + PUSH_AND_CLEAR_GPRS GET_CURRENT(bx)
xen/arch/x86/hvm/vmx/entry.S +2 -2
@@ -22,7 +22,7 @@ #include <asm/page.h> FUNC(vmx_asm_vmexit_handler) - SAVE_ALL + PUSH_AND_CLEAR_GPRS mov %cr2,%rax GET_CURRENT(bx)
@@ -157,7 +157,7 @@ UNLIKELY_END(realmode) .Lvmx_vmentry_fail: sti - SAVE_ALL + PUSH_AND_CLEAR_GPRS /* * SPEC_CTRL_ENTRY notes
Signature · 1 line
2.39.5
Re: [PATCH 1/3] x86/hvm: Use PUSH_AND_CLEAR_GPRS in preference to SAVE_ALL
Quoted 9 lines · Andrew Cooper
SAVE_ALLhides a CLD instruction which is not needed anywhere here.* VMX VMExit always clears flags. VMX VMentry failure never switched away from the host flags, so they're still good.
* SVM VMRUN always saves and restores the host flags.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
PATCH 2/3 x86/entry: Use POP_GPRS and remove RESTORE_ALL
In reply to Andrew CooperPOP_GPRS is shorter than RESTORE_ALL in terms of emitted code.
By separating the popping of entry_vector/error_code off the stack, SPEC_CTRL_COND_VERW doesn't need custom displacements.
Get rid of the compat=1 special case for PV32. It's not obviously a win, and PV32 is getting increasingly rare these days.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
Bloat-o-meter reports:
add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-128 (-128)
Function old new delta compat_restore_all_guest 187 158 -29 restore_all_guest 372 324 -48 restore_all_xen 165 114 -51 --- xen/arch/x86/include/asm/asm_defns.h | 50 +--------------------------- xen/arch/x86/x86_64/compat/entry.S | 9 +++-- xen/arch/x86/x86_64/entry.S | 12 +++---- 3 files changed, 10 insertions(+), 61 deletions(-)
xen/arch/x86/include/asm/asm_defns.h +1 -49
@@ -264,54 +264,6 @@ static always_inline void stac(void) xor %r15d, %r15d .endm -#define LOAD_ONE_REG (reg, compat) \ -.if !(compat); \ - movq UREGS_r##reg(%rsp),%r##reg; \ -.else; \ - movl UREGS_r##reg(%rsp),%e##reg; \ -.endif - -/* -* Restore all previously saved registers. -* -* @adj: extra stack pointer adjustment to be folded into the adjustment done -* anyway at the end of the macro -* @compat: R8-R15 don't need reloading, but they are clobbered for added -* safety against information leaks. -*/ -.macro RESTORE_ALL adj=0, compat=0 -.if !\compat - movq UREGS_r15(%rsp), %r15 - movq UREGS_r14(%rsp), %r14 - movq UREGS_r13(%rsp), %r13 - movq UREGS_r12(%rsp), %r12 -.else - xor %r15d, %r15d - xor %r14d, %r14d - xor %r13d, %r13d - xor %r12d, %r12d -.endif - LOAD_ONE_REG(bp, \compat) - LOAD_ONE_REG(bx, \compat) -.if !\compat - movq UREGS_r11(%rsp),%r11 - movq UREGS_r10(%rsp),%r10 - movq UREGS_r9(%rsp),%r9 - movq UREGS_r8(%rsp),%r8 -.else - xor %r11d, %r11d - xor %r10d, %r10d - xor %r9d, %r9d - xor %r8d, %r8d -.endif - LOAD_ONE_REG(ax, \compat) - LOAD_ONE_REG(cx, \compat) - LOAD_ONE_REG(dx, \compat) - LOAD_ONE_REG(si, \compat) - LOAD_ONE_REG(di, \compat) - subq $-(UREGS_error_code-UREGS_r15+\adj), %rsp -.endm -/* * Push and clear GPRs */
@@ -369,7 +321,7 @@ static always_inline void stac(void) pop %r9 pop %r8 .if \skip_rax - pop %rcx + pop %rcx /* Any register yet to restore. */ .else pop %rax .endif
xen/arch/x86/x86_64/compat/entry.S +4 -5
@@ -160,12 +160,11 @@ FUNC(compat_restore_all_guest) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ - RESTORE_ALL adj=8, compat=1 + POP_GPRS - /* Account for ev/ec having already been popped off the stack. */ - SPEC_CTRL_COND_VERW \ - scf=STK_REL(CPUINFO_scf, CPUINFO_rip), \ - sel=STK_REL(CPUINFO_verw_sel, CPUINFO_rip) + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + + add $8, %rsp /* Pop ev/ec off the stack */ jmp iret_to_guest END(compat_restore_all_guest)
xen/arch/x86/x86_64/entry.S +5 -7
@@ -226,7 +226,8 @@ FUNC_LOCAL(restore_all_guest) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ - RESTORE_ALL + POP_GPRS + BUILD_BUG_ON(TRAP_syscall & 0xff) testb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) jz iret_exit_to_guest
@@ -753,20 +754,17 @@ UNLIKELY_END(exit_cr3) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ SPEC_CTRL_EXIT_TO_XEN /* Req: %r12=ist_exit %r14=end %rsp=regs, Clob: abcd */ - RESTORE_ALL adj=8 + POP_GPRS /* * When the CPU pushed this exception frame, it zero-extended eflags. * For an IST exit, SPEC_CTRL_EXIT_TO_XEN stashed shadow copies of * scf and ver_sel above eflags, as we can't use any GPRs, * and we're at a random place on the stack, not in a CPUFINFO block. - * - * Account for ev/ec having already been popped off the stack. */ - SPEC_CTRL_COND_VERW \ - scf=STK_REL(EFRAME_shadow_scf, EFRAME_rip), \ - sel=STK_REL(EFRAME_shadow_sel, EFRAME_rip) + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + add $8, %rsp /* Pop ev/ec off the stack */ iretq END(restore_all_xen)
Signature · 1 line
2.39.5
Re: [PATCH 2/3] x86/entry: Use POP_GPRS and remove RESTORE_ALL
Quoted 11 lines · Andrew Cooper
POP_GPRSis shorter thanRESTORE_ALLin terms of emitted code.By separating the popping of entry_vector/error_code off the stack,
SPEC_CTRL_COND_VERWdoesn't need custom displacements.Get rid of the compat=1 special case for PV32. It's not obviously a win, and PV32 is getting increasingly rare these days.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
as-is, however ...
Quoted 44 lines
xen/arch/x86/x86_64/compat/entry.S +4
-5@@ -160,12 +160,11 @@ FUNC(compat_restore_all_guest) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ - RESTORE_ALL adj=8, compat=1 + POP_GPRS - /* Account for ev/ec having already been popped off the stack. */ - SPEC_CTRL_COND_VERW \ - scf=STK_REL(CPUINFO_scf, CPUINFO_rip), \ - sel=STK_REL(CPUINFO_verw_sel, CPUINFO_rip) + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + + add $8, %rsp /* Pop ev/ec off the stack */ jmp iret_to_guest END(compat_restore_all_guest)xen/arch/x86/x86_64/entry.S +3
-3@@ -226,7 +226,8 @@ FUNC_LOCAL(restore_all_guest) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ - RESTORE_ALL + POP_GPRS + BUILD_BUG_ON(TRAP_syscall & 0xff) testb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) jz iret_exit_to_guest@@ -753,20 +754,17 @@ UNLIKELY_END(exit_cr3) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ SPEC_CTRL_EXIT_TO_XEN /* Req: %r12=ist_exit %r14=end %rsp=regs, Clob: abcd */ - RESTORE_ALL adj=8 + POP_GPRS /* * When the CPU pushed this exception frame, it zero-extended eflags. * For an IST exit, SPEC_CTRL_EXIT_TO_XEN stashed shadow copies of * scf and ver_sel above eflags, as we can't use any GPRs, * and we're at a random place on the stack, not in a CPUFINFO block. - *
xen/arch/x86/x86_64/entry.S UNLIKELY_END(exit_cr3) · line 769
Quoted 10 lines
xen/arch/x86/x86_64/entry.S +2
-4- * Account for ev/ec having already been popped off the stack. */ - SPEC_CTRL_COND_VERW \ - scf=STK_REL(EFRAME_shadow_scf, EFRAME_rip), \ - sel=STK_REL(EFRAME_shadow_sel, EFRAME_rip) + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + add $8, %rsp /* Pop ev/ec off the stack */ iretq END(restore_all_xen)
... both uses of SPEC_CTRL_COND_VERW's with arguments go away. Shouldn't the macro thus also be pruned of its parameters?
Jan
Re: [PATCH 2/3] x86/entry: Use POP_GPRS and remove RESTORE_ALL
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Andrew Cooper
POP_GPRSis shorter thanRESTORE_ALLin terms of emitted code.By separating the popping of entry_vector/error_code off the stack,
SPEC_CTRL_COND_VERWdoesn't need custom displacements.
Quoted 7 lines
Quoted 6 lines
Get rid of the compat=1 special case for PV32. It's not obviously a win, and PV32 is getting increasingly rare these days.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Thanks.
Quoted 53 lines
as-is, however ...
Quoted 51 lines
xen/arch/x86/x86_64/compat/entry.S +4
-5@@ -160,12 +160,11 @@ FUNC(compat_restore_all_guest) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ - RESTORE_ALL adj=8, compat=1 + POP_GPRS - /* Account for ev/ec having already been popped off the stack. */ - SPEC_CTRL_COND_VERW \ - scf=STK_REL(CPUINFO_scf, CPUINFO_rip), \ - sel=STK_REL(CPUINFO_verw_sel, CPUINFO_rip) + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + + add $8, %rsp /* Pop ev/ec off the stack */ jmp iret_to_guest END(compat_restore_all_guest)xen/arch/x86/x86_64/entry.S +4
-7@@ -226,7 +226,8 @@ FUNC_LOCAL(restore_all_guest) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ - RESTORE_ALL + POP_GPRS + BUILD_BUG_ON(TRAP_syscall & 0xff) testb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) jz iret_exit_to_guest@@ -753,20 +754,17 @@ UNLIKELY_END(exit_cr3) /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ SPEC_CTRL_EXIT_TO_XEN /* Req: %r12=ist_exit %r14=end %rsp=regs, Clob: abcd */ - RESTORE_ALL adj=8 + POP_GPRS /* * When the CPU pushed this exception frame, it zero-extended eflags. * For an IST exit, SPEC_CTRL_EXIT_TO_XEN stashed shadow copies of * scf and ver_sel above eflags, as we can't use any GPRs, * and we're at a random place on the stack, not in a CPUFINFO block. - * - * Account for ev/ec having already been popped off the stack. */ - SPEC_CTRL_COND_VERW \ - scf=STK_REL(EFRAME_shadow_scf, EFRAME_rip), \ - sel=STK_REL(EFRAME_shadow_sel, EFRAME_rip) + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */
Quoted 5 lines
xen/arch/x86/x86_64/entry.S UNLIKELY_END(exit_cr3) · line 769
Quoted 3 lines
xen/arch/x86/x86_64/entry.S +1
-0+ add $8, %rsp /* Pop ev/ec off the stack */ iretq END(restore_all_xen)... both uses of SPEC_CTRL_COND_VERW's with arguments go away. Shouldn't the macro thus also be pruned of its parameters?
Not in this patch.
~Andrew
PATCH 3/3 x86/entry: Use PUSH_AND_CLEAR_GPRS and drop SAVE_ALL
In reply to Andrew CooperPUSH_AND_CLEAR_GPRS is shorter than SAVE_ALL in terms of emitted code.
lstar_enter() and cstar_enter() do not need CLD. The SYSCALL instruction sanitises flags based on MSR_SYSCALL_MASK. For all other cases, place the CLD instruction next to STAC/CLAC so the flag handling is together.
Get rid of the compat=1 special case for PV32. It's not obviously a win, and PV32 is getting increasingly rare these days.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
Bloat-o-meter reports:
add/remove: 0/0 grow/shrink: 0/12 up/down: 0/-518 (-518)
Function old new delta
symbols_names 135277 135276 -1
symbols_offsets 53664 53660 -4
entry_int82 229 213 -16 sysenter_entry 383 328 -55 handle_ist_exception 450 395 -55 handle_exception 683 628 -55 entry_int80 432 377 -55 entry_DF 294 239 -55 early_page_fault 139 84 -55 common_interrupt 327 272 -55 lstar_enter 322 266 -56 cstar_enter 323 267 -56 --- xen/arch/x86/include/asm/asm_defns.h | 45 ---------------------------- xen/arch/x86/x86_64/compat/entry.S | 3 +- xen/arch/x86/x86_64/entry.S | 25 ++++++++++------ 3 files changed, 18 insertions(+), 55 deletions(-)
xen/arch/x86/include/asm/asm_defns.h +0 -45
@@ -219,51 +219,6 @@ static always_inline void stac(void)#endif #ifdef __ASSEMBLER__ -.macro SAVE_ALL compat=0 - addq $-(UREGS_error_code-UREGS_r15), %rsp - cld - movq %rdi,UREGS_rdi(%rsp) - xor %edi, %edi - movq %rsi,UREGS_rsi(%rsp) - xor %esi, %esi - movq %rdx,UREGS_rdx(%rsp) - xor %edx, %edx - movq %rcx,UREGS_rcx(%rsp) - xor %ecx, %ecx - movq %rax,UREGS_rax(%rsp) - xor %eax, %eax -.if !\compat - movq %r8,UREGS_r8(%rsp) - movq %r9,UREGS_r9(%rsp) - movq %r10,UREGS_r10(%rsp) - movq %r11,UREGS_r11(%rsp) -.endif - xor %r8d, %r8d - xor %r9d, %r9d - xor %r10d, %r10d - xor %r11d, %r11d - movq %rbx,UREGS_rbx(%rsp) - xor %ebx, %ebx - movq %rbp,UREGS_rbp(%rsp) -#ifdef CONFIG_FRAME_POINTER -/* Indicate special exception stack frame by inverting the frame pointer. */ - leaq UREGS_rbp(%rsp), %rbp - notq %rbp -#else - xor %ebp, %ebp -#endif -.if !\compat - movq %r12,UREGS_r12(%rsp) - movq %r13,UREGS_r13(%rsp) - movq %r14,UREGS_r14(%rsp) - movq %r15,UREGS_r15(%rsp) -.endif - xor %r12d, %r12d - xor %r13d, %r13d - xor %r14d, %r14d - xor %r15d, %r15d -.endm -/* * Push and clear GPRs */
xen/arch/x86/x86_64/compat/entry.S +2 -1
@@ -13,10 +13,11 @@ FUNC(entry_int82) ENDBR64 + cld ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP pushq $0 movb $HYPERCALL_VECTOR, EFRAME_entry_vector(%rsp) - SAVE_ALL compat=1 /* DPL1 gate, restricted to 32bit PV guests only. */ + PUSH_AND_CLEAR_GPRS GET_STACK_END(14)
xen/arch/x86/x86_64/entry.S +16 -9
@@ -305,7 +305,7 @@ FUNC(lstar_enter) pushq $0 BUILD_BUG_ON(TRAP_syscall & 0xff) movb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) - SAVE_ALL + PUSH_AND_CLEAR_GPRS GET_STACK_END(14)
@@ -345,7 +345,7 @@ FUNC(cstar_enter) pushq $0 BUILD_BUG_ON(TRAP_syscall & 0xff) movb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) - SAVE_ALL + PUSH_AND_CLEAR_GPRS GET_STACK_END(14)
@@ -383,13 +383,14 @@ FUNC(sysenter_entry) pushq $0 pushfq LABEL(sysenter_eflags_saved, 0) + cld ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP pushq $3 /* ring 3 null cs */ pushq $0 /* null rip */ pushq $0 BUILD_BUG_ON(TRAP_syscall & 0xff) movb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) - SAVE_ALL + PUSH_AND_CLEAR_GPRS GET_STACK_END(14)
@@ -442,10 +443,11 @@ END(sysenter_entry) FUNC(entry_int80) ENDBR64 + cld ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP pushq $0 movb $0x80, EFRAME_entry_vector(%rsp) - SAVE_ALL + PUSH_AND_CLEAR_GPRS GET_STACK_END(14)
@@ -722,8 +724,9 @@ END(ret_from_intr) .section .init.text, "ax", @progbits FUNC(early_page_fault) ENDBR64 + cld movb $X86_EXC_PF, EFRAME_entry_vector(%rsp) - SAVE_ALL + PUSH_AND_CLEAR_GPRS movq %rsp, %rdi call do_early_page_fault jmp restore_all_xen
@@ -769,8 +772,9 @@ UNLIKELY_END(exit_cr3) END(restore_all_xen) FUNC(common_interrupt) + cld ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP - SAVE_ALL + PUSH_AND_CLEAR_GPRS GET_STACK_END(14)
@@ -805,8 +809,9 @@ FUNC(entry_PF) END(entry_PF) /* No special register assumptions. */ FUNC(handle_exception, 0) + cld ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP - SAVE_ALL + PUSH_AND_CLEAR_GPRS GET_STACK_END(14)
@@ -1103,9 +1108,10 @@ END(entry_CP) FUNC(entry_DF) ENDBR64 movb $X86_EXC_DF, EFRAME_entry_vector(%rsp) + cld /* Set AC to reduce chance of further SMAP faults */ ALTERNATIVE "", stac, X86_FEATURE_XEN_SMAP - SAVE_ALL + PUSH_AND_CLEAR_GPRS GET_STACK_END(14)
@@ -1132,8 +1138,9 @@ FUNC(entry_NMI) END(entry_NMI) FUNC(handle_ist_exception) + cld ALTERNATIVE "", clac, X86_FEATURE_XEN_SMAP - SAVE_ALL + PUSH_AND_CLEAR_GPRS GET_STACK_END(14)
Signature · 1 line
2.39.5
Re: [PATCH 3/3] x86/entry: Use PUSH_AND_CLEAR_GPRS and drop SAVE_ALL
Quoted 1 line · Andrew Cooper
PUSH_AND_CLEAR_GPRSis shorter thanSAVE_ALLin terms of emitted code.
Could patch 1 perhaps also gain this sentence?
Quoted 3 lines
lstar_enter()andcstar_enter()do not need CLD. The SYSCALL instruction sanitises flags based onMSR_SYSCALL_MASK. For all other cases, place the CLD instruction next to STAC/CLAC so the flag handling is together.
And really the earlier the better. Relevant perhaps for early_page_fault(), which has no CLAC.
Quoted 6 lines
Get rid of the compat=1 special case for PV32. It's not obviously a win, and PV32 is getting increasingly rare these days.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 5 lines
Bloat-o-meter reports:
add/remove: 0/0 grow/shrink: 0/12 up/down: 0/-518 (-518)
Function old new delta
symbols_names135277 135276 -1
symbols_offsets53664 53660 -4
Interesting. Likely an artifact of padding going away between two functions. Which likely would change again if the SLS patches would finally land ("x86: guard against straight-line speculation past JMP or RET in assembly files" here in particular).
Btw, as it occurs to me while mentioning SLS: Judging from the patches I have, IRET looks to be immune, albeit I can't find any statement in the doc. What about ERET{S,U}, uses of which we've gained only relatively recently?
Jan
Re: [PATCH 3/3] x86/entry: Use PUSH_AND_CLEAR_GPRS and drop SAVE_ALL
Quoted 3 lines · Jan Beulich
Quoted 1 line · Andrew Cooper
PUSH_AND_CLEAR_GPRSis shorter thanSAVE_ALLin terms of emitted code.Could patch 1 perhaps also gain this sentence?
Done.
Quoted 7 lines
Quoted 4 lines
lstar_enter()andcstar_enter()do not need CLD. The SYSCALL instruction sanitises flags based onMSR_SYSCALL_MASK. For all other cases, place the CLD instruction next to STAC/CLAC so the flag handling is together.And really the earlier the better. Relevant perhaps for
early_page_fault(), which has no CLAC.
Quoted 7 lines
Quoted 6 lines
Get rid of the compat=1 special case for PV32. It's not obviously a win, and PV32 is getting increasingly rare these days.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Thanks.
Quoted 6 lines
Quoted 6 lines
Bloat-o-meter reports:
add/remove: 0/0 grow/shrink: 0/12 up/down: 0/-518 (-518)
Function old new delta
symbols_names135277 135276 -1
symbols_offsets53664 53660 -4
Quoted 8 lines
Interesting. Likely an artifact of padding going away between two functions. Which likely would change again if the SLS patches would finally land ("x86: guard against straight-line speculation past JMP or RET in assembly files" here in particular).
Btw, as it occurs to me while mentioning SLS: Judging from the patches I have, IRET looks to be immune, albeit I can't find any statement in the doc. What about ERET{S,U}, uses of which we've gained only relatively recently?
I think the bit you want is in SDM Vol2. For ERETS:
"Instruction ordering. Instructions following execution of ERETS may be fetched from memory before earlier instructions complete execution, but they will not execute (even speculatively) until all instructions prior to ERETS have completed execution (the later instructions may execute before data stored by the earlier instructions have become globally visible)."
and says the same for ERETU. Sadly, "following" is ambiguous in the context of SLS, but an ERETS-to-self could end up legitimately executing the next sequential instruction. Either way, the "not execute even speculatively" is the property wanted.
IRET notes that it's architecturally serialising, which is a much stronger guarantee.
~Andrew
Re: [PATCH 3/3] x86/entry: Use PUSH_AND_CLEAR_GPRS and drop SAVE_ALL
Quoted 13 lines · Andrew Cooper
Quoted 3 lines · Jan Beulich
Btw, as it occurs to me while mentioning SLS: Judging from the patches I have, IRET looks to be immune, albeit I can't find any statement in the doc. What about ERET{S,U}, uses of which we've gained only relatively recently?
I think the bit you want is in SDM Vol2. For ERETS:
"Instruction ordering. Instructions following execution of ERETS may be fetched from memory before earlier instructions complete execution, but they will not execute (even speculatively) until all instructions prior to ERETS have completed execution (the later instructions may execute before data stored by the earlier instructions have become globally visible)."
Quoted 4 lines
and says the same for ERETU. Sadly, "following" is ambiguous in the context of SLS, but an ERETS-to-self could end up legitimately executing the next sequential instruction. Either way, the "not execute even speculatively" is the property wanted.
There's a worse ambiguity here, imo: What they say excludes ERETS itself. I.e. while ERETS itself executes, subsequent instruction may already be speculated.
Interestingly the FRED spec (9.0) says such only for ERETU, not ERETS.
Jan