0007-KVM-x86-fix-APIC-page-invalidation.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. From 4255a36150de32fd3a21f4030210f87a5f58caf1 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= <[email protected]>
  3. Date: Thu, 30 Nov 2017 19:05:45 +0100
  4. Subject: [PATCH 07/10] KVM: x86: fix APIC page invalidation
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Implementation of the unpinned APIC page didn't update the VMCS address
  9. cache when invalidation was done through range mmu notifiers.
  10. This became a problem when the page notifier was removed.
  11. Re-introduce the arch-specific helper and call it from ...range_start.
  12. Fixes: 38b9917350cb ("kvm: vmx: Implement set_apic_access_page_addr")
  13. Fixes: 369ea8242c0f ("mm/rmap: update to new mmu_notifier semantic v2")
  14. Signed-off-by: Radim Krčmář <[email protected]>
  15. Signed-off-by: Fabian Grünbichler <[email protected]>
  16. ---
  17. arch/x86/include/asm/kvm_host.h | 3 +++
  18. arch/x86/kvm/x86.c | 14 ++++++++++++++
  19. virt/kvm/kvm_main.c | 8 ++++++++
  20. 3 files changed, 25 insertions(+)
  21. diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
  22. index 92c9032502d8..b69af3df978a 100644
  23. --- a/arch/x86/include/asm/kvm_host.h
  24. +++ b/arch/x86/include/asm/kvm_host.h
  25. @@ -1437,4 +1437,7 @@ static inline int kvm_cpu_get_apicid(int mps_cpu)
  26. #endif
  27. }
  28. +void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm,
  29. + unsigned long start, unsigned long end);
  30. +
  31. #endif /* _ASM_X86_KVM_HOST_H */
  32. diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
  33. index 7351cdc46cc7..703cd4171921 100644
  34. --- a/arch/x86/kvm/x86.c
  35. +++ b/arch/x86/kvm/x86.c
  36. @@ -6711,6 +6711,20 @@ static void kvm_vcpu_flush_tlb(struct kvm_vcpu *vcpu)
  37. kvm_x86_ops->tlb_flush(vcpu);
  38. }
  39. +void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm,
  40. + unsigned long start, unsigned long end)
  41. +{
  42. + unsigned long apic_address;
  43. +
  44. + /*
  45. + * The physical address of apic access page is stored in the VMCS.
  46. + * Update it when it becomes invalid.
  47. + */
  48. + apic_address = gfn_to_hva(kvm, APIC_DEFAULT_PHYS_BASE >> PAGE_SHIFT);
  49. + if (start <= apic_address && apic_address < end)
  50. + kvm_make_all_cpus_request(kvm, KVM_REQ_APIC_PAGE_RELOAD);
  51. +}
  52. +
  53. void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu)
  54. {
  55. struct page *page = NULL;
  56. diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
  57. index bfa9c4d34102..d0085c9d6297 100644
  58. --- a/virt/kvm/kvm_main.c
  59. +++ b/virt/kvm/kvm_main.c
  60. @@ -136,6 +136,11 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm);
  61. static unsigned long long kvm_createvm_count;
  62. static unsigned long long kvm_active_vms;
  63. +__weak void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm,
  64. + unsigned long start, unsigned long end)
  65. +{
  66. +}
  67. +
  68. bool kvm_is_reserved_pfn(kvm_pfn_t pfn)
  69. {
  70. if (pfn_valid(pfn))
  71. @@ -361,6 +366,9 @@ static void kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn,
  72. kvm_flush_remote_tlbs(kvm);
  73. spin_unlock(&kvm->mmu_lock);
  74. +
  75. + kvm_arch_mmu_notifier_invalidate_range(kvm, start, end);
  76. +
  77. srcu_read_unlock(&kvm->srcu, idx);
  78. }
  79. --
  80. 2.14.2