From: Paolo Bonzini <bonzini@gnu.org>
To: Zhao Liu <zhao1.liu@intel.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
qemu-rust@nongnu.org,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Daniel Berrange" <berrange@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>
Subject: Re: Rust in QEMU update, April 2025
Date: Tue, 20 May 2025 19:48:11 +0200 [thread overview]
Message-ID: <abe683f2-e679-4579-b68a-38a11d41e00b@gnu.org> (raw)
In-Reply-To: <aCysct2L8Bosqy0N@intel.com>
On 5/20/25 18:23, Zhao Liu wrote:
>> HPET does some very simple memory accesses; a good safe solution
>> for this may be the ``vm-memory`` crate. While I have not looked into
>> using it, ``vm-memory`` and ``vm-virtio`` were written with QEMU's
>> use cases in mind.
> I'm working on this and trying to wrap simple memory access by
> vm-memory.
Ok. Note that while the GuestAddressSpace corresponds QEMU's
AddressSpace (so far so good :)), QEMU's MemoryRegion is completely
unrelated to vm-memory's GuestMemoryRegion. That's because vm-memory
only operates on an array of non-overlapping regions, like QEMU's
FlatRange or MemoryRegionSection structs.
The GuestMemory (GuestAddressSpace::M) corresponds to QEMU's FlatView.
Indeed the functions in the trait match with what you expect of a FlatView:
fn num_regions(&self) -> usize;
fn find_region(&self, addr: GuestAddress) -> Option<&Self::R>;
fn iter(&self) -> impl Iterator<Item = &Self::R>;
If the GuestMemory is a FlatView, the GuestAddressSpace::T, implements
Clone + Deref<Target = FlatView>. It's not too hard to see that
GuestAddressSpace's memory() method must call
address_space_get_flatview() and the GuestAddressSpace::T's drop method
must call flatview_unref(). Let's call this (Rust-specific) struct
FlatViewRefGuard, or something like that.
Going back to the GuestMemoryRegion (<FlatView as GuestMemory>::R), it
could be either a QEMU FlatRange or a MemoryRegionSection. Neither are
good options. Without a MemoryRegionSection you can't support IOMMU
regions; but flatview_do_translate() returns the MemoryRegionSection by
value, and GuestMemory's
fn find_region(&self, addr: GuestAddress) -> Option<&Self::R>;
wants a reference instead!
Anyhow, all three types (AddressSpace, FlatView, FlatRange) are better
wrapped with Opaque.
Looking more at FlatRange, these are easy:
// Required methods
fn len(&self) -> GuestUsize;
fn start_addr(&self) -> GuestAddress;
But this one is another problem:
fn bitmap(&self) -> &Self::B;
because it returns the "Bitmap" by reference. QEMU's bitmap is a global
variable indexed by ram_addr_t. It would be better if this was declared
like this:
fn bitmap(&'a self) ->
<Self::B as WithBitmapSlice<'a>>::S
I have no idea if this can be changed in upstream vm-virtio. For now
maybe you can leave it as (). That's buggy but it's ok for a proof of
concept.
So... not sure what to do there. It seems like vm-memory is very close
to being usable by QEMU, but maybe not completely. :(
Paolo
next prev parent reply other threads:[~2025-05-20 17:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 12:13 Rust in QEMU update, April 2025 Paolo Bonzini
2025-05-05 12:26 ` Manos Pitsidianakis
2025-05-05 13:44 ` Paolo Bonzini
2025-05-05 14:03 ` Peter Maydell
2025-05-06 8:40 ` Manos Pitsidianakis
2025-05-14 13:16 ` Paolo Bonzini
2025-05-20 16:23 ` Zhao Liu
2025-05-20 17:48 ` Paolo Bonzini [this message]
2025-05-21 8:42 ` Zhao Liu
2025-05-21 8:36 ` Paolo Bonzini
2025-05-21 9:35 ` Manos Pitsidianakis
2025-05-21 10:51 ` Paolo Bonzini
2025-05-21 21:00 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=abe683f2-e679-4579-b68a-38a11d41e00b@gnu.org \
--to=bonzini@gnu.org \
--cc=alex.bennee@linaro.org \
--cc=berrange@redhat.com \
--cc=kwolf@redhat.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nongnu.org \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.