KVM: Don't let dirty ring resets pass dirty_index
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest4 patches 1 replyIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | KVM: Don't reset dirty ring entries that KVM hasn't pushedvirt/ | +15 | 0 replies | |
| 2/4 | KVM: Use smp_store_release() to mark dirty ring entries as dirtiedvirt/ | +1 | 0 replies | |
| 3/4 | KVM: Annotate concurrent accesses to dirty ring indicesinclude/ virt/ | +3 | 0 replies | |
| 4/4 | KVM: selftests: Verify KVM doesn't reset unused dirty ring entriestools/ | +18 | 1 reply |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/4] KVM: Don't let dirty ring resets pass dirty_index
Fix a userspace-triggerable WARN in kvm_dirty_ring_push() reported by syzbot [1], and tidy up the memory ordering and annotations around the dirty ring indices while in the area.
Patch 1 is the fix. The dirty ring is mapped writable into userspace, so userspace can set KVM_DIRTY_GFN_F_RESET on entries that KVM never pushed. KVM_RESET_DIRTY_RINGS then advances reset_index past dirty_index, the u32 math in kvm_dirty_ring_used() underflows, and the next push hits WARN_ON_ONCE(kvm_dirty_ring_full(ring)). Stop resetting entries once reset_index catches up to dirty_index, and bump dirty_index before publishing the DIRTY flag, so that a VMM that reaps the ring while the vCPU is running never has a legitimately harvested entry skipped.
Patch 2 converts the DIRTY side of the flags handshake with userspace to smp_store_release(), to match the acquire/release semantics already used for the RESET side. No functional change intended.
Patch 3 is optional. It marks the remaining concurrent accesses to the ring indices: WRITE_ONCE() for reset_index, which the vCPU reads with READ_ONCE(), and READ_ONCE() for the reads of the other task's index in the kvm_dirty_ring_push and kvm_dirty_ring_reset tracepoints. I'm not aware of any KCSAN reports or miscompiles, so this mostly documents the concurrency and ensures the compiler can't tear the accesses. Feel free to drop it if that is appropriate.
Patch 4 adds a regression test for patch 1 to dirty_log_test. It fails without patch 1 (KVM resets two entries it never pushed), and passes with the series applied, including with a minimally sized ring so that the vCPU repeatedly exits with KVM_EXIT_DIRTY_RING_FULL while the ring is being reaped.
[1] https://lore.kernel.org/all/[email protected]
James Houghton (4):
KVM: Don't reset dirty ring entries that KVM hasn't pushed
KVM: Use smp_store_release() to mark dirty ring entries as dirtied
KVM: Annotate concurrent accesses to dirty ring indices
KVM: selftests: Verify KVM doesn't reset unused dirty ring entries
include/trace/events/kvm.h | 4 ++-- tools/testing/selftests/kvm/dirty_log_test.c | 18 +++++++++++++++ virt/kvm/dirty_ring.c | 23 +++++++++++++++----- 3 files changed, 37 insertions(+), 8 deletions(-)
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
Signature · 1 line
2.56.1.708.g77570a6a1d-goog