set_log_base: use MmapRegion::bitmap() directly

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 <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2025-05-21 12:03:40 +02:00 committed by Stefano Garzarella
parent cd05ac59b7
commit 888165bd8b

View file

@ -30,10 +30,7 @@ use vhost::vhost_user::{
use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use virtio_queue::{Error as VirtQueError, QueueT};
use vm_memory::mmap::NewBitmap;
use vm_memory::{
GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryMmap, GuestMemoryRegion,
GuestRegionMmap,
};
use vm_memory::{GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryMmap, GuestRegionMmap};
use vmm_sys_util::epoll::EventSet;
use super::backend::VhostUserBackend;
@ -788,7 +785,7 @@ where
}
for (region, bitmap) in bitmaps {
region.bitmap().replace(bitmap);
(*region).bitmap().replace(bitmap);
}
Ok(())