KVM: VMX: Fix SPEC_CTRL handling
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
--- arch/x86/kvm/vmx/vmenter.S | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
arch/x86/kvm/vmx/vmenter.S +15 -5
@@ -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
Quoted 4 lines · Uros Bizjak
SPEC_CTRLis 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