Re: [PATCH 7/7] KVM: VMX: replace vmx_spec_ctrl_restore_host with RESTORE_HOST_SPEC_CTRL_BODY
From: Chang S. Bae
Date: Thu Apr 09 2026 - 20:17:20 EST
On 4/8/2026 2:48 PM, Paolo Bonzini wrote:
On 4/8/26 20:22, Paolo Bonzini wrote:
#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
Also, that CMP appears unnecessary with X86_FEATURE_KERNEL_IBRS. Maybe something like the attached diff is possible.
Thanks,
CHang
diff --git a/arch/x86/kvm/vmenter.h b/arch/x86/kvm/vmenter.h
index e17aedc37187..c67ec56d5110 100644
--- a/arch/x86/kvm/vmenter.h
+++ b/arch/x86/kvm/vmenter.h
@@ -54,20 +54,23 @@
/* Now restore the host value of the MSR if different from the guest's. */
#ifdef CONFIG_X86_64
mov PER_CPU_VAR(x86_spec_ctrl_current), %rdx
+ ALTERNATIVE "", __stringify(jmp 999f), X86_FEATURE_KERNEL_IBRS
cmp \guest_spec_ctrl, %rdx
- ALTERNATIVE __stringify(je \label), "", X86_FEATURE_KERNEL_IBRS
+ je \label
movl %edx, %eax
shr $32, %rdx
#else
mov PER_CPU_VAR(x86_spec_ctrl_current), %eax
+ mov PER_CPU_VAR(x86_spec_ctrl_current + 4), %edx
+ ALTERNATIVE "", __stringify(jmp 999f), X86_FEATURE_KERNEL_IBRS
mov \guest_spec_ctrl, %esi
xor %eax, %esi
- mov PER_CPU_VAR(x86_spec_ctrl_current + 4), %edx
mov 4 + \guest_spec_ctrl, %edi
xor %edx, %edi
or %edi, %esi
- ALTERNATIVE __stringify(je \label), "", X86_FEATURE_KERNEL_IBRS
+ je \label
#endif
+999:
wrmsr
.endm