[RFC PATCH 3/4] KVM: SEV: Limit the call of WBINVDs based on the event type of mmu notifier

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The cache flush was originally introduced to enforce the cache coherency
across VM boundary in SEV, so the flush is not needed in some cases when
the page remains in the same VM. wbinvd_on_all_cpus() is a costly
operation so use the mmu notifier event type information in the range
struct to only do cache flush when needed.

The physical page might be allocated to a different VM after the range
is unmapped, cleared, released or migrated. So do a cache flush only on
those events.

Signed-off-by: Jacky Li <jackyli@xxxxxxxxxx>
Signed-off-by: Mingwei Zhang <mizhang@xxxxxxxxxx>
Suggested-by: Sean Christpherson <seanjc@xxxxxxxxxx>
---
 arch/x86/kvm/svm/sev.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 8d30f6c5e872..477df8a06629 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -2335,7 +2335,11 @@ void sev_guest_memory_reclaimed(struct kvm *kvm,
 	if (!sev_guest(kvm))
 		return;
 
-	wbinvd_on_all_cpus();
+	if (mmu_notifier_event == MMU_NOTIFY_UNMAP ||
+	    mmu_notifier_event == MMU_NOTIFY_CLEAR ||
+	    mmu_notifier_event == MMU_NOTIFY_RELEASE ||
+	    mmu_notifier_event == MMU_NOTIFY_MIGRATE)
+		wbinvd_on_all_cpus();
 }
 
 void sev_free_vcpu(struct kvm_vcpu *vcpu)
-- 
2.43.0.rc0.421.g78406f8d94-goog





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux