On Thu, Feb 27, 2025 at 03:22:11PM +0100, Paolo Bonzini wrote: > Date: Thu, 27 Feb 2025 15:22:11 +0100 > From: Paolo Bonzini <pbonz...@redhat.com> > Subject: [PATCH 04/12] rust: timer: wrap QEMUTimer with Opaque<> and > express pinning requirements > X-Mailer: git-send-email 2.48.1 > > Timers must be pinned in memory, because modify() stores a pointer to them > in the TimerList. To ensure this is the case, replace the separate new() > and init_full() with a single function that returns a pinned box. Because > the only way to obtain a Timer is through Timer::new_full(), modify() > knows that the timer it got is also pinned. In the future the pinning > requirement will be expressed through the pin_init crate instead. > > Note that Timer is a bit different from other users of Opaque, in that > it is created in Rust code rather than C code. This is why it has to > use the unsafe Opaque::new() function. > > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> > --- > meson.build | 7 ----- > rust/hw/timer/hpet/src/hpet.rs | 23 ++++++++--------- > rust/qemu-api/src/timer.rs | 47 ++++++++++++++++++++++------------ > 3 files changed, 41 insertions(+), 36 deletions(-)
Great! LGTM, Reviewed-by: Zhao Liu <zhao1....@intel.com> (But pls wait, I have a question below...) > @@ -156,7 +157,7 @@ pub struct HPETTimer { > /// timer N index within the timer block (`HPETState`) > #[doc(alias = "tn")] > index: usize, > - qemu_timer: Option<Box<Timer>>, > + qemu_timer: Option<Pin<Box<Timer>>>, I'm removing this Option<> wrapper in migration series. This is because Option<> can't be treated as pointer as you mentioned in [*]. So for this reason, does this mean that VMStateField cannot accept Option<>? I realize that all the current VMStateFlags don't seem compatible with Option<> unless a new flag is introduced. [*]: https://lore.kernel.org/qemu-devel/9a0389fa-765c-443b-ac2f-7c99ed862...@redhat.com/ Thanks, Zhao