mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: Bound KVM_PRE_FAULT_MEMORY by the vCPU's dirty ring
@ 2026-11-10 11:07 Fuad Tabba
  2026-11-10 11:07 ` [PATCH 1/2] KVM: Stop KVM_PRE_FAULT_MEMORY when the vCPU's dirty ring is full Fuad Tabba
  2026-11-10 11:07 ` [PATCH 2/2] KVM: selftests: Test KVM_PRE_FAULT_MEMORY against a full dirty ring Fuad Tabba
  0 siblings, 2 replies; 10+ messages in thread
From: Fuad Tabba @ 2026-11-10 11:07 UTC (permalink / raw)
  To: Paolo Bonzini, Sean Christopherson
  Cc: kvm, linux-kselftest, linux-doc, linux-kernel, Jonathan Corbet,
	Shuah Khan, Isaku Yamahata, Rick Edgecombe, Lorenzo Stoakes,
	Marc Zyngier, Oliver Upton, kvmarm, Wei-Lin Chang, Will Deacon,
	Fuad Tabba

Hi folks,

KVM_PRE_FAULT_MEMORY never checks the vCPU's dirty ring, so one call
over enough populated, dirty-logged pages overflows it. The first patch
stops the loop at the soft limit, as KVM_RUN does. A stopped call
returns its partial progress, or, if it stopped before any, -ENOSPC
rather than the retryable -EAGAIN, since no retry can succeed until the
ring is harvested. The second patch adds the case to
pre_fault_memory_test.

On x86 a read fault normally maps a host-writable page writable and logs
it at once, so pre-faulting overflows the ring. Sean's auto-prefetch
series [1] keeps that behaviour for a pre-fault, so this series bounds
the loop rather than have x86 write-protect a pre-faulted page. On
arm64, which gained the ioctl in 7.4, pre-faulting RAM logged with the
ring alone overflows it too, until Wei-Lin's fix [2] is in mainline.

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: up to a few hundred entries in a single
call, with no bound across calls. KVM_SET_MSRS can't take the same
stop, since a short count from it means the MSR failed and QEMU asserts
on it.

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.
Pre-faulting a large logged range is a supported use of the ioctl, so
the loop should handle a full ring rather than lose entries.

Tested on x86 and arm64 under QEMU: without the first patch, the new
case hits the WARN on both.

Based on Linux 7.4-rc2 (7475ea8b58616).

Cheers,
/fuad

[1] https://lore.kernel.org/all/20261028202607.1844883-1-seanjc@google.com/
[2] https://lore.kernel.org/all/20261029175238.3214788-2-weilin.chang@arm.com/

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                |  6 ++
 .../selftests/kvm/pre_fault_memory_test.c     | 85 +++++++++++++++++++
 virt/kvm/dirty_ring.c                         |  2 +-
 virt/kvm/kvm_main.c                           |  6 ++
 5 files changed, 105 insertions(+), 3 deletions(-)


base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
-- 
2.47.3


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-10 16:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 11:07 [PATCH 0/2] KVM: Bound KVM_PRE_FAULT_MEMORY by the vCPU's dirty ring Fuad Tabba
2026-11-10 11:07 ` [PATCH 1/2] KVM: Stop KVM_PRE_FAULT_MEMORY when the vCPU's dirty ring is full Fuad Tabba
2026-11-10 14:22   ` Lorenzo Stoakes (ARM)
2026-11-10 15:48   ` Sean Christopherson
2026-11-10 11:07 ` [PATCH 2/2] KVM: selftests: Test KVM_PRE_FAULT_MEMORY against a full dirty ring Fuad Tabba
2026-11-10 14:38   ` Lorenzo Stoakes (ARM)
2026-11-10 15:37     ` Fuad Tabba
2026-11-10 15:53       ` Sean Christopherson
2026-11-10 16:02         ` Lorenzo Stoakes (ARM)
2026-11-10 15:57       ` Lorenzo Stoakes (ARM)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®