* [PATCH v2] KVM, x86/mmu: Fix the comment around kvm_tdp_mmu_zap_leafs()
@ 2022-07-13 0:44 Kai Huang
2022-07-19 19:02 ` Sean Christopherson
0 siblings, 1 reply; 3+ messages in thread
From: Kai Huang @ 2022-07-13 0:44 UTC (permalink / raw)
To: kvm; +Cc: pbonzini, seanjc, bgardon, 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 around it isn't
right.
Fix it by shifting the comment from tdp_mmu_zap_leafs() instead of
duplicating it, as tdp_mmu_zap_leafs() is static and is only called by
kvm_tdp_mmu_zap_leafs().
Opportunistically tweak the blurb about SPTEs being cleared to (a) say
"zapped" instead of "cleared" because "cleared" will be wrong if/when
KVM allows a non-zero value for non-present SPTE (i.e. for Intel TDX),
and (b) to clarify that a flush is needed if and only if a SPTE has been
zapped since MMU lock was last acquired.
Fixes: f47e5bbbc92f ("KVM: x86/mmu: Zap only TDP MMU leafs in zap range and mmu_notifier unmap")
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Kai Huang <kai.huang@intel.com>
---
arch/x86/kvm/mmu/tdp_mmu.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index f3a430d64975..58b34f7cd0f5 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -924,9 +924,6 @@ bool kvm_tdp_mmu_zap_sp(struct kvm *kvm, struct kvm_mmu_page *sp)
}
/*
- * Zap leafs SPTEs for the range of gfns, [start, end). Returns true if SPTEs
- * have been cleared and a TLB flush is needed before releasing the MMU lock.
- *
* 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
@@ -969,10 +966,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 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)
--
2.36.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] KVM, x86/mmu: Fix the comment around kvm_tdp_mmu_zap_leafs()
2022-07-13 0:44 [PATCH v2] KVM, x86/mmu: Fix the comment around kvm_tdp_mmu_zap_leafs() Kai Huang
@ 2022-07-19 19:02 ` Sean Christopherson
2022-07-28 3:07 ` Kai Huang
0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2022-07-19 19:02 UTC (permalink / raw)
To: Kai Huang; +Cc: kvm, pbonzini, bgardon
On Wed, Jul 13, 2022, Kai Huang wrote:
> Now kvm_tdp_mmu_zap_leafs() only zaps leaf SPTEs but not any non-root
> pages within that GFN range anymore, so the comment around it isn't
> right.
>
> Fix it by shifting the comment from tdp_mmu_zap_leafs() instead of
> duplicating it, as tdp_mmu_zap_leafs() is static and is only called by
> kvm_tdp_mmu_zap_leafs().
>
> Opportunistically tweak the blurb about SPTEs being cleared to (a) say
> "zapped" instead of "cleared" because "cleared" will be wrong if/when
> KVM allows a non-zero value for non-present SPTE (i.e. for Intel TDX),
> and (b) to clarify that a flush is needed if and only if a SPTE has been
> zapped since MMU lock was last acquired.
>
> Fixes: f47e5bbbc92f ("KVM: x86/mmu: Zap only TDP MMU leafs in zap range and mmu_notifier unmap")
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Kai Huang <kai.huang@intel.com>
> ---
> arch/x86/kvm/mmu/tdp_mmu.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index f3a430d64975..58b34f7cd0f5 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -924,9 +924,6 @@ bool kvm_tdp_mmu_zap_sp(struct kvm *kvm, struct kvm_mmu_page *sp)
> }
>
> /*
> - * Zap leafs SPTEs for the range of gfns, [start, end). Returns true if SPTEs
> - * have been cleared and a TLB flush is needed before releasing the MMU lock.
> - *
> * 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
> @@ -969,10 +966,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
s/leafs/leaf (my fault, sorry)
With that tweak,
Reviewed-by: Sean Christopherson <seanjc@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] KVM, x86/mmu: Fix the comment around kvm_tdp_mmu_zap_leafs()
2022-07-19 19:02 ` Sean Christopherson
@ 2022-07-28 3:07 ` Kai Huang
0 siblings, 0 replies; 3+ messages in thread
From: Kai Huang @ 2022-07-28 3:07 UTC (permalink / raw)
To: Sean Christopherson; +Cc: kvm, pbonzini, bgardon
On Tue, 2022-07-19 at 19:02 +0000, Sean Christopherson wrote:
> On Wed, Jul 13, 2022, Kai Huang wrote:
> > Now kvm_tdp_mmu_zap_leafs() only zaps leaf SPTEs but not any non-root
> > pages within that GFN range anymore, so the comment around it isn't
> > right.
> >
> > Fix it by shifting the comment from tdp_mmu_zap_leafs() instead of
> > duplicating it, as tdp_mmu_zap_leafs() is static and is only called by
> > kvm_tdp_mmu_zap_leafs().
> >
> > Opportunistically tweak the blurb about SPTEs being cleared to (a) say
> > "zapped" instead of "cleared" because "cleared" will be wrong if/when
> > KVM allows a non-zero value for non-present SPTE (i.e. for Intel TDX),
> > and (b) to clarify that a flush is needed if and only if a SPTE has been
> > zapped since MMU lock was last acquired.
> >
> > Fixes: f47e5bbbc92f ("KVM: x86/mmu: Zap only TDP MMU leafs in zap range and mmu_notifier unmap")
> > Suggested-by: Sean Christopherson <seanjc@google.com>
> > Signed-off-by: Kai Huang <kai.huang@intel.com>
> > ---
> > arch/x86/kvm/mmu/tdp_mmu.c | 10 +++-------
> > 1 file changed, 3 insertions(+), 7 deletions(-)
> >
> > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> > index f3a430d64975..58b34f7cd0f5 100644
> > --- a/arch/x86/kvm/mmu/tdp_mmu.c
> > +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> > @@ -924,9 +924,6 @@ bool kvm_tdp_mmu_zap_sp(struct kvm *kvm, struct kvm_mmu_page *sp)
> > }
> >
> > /*
> > - * Zap leafs SPTEs for the range of gfns, [start, end). Returns true if SPTEs
> > - * have been cleared and a TLB flush is needed before releasing the MMU lock.
> > - *
> > * 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
> > @@ -969,10 +966,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
>
> s/leafs/leaf (my fault, sorry)
>
> With that tweak,
>
> Reviewed-by: Sean Christopherson <seanjc@google.com>
I should have checked error too :)
I have sent out v3 with above fixed. Thanks.
--
Thanks,
-Kai
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-28 3:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-13 0:44 [PATCH v2] KVM, x86/mmu: Fix the comment around kvm_tdp_mmu_zap_leafs() Kai Huang
2022-07-19 19:02 ` Sean Christopherson
2022-07-28 3:07 ` Kai Huang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.