Skip to contentSkip to conversation

KVM: VMX: Fix SPEC_CTRL handling

PATCH Applied Uros Bizjak 2 participants 2 messages Aug 20, 2025 – Nov 10, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: VMX: Fix SPEC_CTRL handling

SPEC_CTRL is an MSR, i.e. a 64-bit value, but the assembly code assumes bits 63:32 are always zero. The bug is _currently_ benign because neither KVM nor the kernel support setting any of bits 63:32, but it's still a bug that needs to be fixed

Fixes 07853adc29a0 ("KVM: VMX: Prevent RSB underflow before vmenter")
Cc Sean Christopherson <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kvm/vmx/vmenter.S | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
arch/x86/kvm/vmx/vmenter.S +15 -5
index 0a6cf5bff2aa..fb250ddae00b 100644
@@ -118,13 +118,23 @@ SYM_FUNC_START(__vmx_vcpu_run)
 	 * and vmentry.
 	 */
 	mov 2*WORD_SIZE(%_ASM_SP), %_ASM_DI
-	movl VMX_spec_ctrl(%_ASM_DI), %edi
-	movl PER_CPU_VAR(x86_spec_ctrl_current), %esi
-	cmp %edi, %esi
+#ifdef CONFIG_X86_64
+	mov VMX_spec_ctrl(%rdi), %rdx
+	cmp PER_CPU_VAR(x86_spec_ctrl_current), %rdx
+	je .Lspec_ctrl_done
+	movl %edx, %eax
+	shr $32, %rdx
+#else
+	mov VMX_spec_ctrl(%edi), %eax
+	mov PER_CPU_VAR(x86_spec_ctrl_current), %ecx
+	xor %eax, %ecx
+	mov VMX_spec_ctrl + 4(%edi), %edx
+	mov PER_CPU_VAR(x86_spec_ctrl_current + 4), %edi
+	xor %edx, %edi
+	or %edi, %ecx
 	je .Lspec_ctrl_done
+#endif
 	mov $MSR_IA32_SPEC_CTRL, %ecx
-	xor %edx, %edx
-	mov %edi, %eax
 	wrmsr
 
 .Lspec_ctrl_done:
Signature · 1 line
2.50.1
maintainer Applied
#1 lore raw
Quoted 4 lines · Uros Bizjak

SPEC_CTRL is an MSR, i.e. a 64-bit value, but the assembly code assumes bits 63:32 are always zero. The bug is _currently_ benign because neither KVM nor the kernel support setting any of bits 63:32, but it's still a bug that needs to be fixed

Applied to kvm-x86 vmx, with a slightly tweaked shortlog+changelog to call out that only the guest's value is affected (whereas on SVM both guest and host values are affected). Thanks!

[1/1] KVM: VMX: Ensure guest's SPEC_CTRL[63:32] is loaded on VM-Enter

      https://github.com/kvm-x86/linux/commit/32ed0bc2f0f8

--
https://github.com/kvm-x86/linux/tree/next