alistair23-linux/arch/x86/kvm
Vitaly Kuznetsov d176620277 x86/kvm/lapic: always disable MMIO interface in x2APIC mode
When VMX is used with flexpriority disabled (because of no support or
if disabled with module parameter) MMIO interface to lAPIC is still
available in x2APIC mode while it shouldn't be (kvm-unit-tests):

PASS: apic_disable: Local apic enabled in x2APIC mode
PASS: apic_disable: CPUID.1H:EDX.APIC[bit 9] is set
FAIL: apic_disable: *0xfee00030: 50014

The issue appears because we basically do nothing while switching to
x2APIC mode when APIC access page is not used. apic_mmio_{read,write}
only check if lAPIC is disabled before proceeding to actual write.

When APIC access is virtualized we correctly manipulate with VMX controls
in vmx_set_virtual_apic_mode() and we don't get vmexits from memory writes
in x2APIC mode so there's no issue.

Disabling MMIO interface seems to be easy. The question is: what do we
do with these reads and writes? If we add apic_x2apic_mode() check to
apic_mmio_in_range() and return -EOPNOTSUPP these reads and writes will
go to userspace. When lAPIC is in kernel, Qemu uses this interface to
inject MSIs only (see kvm_apic_mem_write() in hw/i386/kvm/apic.c). This
somehow works with disabled lAPIC but when we're in xAPIC mode we will
get a real injected MSI from every write to lAPIC. Not good.

The simplest solution seems to be to just ignore writes to the region
and return ~0 for all reads when we're in x2APIC mode. This is what this
patch does. However, this approach is inconsistent with what currently
happens when flexpriority is enabled: we allocate APIC access page and
create KVM memory region so in x2APIC modes all reads and writes go to
this pre-allocated page which is, btw, the same for all vCPUs.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-09-20 00:26:43 +02:00
..
cpuid.c KVM: X86: Implement "send IPI" hypercall 2018-08-06 17:59:20 +02:00
cpuid.h
debugfs.c
emulate.c kvm: x86: Remove CR3_PCID_INVD flag 2018-08-06 17:59:02 +02:00
hyperv.c KVM: x86: ensure all MSRs can always be KVM_GET/SET_MSR'd 2018-08-06 17:32:01 +02:00
hyperv.h KVM: x86: ensure all MSRs can always be KVM_GET/SET_MSR'd 2018-08-06 17:32:01 +02:00
i8254.c
i8254.h
i8259.c
ioapic.c
ioapic.h
irq.c
irq.h
irq_comm.c
Kconfig x86/kvm/Kconfig: Ensure CRYPTO_DEV_CCP_DD state at minimum matches KVM_AMD 2018-07-15 17:36:57 +02:00
kvm_cache_regs.h
lapic.c x86/kvm/lapic: always disable MMIO interface in x2APIC mode 2018-09-20 00:26:43 +02:00
lapic.h
Makefile
mmu.c Fixes for KVM/ARM for Linux v4.19 v2: 2018-09-07 18:38:25 +02:00
mmu.h kvm: x86: Propagate guest PCIDs to host PCIDs 2018-08-06 17:58:56 +02:00
mmu_audit.c
mmutrace.h
mtrr.c
page_track.c treewide: kvzalloc() -> kvcalloc() 2018-06-12 16:19:22 -07:00
paging_tmpl.h kvm: x86: Add a root_hpa parameter to kvm_mmu->invlpg() 2018-08-06 17:58:58 +02:00
pmu.c
pmu.h
pmu_amd.c
pmu_intel.c
svm.c KVM: x86: Rename emulate_instruction() to kvm_emulate_instruction() 2018-08-30 16:20:44 +02:00
trace.h KVM: x86: hyperv: simplistic HVCALL_FLUSH_VIRTUAL_ADDRESS_{LIST,SPACE}_EX implementation 2018-05-26 15:35:35 +02:00
tss.h
vmx.c KVM: nVMX: Fix loss of pending IRQ/NMI before entering L2 2018-09-07 18:38:42 +02:00
vmx_evmcs.h
vmx_shadow_fields.h
x86.c KVM: x86: Unexport x86_emulate_instruction() 2018-08-30 16:20:44 +02:00
x86.h KVM: x86: Unexport x86_emulate_instruction() 2018-08-30 16:20:44 +02:00