x86/entry: Use POP_GPRS and remove RESTORE_ALL

POP_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.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Andrew Cooper committed 2026-07-07 17:19:38 +01:00
1 parent 1557e03579
commit 8af337dfb8
3 files changed
+10 -61

No files matched your search

+1 -49
View File
@@ -264,54 +264,6 @@ static always_inline void stac(void)
xor %r15d, %r15d xor %r15d, %r15d
.endm .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 * Push and clear GPRs
*/ */
@@ -369,7 +321,7 @@ static always_inline void stac(void)
pop %r9 pop %r9
pop %r8 pop %r8
.if \skip_rax .if \skip_rax
pop %rcx pop %rcx /* Any register yet to restore. */
.else .else
pop %rax pop %rax
.endif .endif
+4 -5
View File
@@ -160,12 +160,11 @@ FUNC(compat_restore_all_guest)
/* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */
SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ 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 /* Req: %rsp=eframe Clob: efl */
SPEC_CTRL_COND_VERW \
scf=STK_REL(CPUINFO_scf, CPUINFO_rip), \ add $8, %rsp /* Pop ev/ec off the stack */
sel=STK_REL(CPUINFO_verw_sel, CPUINFO_rip)
jmp iret_to_guest jmp iret_to_guest
END(compat_restore_all_guest) END(compat_restore_all_guest)
+5 -7
View File
@@ -226,7 +226,8 @@ FUNC_LOCAL(restore_all_guest)
/* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */
SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */
RESTORE_ALL POP_GPRS
BUILD_BUG_ON(TRAP_syscall & 0xff) BUILD_BUG_ON(TRAP_syscall & 0xff)
testb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp) testb $TRAP_syscall >> 8, EFRAME_entry_vector + 1(%rsp)
jz iret_exit_to_guest jz iret_exit_to_guest
@@ -753,20 +754,17 @@ UNLIKELY_END(exit_cr3)
/* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */
SPEC_CTRL_EXIT_TO_XEN /* Req: %r12=ist_exit %r14=end %rsp=regs, Clob: abcd */ 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. * When the CPU pushed this exception frame, it zero-extended eflags.
* For an IST exit, SPEC_CTRL_EXIT_TO_XEN stashed shadow copies of * 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, * 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. * 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 \ SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */
scf=STK_REL(EFRAME_shadow_scf, EFRAME_rip), \
sel=STK_REL(EFRAME_shadow_sel, EFRAME_rip)
add $8, %rsp /* Pop ev/ec off the stack */
iretq iretq
END(restore_all_xen) END(restore_all_xen)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.