Skip to content

Commit b1394e7

Browse files
committed
KVM: x86: fix APIC page invalidation
Implementation of the unpinned APIC page didn't update the VMCS address cache when invalidation was done through range mmu notifiers. This became a problem when the page notifier was removed. Re-introduce the arch-specific helper and call it from ...range_start. Reported-by: Fabian Grünbichler <[email protected]> Fixes: 38b9917 ("kvm: vmx: Implement set_apic_access_page_addr") Fixes: 369ea82 ("mm/rmap: update to new mmu_notifier semantic v2") Cc: <[email protected]> Reviewed-by: Paolo Bonzini <[email protected]> Reviewed-by: Andrea Arcangeli <[email protected]> Tested-by: Wanpeng Li <[email protected]> Tested-by: Fabian Grünbichler <[email protected]> Signed-off-by: Radim Krčmář <[email protected]>
1 parent d29899a commit b1394e7

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,4 +1448,7 @@ static inline int kvm_cpu_get_apicid(int mps_cpu)
14481448
#define put_smstate(type, buf, offset, val) \
14491449
*(type *)((buf) + (offset) - 0x7e00) = val
14501450

1451+
void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm,
1452+
unsigned long start, unsigned long end);
1453+
14511454
#endif /* _ASM_X86_KVM_HOST_H */

arch/x86/kvm/x86.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6764,6 +6764,20 @@ static void kvm_vcpu_flush_tlb(struct kvm_vcpu *vcpu)
67646764
kvm_x86_ops->tlb_flush(vcpu);
67656765
}
67666766

6767+
void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm,
6768+
unsigned long start, unsigned long end)
6769+
{
6770+
unsigned long apic_address;
6771+
6772+
/*
6773+
* The physical address of apic access page is stored in the VMCS.
6774+
* Update it when it becomes invalid.
6775+
*/
6776+
apic_address = gfn_to_hva(kvm, APIC_DEFAULT_PHYS_BASE >> PAGE_SHIFT);
6777+
if (start <= apic_address && apic_address < end)
6778+
kvm_make_all_cpus_request(kvm, KVM_REQ_APIC_PAGE_RELOAD);
6779+
}
6780+
67676781
void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu)
67686782
{
67696783
struct page *page = NULL;

virt/kvm/kvm_main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm);
135135
static unsigned long long kvm_createvm_count;
136136
static unsigned long long kvm_active_vms;
137137

138+
__weak void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm,
139+
unsigned long start, unsigned long end)
140+
{
141+
}
142+
138143
bool kvm_is_reserved_pfn(kvm_pfn_t pfn)
139144
{
140145
if (pfn_valid(pfn))
@@ -360,6 +365,9 @@ static void kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn,
360365
kvm_flush_remote_tlbs(kvm);
361366

362367
spin_unlock(&kvm->mmu_lock);
368+
369+
kvm_arch_mmu_notifier_invalidate_range(kvm, start, end);
370+
363371
srcu_read_unlock(&kvm->srcu, idx);
364372
}
365373

0 commit comments

Comments
 (0)