Skip to content

KVM: x86/mmu: Introduce MMU_PRESENT and fix bugs

Sean Christopherson kvm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest24 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/24KVM: x86/mmu: Set SPTE_AD_WRPROT_ONLY_MASK if and only if PML is enabledarch/x86/kvm/mmu/mmu_internal.h+8 -80 replies
2/24KVM: x86/mmu: Check for shadow-present SPTE before querying A/D statusarch/x86/kvm/mmu/tdp_mmu.c+3 -40 replies
3/24KVM: x86/mmu: Bail from fast_page_fault() if SPTE is not shadow-presentarch/x86/kvm/mmu/mmu.c+3 -00 replies
4/24KVM: x86/mmu: Disable MMIO caching if MMIO value collides with L1TFarch/x86/kvm/mmu/spte.c+12 -10 replies
5/24KVM: x86/mmu: Retry page faults that hit an invalid memslotarch/x86/kvm/mmu/mmu.c+8 -00 replies
6/24KVM: x86/mmu: Don't install bogus MMIO SPTEs if MMIO caching is disabledarch/x86/kvm/mmu/mmu.c arch/x86/kvm/mmu/spte.c+17 -20 replies
7/24KVM: x86/mmu: Handle MMIO SPTEs directly in mmu_set_spte()arch/x86/kvm/mmu/mmu.c+5 -170 replies
8/24KVM: x86/mmu: Drop redundant trace_kvm_mmu_set_spte() in the TDP MMUarch/x86/kvm/mmu/tdp_mmu.c+2 -30 replies
9/24KVM: x86/mmu: Rename 'mask' to 'spte' in MMIO SPTE helpersarch/x86/kvm/mmu/mmu.c arch/x86/kvm/mmu/spte.c+8 -80 replies
10/24KVM: x86/mmu: Stop using software available bits to denote MMIO SPTEsarch/x86/kvm/mmu.h arch/x86/kvm/mmu/mmu.c arch/x86/kvm/mmu/spte.c +3 more+15 -150 replies
11/24KVM: x86/mmu: Add module param to disable MMIO caching (for testing)arch/x86/kvm/mmu/spte.c+6 -00 replies
12/24KVM: x86/mmu: Rename and document A/D scheme for TDP SPTEsDocumentation/virt/kvm/locking.rst arch/x86/kvm/mmu/spte.c arch/x86/kvm/mmu/spte.h+56 -320 replies
13/24KVM: x86/mmu: Use MMIO SPTE bits 53 and 52 for the MMIO generationarch/x86/kvm/mmu/spte.c arch/x86/kvm/mmu/spte.h+4 -50 replies
14/24KVM: x86/mmu: Document dependency bewteen TDP A/D type and saved bitsarch/x86/kvm/mmu/spte.h+5 -30 replies
15/24KVM: x86/mmu: Move initial kvm_mmu_set_mask_ptes() call into MMU properarch/x86/kvm/mmu/mmu.c arch/x86/kvm/x86.c+4 -30 replies
16/24KVM: x86/mmu: Co-locate code for setting various SPTE masksarch/x86/kvm/mmu/mmu.c arch/x86/kvm/mmu/spte.c arch/x86/kvm/vmx/vmx.c+25 -360 replies
17/24KVM: x86/mmu: Move logic for setting SPTE masks for EPT into the MMU properarch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu.h arch/x86/kvm/mmu/spte.c +1 more+29 -550 replies
18/24KVM: x86/mmu: Make Host-writable and MMU-writable bit locations dynamicDocumentation/virt/kvm/locking.rst arch/x86/kvm/mmu.h arch/x86/kvm/mmu/mmu.c +4 more+38 -340 replies
19/24KVM: x86/mmu: Use high bits for host/mmu writable masks for EPT SPTEsarch/x86/kvm/mmu/spte.c arch/x86/kvm/mmu/spte.h+36 -150 replies
20/24KVM: x86/mmu: Use a dedicated bit to track shadow/MMU-present SPTEsarch/x86/kvm/mmu/spte.c arch/x86/kvm/mmu/spte.h+14 -54 replies
21/24KVM: x86/mmu: Tweak auditing WARN for A/D bits to !PRESENT (was MMIO)arch/x86/kvm/mmu/spte.h+9 -92 replies
22/24KVM: x86/mmu: Use is_removed_spte() instead of open coded equivalentsarch/x86/kvm/mmu/tdp_mmu.c+2 -20 replies
23/24KVM: x86/mmu: Use low available bits for removed SPTEsarch/x86/kvm/mmu/spte.c arch/x86/kvm/mmu/spte.h+17 -50 replies
24/24KVM: x86/mmu: Dump reserved bits if they're detected on non-MMIO SPTEarch/x86/kvm/mmu/mmu.c+4 -30 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH 00/24] KVM: x86/mmu: Introduce MMU_PRESENT and fix bugs

