linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/12] KVM: MMU: do not unload MMU roots on all role changes
@ 2022-02-09 17:00 Paolo Bonzini
  2022-02-09 17:00 ` [PATCH 01/12] KVM: x86: host-initiated EFER.LME write affects the MMU Paolo Bonzini
                   ` (12 more replies)
  0 siblings, 13 replies; 50+ messages in thread
From: Paolo Bonzini @ 2022-02-09 17:00 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: vkuznets, mlevitsk, dmatlack, seanjc

The TDP MMU has a performance regression compared to the legacy MMU
when CR0 changes often.  This was reported for the grsecurity kernel,
which uses CR0.WP to implement kernel W^X.  In that case, each change to
CR0.WP unloads the MMU and causes a lot of unnecessary work.  When running
nested, this can even cause the L1 to hardly make progress, as the L0
hypervisor it is overwhelmed by the amount of MMU work that is needed.

Initially, my plan for this was to pull kvm_mmu_unload from
kvm_mmu_reset_context into kvm_init_mmu.  Therefore I started by separating
the CPU setup (CR0/CR4/EFER, SMM, guest mode, etc.) from the shadow
page table format.  Right now the "MMU role" is a messy mix of the two
and, whenever something is different between the MMU and the CPU, it is
stored as an extra field in struct kvm_mmu; for extra bonus complication,
sometimes the same thing is stored in both the role and an extra field.
The aim was to keep kvm_mmu_unload only if the MMU role changed, and
drop it if the CPU role changed.

I even posted that cleanup, but it occurred to me later that even
a conditional kvm_mmu_unload in kvm_init_mmu would be overkill.
kvm_mmu_unload is only needed in the rare cases where a TLB flush is
needed (e.g. CR0.PG changing from 1 to 0) or where the guest page table
interpretation changes in way not captured by the role (that is, CPUID
changes).  But the implementation of fast PGD switching is subtle
and requires a call to kvm_mmu_new_pgd (and therefore knowing the
new MMU role) before kvm_init_mmu, therefore kvm_mmu_reset_context
chickens and drops all the roots.

Therefore, the meat of this series is a reorganization of fast PGD
switching; it makes it possible to call kvm_mmu_new_pgd *after*
the MMU has been set up, just using the MMU role instead of
kvm_mmu_calc_root_page_role.

Patches 1 to 3 are bugfixes found while working on the series.

Patches 4 to 5 add more sanity checks that triggered a lot during
development.

Patches 6 and 7 are related cleanups.  In particular patch 7 makes
the cache lookup code a bit more pleasant.

Patches 8 to 9 rework the fast PGD switching.  Patches 10 and
11 are cleanups enabled by the rework, and the only survivors
of the CPU role patchset.

Finally, patch 12 optimizes kvm_mmu_reset_context.

Paolo


Paolo Bonzini (12):
  KVM: x86: host-initiated EFER.LME write affects the MMU
  KVM: MMU: move MMU role accessors to header
  KVM: x86: do not deliver asynchronous page faults if CR0.PG=0
  KVM: MMU: WARN if PAE roots linger after kvm_mmu_unload
  KVM: MMU: avoid NULL-pointer dereference on page freeing bugs
  KVM: MMU: rename kvm_mmu_reload
  KVM: x86: use struct kvm_mmu_root_info for mmu->root
  KVM: MMU: do not consult levels when freeing roots
  KVM: MMU: look for a cached PGD when going from 32-bit to 64-bit
  KVM: MMU: load new PGD after the shadow MMU is initialized
  KVM: MMU: remove kvm_mmu_calc_root_page_role
  KVM: x86: do not unload MMU roots on all role changes

 arch/x86/include/asm/kvm_host.h |   3 +-
 arch/x86/kvm/mmu.h              |  28 +++-
 arch/x86/kvm/mmu/mmu.c          | 253 ++++++++++++++++----------------
 arch/x86/kvm/mmu/mmu_audit.c    |   4 +-
 arch/x86/kvm/mmu/paging_tmpl.h  |   2 +-
 arch/x86/kvm/mmu/tdp_mmu.c      |   2 +-
 arch/x86/kvm/mmu/tdp_mmu.h      |   2 +-
 arch/x86/kvm/svm/nested.c       |   6 +-
 arch/x86/kvm/vmx/nested.c       |   8 +-
 arch/x86/kvm/vmx/vmx.c          |   2 +-
 arch/x86/kvm/x86.c              |  39 +++--
 11 files changed, 190 insertions(+), 159 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 50+ messages in thread

