Skip to content

KVM: Bound KVM_PRE_FAULT_MEMORY by the vCPU's dirty ring

Fuad Tabba kvm kvmarm linux-doc linux-kselftest lkml stable 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 8 repliesIn review
  2. v12 patches 16 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2KVM: Stop KVM_PRE_FAULT_MEMORY when the vCPU's dirty ring is fullDocumentation/virt/kvm/api.rst include/linux/kvm_dirty_ring.h virt/kvm/kvm_main.c+17 -27 replies
2/2KVM: selftests: Test KVM_PRE_FAULT_MEMORY against a full dirty ringtools/testing/selftests/kvm/pre_fault_memory_test.c+101 -01 reply

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchLorenzo Stoakes (ARM)
1/2
2/2A-b

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

Read the v2 thread

Cover letter [PATCH v2 0/2] KVM: Bound KVM_PRE_FAULT_MEMORY by the vCPU's dirty ring

Hi folks,

Changes since v1 [1]:
- Switched the check to kvm_dirty_ring_check_request(). (Sean)
- The test checks that each page is reported exactly once, whatever the order. (Lorenzo)
- Fixed the test on 64K-page arm64 hosts by sizing its range in host pages.
- Various fixes. (Lorenzo)
- Dropped Lorenzo's Reviewed-by on patch 1, since the check changed.

KVM_PRE_FAULT_MEMORY never checks the vCPU's dirty ring, so one call over a large enough range of populated, dirty-logged pages overflows it. The first patch stops the loop at the soft limit, as KVM_RUN does. The second patch adds the case to pre_fault_memory_test.

Pre-faulting isn't the only ioctl that can push past the ring's reserve. On x86, KVM_SET_MSRS does too when it writes the wall clock or the Hyper-V hypercall page. A guest can also push past the reserve within one exit, for example through the arm64 ITS. What those paths should do when the ring fills is an open question for the dirty ring API, which I don't think belongs in this series.

I didn't include the kvm_dirty_ring_check_request() rewrite that Sean sketched on v1, since I think it can lose a request. It tests the request first and clears it afterwards. If the vCPU is scheduled out in between, loongarch sets the PV preempted flag in guest memory and x86 updates a Xen guest's runstate area, either of which pushes an entry. When that push makes the ring soft full, the request it makes is then cleared, and the vCPU runs with the ring soft full until its next push. Clearing first and re-setting, as the code does now, doesn't have that window.

Based on Linux 7.4-rc2 (7475ea8b58616; also applies to kvm-x86/next cbe54fc3462b3 with git am -3).

Cheers,
/fuad

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

Fuad Tabba (2):
KVM: Stop KVM_PRE_FAULT_MEMORY when the vCPU's dirty ring is full
KVM: selftests: Test KVM_PRE_FAULT_MEMORY against a full dirty ring

 Documentation/virt/kvm/api.rst                |   9 +-
 include/linux/kvm_dirty_ring.h                |   5 +
 .../selftests/kvm/pre_fault_memory_test.c     | 101 ++++++++++++++++++
 virt/kvm/kvm_main.c                           |   5 +
 4 files changed, 118 insertions(+), 2 deletions(-)
Signature · 1 line
2.47.3