Skip to content

Introduce a quirk to control memslot zap behavior

Yan Zhao kvm lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 8 repliesIn review
  2. v15 patches 7 repliesSuperseded

Changes in v2 from the cover letter

- Make KVM behave as if the quirk is always disabled on non-KVM_X86_DEFAULT_VM VMs. (Sean, Rick)
- Removed the patch for selftest private_mem_kvm_exits_test, since that selftest is for VM type KVM_X86_SW_PROTECTED_VM.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4KVM: x86/mmu: Introduce a quirk to control memslot zap behaviorDocumentation/virt/kvm/api.rst arch/x86/include/asm/kvm_host.h arch/x86/include/uapi/asm/kvm.h +1 more+52 -25 replies
2/4KVM: selftests: Test slot move/delete with slot zap quirk enabled/disabledtools/testing/selftests/kvm/set_memory_region_test.c+21 -80 replies
3/4KVM: selftests: Allow slot modification stress test with quirk disabledtools/testing/selftests/kvm/memslot_modification_stress_test.c+17 -23 replies
4/4KVM: selftests: Test memslot move in memslot_perf_test with quirk disabledtools/testing/selftests/kvm/memslot_perf_test.c+11 -10 replies

Reviews trailers per patch

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

Read the v2 thread

Cover letter [PATCH v2 0/4] Introduce a quirk to control memslot zap behavior

Today "zapping only leaf SPTEs with memslot range" ("zap-slot-leafs-only" for short) on moving/deleting a memslot is not done. Instead, KVM opts to invalidate all page tables and generate fresh new ones based on the new memslot layout ("zap-all" for short). This "zap-all" behavior is of low overhead for most use cases, and is adopted primarily due to a bug which caused VM instability when a VM is with Nvidia Geforce GPU assigned (see link in patch 1).

However, the "zap-all" behavior is not desired for certain specific scenarios. e.g.
- It's not viable for TDX,
a) TDX requires root page of private page table remains unaltered throughout the TD life cycle.
b) TDX mandates that leaf entries in private page table must be zapped prior to non-leaf entries.
c) TDX requires re-accepting of private pages after page dropping.
- It's not performant for scenarios involving frequent deletion and re-adding of numerous small memslots.

This series therefore introduces the KVM_X86_QUIRK_SLOT_ZAP_ALL quirk, enabling users to control the behavior of memslot zapping when a memslot is moved/deleted for VMs of type KVM_X86_DEFAULT_VM.

The quirk is turned on by default for VMs of type KVM_X86_DEFAULT_VM, leading to "zap-all" behavior.

Users have the option to turn off the quirk. Doing so will have KVM go "zap-slot-leafs-only" on memslot moving/deleting.

KVM will always select "zap-slot-leafs-only" as if the quirk is disabled for non-KVM_X86_DEFAULT_VM VMs for reasons explained in patch 1.

This series has been tested with
- Normal VMs
w/ and w/o device assignment, and kvm selftests

- TDX guests.
Tested with shared device assignment and guest memory hot-plug/unplug.

It can be applied to both kvm/queue and kvm-coco-queue.

Patch 1:   KVM changes.
Patch 2-4: Selftests updates. Verify memslot move/deletion functionality

with the quirk enabled/disabled.

Changelog:
v1 --> v2:
- Make KVM behave as if the quirk is always disabled on non-KVM_X86_DEFAULT_VM VMs. (Sean, Rick)
- Removed the patch for selftest private_mem_kvm_exits_test, since that selftest is for VM type KVM_X86_SW_PROTECTED_VM.

v1: https://lore.kernel.org/all/[email protected]

Yan Zhao (4):
KVM: x86/mmu: Introduce a quirk to control memslot zap behavior
KVM: selftests: Test slot move/delete with slot zap quirk
enabled/disabled
KVM: selftests: Allow slot modification stress test with quirk
disabled
KVM: selftests: Test memslot move in memslot_perf_test with quirk
disabled

 Documentation/virt/kvm/api.rst                |  8 ++++
 arch/x86/include/asm/kvm_host.h               |  3 +-
 arch/x86/include/uapi/asm/kvm.h               |  1 +
 arch/x86/kvm/mmu/mmu.c                        | 42 ++++++++++++++++++-
 .../kvm/memslot_modification_stress_test.c    | 19 ++++++++-
 .../testing/selftests/kvm/memslot_perf_test.c | 12 +++++-
 .../selftests/kvm/set_memory_region_test.c    | 29 +++++++++----
 7 files changed, 101 insertions(+), 13 deletions(-)
Signature · 1 line
2.43.2