This series adds the simple idea of tagging shadow-present SPTEs with a single bit, instead of looking for non-zero SPTEs that aren't MMIO and aren't REMOVED. Doing so reduces KVM's code footprint by 2k bytes on x86-64, and presumably adds a tiny performance boost in related paths.

But, actually adding MMU_PRESENT without breaking one flow or another is a bit of a debacle. The main issue is that EPT doesn't have many low available bits, and PAE doesn't have any high available bits. And, the existing MMU_WRITABLE and HOST_WRITABLE flags aren't optional, i.e. are needed for all flavors of paging. The solution I settled on is to let make the *_WRITABLE bit configurable so that EPT can use high available bits.

Of course, I forgot the above PAE restriction multiple times, and journeyed down several dead ends. The most notable failed idea was using the AD_* masks in bits 52 and 53 to denote shadow-present SPTEs. That would have been quite clever as it would provide the same benefits without burning another available bit.

Along the many failed attempts, I collected a variety of bug fixes and cleanups, mostly things found by inspection after doing a deep dive to figure out what I broke.

Sean Christopherson (24):
KVM: x86/mmu: Set SPTE_AD_WRPROT_ONLY_MASK if and only if PML is
enabled
KVM: x86/mmu: Check for shadow-present SPTE before querying A/D status
KVM: x86/mmu: Bail from fast_page_fault() if SPTE is not
shadow-present
KVM: x86/mmu: Disable MMIO caching if MMIO value collides with L1TF
KVM: x86/mmu: Retry page faults that hit an invalid memslot
KVM: x86/mmu: Don't install bogus MMIO SPTEs if MMIO caching is
disabled
KVM: x86/mmu: Handle MMIO SPTEs directly in mmu_set_spte()
KVM: x86/mmu: Drop redundant trace_kvm_mmu_set_spte() in the TDP MMU
KVM: x86/mmu: Rename 'mask' to 'spte' in MMIO SPTE helpers
KVM: x86/mmu: Stop using software available bits to denote MMIO SPTEs
KVM: x86/mmu: Add module param to disable MMIO caching (for testing)
KVM: x86/mmu: Rename and document A/D scheme for TDP SPTEs
KVM: x86/mmu: Use MMIO SPTE bits 53 and 52 for the MMIO generation
KVM: x86/mmu: Document dependency bewteen TDP A/D type and saved bits
KVM: x86/mmu: Move initial kvm_mmu_set_mask_ptes() call into MMU
proper
KVM: x86/mmu: Co-locate code for setting various SPTE masks
KVM: x86/mmu: Move logic for setting SPTE masks for EPT into the MMU
proper
KVM: x86/mmu: Make Host-writable and MMU-writable bit locations
dynamic
KVM: x86/mmu: Use high bits for host/mmu writable masks for EPT SPTEs
KVM: x86/mmu: Use a dedicated bit to track shadow/MMU-present SPTEs
KVM: x86/mmu: Tweak auditing WARN for A/D bits to !PRESENT (was MMIO)
KVM: x86/mmu: Use is_removed_spte() instead of open coded equivalents
KVM: x86/mmu: Use low available bits for removed SPTEs
KVM: x86/mmu: Dump reserved bits if they're detected on non-MMIO SPTE

 Documentation/virt/kvm/locking.rst |  49 +++++----
 arch/x86/include/asm/kvm_host.h    |   3 -
 arch/x86/kvm/mmu.h                 |  15 +--
 arch/x86/kvm/mmu/mmu.c             |  87 +++++++---------
 arch/x86/kvm/mmu/mmu_internal.h    |  16 +--
 arch/x86/kvm/mmu/paging_tmpl.h     |   2 +-
 arch/x86/kvm/mmu/spte.c            | 157 ++++++++++++++++++++---------
 arch/x86/kvm/mmu/spte.h            | 135 +++++++++++++++++--------
 arch/x86/kvm/mmu/tdp_mmu.c         |  22 ++--
 arch/x86/kvm/svm/svm.c             |   2 +-
 arch/x86/kvm/vmx/vmx.c             |  24 +----
 arch/x86/kvm/x86.c                 |   3 -
 12 files changed, 290 insertions(+), 225 deletions(-)
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog