Skip to contentSkip to conversation

kvm: mmu: Use fast PF path for access tracking of huge pages when possible

PATCH Superseded Junaid Shahid 3 participants 3 messages Nov 2, 2021 – Nov 3, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: mmu: Use fast PF path for access tracking of huge pages when possible

The fast page fault path bails out on write faults to huge pages in order to accommodate dirty logging. This change adds a check to do that only when dirty logging is actually enabled, so that access tracking for huge pages can still use the fast path for write faults in the common case.

---
 arch/x86/kvm/mmu/mmu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/kvm/mmu/mmu.c +5 -3
index 354d2ca92df4..5df9181c5082 100644
@@ -3191,8 +3191,9 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
 			new_spte |= PT_WRITABLE_MASK;
 
 			/*
-			 * Do not fix write-permission on the large spte.  Since
-			 * we only dirty the first page into the dirty-bitmap in
+			 * Do not fix write-permission on the large spte when
+			 * dirty logging is enabled. Since we only dirty the
+			 * first page into the dirty-bitmap in
 			 * fast_pf_fix_direct_spte(), other pages are missed
 			 * if its slot has dirty logging enabled.
 			 *
@@ -3201,7 +3202,8 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
 			 *
 			 * See the comments in kvm_arch_commit_memory_region().
 			 */
-			if (sp->role.level > PG_LEVEL_4K)
+			if (sp->role.level > PG_LEVEL_4K &&
+			    kvm_slot_dirty_track_enabled(fault->slot))
 				break;
 		}
 
Signature · 1 line
2.33.1.1089.g2158813163f-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Junaid Shahid

The fast page fault path bails out on write faults to huge pages in order to accommodate dirty logging. This change adds a check to do that only when dirty logging is actually enabled, so that access tracking for huge pages can still use the fast path for write faults in the common case.

Quoted 33 lines
---
 arch/x86/kvm/mmu/mmu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/kvm/mmu/mmu.c +5 -4
index 354d2ca92df4..5df9181c5082 100644
@@ -3191,8 +3191,9 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
                        new_spte |= PT_WRITABLE_MASK;
 
                        /*
-                        * Do not fix write-permission on the large spte.  Since
-                        * we only dirty the first page into the dirty-bitmap in
+                        * Do not fix write-permission on the large spte when
+                        * dirty logging is enabled. Since we only dirty the
+                        * first page into the dirty-bitmap in
                         * fast_pf_fix_direct_spte(), other pages are missed
                         * if its slot has dirty logging enabled.
                         *
@@ -3201,7 +3202,8 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
                         *
                         * See the comments in kvm_arch_commit_memory_region().
                         */
-                       if (sp->role.level > PG_LEVEL_4K)
+                       if (sp->role.level > PG_LEVEL_4K &&
+                           kvm_slot_dirty_track_enabled(fault->slot))
                                break;
                }
 
--

2.33.1.1089.g2158813163f-goog

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Junaid Shahid
Quoted 7 lines · Junaid Shahid

The fast page fault path bails out on write faults to huge pages in order to accommodate dirty logging. This change adds a check to do that only when dirty logging is actually enabled, so that access tracking for huge pages can still use the fast path for write faults in the common case.

One nit, otherwise

Quoted 21 lines
---
 arch/x86/kvm/mmu/mmu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/kvm/mmu/mmu.c +3 -2
index 354d2ca92df4..5df9181c5082 100644
@@ -3191,8 +3191,9 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
 			new_spte |= PT_WRITABLE_MASK;
 
 			/*
-			 * Do not fix write-permission on the large spte.  Since
-			 * we only dirty the first page into the dirty-bitmap in
+			 * Do not fix write-permission on the large spte when
+			 * dirty logging is enabled. Since we only dirty the
+			 * first page into the dirty-bitmap in
 			 * fast_pf_fix_direct_spte(), other pages are missed
 			 * if its slot has dirty logging enabled.
 			 *

arch/x86/kvm/mmu/mmu.c static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) · line 3203

Quoted 2 lines
arch/x86/kvm/mmu/mmu.c +0 -0
@@ -3201,7 +3202,8 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
 			 *
 			 * See the comments in kvm_arch_commit_memory_region().

This part is slightly stale as kvm_mmu_slot_apply_flags() now has the comments. Maybe just drop it entirely? The comments there don't do a whole lot to make this code more understandable.

Quoted 10 lines
arch/x86/kvm/mmu/mmu.c +2 -1
 			 */
-			if (sp->role.level > PG_LEVEL_4K)
+			if (sp->role.level > PG_LEVEL_4K &&
+			    kvm_slot_dirty_track_enabled(fault->slot))
 				break;
 		}
 
Signature · 1 line
2.33.1.1089.g2158813163f-goog