All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhao Liu <zhao1.liu@intel.com>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>,
	Fabiano Rosas <farosas@suse.de>,
	Manos Pitsidianakis <manos.pitsidianakis@linaro.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	qemu-rust@nongnu.org, Zhao Liu <zhao1.liu@intel.com>
Subject: Re: [PATCH for-12.0 5/6] rust: Replace vmstate_validate with post_load
Date: Mon, 23 Nov 2026 11:46:26 +0800	[thread overview]
Message-ID: <awO3EjQI/8QJsyZ9@intel.com> (raw)
In-Reply-To: <awBqoiy3zjHiXXEG@zhexu-thinkpadt14gen5.rmtcaon.csb>

> > And I find C side (in patch 3) handles this differently via using the local
> > "num_timers".
> > 
> > In this case, I think we still have the option to keep the logic
> > consistent between C and Rust :). We can add VMSTATE_STRUCT_VARRAY_TEST
> > for C side:
> > 
> > #define VMSTATE_STRUCT_VARRAY_TEST(_field, _state, _field_num, _test,\
> >                                    _version, _vmsd, _type) {\
> >     .name         = (stringify(_field)),\
> >     .num_indirect = vmstate_field_offset(_state, _field_num),\
> >     .version_id   = (_version),\
> >     .field_exists = (_test),\
> >     .vmsd         = &(_vmsd),\
> >     .size         = sizeof(_type),\
> >     .flags        = VMS_STRUCT | VMS_VARRAY,\
> >     .offset       = vmstate_offset_varray(_state, _field, _type),\
> > }
> > 
> > and make C hpet use this:
> > 
> >         VMSTATE_STRUCT_VARRAY_TEST(timer, HPETState, num_timers_save,
> >                                    hpet_validate_num_timers, 0,
> >                                    vmstate_hpet_timer, HPETTimer),
> 
> One thing to mention is, here the test() function is not for validation,
> but for checking if the field exists.
> 
> It means, assuming dest QEMU has num_timers=8, source QEMU has
> num_timers=4, when migration happens with your VARRAY_TEST(), it won't
> sanity check it, but since it saw 4!=8 it will assume the whole VARRAY
> doesn't exist.
> 
> That's one reason why I want to get rid of VALIDATE(), because it's abusing
> field_exist() IMO, and we don't necessarily need such abuse when we have
> post_load.

I see, this makes sense.

> > 
> > Alternatively, we can also have Rust use num_timers (as u8) for timers
> > array VMState, but this will bring back the conversion issue between u8
> > and usize, which is the commit b3bf86b8936d & 6e85cfe44c0e want to fix...
> 
> Ohhh, I decided to not dig into this part. May I make a request instead? :)

Happy to help :-)

> Could you help me to come up with a Rust patch that does what's needed for
> this series to drop VALIDATE and VMS_MUST_EXIST and replace this one (drop
> my Author), meanwhile matches the best you'd like to?  It'll be much easier
> to me then because my Rust is rust (this is not strict; it never shined),
> so I can just pick it up when repost.

I find it's possible to use num_timers directly without going back to
u8 type. Since the commit 1f0b40dccfe5 ("migration: Remove redundant
flags"), C side has already dropped VMS_VARRAY_UINT8/16/32, so Rust
side can use usize as the array length type (without migrating it), like:

unsafe impl VMState for usize {
    const BASE: VMStateField = {
    	panic!("usize cannot be migrated, use a fixed-size integer type");
    };
    const VARRAY_FLAG: VMStateFlags = VMStateFlags::VMS_VARRAY;
}

I'll think more/cook a patch based on this approach.

Thanks,
Zhao



  reply	other threads:[~2026-11-23  3:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 12:49 [PATCH for-12.0 0/6] migration: Remove VMSTATE_VALIDATE() and VMS_MUST_EXIST Peter Xu
2026-11-20 12:49 ` [PATCH for-12.0 1/6] pcie/aer: Remove the usage of VMSTATE_VALIDATE() Peter Xu
2026-11-20 12:49 ` [PATCH for-12.0 2/6] hw/gpio/zaurus: Move VMSTATE_VALIDATE() check into post_load_errp() Peter Xu
2026-11-23 12:21   ` Peter Maydell
2026-11-25 20:28     ` Peter Xu
2026-11-20 12:49 ` [PATCH for-12.0 3/6] hpet: Move VMSTATE_VALIDATE() check into post_load Peter Xu
2026-11-23 15:46   ` Peter Maydell
2026-11-25 20:46     ` Peter Xu
2026-11-20 12:49 ` [PATCH for-12.0 4/6] arm/machine: Move all VMSTATE_VALIDATE() usages " Peter Xu
2026-11-23 12:20   ` Peter Maydell
2026-11-25 21:35     ` Peter Xu
2026-11-20 12:49 ` [PATCH for-12.0 5/6] rust: Replace vmstate_validate with post_load Peter Xu
2026-11-20 14:25   ` Zhao Liu
2026-11-20 15:43     ` Peter Xu
2026-11-23  3:46       ` Zhao Liu [this message]
2026-11-23 12:03         ` Peter Xu
2026-11-20 12:49 ` [PATCH for-12.0 6/6] migration: Drop VMSTATE_VALIDATE() and VMS_MUST_EXIST Peter Xu

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=awO3EjQI/8QJsyZ9@intel.com \
    --to=zhao1.liu@intel.com \
    --cc=farosas@suse.de \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    /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.