Re: [PATCH 7/7] KVM: VMX: replace vmx_spec_ctrl_restore_host with RESTORE_HOST_SPEC_CTRL_BODY

From: Paolo Bonzini

Date: Wed Apr 08 2026 - 17:48:35 EST


On 4/8/26 20:22, Paolo Bonzini wrote:
Reuse the same assembly as SVM, just with alternatives instead
of cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS).

Due to the dearth of registers in 32-bit x86, save/restore %eax
across the restoring sequence, keeping it simple; the main alternative
would be to leave vmx and flags on the stack, avoiding the need to read
flags from %ebx. It's not really measurable difference.

Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
arch/x86/kvm/vmenter.h | 4 ++--
arch/x86/kvm/vmx/vmenter.S | 25 +++++++++++++++----------
arch/x86/kvm/vmx/vmx.c | 25 -------------------------
arch/x86/kvm/vmx/vmx.h | 1 -
4 files changed, 17 insertions(+), 38 deletions(-)

diff --git a/arch/x86/kvm/vmenter.h b/arch/x86/kvm/vmenter.h
index e746e1328d3f..d822dafc75f7 100644
--- a/arch/x86/kvm/vmenter.h
+++ b/arch/x86/kvm/vmenter.h
@@ -55,7 +55,7 @@
#ifdef CONFIG_X86_64
mov PER_CPU_VAR(x86_spec_ctrl_current), %rdx
cmp \guest_spec_ctrl, %rdx
- je \label
+ ALTERNATIVE "", __stringify(je \label), X86_FEATURE_KERNEL_IBRS

Actually the other way round:

ALTERNATIVE __stringify(je \label), "", X86_FEATURE_KERNEL_IBRS

movl %edx, %eax
shr $32, %rdx
#else
@@ -66,7 +66,7 @@
mov 4 + \guest_spec_ctrl, %edi
xor %edx, %edi
or %edi, %esi
- je \label
+ ALTERNATIVE "", __stringify(je \label), X86_FEATURE_KERNEL_IBRS

Same here.

Paolo