Skip to contentSkip to conversation

KVM, x86/mmu: Fix the comment around kvm_tdp_mmu_zap_leafs()

PATCH Superseded Kai Huang 2 participants 3 messages Jul 12, 2022

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kai Huang

author
#0 lore raw

PATCH 1/1 KVM, x86/mmu: Fix the comment around kvm_tdp_mmu_zap_leafs()

Now kvm_tdp_mmu_zap_leafs() only zaps leaf SPTEs but not any non-root pages within that GFN range anymore, so the comment isn't right.

Fixes f47e5bbbc92f ("KVM: x86/mmu: Zap only TDP MMU leafs in zap range and mmu_notifier unmap")
---
 arch/x86/kvm/mmu/tdp_mmu.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu/tdp_mmu.c +3 -4
index f3a430d64975..7692e6273462 100644
@@ -969,10 +969,9 @@ static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root,
 }
 
 /*
- * Tears down the mappings for the range of gfns, [start, end), and frees the
- * non-root pages mapping GFNs strictly within that range. Returns true if
- * SPTEs have been cleared and a TLB flush is needed before releasing the
- * MMU lock.
+ * Zap leafs SPTEs for the range of gfns, [start, end) for all roots. Returns
+ * true if SPTEs have been cleared and a TLB flush is needed before releasing
+ * the MMU lock.
  */
 bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, int as_id, gfn_t start, gfn_t end,
 			   bool can_yield, bool flush)
Signature · 1 line
2.36.1
#1 lore raw
Quoted 14 lines · Kai Huang

Now kvm_tdp_mmu_zap_leafs() only zaps leaf SPTEs but not any non-root pages within that GFN range anymore, so the comment isn't right.

Fixes f47e5bbbc92f ("KVM: x86/mmu: Zap only TDP MMU leafs in zap range and mmu_notifier unmap")
---
 arch/x86/kvm/mmu/tdp_mmu.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu/tdp_mmu.c +0 -0
index f3a430d64975..7692e6273462 100644

arch/x86/kvm/mmu/tdp_mmu.c static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root, · line 974

Quoted 10 lines
arch/x86/kvm/mmu/tdp_mmu.c +3 -4
@@ -969,10 +969,9 @@ static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root,
 }
 
 /*
- * Tears down the mappings for the range of gfns, [start, end), and frees the
- * non-root pages mapping GFNs strictly within that range. Returns true if
- * SPTEs have been cleared and a TLB flush is needed before releasing the
- * MMU lock.
+ * Zap leafs SPTEs for the range of gfns, [start, end) for all roots. Returns
+ * true if SPTEs have been cleared and a TLB flush is needed before releasing
+ * the MMU lock.

What about shifting the comment from tdp_mmu_zap_leafs() instead of duplicating it? tdp_mmu_zap_leafs() is static and kvm_tdp_mmu_zap_leafs() is the sole caller. And opportunistically tweak the blurb about SPTEs being cleared to (a) say "zapped" instead of "cleared" because "cleared" will be wrong if/when KVM sets SUPPRESS_VE, and (b) to clarify that a flush is needed if and only if a SPTE has been zapped since MMU lock was last acquired.

E.g.

/*
* If can_yield is true, will release the MMU lock and reschedule if the
* scheduler needs the CPU or there is contention on the MMU lock. If this
* function cannot yield, it will not release the MMU lock or reschedule and
* the caller must ensure it does not supply too large a GFN range, or the
* operation can cause a soft lockup.
*/
static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root,
gfn_t start, gfn_t end, bool can_yield, bool flush)

/*
* Zap leafs SPTEs for the range of gfns, [start, end), for all roots. Returns
* true if a TLB flush is needed before releasing the MMU lock, i.e. if one or
* more SPTEs were zapped since the MMU lock was last acquired.
*/
bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, int as_id, gfn_t start, gfn_t end,
bool can_yield, bool flush)

author
#2 lore raw
Quoted 45 lines · Sean Christopherson
Quoted 14 lines · Kai Huang

Now kvm_tdp_mmu_zap_leafs() only zaps leaf SPTEs but not any non-root pages within that GFN range anymore, so the comment isn't right.

Fixes f47e5bbbc92f ("KVM: x86/mmu: Zap only TDP MMU leafs in zap range and mmu_notifier unmap")
---
 arch/x86/kvm/mmu/tdp_mmu.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu/tdp_mmu.c +0 -0
index f3a430d64975..7692e6273462 100644

arch/x86/kvm/mmu/tdp_mmu.c static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root, · line 974

Quoted 10 lines
arch/x86/kvm/mmu/tdp_mmu.c +3 -4
@@ -969,10 +969,9 @@ static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root,
 }
 
 /*
- * Tears down the mappings for the range of gfns, [start, end), and frees the
- * non-root pages mapping GFNs strictly within that range. Returns true if
- * SPTEs have been cleared and a TLB flush is needed before releasing the
- * MMU lock.
+ * Zap leafs SPTEs for the range of gfns, [start, end) for all roots. Returns
+ * true if SPTEs have been cleared and a TLB flush is needed before releasing
+ * the MMU lock.

What about shifting the comment from tdp_mmu_zap_leafs() instead of duplicating it? tdp_mmu_zap_leafs() is static and kvm_tdp_mmu_zap_leafs() is the sole caller. And opportunistically tweak the blurb about SPTEs being cleared to (a) say "zapped" instead of "cleared" because "cleared" will be wrong if/when KVM sets SUPPRESS_VE, and (b) to clarify that a flush is needed if and only if a SPTE has been zapped since MMU lock was last acquired.

E.g.

/*
* If can_yield is true, will release the MMU lock and reschedule if the
* scheduler needs the CPU or there is contention on the MMU lock. If this
* function cannot yield, it will not release the MMU lock or reschedule and
* the caller must ensure it does not supply too large a GFN range, or the
* operation can cause a soft lockup.
*/
static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root,
gfn_t start, gfn_t end, bool can_yield, bool flush)

Quoted 7 lines

/*
* Zap leafs SPTEs for the range of gfns, [start, end), for all roots. Returns
* true if a TLB flush is needed before releasing the MMU lock, i.e. if one or
* more SPTEs were zapped since the MMU lock was last acquired.
*/
bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, int as_id, gfn_t start, gfn_t end,
bool can_yield, bool flush)

Yes looks better. Will send out a new patch soon. Thanks.

Signature · 2 lines
Thanks,
-Kai