Skip to content

Conversation

davidkleymann
Copy link

Summary of the PR

Add support for dirty page tracking via the Dirty ring interface. Adds KvmDirtyLogRing structure for keeping track of the indices and the base pointer to the shared memory buffer. Implements iterating over dirty pages, thereby harvesting them. Implements reset_dirty_rings on VmFd to trigger recycling of dirty ring buffer elements by the kernel after processing. Adds the dirty_log_ring field to VcpuFd.

This is a draft that needs some review and improvements, I'm hereby asking for suggestions for improving the following remaining weaknesses:

  1. mmap_from_fd will succeed with a size supplied that is smaller than the full size of the shared memory buffer.
  2. Send and Sync are probably not safe on KvmDirtyLogRing because accesses are not stateless, due to the state we need to keep track of in user space (next_dirty)
  3. If any vCPU is running while harvesting dirty pages, the user of KvmDirtyLogRing needs to call reset_dirty_rings before reading contents of dirty pages. This is currently the users responsibility, which allows for calling reset_dirty_rings after all dirty pages have been read by the VMM for cases where all vCPUs are halted, but this may be a confusing interface for other cases.
  4. KvmDirtyLogRing is currently pub, perhaps it can be hidden behind an interface on VcpuFd
  5. No unit tests

More info on the interface:
https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-cap-dirty-log-ring-kvm-cap-dirty-log-ring-acq-rel

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

David Kleymann and others added 10 commits August 26, 2025 14:05
The capability is used for the KVM dirty ring interface for tracking
dirtied pages.

Signed-off-by: David Kleymann <[email protected]>
Adds the KVM_RESET_DIRTY_RINGS ioctl and the function reset_dirty_rings
in impl VmFd to wrap it.

Signed-off-by: David Kleymann <[email protected]>
Adds vCPU functions to mmap the dirty ring and iterate over dirty
pages. Also adds return value to reset_dirty_rings and flush_dirty_gfns.

More info: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-cap-dirty-log-ring-kvm-cap-dirty-log-ring-acq-rel

Signed-off-by: David Kleymann <[email protected]>
… of map_dirty_log_ring

Signed-off-by: David Kleymann <[email protected]>
Comments on the safety on the operations used to mmap the shared memory
buffer of kvm_dirty_gfn entries.

Signed-off-by: David Kleymann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant