Skip to content

Commit 32ed0bc

Browse files
ubizjaksean-jc
authored andcommitted
KVM: VMX: Ensure guest's SPEC_CTRL[63:32] is loaded on VM-Enter
SPEC_CTRL is an MSR, i.e. a 64-bit value, but the assembly code that loads the guest's value 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. Note, the host's value is restored in C code and is unaffected. Fixes: 07853ad ("KVM: VMX: Prevent RSB underflow before vmenter") Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Josh Poimboeuf <jpoimboe@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Link: https://patch.msgid.link/20250820100007.356761-1-ubizjak@gmail.com [sean: call out that only the guest's value is affected] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 1100e49 commit 32ed0bc

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

arch/x86/kvm/vmx/vmenter.S

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,23 @@ SYM_FUNC_START(__vmx_vcpu_run)
118118
* and vmentry.
119119
*/
120120
mov 2*WORD_SIZE(%_ASM_SP), %_ASM_DI
121-
movl VMX_spec_ctrl(%_ASM_DI), %edi
122-
movl PER_CPU_VAR(x86_spec_ctrl_current), %esi
123-
cmp %edi, %esi
121+
#ifdef CONFIG_X86_64
122+
mov VMX_spec_ctrl(%rdi), %rdx
123+
cmp PER_CPU_VAR(x86_spec_ctrl_current), %rdx
124+
je .Lspec_ctrl_done
125+
movl %edx, %eax
126+
shr $32, %rdx
127+
#else
128+
mov VMX_spec_ctrl(%edi), %eax
129+
mov PER_CPU_VAR(x86_spec_ctrl_current), %ecx
130+
xor %eax, %ecx
131+
mov VMX_spec_ctrl + 4(%edi), %edx
132+
mov PER_CPU_VAR(x86_spec_ctrl_current + 4), %edi
133+
xor %edx, %edi
134+
or %edi, %ecx
124135
je .Lspec_ctrl_done
136+
#endif
125137
mov $MSR_IA32_SPEC_CTRL, %ecx
126-
xor %edx, %edx
127-
mov %edi, %eax
128138
wrmsr
129139

130140
.Lspec_ctrl_done:

0 commit comments

Comments
 (0)