Skip to content

KVM: MMU: MMU role refactoring

Paolo Bonzini kvm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest23 patches 48 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/23KVM: MMU: pass uses_nx directly to reset_shadow_zero_bits_maskarch/x86/kvm/mmu/mmu.c+13 -136 replies
2/23KVM: MMU: nested EPT cannot be used in SMMarch/x86/kvm/mmu/mmu.c+0 -32 replies
3/23KVM: MMU: remove valid from extended rolearch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/mmu.c+4 -94 replies
4/23KVM: MMU: constify uses of struct kvm_mmu_role_regsarch/x86/kvm/mmu/mmu.c+11 -82 replies
5/23KVM: MMU: pull computation of kvm_mmu_role_regs to kvm_init_mmuarch/x86/kvm/mmu/mmu.c+17 -161 reply
6/23KVM: MMU: load new PGD once nested two-dimensional paging is initializedarch/x86/kvm/mmu/mmu.c+19 -224 replies
7/23KVM: MMU: remove kvm_mmu_calc_root_page_rolearch/x86/kvm/mmu/mmu.c+4 -256 replies
8/23KVM: MMU: rephrase unclear commentarch/x86/kvm/mmu/paging_tmpl.h+1 -11 reply
9/23KVM: MMU: remove "bool base_only" argumentsarch/x86/kvm/mmu/mmu.c+22 -411 reply
10/23KVM: MMU: split cpu_role from mmu_rolearch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/mmu.c arch/x86/kvm/mmu/paging_tmpl.h+64 -393 replies
11/23KVM: MMU: do not recompute root level from kvm_mmu_role_regsarch/x86/kvm/mmu/mmu.c+8 -152 replies
12/23KVM: MMU: remove ept_ad fieldarch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/mmu.c arch/x86/kvm/mmu/paging_tmpl.h+1 -30 replies
13/23KVM: MMU: remove kvm_calc_shadow_root_page_role_commonarch/x86/kvm/mmu/mmu.c+2 -191 reply
14/23KVM: MMU: cleanup computation of MMU roles for two-dimensional pagingarch/x86/kvm/mmu/mmu.c+8 -310 replies
15/23KVM: MMU: cleanup computation of MMU roles for shadow pagingarch/x86/kvm/mmu/mmu.c+6 -110 replies
16/23KVM: MMU: remove extended bits from mmu_rolearch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/mmu.c arch/x86/kvm/mmu/paging_tmpl.h +1 more+34 -350 replies
17/23KVM: MMU: remove redundant bits from extended rolearch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/mmu.c+10 -60 replies
18/23KVM: MMU: fetch shadow EFER.NX from MMU rolearch/x86/kvm/mmu/mmu.c+4 -40 replies
19/23KVM: MMU: simplify and/or inline computation of shadow MMU rolesarch/x86/kvm/mmu/mmu.c+7 -250 replies
20/23KVM: MMU: pull CPU role computation to kvm_init_mmuarch/x86/kvm/mmu/mmu.c+9 -121 reply
21/23KVM: MMU: store shadow_root_level into mmu_rolearch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu.h arch/x86/kvm/mmu/mmu.c +3 more+20 -251 reply
22/23KVM: MMU: use cpu_role for root_levelarch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/mmu.c arch/x86/kvm/mmu/mmu_audit.c +1 more+14 -191 reply
23/23KVM: MMU: replace direct_map with mmu_role.directarch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/mmu.c arch/x86/kvm/x86.c+20 -231 reply

Reviews trailers per patch

12 of 23 patches have a Reviewed-by or Acked-by.

PatchDavid Matlack
1/23R-b
2/23R-b
3/23
4/23R-b
5/23R-b
6/23R-b
7/23
8/23R-b
9/23R-b
10/23
11/23R-b
12/23
13/23R-b
14/23
15/23
16/23
17/23
18/23
19/23
20/23
21/23R-b
22/23R-b
23/23R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 00/23] KVM: MMU: MMU role refactoring

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.

The root cause of the issue is that the "MMU role" in KVM is a mess that mixes the CPU setup (CR0/CR4/EFER, SMM, guest mode, etc.) and the shadow page table format. Whenever something is different between the MMU and the CPU, it is stored as an extra field in struct kvm_mmu---and for extra bonus complication, sometimes the same thing is stored in both the role and an extra field.

So, this is the "no functional change intended" part of the changes required to fix the performance regression. It separates neatly the shadow page table format ("MMU role") from the guest page table format ("CPU role"), and removes the duplicate fields. The next step then is to avoid unloading the MMU as long as the MMU role stays the same.

Please review!

Paolo

Paolo Bonzini (23):
KVM: MMU: pass uses_nx directly to reset_shadow_zero_bits_mask
KVM: MMU: nested EPT cannot be used in SMM
KVM: MMU: remove valid from extended role
KVM: MMU: constify uses of struct kvm_mmu_role_regs
KVM: MMU: pull computation of kvm_mmu_role_regs to kvm_init_mmu
KVM: MMU: load new PGD once nested two-dimensional paging is
initialized
KVM: MMU: remove kvm_mmu_calc_root_page_role
KVM: MMU: rephrase unclear comment
KVM: MMU: remove "bool base_only" arguments
KVM: MMU: split cpu_role from mmu_role
KVM: MMU: do not recompute root level from kvm_mmu_role_regs
KVM: MMU: remove ept_ad field
KVM: MMU: remove kvm_calc_shadow_root_page_role_common
KVM: MMU: cleanup computation of MMU roles for two-dimensional paging
KVM: MMU: cleanup computation of MMU roles for shadow paging
KVM: MMU: remove extended bits from mmu_role
KVM: MMU: remove redundant bits from extended role
KVM: MMU: fetch shadow EFER.NX from MMU role
KVM: MMU: simplify and/or inline computation of shadow MMU roles
KVM: MMU: pull CPU role computation to kvm_init_mmu
KVM: MMU: store shadow_root_level into mmu_role
KVM: MMU: use cpu_role for root_level
KVM: MMU: replace direct_map with mmu_role.direct

 arch/x86/include/asm/kvm_host.h |  13 +-
 arch/x86/kvm/mmu.h              |   2 +-
 arch/x86/kvm/mmu/mmu.c          | 408 ++++++++++++--------------------
 arch/x86/kvm/mmu/mmu_audit.c    |   6 +-
 arch/x86/kvm/mmu/paging_tmpl.h  |  12 +-
 arch/86/kvm/mmu/tdp_mmu.c      |   4 +-
 arch/x86/kvm/svm/svm.c          |   2 +-
 arch/x86/kvm/vmx/vmx.c          |   2 +-
 arch/x86/kvm/x86.c              |  12 +-
 10 files changed, 178 insertions(+), 284 deletions(-)
Signature · 1 line
2.31.1