Skip to content

Conversation

@bonzini
Copy link
Member

@bonzini bonzini commented May 21, 2025

Summary of the PR

QEMU uses a global bitmap, with each RAM region using an offset into it. This could be easily represented if bitmap() returned a BaseSlice<&'static GlobalBitmap>, but there is a problem: bitmap() currently wants to return a reference to the bitmap!

So change it to always return a slice, like VolatileMemory already does. This is more flexible, and in general it isn't going to affect performance because using bitmap() is pretty niche; it's much more common to use VolatileMemory::get_slice() which already builds a BitmapSlice.

Because this is a breaking change, I tried to see how much it breaks. I tried building cloud-hypervisor and all the places that needed bitmap() -> &Self::B actually knew the type of the region. So it only needed a few extra * to go from the GuestRegionMmap to the MmapRegion.

Example changes to clients

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.

bonzini added a commit to bonzini/cloud-hypervisor that referenced this pull request May 21, 2025
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 methods of AtomicBitmap, and in
particular reset() and get_and_reset().  Fortunately, cloud-hypervisor
always uses GuestMemoryMmap, and therefore `region` is known to be a
&GuestRegionMmap.  Dereferencing it returns the MmapRegion to which the
bitmap is attached, thus calling MmapRegion::bitmap(); this has the
same effect as `<GuestRegionMmap as GuestRegion>::bitmap()`, and works
both with or without rust-vmm/vm-memory#324.

Signed-off-by: Paolo Bonzini <[email protected]>
@bonzini bonzini force-pushed the global-dirty-bitmap branch 3 times, most recently from 34f3532 to 0b3bca9 Compare May 21, 2025 11:42
bonzini added a commit to bonzini/cloud-hypervisor that referenced this pull request May 21, 2025
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 methods of AtomicBitmap, and in
particular reset() and get_and_reset().  Fortunately, cloud-hypervisor
always uses GuestMemoryMmap, and therefore `region` is known to be a
&GuestRegionMmap.  Dereferencing it returns the MmapRegion to which the
bitmap is attached, thus calling MmapRegion::bitmap(); this has the
same effect as `<GuestRegionMmap as GuestRegion>::bitmap()`, and works
both with or without rust-vmm/vm-memory#324.

Signed-off-by: Paolo Bonzini <[email protected]>
@bonzini bonzini marked this pull request as ready for review May 21, 2025 11:44
bonzini added 2 commits May 21, 2025 13:47
QEMU uses a global bitmap, with each RAM region using an offset into
it.  This could be easily represented if bitmap() returned a
BaseSlice<&'static GlobalBitmap>, but there is a problem: bitmap()
currently wants to return a reference to the bitmap!

So change it to always return a slice.  This is more flexible, and
it isn't a performance problem because BitmapSlices are meant to be cheap
wrappers around a reference or Arc<>

Signed-off-by: Paolo Bonzini <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
@bonzini bonzini force-pushed the global-dirty-bitmap branch from 0b3bca9 to 817e45b Compare May 21, 2025 11:48
github-merge-queue bot pushed a commit to cloud-hypervisor/cloud-hypervisor that referenced this pull request May 21, 2025
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 methods of AtomicBitmap, and in
particular reset() and get_and_reset().  Fortunately, cloud-hypervisor
always uses GuestMemoryMmap, and therefore `region` is known to be a
&GuestRegionMmap.  Dereferencing it returns the MmapRegion to which the
bitmap is attached, thus calling MmapRegion::bitmap(); this has the
same effect as `<GuestRegionMmap as GuestRegion>::bitmap()`, and works
both with or without rust-vmm/vm-memory#324.

Signed-off-by: Paolo Bonzini <[email protected]>
@bonzini bonzini merged commit 2b7967c into rust-vmm:main May 21, 2025
2 checks passed
@bonzini bonzini added this to the vm-memory 0.17.0 milestone Sep 8, 2025
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