end of thread, other threads:[~2022-02-15  8:17 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 17:00 [PATCH 00/12] KVM: MMU: do not unload MMU roots on all role changes Paolo Bonzini
2022-02-09 17:00 ` [PATCH 01/12] KVM: x86: host-initiated EFER.LME write affects the MMU Paolo Bonzini
2022-02-10 22:49   ` Sean Christopherson
2022-02-09 17:00 ` [PATCH 02/12] KVM: MMU: move MMU role accessors to header Paolo Bonzini
2022-02-10 23:00   ` Sean Christopherson
2022-02-09 17:00 ` [PATCH 03/12] KVM: x86: do not deliver asynchronous page faults if CR0.PG=0 Paolo Bonzini
2022-02-10 23:10   ` Sean Christopherson
2022-02-10 23:14     ` Sean Christopherson
2022-02-10 23:16       ` Sean Christopherson
2022-02-11 11:16         ` Paolo Bonzini
2022-02-09 17:00 ` [PATCH 04/12] KVM: MMU: WARN if PAE roots linger after kvm_mmu_unload Paolo Bonzini
2022-02-10 23:20   ` Sean Christopherson
2022-02-11 11:18     ` Paolo Bonzini
2022-02-09 17:00 ` [PATCH 05/12] KVM: MMU: avoid NULL-pointer dereference on page freeing bugs Paolo Bonzini
2022-02-11  0:24   ` Sean Christopherson
2022-02-11 11:21     ` Paolo Bonzini
2022-02-09 17:00 ` [PATCH 06/12] KVM: MMU: rename kvm_mmu_reload Paolo Bonzini
2022-02-11  0:27   ` Sean Christopherson
2022-02-11 10:07     ` Paolo Bonzini
2022-02-11 16:16       ` Sean Christopherson
2022-02-11 16:52         ` Paolo Bonzini
2022-02-09 17:00 ` [PATCH 07/12] KVM: x86: use struct kvm_mmu_root_info for mmu->root Paolo Bonzini
2022-02-11 17:39   ` Sean Christopherson
2022-02-09 17:00 ` [PATCH 08/12] KVM: MMU: do not consult levels when freeing roots Paolo Bonzini
2022-02-11  0:41   ` Sean Christopherson
2022-02-11  0:54     ` Sean Christopherson
2022-02-11  1:07       ` Paolo Bonzini
2022-02-11  1:35         ` Sean Christopherson
2022-02-11  1:44           ` Sean Christopherson
2022-02-11  2:20             ` Sean Christopherson
2022-02-09 17:00 ` [PATCH 09/12] KVM: MMU: look for a cached PGD when going from 32-bit to 64-bit Paolo Bonzini
2022-02-11  1:32   ` Sean Christopherson
2022-02-11  1:37     ` Sean Christopherson
2022-02-11 10:09       ` Paolo Bonzini
2022-02-11 11:45     ` Paolo Bonzini
2022-02-11 17:38       ` Sean Christopherson
2022-02-09 17:00 ` [PATCH 10/12] KVM: MMU: load new PGD after the shadow MMU is initialized Paolo Bonzini
2022-02-11 17:45   ` Sean Christopherson
2022-02-11 17:47     ` Paolo Bonzini
2022-02-09 17:00 ` [PATCH 11/12] KVM: MMU: remove kvm_mmu_calc_root_page_role Paolo Bonzini
2022-02-11 17:53   ` Sean Christopherson
2022-02-09 17:00 ` [PATCH 12/12] KVM: x86: do not unload MMU roots on all role changes Paolo Bonzini
2022-02-11  9:08   ` Nikunj A. Dadhania
2022-02-11 18:48   ` Sean Christopherson
2022-02-14 16:34     ` Paolo Bonzini
2022-02-14 19:24       ` Sean Christopherson
2022-02-15  8:17         ` Paolo Bonzini
2022-02-09 17:07 ` [PATCH 00/12] KVM: MMU: " Sean Christopherson
2022-02-09 17:11   ` Paolo Bonzini
2022-02-09 17:16     ` Sean Christopherson

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).