All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Zhang <yu.c.zhang@linux.intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Ben Gardon <bgardon@google.com>
Cc: kvm@vger.kernel.org
Subject: A question of TDP unloading.
Date: Wed, 28 Jul 2021 00:19:57 +0800	[thread overview]
Message-ID: <20210727161957.lxevvmy37azm2h7z@linux.intel.com> (raw)

Hi all,

  I'd like to ask a question about kvm_reset_context(): is there any
  reason that we must alway unload TDP root in kvm_mmu_reset_context()?
  
  As you know, KVM MMU needs to track guest paging mode changes, to
  recalculate the mmu roles and reset callback routines(e.g., guest
  page table walker). These are done in kvm_mmu_reset_context(). Also,
  entering SMM, cpuid updates, and restoring L1 VMM's host state will
  trigger kvm_mmu_reset_context() too.
  
  Meanwhile, another job done by kvm_mmu_reset_context() is to unload
  the KVM MMU:
  
  - For shadow & legacy TDP, it means to unload the root shadow/TDP
    page and reconstruct another one in kvm_mmu_reload(), before
    entering guest. Old shadow/TDP pages will probably be reused later,
    after future guest paging mode switches.
  
  - For TDP MMU, it is even more aggressive, all TDP pages will be
    zapped, meaning a whole new TDP page table will be recontrustred,
    with each paging mode change in the guest. I witnessed dozens of
    rebuildings of TDP when booting a Linux guest(besides the ones
    caused by memslots rearrangement).
  
  However, I am wondering, why do we need the unloading, if GPA->HPA
  relationship is not changed? And if this is not a must, could we
  find a way to refactor kvm_mmu_reset_context(), so that unloading
  of TDP root is only performed when necessary(e.g, SMM switches and
  maybe after cpuid updates which may change the level of TDP)? 
  
  I tried to add a parameter in kvm_mmu_reset_context(), to make the
  unloading optional:  

+void kvm_mmu_reset_context(struct kvm_vcpu *vcpu, bool force_tdp_unload)
 {
-       kvm_mmu_unload(vcpu);
+       if (!tdp_enabled || force_tdp_unload)
+               kvm_mmu_unload(vcpu);
+
        kvm_init_mmu(vcpu);
 }

  But this change brings another problem - if we keep the TDP root, the
  role of existing SPs will be obsolete after guest paging mode changes.
  Altough I guess most role flags are irrelevant in TDP, I am not sure
  if this could cause any trouble.
  
  Is there anyone looking at this issue? Or do you have any suggestion?
  Thanks!
  
B.R.
Yu


             reply	other threads:[~2021-07-27 16:20 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 16:19 Yu Zhang [this message]
2021-07-27 18:07 ` A question of TDP unloading 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
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=20210727161957.lxevvmy37azm2h7z@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.