LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ben Gardon <bgardon@google.com>
Subject: Re: [PATCH 1/2] KVM: x86/mmu: Don't skip non-leaf SPTEs when zapping all SPTEs
Date: Thu, 12 Aug 2021 18:18:24 +0200	[thread overview]
Message-ID: <01b22936-49b0-638e-baf8-269ba93facd8@redhat.com> (raw)
In-Reply-To: <20210812050717.3176478-2-seanjc@google.com>

On 12/08/21 07:07, Sean Christopherson wrote:
> @@ -739,8 +749,16 @@ static bool zap_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
>   			  gfn_t start, gfn_t end, bool can_yield, bool flush,
>   			  bool shared)
>   {
> +	bool zap_all = (end == ZAP_ALL_END);
>   	struct tdp_iter iter;
>   
> +	/*
> +	 * Bound the walk at host.MAXPHYADDR, guest accesses beyond that will
> +	 * hit a #PF(RSVD) and never get to an EPT Violation/Misconfig / #NPF,
> +	 * and so KVM will never install a SPTE for such addresses.
> +	 */
> +	end = min(end, 1ULL << (shadow_phys_bits - PAGE_SHIFT));

Then zap_all need not have any magic value.  You can use 0/-1ull, it's 
readable enough.  ZAP_ALL_END is also unnecessary here if you do:

	gfn_t max_gfn_host = 1ULL << (shadow_phys_bits - PAGE_SHIFT);
	bool zap_all = (start == 0 && end >= max_gfn_host);

	end = min(end, max_gfn_host);

And as a small commit message nit, I would say "don't leak" instead of 
"don't skip", since that's really the effect.

Paolo


>   	kvm_lockdep_assert_mmu_lock_held(kvm, shared);
>   
>   	rcu_read_lock();
> @@ -759,9 +777,10 @@ static bool zap_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
>   		/*
>   		 * If this is a non-last-level SPTE that covers a larger range
>   		 * than should be zapped, continue, and zap the mappings at a
> -		 * lower level.
> +		 * lower level, except when zapping all SPTEs.
>   		 */
> -		if ((iter.gfn < start ||
> +		if (!zap_all &&
> +		    (iter.gfn < start ||
>   		     iter.gfn + KVM_PAGES_PER_HPAGE(iter.level) > end) &&


  reply	other threads:[~2021-08-12 16:18 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 [this message]
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
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=01b22936-49b0-638e-baf8-269ba93facd8@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=bgardon@google.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --subject='Re: [PATCH 1/2] KVM: x86/mmu: Don'\''t skip non-leaf SPTEs 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).