[PATCH 0/2] KVM: Fix lost dirty ring entries when a vCPU is preempted
From: Siddharth Mishra
Date: Mon Nov 23 2026 - 10:33:19 EST
A push to a vCPU's dirty ring can be interrupted by another push to the
same ring when the vCPU task is preempted, which leaves one entry
unwritten and makes userspace stop harvesting the ring. Patch 1 fixes
kvm_dirty_ring_push(), patch 2 adds a regression test.
Found while fuzzing. An AI tool helped with the analysis and the patches.
The series is independent of James' series that changes the same
function, and applies with or without it:
https://lore.kernel.org/all/20261117212913.3634487-1-jthoughton@xxxxxxxxxx/
Tested on Intel with PML, in a nested VM on mainline at
commit 4843f6873f7c ("Merge tag 'sysctl-7.04-fixes-rc4' of
git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl") and on the
v7.2.8 host:
- Patch 2 fails within seconds without patch 1 (11 of 12 runs), and
passes with it (0 failures in 15 runs).
- All x86 and common KVM selftests, with PREEMPT, DEBUG_PREEMPT,
DEBUG_ATOMIC_SLEEP, PROVE_LOCKING, PROVE_RCU, DEBUG_PAGEALLOC,
SLUB_DEBUG, DEBUG_OBJECTS_RCU_HEAD, KVM_SMM and KVM_XEN: the same
results with and without the series. hardware_disable_test fails and
xen_shinfo_test triggers a lockdep "Invalid wait context" report in
kvm_xen_set_evtchn_fast() on both.
- The dirty logging tests with kvm_intel.pml=0: the same results with and
without the series.
- Builds with W=1: KVM_INTEL=m KVM_AMD=m KVM_WERROR=y, SMP=n,
allnoconfig, gcc allmodconfig and allyesconfig, clang allmodconfig, and
clang for arm64, riscv and loongarch.
- KVM-unit-tests (a2891d9) for x86 in the same nested VM: the same
results with and without the series. vmx_apicv_test times out and
vmx reports "Guest didn't run to completion" and a too high RDTSC to
VM-exit delta on both.
- sparse (84ec065) with C=2 on arch/x86/kvm/: no reports in
virt/kvm/dirty_ring.c.
Not tested: AMD, the Xen runstate path.
Siddharth Mishra (2):
KVM: Disable preemption while pushing to the dirty ring
KVM: selftests: Test dirty ring pushes from vCPU preemption
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../kvm/x86/dirty_ring_steal_time_test.c | 146 ++++++++++++++++++
virt/kvm/dirty_ring.c | 2 +
3 files changed, 149 insertions(+)
create mode 100644 tools/testing/selftests/kvm/x86/dirty_ring_steal_time_test.c
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.54.0