LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Ben Gardon <bgardon@google.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	kvm <kvm@vger.kernel.org>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] KVM: x86/mmu: Don't step down in the TDP iterator when zapping all SPTEs
Date: Thu, 12 Aug 2021 09:47:58 -0700	[thread overview]
Message-ID: <CANgfPd8HSYZbqmi21XQ=XeMCndXJ0+Ld0eZNKPWLa1fKtutiBA@mail.gmail.com> (raw)
In-Reply-To: <20210812050717.3176478-3-seanjc@google.com>

On Wed, Aug 11, 2021 at 10:07 PM Sean Christopherson <seanjc@google.com> wrote:
>
> Set the min_level for the TDP iterator at the root level when zapping all
> SPTEs so that the _iterator_ only processes top-level SPTEs.  Zapping a
> non-leaf SPTE will recursively zap all its children, thus there is no
> need for the iterator to attempt to step down.  This avoids rereading all
> the top-level SPTEs after they are zapped by causing try_step_down() to
> short-circuit.
>
> Cc: Ben Gardon <bgardon@google.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

This change looks functionally correct, but I'm not sure it's worth
adding more code special cased on zap-all for what seems like a small
performance improvement in a context which shouldn't be particularly
performance sensitive.
Change is a correct optimization though and it's not much extra code,
so I'm happy to give a:
Reviewed-by: Ben Gardon <bgardon@google.com>

> ---
>  arch/x86/kvm/mmu/tdp_mmu.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index 6566f70a31c1..aec069c18d82 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -751,6 +751,16 @@ static bool zap_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
>  {
>         bool zap_all = (end == ZAP_ALL_END);
>         struct tdp_iter iter;
> +       int min_level;
> +
> +       /*
> +        * No need to step down in the iterator when zapping all SPTEs, zapping
> +        * the top-level non-leaf SPTEs will recurse on all their children.
> +        */
> +       if (zap_all)
> +               min_level = root->role.level;
> +       else
> +               min_level = PG_LEVEL_4K;
>
>         /*
>          * Bound the walk at host.MAXPHYADDR, guest accesses beyond that will
> @@ -763,7 +773,8 @@ static bool zap_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
>
>         rcu_read_lock();
>
> -       tdp_root_for_each_pte(iter, root, start, end) {
> +       for_each_tdp_pte_min_level(iter, root->spt, root->role.level,
> +                                  min_level, start, end) {
>  retry:
>                 if (can_yield &&
>                     tdp_mmu_iter_cond_resched(kvm, &iter, flush, shared)) {
> --
> 2.33.0.rc1.237.g0d66db33f3-goog
>

  reply	other threads:[~2021-08-12 16:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12  5:07 [PATCH 0/2] KVM: x86/mmu: Fix a TDP MMU leak and optimize zap all Sean Christopherson
2021-08-12  5:07 ` [PATCH 1/2] KVM: x86/mmu: Don't skip non-leaf SPTEs when zapping all SPTEs Sean Christopherson
2021-08-12 16:18   ` Paolo Bonzini
2021-08-12 16:43     ` Sean Christopherson
2021-08-12 18:09       ` Sean Christopherson
2021-08-12  5:07 ` [PATCH 2/2] KVM: x86/mmu: Don't step down in the TDP iterator " Sean Christopherson
2021-08-12 16:47   ` Ben Gardon [this message]
2021-08-12 17:07     ` Sean Christopherson
2021-08-12 17:15       ` Paolo Bonzini
2021-08-12 17:33         ` Sean Christopherson
2021-08-12 17:38           ` Paolo Bonzini
2021-08-12 17:46             ` Sean Christopherson
2021-08-13  7:27               ` Paolo Bonzini
2021-08-13 16:13                 ` Sean Christopherson
2021-08-13 16:38                   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANgfPd8HSYZbqmi21XQ=XeMCndXJ0+Ld0eZNKPWLa1fKtutiBA@mail.gmail.com' \
    --to=bgardon@google.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --subject='Re: [PATCH 2/2] KVM: x86/mmu: Don'\''t step down in the TDP iterator when zapping all SPTEs' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).