Skip to content

Commit 02efd81

Browse files
committed
KVM: VMX: Intercept reads to invalid and write-only x2APIC registers
Intercept reads to invalid (non-existent) and write-only x2APIC registers when configuring VMX's MSR bitmaps for x2APIC+APICv. When APICv is fully enabled, Intel hardware doesn't validate the registers on RDMSR and instead blindly retrieves data from the vAPIC page, i.e. it's software's responsibility to intercept reads to non-existent and write-only MSRs. Fixes: 8d14695 ("x86, apicv: add virtual x2apic support") Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Link: https://lore.kernel.org/r/20230107011025.565472-7-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent c39857c commit 02efd81

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

arch/x86/kvm/vmx/vmx.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,7 +4031,7 @@ static void vmx_update_msr_bitmap_x2apic(struct kvm_vcpu *vcpu)
40314031
u64 *msr_bitmap = (u64 *)vmx->vmcs01.msr_bitmap;
40324032
u8 mode;
40334033

4034-
if (!cpu_has_vmx_msr_bitmap())
4034+
if (!cpu_has_vmx_msr_bitmap() || WARN_ON_ONCE(!lapic_in_kernel(vcpu)))
40354035
return;
40364036

40374037
if (cpu_has_secondary_exec_ctrls() &&
@@ -4053,11 +4053,11 @@ static void vmx_update_msr_bitmap_x2apic(struct kvm_vcpu *vcpu)
40534053
* Reset the bitmap for MSRs 0x800 - 0x83f. Leave AMD's uber-extended
40544054
* registers (0x840 and above) intercepted, KVM doesn't support them.
40554055
* Intercept all writes by default and poke holes as needed. Pass
4056-
* through all reads by default in x2APIC+APICv mode, as all registers
4057-
* except the current timer count are passed through for read.
4056+
* through reads for all valid registers by default in x2APIC+APICv
4057+
* mode, only the current timer count needs on-demand emulation by KVM.
40584058
*/
40594059
if (mode & MSR_BITMAP_MODE_X2APIC_APICV)
4060-
msr_bitmap[read_idx] = 0;
4060+
msr_bitmap[read_idx] = ~kvm_lapic_readable_reg_mask(vcpu->arch.apic);
40614061
else
40624062
msr_bitmap[read_idx] = ~0ull;
40634063
msr_bitmap[write_idx] = ~0ull;

0 commit comments

Comments
 (0)