Skip to content

RFC x86/kvm/nVMX: optimize MMU switch between L1 and L2

Vitaly Kuznetsov kvm lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest7 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7x86/kvm/mmu: make vcpu->mmu a pointer to the current MMUarch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu.c arch/x86/kvm/mmu.h +5 more+120 -1130 replies
2/7x86/kvm/mmu.c: set get_pdptr hook in kvm_init_shadow_ept_mmu()arch/x86/kvm/mmu.c+2 -00 replies
3/7x86/kvm/mmu.c: add kvm_mmu parameter to kvm_mmu_free_roots()arch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu.c+4 -50 replies
4/7x86/kvm/mmu: introduce guest_mmuarch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu.c arch/x86/kvm/vmx.c+31 -130 replies
5/7x86/kvm/mmu: get rid of redundant kvm_mmu_setup()arch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu.c arch/x86/kvm/x86.c+4 -160 replies
6/7x86/kvm/nVMX: introduce scache for kvm_init_shadow_ept_mmuarch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu.c arch/x86/kvm/vmx.c+67 -30 replies
7/7x86/kvm/nVMX: optimize MMU switch from nested_vmx_load_cr3()arch/x86/include/asm/kvm_host.h arch/x86/kvm/cpuid.c arch/x86/kvm/mmu.c +3 more+81 -320 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH RFC 0/7] x86/kvm/nVMX: optimize MMU switch between L1 and L2

Currently, when we switch from L1 to L2 we do the following:
- Re-initialize L1 MMU as shadow EPT MMU (nested_ept_init_mmu_context())
- Re-initialize 'nested' MMU (nested_vmx_load_cr3() -> init_kvm_nested_mmu())
- Reload MMU root upon guest entry.

When we switch back we do:
- Re-initialize L1 MMU (nested_vmx_load_cr3() -> init_kvm_tdp_mmu())
- Reload MMU root upon guest entry.

This seems to be sub-optimal. Initializing MMU is expensive (thanks to update_permission_bitmask(), update_pkru_bitmask(),..) and reloading MMU root doesn't come for free.

Try to approach the issue by splitting L1-normal and L1-nested MMUs and checking if MMU reset is really needed. This spares us about 1000 cpu cycles on nested vmexit.

RFC part:
- Does this look like a plausible solution?
- SVM nested can probably be optimized in the same way.
- Doesn mmu_update_needed() cover everything?

Vitaly Kuznetsov (7):
x86/kvm/mmu: make vcpu->mmu a pointer to the current MMU x86/kvm/mmu.c: set get_pdptr hook in kvm_init_shadow_ept_mmu() x86/kvm/mmu.c: add kvm_mmu parameter to kvm_mmu_free_roots() x86/kvm/mmu: introduce guest_mmu
x86/kvm/mmu: get rid of redundant kvm_mmu_setup() x86/kvm/nVMX: introduce scache for kvm_init_shadow_ept_mmu x86/kvm/nVMX: optimize MMU switch from nested_vmx_load_cr3()

 arch/x86/include/asm/kvm_host.h |  36 ++++-
 arch/x86/kvm/cpuid.c            |   2 +-
 arch/x86/kvm/mmu.c              | 282 ++++++++++++++++++++++++++--------------
 arch/x86/kvm/mmu.h              |   2 +-
 arch/x86/kvm/mmu_audit.c        |  12 +-
 arch/x86/kvm/paging_tmpl.h      |  17 +--
 arch/x86/kvm/svm.c              |  20 +--
 arch/x86/kvm/vmx.c              |  52 +++++---
 arch/x86/kvm/x86.c              |  34 ++---
 9 files changed, 292 insertions(+), 165 deletions(-)
Signature · 1 line
2.14.4