qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Cc: qemu-rust@nondevel.org, qemu-devel <qemu-devel@nongnu.org>,
	Zhao Liu <zhao1.liu@intel.com>
Subject: Re: Rust high-level pre/post migration callbacks
Date: Mon, 8 Sep 2025 12:19:33 +0200	[thread overview]
Message-ID: <ee80babd-6e48-483b-93d8-849539c0f378@redhat.com> (raw)
In-Reply-To: <CAAjaMXaPM0qrCwrMY_n531R4d5X3h+GjRHKzjHLeY3FprT5_TA@mail.gmail.com>

On 9/8/25 12:02, Manos Pitsidianakis wrote:
> Hi Paolo,
> 
> I'm not familiar with how migration works under the hood, but this
> data transformation design looks very clean and neat to me.

Thanks!

>> Using it is very easy, you can just declare your state like:
>>
>>       regs: Migratable<Mutex<MyDeviceRegisters>>
> 
> Hm it's a shame we cannot do this with a trait since it requires state
> storage for migration_state.

Yeah, but a Box is just a single pointer.  We need to have an actual 
location in memory for the C code to retrieve the pointer.

> A suggestion: we could declare a "mirror" struct to hold
> `migration_state` with a Derive macro. This is what the `rkyv` crate
> does with its `Archive` derive macro and trait
> <https://docs.rs/rkyv/latest/rkyv/trait.Archive.html>

Nice!  I'm not familiar with rkyv but it does look very similar.

When I tried to clean up the HPET (create HPETRegisters, and replace use 
of raw pointers with self_cell to implement self-referential structs), 
migration was the big mess, so I hope that this design will fix both 
that and Mutex<>.  And indeed having a derive macro is very similar to 
what I came up with one day later :) while thinking about how HPET could 
use it in practice.

Probably the derive macro would require some changes to the trait, but 
the basic idea remains the same.

Paolo



  reply	other threads:[~2025-09-08 10:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-06  6:45 Rust high-level pre/post migration callbacks Paolo Bonzini
2025-09-07 14:35 ` Paolo Bonzini
2025-09-08 10:02 ` Manos Pitsidianakis
2025-09-08 10:19   ` Paolo Bonzini [this message]
2025-09-08 10:25     ` Manos Pitsidianakis
2025-09-10  8:19 ` Zhao Liu
2025-09-10 11:33   ` Paolo Bonzini
2025-09-10 16:24     ` Zhao Liu

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=ee80babd-6e48-483b-93d8-849539c0f378@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nondevel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).