Skip to content

KVM: selftests: Add Nested NPT support

Sean Christopherson kvm kvm-riscv kvmarm linux-arm-kernel linux-riscv lkml loongarch 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v4 Latest21 patches 17 repliesIn review

Changes in v4 from the cover letter

- Document the likely reason for setting A/D bits.
- Put "mmu" structure in common "struct kvm".
- Make it clear PTE accessors are predicates.
- Assert that the stage-2 MMU is initialized at most once.
- Make READABLE a standalone bit (don't overload USER).
- Don't alias PRESENT => READABLE for EPT.
- Fix the A/D bit definitions for EPT.
- Drop the function comment for __tdp_map().
- Add a patch to extend the nested_dirty_log_test to verify that KVM creates writable SPTEs when the gPTEs are writable and dirty.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/21KVM: selftests: Make __vm_get_page_table_entry() statictools/testing/selftests/kvm/include/x86/processor.h tools/testing/selftests/kvm/lib/x86/processor.c+2 -40 replies
2/21KVM: selftests: Stop passing a memslot to nested_map_memslot()tools/testing/selftests/kvm/include/x86/vmx.h tools/testing/selftests/kvm/lib/x86/vmx.c tools/testing/selftests/kvm/x86/vmx_dirty_log_test.c+11 -70 replies
3/21KVM: selftests: Rename nested TDP mapping functionstools/testing/selftests/kvm/include/x86/vmx.h tools/testing/selftests/kvm/lib/x86/memstress.c tools/testing/selftests/kvm/lib/x86/vmx.c +1 more+37 -390 replies
4/21KVM: selftests: Kill eptPageTablePointertools/testing/selftests/kvm/lib/x86/vmx.c+16 -190 replies
5/21KVM: selftests: Stop setting A/D bits when creating EPT PTEstools/testing/selftests/kvm/lib/x86/vmx.c+0 -80 replies
6/21KVM: selftests: Add "struct kvm_mmu" to track a given MMU instancetools/testing/selftests/kvm/include/kvm_util.h tools/testing/selftests/kvm/lib/arm64/processor.c tools/testing/selftests/kvm/lib/kvm_util.c +5 more+94 -881 reply
7/21KVM: selftests: Plumb "struct kvm_mmu" into x86's MMU APIstools/testing/selftests/kvm/include/x86/processor.h tools/testing/selftests/kvm/lib/x86/processor.c+41 -300 replies
8/21KVM: selftests: Add a "struct kvm_mmu_arch arch" member to kvm_mmutools/testing/selftests/kvm/include/arm64/kvm_util_arch.h tools/testing/selftests/kvm/include/kvm_util.h tools/testing/selftests/kvm/include/loongarch/kvm_util_arch.h +3 more+9 -02 replies
9/21KVM: selftests: Move PTE bitmasks to kvm_mmutools/testing/selftests/kvm/include/x86/kvm_util_arch.h tools/testing/selftests/kvm/include/x86/processor.h tools/testing/selftests/kvm/lib/x86/processor.c+76 -390 replies
10/21KVM: selftests: Use a TDP MMU to share EPT page tables between vCPUstools/testing/selftests/kvm/include/x86/kvm_util_arch.h tools/testing/selftests/kvm/include/x86/processor.h tools/testing/selftests/kvm/include/x86/vmx.h +4 more+48 -320 replies
11/21KVM: selftests: Stop passing VMX metadata to TDP mapping functionstools/testing/selftests/kvm/include/x86/vmx.h tools/testing/selftests/kvm/lib/x86/memstress.c tools/testing/selftests/kvm/lib/x86/vmx.c +1 more+24 -402 replies
12/21KVM: selftests: Add a stage-2 MMU instance to kvm_vmtools/testing/selftests/kvm/include/kvm_util.h+5 -01 reply
13/21KVM: selftests: Reuse virt mapping functions for nested EPTstools/testing/selftests/kvm/include/x86/kvm_util_arch.h tools/testing/selftests/kvm/include/x86/processor.h tools/testing/selftests/kvm/lib/x86/processor.c +1 more+52 -1080 replies
14/21KVM: selftests: Move TDP mapping functions outside of vmx.ctools/testing/selftests/kvm/include/x86/processor.h tools/testing/selftests/kvm/include/x86/vmx.h tools/testing/selftests/kvm/lib/x86/processor.c +1 more+57 -740 replies
15/21KVM: selftests: Allow kvm_cpu_has_ept() to be called on AMD CPUstools/testing/selftests/kvm/lib/x86/vmx.c+3 -00 replies
16/21KVM: selftests: Add support for nested NPTstools/testing/selftests/kvm/include/x86/processor.h tools/testing/selftests/kvm/include/x86/svm_util.h tools/testing/selftests/kvm/lib/x86/memstress.c +3 more+51 -41 reply
17/21KVM: selftests: Set the user bit on nested NPT PTEstools/testing/selftests/kvm/include/x86/kvm_util_arch.h tools/testing/selftests/kvm/include/x86/processor.h tools/testing/selftests/kvm/lib/x86/processor.c +1 more+9 -20 replies
18/21KVM: selftests: Extend vmx_dirty_log_test to cover SVMtools/testing/selftests/kvm/Makefile.kvm tools/testing/selftests/kvm/x86/nested_dirty_log_test.c+54 -210 replies
19/21KVM: selftests: Extend memstress to run on nested SVMtools/testing/selftests/kvm/lib/x86/memstress.c+35 -70 replies
20/21KVM: selftests: Rename vm_get_page_table_entry() to vm_get_pte()tools/testing/selftests/kvm/include/x86/processor.h tools/testing/selftests/kvm/lib/x86/processor.c tools/testing/selftests/kvm/x86/hyperv_tlb_flush.c +1 more+4 -61 reply
21/21KVM: selftests: Test READ=>WRITE dirty logging behavior for shadow MMUtools/testing/selftests/kvm/include/x86/processor.h tools/testing/selftests/kvm/lib/x86/processor.c tools/testing/selftests/kvm/x86/nested_dirty_log_test.c+90 -338 replies

Reviews trailers per patch

4 of 21 patches have a Reviewed-by or Acked-by.

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

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

Read the v4 thread

Cover letter [PATCH v4 00/21] KVM: selftests: Add Nested NPT support

Yosry's series to add support for nested NPT, and extends vmx_dirty_log_test and kvm_dirty_log_test (with -n, using memstress) to cover nested SVM.

Note, I'm mildly concerned the last patch to extend nested_dirty_log_test to validate KVM's handling of READ faults could be flaky, e.g. maybe if someone is running the test under heavy memory pressure and the to-be-access page is swapped between the write-from-host and read-from-guest? But unless someone knows/shows it'll be flaky, I'm inclined to apply it and hope for the best.

v4:
- Document the likely reason for setting A/D bits.
- Put "mmu" structure in common "struct kvm".
- Make it clear PTE accessors are predicates.
- Assert that the stage-2 MMU is initialized at most once.
- Make READABLE a standalone bit (don't overload USER).
- Don't alias PRESENT => READABLE for EPT.
- Fix the A/D bit definitions for EPT.
- Drop the function comment for __tdp_map().
- Add a patch to extend the nested_dirty_log_test to verify that KVM creates writable SPTEs when the gPTEs are writable and dirty.

v3:
- https://lore.kernel.org/all/[email protected]
- Dropped the patches that landed in kvm-x86.
- Reshuffled some patches and cleanups.
- Introduced kvm_mmu data structures to hold the root, page table levels, and page table masks (Sean).
- Extended memstress as well to cover nested SVM.

v2: https://lore.kernel.org/kvm/[email protected]

Sean Christopherson (7):
KVM: selftests: Add "struct kvm_mmu" to track a given MMU instance
KVM: selftests: Plumb "struct kvm_mmu" into x86's MMU APIs
KVM: selftests: Add a "struct kvm_mmu_arch arch" member to kvm_mmu
KVM: selftests: Add a stage-2 MMU instance to kvm_vm
KVM: selftests: Move TDP mapping functions outside of vmx.c
KVM: selftests: Rename vm_get_page_table_entry() to vm_get_pte()
KVM: selftests: Test READ=>WRITE dirty logging behavior for shadow MMU

Yosry Ahmed (14):
KVM: selftests: Make __vm_get_page_table_entry() static
KVM: selftests: Stop passing a memslot to nested_map_memslot()
KVM: selftests: Rename nested TDP mapping functions
KVM: selftests: Kill eptPageTablePointer
KVM: selftests: Stop setting A/D bits when creating EPT PTEs
KVM: selftests: Move PTE bitmasks to kvm_mmu
KVM: selftests: Use a TDP MMU to share EPT page tables between vCPUs
KVM: selftests: Stop passing VMX metadata to TDP mapping functions
KVM: selftests: Reuse virt mapping functions for nested EPTs
KVM: selftests: Allow kvm_cpu_has_ept() to be called on AMD CPUs
KVM: selftests: Add support for nested NPTs
KVM: selftests: Set the user bit on nested NPT PTEs
KVM: selftests: Extend vmx_dirty_log_test to cover SVM
KVM: selftests: Extend memstress to run on nested SVM

 tools/testing/selftests/kvm/Makefile.kvm      |   2 +-
 .../kvm/include/arm64/kvm_util_arch.h         |   2 +
 .../testing/selftests/kvm/include/kvm_util.h  |  18 +-
 .../kvm/include/loongarch/kvm_util_arch.h     |   1 +
 .../kvm/include/riscv/kvm_util_arch.h         |   1 +
 .../kvm/include/s390/kvm_util_arch.h          |   1 +
 .../selftests/kvm/include/x86/kvm_util_arch.h |  22 ++
 .../selftests/kvm/include/x86/processor.h     |  58 +++-
 .../selftests/kvm/include/x86/svm_util.h      |   9 +
 tools/testing/selftests/kvm/include/x86/vmx.h |  16 +-
 .../selftests/kvm/lib/arm64/processor.c       |  38 +--
 tools/testing/selftests/kvm/lib/kvm_util.c    |  28 +-
 .../selftests/kvm/lib/loongarch/processor.c   |  28 +-
 .../selftests/kvm/lib/riscv/processor.c       |  31 ++-
 .../selftests/kvm/lib/s390/processor.c        |  16 +-
 .../testing/selftests/kvm/lib/x86/memstress.c |  66 +++--
 .../testing/selftests/kvm/lib/x86/processor.c | 237 ++++++++++++----
 tools/testing/selftests/kvm/lib/x86/svm.c     |  24 ++
 tools/testing/selftests/kvm/lib/x86/vmx.c     | 251 ++++-------------
 .../selftests/kvm/x86/hyperv_tlb_flush.c      |   2 +-
 .../selftests/kvm/x86/nested_dirty_log_test.c | 259 ++++++++++++++++++
 .../x86/smaller_maxphyaddr_emulation_test.c   |   4 +-
 .../selftests/kvm/x86/vmx_dirty_log_test.c    | 179 ------------
 .../kvm/x86/vmx_nested_la57_state_test.c      |   2 +-
 24 files changed, 726 insertions(+), 569 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/x86/nested_dirty_log_test.c
 delete mode 100644 tools/testing/selftests/kvm/x86/vmx_dirty_log_test.c

base-commit: 9448598b22c50c8a5bb77a9103e2d49f134c9578

Signature · 1 line
2.52.0.351.gbe84eed79e-goog