From: Sean Christopherson <seanjc@google.com>
To: Yan Zhao <yan.y.zhao@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: x86/mmu: fix KVM_X86_QUIRK_SLOT_ZAP_ALL for shadow MMU
Date: Wed, 9 Oct 2024 06:05:42 -0700 [thread overview]
Message-ID: <ZwZ_pkw3pGoA0gA6@google.com> (raw)
In-Reply-To: <ZwZEEHeRWEA2JUsj@yzhao56-desk.sh.intel.com>
On Wed, Oct 09, 2024, Yan Zhao wrote:
> On Fri, Oct 04, 2024 at 09:56:07AM -0700, Sean Christopherson wrote:
> > > arch/x86/kvm/mmu/mmu.c | 60 ++++++++++++++++++++++++++++++++----------
> > > 1 file changed, 46 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> > > index e081f785fb23..912bad4fa88c 100644
> > > --- a/arch/x86/kvm/mmu/mmu.c
> > > +++ b/arch/x86/kvm/mmu/mmu.c
> > > @@ -1884,10 +1884,14 @@ static bool sp_has_gptes(struct kvm_mmu_page *sp)
> > > if (is_obsolete_sp((_kvm), (_sp))) { \
> > > } else
> > >
> > > -#define for_each_gfn_valid_sp_with_gptes(_kvm, _sp, _gfn) \
> > > +#define for_each_gfn_valid_sp(_kvm, _sp, _gfn) \
> > > for_each_valid_sp(_kvm, _sp, \
> > > &(_kvm)->arch.mmu_page_hash[kvm_page_table_hashfn(_gfn)]) \
> > > - if ((_sp)->gfn != (_gfn) || !sp_has_gptes(_sp)) {} else
> > > + if ((_sp)->gfn != (_gfn)) {} else
> >
> > I don't think we should provide this iterator, because it won't do what most people
> > would it expect it to do. Specifically, the "round gfn for level" adjustment that
> > is done for direct SPs means that the exact gfn comparison will not get a match,
> > even when a SP does "cover" a gfn, or was even created specifically for a gfn.
> Right, zapping of sps with no gptes are not necessary.
> When role.direct is true, the sp->gfn can even be a non-slot gfn with the leaf
> entries being mmio sptes. So, it should be ok to ignore
> "!sp_has_gptes(_sp) && (_sp)->gfn == (_gfn)".
>
> Tests of "normal VM + nested VM + 3 selftests" passed on the 3 configs
> 1) modprobe kvm_intel ept=0,
> 2) modprobe kvm tdp_mmu=0
> modprobe kvm_intel ept=1
> 3) modprobe kvm tdp_mmu=1
> modprobe kvm_intel ept=1
>
> with quirk disabled + below change
>
> @@ -7071,7 +7077,7 @@ static void kvm_mmu_zap_memslot_pages_and_flush(struct kvm *kvm,
> struct kvm_mmu_page *sp;
> gfn_t gfn = slot->base_gfn + i;
>
> - for_each_gfn_valid_sp(kvm, sp, gfn)
> + for_each_gfn_valid_sp_with_gptes(kvm, sp, gfn)
> kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list);
>
> if (need_resched() || rwlock_needbreak(&kvm->mmu_lock)) {
Ya, I have a patch that I'll send today.
prev parent reply other threads:[~2024-10-09 13:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-03 23:01 [PATCH] KVM: x86/mmu: fix KVM_X86_QUIRK_SLOT_ZAP_ALL for shadow MMU Paolo Bonzini
2024-10-04 16:56 ` Sean Christopherson
2024-10-07 15:07 ` Sean Christopherson
2024-10-09 8:51 ` Yan Zhao
2024-10-09 13:05 ` Sean Christopherson [this message]
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=ZwZ_pkw3pGoA0gA6@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=yan.y.zhao@intel.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox