Skip to content

Conversation

@bonzini
Copy link
Member

@bonzini bonzini commented May 21, 2025

Summary of the PR

For use in QEMU, I would like GuestMemoryRegion to return a BitmapSlice instead of a &Bitmap (rust-vmm/vm-memory#324). This adds some flexibility that QEMU needs in order to support a single global dirty bitmap that is sliced by the various GuestMemoryRegions.

However, this removes access to the BitmapReplace trait, because it is of course not possible to replace a slice of the bitmap only. Fortunately, vhost is built around the GM<> type alias, which has a pluggable bitmap type but hardcodes the backend:

type GM<B> = GuestMemoryAtomic<GuestMemoryMmap<B>>;

and therefore region is known to be a GuestRegionMmap. Adding a single dereference of the GuestRegionMmap returns the MmapRegion to which the bitmap is attached, thus calling MmapRegion::bitmap() instead of ::bitmap().

The change works either with or without the changes in vm-memory.

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.

For use in QEMU, I would like GuestMemoryRegion to return a BitmapSlice
instead of a &Bitmap.  This adds some flexibility that QEMU needs in
order to support a single global dirty bitmap that is sliced by the
various GuestMemoryRegions.

However, this removes access to the BitmapReplace trait, because it is of
course not possible to replace a slice of the bitmap only.  Fortunately,
vhost is built around the GM<> type alias, which has a pluggable bitmap
type but hardcodes the backend:

    type GM<B> = GuestMemoryAtomic<GuestMemoryMmap<B>>;

and therefore `region` is known to be a GuestRegionMmap.  Adding a
single dereference of the GuestRegionMmap returns the MmapRegion to
which the bitmap is attached, thus calling MmapRegion::bitmap() instead
of <GuestRegionMmap as GuestRegion>::bitmap().

Signed-off-by: Paolo Bonzini <[email protected]>
@bonzini bonzini force-pushed the mmapregion-bitmap branch from a704d3e to 5caa96b Compare May 21, 2025 11:29
@stefano-garzarella stefano-garzarella merged commit 888165b into rust-vmm:main May 21, 2025
31 checks passed
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.

3 participants