[PATCH 08/10] kvm: x86: mmu: Refactor kvm_mmu_slot_*_remove_write_access

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

 



Create a common helper function to implement both the _remote_write_access
and _largepage_remove_write_access variants and also introduce a new
variant _leaf_remove_write_access.

Signed-off-by: Junaid Shahid <junaids@xxxxxxxxxx>
---
 arch/x86/kvm/mmu.c | 43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 2714dbea2d88..0839b8cfdf66 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -5732,14 +5732,15 @@ static bool slot_rmap_write_protect(struct kvm *kvm,
 	return __rmap_write_protect(kvm, rmap_head, false);
 }
 
-void kvm_mmu_slot_remove_write_access(struct kvm *kvm,
-				      struct kvm_memory_slot *memslot)
+static bool kvm_mmu_slot_remove_write_access_at_levels(struct kvm *kvm,
+						struct kvm_memory_slot *memslot,
+						int start_level, int end_level)
 {
 	bool flush;
 
 	spin_lock(&kvm->mmu_lock);
-	flush = slot_handle_all_level(kvm, memslot, slot_rmap_write_protect,
-				      false);
+	flush = slot_handle_level(kvm, memslot, slot_rmap_write_protect,
+				  start_level, end_level, false);
 	spin_unlock(&kvm->mmu_lock);
 
 	/*
@@ -5749,6 +5750,18 @@ void kvm_mmu_slot_remove_write_access(struct kvm *kvm,
 	 */
 	lockdep_assert_held(&kvm->slots_lock);
 
+	return flush;
+}
+
+void kvm_mmu_slot_remove_write_access(struct kvm *kvm,
+				      struct kvm_memory_slot *memslot)
+{
+	bool flush;
+
+	flush = kvm_mmu_slot_remove_write_access_at_levels(kvm, memslot,
+							   PT_PAGE_TABLE_LEVEL,
+							   PT_MAX_HUGEPAGE_LEVEL);
+
 	/*
 	 * We can flush all the TLBs out of the mmu lock without TLB
 	 * corruption since we just change the spte from writable to
@@ -5833,20 +5846,20 @@ EXPORT_SYMBOL_GPL(kvm_mmu_slot_leaf_clear_dirty);
 bool kvm_mmu_slot_largepage_remove_write_access(struct kvm *kvm,
 					struct kvm_memory_slot *memslot)
 {
-	bool flush;
-
-	spin_lock(&kvm->mmu_lock);
-	flush = slot_handle_large_level(kvm, memslot, slot_rmap_write_protect,
-					false);
-	spin_unlock(&kvm->mmu_lock);
-
-	/* see kvm_mmu_slot_remove_write_access */
-	lockdep_assert_held(&kvm->slots_lock);
-
-	return flush;
+	return kvm_mmu_slot_remove_write_access_at_levels(kvm, memslot,
+						  PT_PAGE_TABLE_LEVEL + 1,
+						  PT_MAX_HUGEPAGE_LEVEL);
 }
 EXPORT_SYMBOL_GPL(kvm_mmu_slot_largepage_remove_write_access);
 
+static bool kvm_mmu_slot_leaf_remove_write_access(struct kvm *kvm,
+					struct kvm_memory_slot *memslot)
+{
+	return kvm_mmu_slot_remove_write_access_at_levels(kvm, memslot,
+							  PT_PAGE_TABLE_LEVEL,
+							  PT_PAGE_TABLE_LEVEL);
+}
+
 void kvm_mmu_slot_wrprot_lpage_and_clear_dirty(struct kvm *kvm,
 					       struct kvm_memory_slot *memslot)
 {
-- 
2.19.1.568.g152ad8e336-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