From: Yu Zhang <yu.c.zhang@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Ben Gardon <bgardon@google.com>,
kvm@vger.kernel.org
Subject: Re: A question of TDP unloading.
Date: Fri, 30 Jul 2021 10:42:51 +0800 [thread overview]
Message-ID: <20210730024251.fpd2vtbkmdnooq6s@linux.intel.com> (raw)
In-Reply-To: <YQMX+Cvo8GKCo3Zt@google.com>
On Thu, Jul 29, 2021 at 09:04:56PM +0000, Sean Christopherson wrote:
> On Thu, Jul 29, 2021, Yu Zhang wrote:
> > On Wed, Jul 28, 2021 at 06:37:38PM +0000, Sean Christopherson wrote:
> > > On Wed, Jul 28, 2021, Yu Zhang wrote:
> > In the caller, force_tdp_unload was set to false for CR0/CR4/EFER changes. For SMM and
> > cpuid updates, it is set to true.
> >
> > With this change, I can successfully boot a VM(and of course, number of unloadings is
> > greatly reduced). But access test case in kvm-unit-test hangs, after CR4.SMEP is flipped.
> > I'm trying to figure out why...
>
> Hrm, I'll look into when I get around to making this into a proper patch.
>
> Note, there's at least once bug, as is_root_usable() will compare the full role
> against a root shadow page's modified role. A common helper to derive the page
> role for a direct/TDP page from an existing mmu_role is likely the way to go, as
> kvm_tdp_mmu_get_vcpu_root_hpa() would want the same functionality.
So, if we know there are some bits meaningless in SP, could we use a
ignored_mask, each time we try to compare the full role.word? This may
be also needed in kvm_mmu_get_page().
>
> > > I'll put this on my todo list, I've been looking for an excuse to update the
> > > cr0/cr4/efer flows anyways :-). If it works, the changes should be relatively
> > > minor, if it works...
> > >
> > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> > > index a8cdfd8d45c4..700664fe163e 100644
> > > --- a/arch/x86/kvm/mmu/mmu.c
> > > +++ b/arch/x86/kvm/mmu/mmu.c
> > > @@ -2077,8 +2077,20 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
> > > role = vcpu->arch.mmu->mmu_role.base;
> > > role.level = level;
> > > role.direct = direct;
> > > - if (role.direct)
> > > + if (role.direct) {
> > > role.gpte_is_8_bytes = true;
> > > +
> > > + /*
> > > + * Guest PTE permissions do not impact SPTE permissions for
> > > + * direct MMUs. Either there are no guest PTEs (CR0.PG=0) or
> > > + * guest PTE permissions are enforced by the CPU (TDP enabled).
> > > + */
> > > + WARN_ON_ONCE(access != ACC_ALL);
> > > + role.efer_nx = 0;
> > > + role.cr0_wp = 0;
> > > + role.smep_andnot_wp = 0;
> > > + role.smap_andnot_wp = 0;
> > > + }
> >
> > How about we do this in kvm_calc_mmu_role_common()? :-)
>
> No, because the role in struct kvm_mmu does need the correct bits, even for TDP,
> as the role is used to detect whether or not the context needs to be re-initialized,
> e.g. it would get a false negative on a cr0_wp change, not go through
> update_permission_bitmask(), and use the wrong page permissions when walking the
> guest page tables.
Oh yes. Regardless of what flags really matter in a SP, all of them are useful for mmu
context. Thanks for correcting me.
B.R.
Yu
next prev parent reply other threads:[~2021-07-30 2:42 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-27 16:19 A question of TDP unloading Yu Zhang
2021-07-27 18:07 ` Sean Christopherson
2021-07-28 6:56 ` Yu Zhang
2021-07-28 7:25 ` Yan Zhao
2021-07-28 16:23 ` Ben Gardon
2021-07-28 17:23 ` Yu Zhang
2021-07-28 17:55 ` Ben Gardon
2021-07-29 3:00 ` Yu Zhang
2021-07-29 2:58 ` Yan Zhao
2021-07-29 5:17 ` Yu Zhang
2021-07-29 5:17 ` Yan Zhao
2021-07-29 6:34 ` Yan Zhao
2021-07-29 8:48 ` Yan Zhao
2021-07-29 20:40 ` Sean Christopherson
2021-07-29 9:19 ` Paolo Bonzini
2021-07-29 16:38 ` Yu Zhang
2021-07-28 18:37 ` Sean Christopherson
2021-07-29 3:22 ` Yu Zhang
2021-07-29 21:04 ` Sean Christopherson
2021-07-30 2:42 ` Yu Zhang [this message]
2021-07-30 9:42 ` Yu Zhang
2021-07-30 8:22 ` Yu Zhang
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=20210730024251.fpd2vtbkmdnooq6s@linux.intel.com \
--to=yu.c.zhang@linux.intel.com \
--cc=bgardon@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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