From: Sean Christopherson <seanjc@google.com>
To: Yan Zhao <yan.y.zhao@intel.com>
Cc: Yu Zhang <yu.c.zhang@linux.intel.com>,
Ben Gardon <bgardon@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: A question of TDP unloading.
Date: Thu, 29 Jul 2021 20:40:49 +0000 [thread overview]
Message-ID: <YQMSUalIaMe9/78r@google.com> (raw)
In-Reply-To: <20210729025809.GA9585@yzhao56-desk.sh.intel.com>
On Thu, Jul 29, 2021, Yan Zhao wrote:
> On Thu, Jul 29, 2021 at 11:00:56AM +0800, Yu Zhang wrote:
> > >
> > > Ooof that's a lot of resets, though if there are only a handful of
> > > pages mapped, it might not be a noticeable performance impact. I think
> > > it'd be worth collecting some performance data to quantify the impact.
> >
> > Yes. Too many reset will definitely hurt the performance, though I did not see
> > obvious delay.
> >
>
> if I add below limits before unloading mmu, and with
> enable_unrestricted_guest=0, the boot time can be reduced to 31 secs
> from more than 5 minutes.
>
> void kvm_mmu_reset_context(struct kvm_vcpu *vcpu)
> {
> - kvm_mmu_unload(vcpu);
> - kvm_init_mmu(vcpu, true);
> + union kvm_mmu_role new_role =
> + kvm_calc_tdp_mmu_root_page_role(vcpu, false);
> + struct kvm_mmu *context = &vcpu->arch.root_mmu;
> + bool reset = false;
> +
> + if (new_role.as_u64 != context->mmu_role.as_u64) {
Aha! A clue!
This hack indicates that the call to kvm_mmu_reset_context() is spurious, i.e.
none of the MMU role bits in CR0/CR4/EFER are changing. Dollars to donuts says
this is due to the long-standing hack-a-fix in enter_rmode() that unconditionally
reset the MMU when the guest entered real mode.
Prior to commit 5babbb43a58a ("KVM: VMX: Remove explicit MMU reset in enter_rmode()").
(sitting in kvm/queue), enter_rmode() to deal with unrestricted_guest=0 would
unconditionally do kvm_mmu_reset_context(). Based on the above, it sounds like
your guest is going in and out of RM/PM, i.e. toggling CR0.PE. CR0.PE isn't a
MMU role bit, so the kvm_mmu_reset_context() is spurious unless CR0.PG is also
being changed.
TL;DR: Try the current kvm/queue, or at least after commit 5babbb43a58a
("KVM: VMX: Remove explicit MMU reset in enter_rmode()").
> + kvm_mmu_unload(vcpu);
> + reset = true;
> + }
> + kvm_init_mmu(vcpu, reset);
>
> But with enable_unrestricted_guest=0, if I further modify the limits to
> "if (new_role.base.word != context->mmu_role.base.word)", the VM would
> fail to boot.
> so, with mmu extended role changes, unload the mmu is necessary in some
> situation, or at least we need to zap related sptes.
>
> Thanks
> Yan
next prev parent reply other threads:[~2021-07-29 20:40 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 [this message]
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
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=YQMSUalIaMe9/78r@google.com \
--to=seanjc@google.com \
--cc=bgardon@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=yan.y.zhao@intel.com \
--cc=yu.c.zhang@linux.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