All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] rust/migration: Remove vmstate_validate!() and VMS_MUST_EXIST
@ 2026-11-24  9:58 Zhao Liu
  2026-11-24  9:58 ` [PATCH 1/3] rust/migration: Allow usize as the length of a varray Zhao Liu
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Zhao Liu @ 2026-11-24  9:58 UTC (permalink / raw)
  To: Peter Xu, Peter Maydell, Fabiano Rosas, Paolo Bonzini,
	Manos Pitsidianakis
  Cc: qemu-devel, qemu-rust, Zhao Liu

Hi,

This simple series is based on Peter Xu's series [*] and mainly refines
patch 5 — removing `vmstate_validate!()` from Rust HPET (while
maintaining consistency logic with C HPET as much as possible).

I originally planned to use a single patch, but breaking it up this way
makes it easier to review. I suppose these three small patches could
also replace Peter's patch 5 :-).

There is also some cleanup work left (e.g., support post_load_errp() in
Rust); I will address this in some separate patch later (without
blocking the current effort to remove `vmstate_validate!()`).

[*]: https://lore.kernel.org/qemu-devel/20261120124923.1656220-6-peterx@redhat.com/

Thanks and Best Regards,
Zhao
---
Zhao Liu (3):
  rust/migration: Allow usize as the length of a varray
  rust/hpet: Move vmstate_validate!() check into post_load
  rust/migration: Remove vmstate_validate!() macro and test

 rust/hw/timer/hpet/src/device.rs  | 45 +++++++++----------
 rust/migration/src/prelude.rs     |  1 -
 rust/migration/src/vmstate.rs     | 33 ++++++--------
 rust/tests/tests/vmstate_tests.rs | 72 ++++++++++---------------------
 4 files changed, 59 insertions(+), 92 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] rust/migration: Allow usize as the length of a varray
  2026-11-24  9:58 [PATCH 0/3] rust/migration: Remove vmstate_validate!() and VMS_MUST_EXIST Zhao Liu
@ 2026-11-24  9:58 ` Zhao Liu
  2026-11-24  9:58 ` [PATCH 2/3] rust/hpet: Move vmstate_validate!() check into post_load Zhao Liu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Zhao Liu @ 2026-11-24  9:58 UTC (permalink / raw)
  To: Peter Xu, Peter Maydell, Fabiano Rosas, Paolo Bonzini,
	Manos Pitsidianakis
  Cc: qemu-devel, qemu-rust, Zhao Liu

Since commit f9f70b50e3eb ("migration: Introduce VMStateStructMember")
and commit 1f0b40dccfe5 ("Rmigration: Remove redundant flags"), the
length of a varray is no longer tied to a specific integer type.

This makes it possible to use `usize` type for varray length. It's safe
since it is used only to resolve varray lengths in the local vmstate
code and is not used for migration.

Thus, implement a "dummy" VMState for `usize` so that it can provide
VARRAY_FLAG, and panic when anyone tries to define VMStateField with
`usize` type (including integers, pointers, [usize; N], Box<usize>,
BqlCell<usize>, etc).

In addition, add a test case for such case.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 rust/migration/src/vmstate.rs     | 16 ++++++++--
 rust/tests/tests/vmstate_tests.rs | 49 +++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs
index 5ed061f2abb6..0b05db4e7049 100644
--- a/rust/migration/src/vmstate.rs
+++ b/rust/migration/src/vmstate.rs
@@ -97,8 +97,8 @@ pub unsafe trait VMState {
 
     /// A flag that is added to another field's `VMStateField` to specify the
     /// length's type in a variable-sized array.  If this is not a supported
-    /// type for the length (i.e. if it is not `u8`, `u16`, `u32`), using it
-    /// in a call to [`vmstate_of!`](crate::vmstate_of) will cause a
+    /// type for the length (i.e. if it is not `u8`, `u16`, `u32`, `usize`),
+    /// using it in a call to [`vmstate_of!`](crate::vmstate_of) will cause a
     /// compile-time error.
     #[doc(hidden)] // https://github.com/rust-lang/rust/issues/149635
     const VARRAY_FLAG: VMStateFlags = {
@@ -256,6 +256,18 @@ unsafe impl $crate::vmstate::VMState for $type {
 impl_vmstate_scalar!(vmstate_info_uint64, u64);
 impl_vmstate_scalar!(vmstate_info_timer, util::timer::Timer);
 
+// SAFETY: BASE is never produced (any use of a usize as migrated data will
+// always result in a compile-time error). VARRAY_FLAG only tells the C code to
+// read `size_of::<usize>()` bytes (see `size_of_field_type!`) at the length's
+// offset.
+unsafe impl VMState for usize {
+    #[doc(hidden)] // https://github.com/rust-lang/rust/issues/149635
+    const BASE: VMStateField = {
+        panic!("usize cannot be migrated, use a fixed-size integer type");
+    };
+    const VARRAY_FLAG: VMStateFlags = VMStateFlags::VMS_VARRAY;
+}
+
 #[macro_export]
 macro_rules! impl_vmstate_c_struct {
     ($type:ty, $vmsd:expr) => {
diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_tests.rs
index 6578d54b37d4..b680cfd3c783 100644
--- a/rust/tests/tests/vmstate_tests.rs
+++ b/rust/tests/tests/vmstate_tests.rs
@@ -483,3 +483,52 @@ fn test_vmstate_validate() {
     // The last VMStateField in VMSTATE_FOOD.
     assert_eq!(foo_fields[3].flags, VMStateFlags::VMS_END);
 }
+
+// =========================== Test VMSTATE_FOOE ===========================
+// Test the use cases of the vmstate macro, corresponding to the following C
+// macro variants:
+//   * VMSTATE_FOOE:
+//     - VMSTATE_VARRAY with a `usize` length
+#[repr(C)]
+#[derive(Default)]
+struct FooE {
+    arr: [u8; FOO_ARRAY_MAX],
+    num: usize,
+}
+
+static VMSTATE_FOOE: VMStateDescription<FooE> = VMStateDescriptionBuilder::<FooE>::new()
+    .name(c"foo_e")
+    .version_id(1)
+    .minimum_version_id(1)
+    .fields(vmstate_fields! {
+        vmstate_of!(FooE, arr[0 .. num]),
+    })
+    .build();
+
+#[test]
+fn test_vmstate_varray_usize() {
+    let foo_fields: &[VMStateField] =
+        unsafe { slice::from_raw_parts(VMSTATE_FOOE.as_ref().fields, 2) };
+
+    // 1st VMStateField ("arr") in VMSTATE_FOOE
+    assert_eq!(
+        unsafe { CStr::from_ptr(foo_fields[0].name) }.to_bytes_with_nul(),
+        b"arr\0"
+    );
+    assert_eq!(foo_fields[0].offset, 0);
+    assert_eq!(
+        foo_fields[0].num_indirect.offset,
+        std::mem::offset_of!(FooE, num) as u32
+    );
+    assert_eq!(foo_fields[0].num_indirect.size, size_of::<usize>() as u8);
+    assert_eq!(foo_fields[0].info, unsafe { &vmstate_info_uint8 });
+    assert_eq!(foo_fields[0].version_id, 0);
+    assert_eq!(foo_fields[0].size, 1);
+    assert_eq!(foo_fields[0].num, 0);
+    assert_eq!(foo_fields[0].flags, VMStateFlags::VMS_VARRAY);
+    assert!(foo_fields[0].vmsd.is_null());
+    assert!(foo_fields[0].field_exists.is_none());
+
+    // The last VMStateField in VMSTATE_FOOE.
+    assert_eq!(foo_fields[1].flags, VMStateFlags::VMS_END);
+}
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] rust/hpet: Move vmstate_validate!() check into post_load
  2026-11-24  9:58 [PATCH 0/3] rust/migration: Remove vmstate_validate!() and VMS_MUST_EXIST Zhao Liu
  2026-11-24  9:58 ` [PATCH 1/3] rust/migration: Allow usize as the length of a varray Zhao Liu
@ 2026-11-24  9:58 ` Zhao Liu
  2026-11-24 10:10   ` Philippe Mathieu-Daudé
  2026-11-24  9:58 ` [PATCH 3/3] rust/migration: Remove vmstate_validate!() macro and test Zhao Liu
  2026-11-25 20:19 ` [PATCH 0/3] rust/migration: Remove vmstate_validate!() and VMS_MUST_EXIST Peter Xu
  3 siblings, 1 reply; 7+ messages in thread
From: Zhao Liu @ 2026-11-24  9:58 UTC (permalink / raw)
  To: Peter Xu, Peter Maydell, Fabiano Rosas, Paolo Bonzini,
	Manos Pitsidianakis
  Cc: qemu-devel, qemu-rust, Zhao Liu

To pave way for removing VMSTATE_VALIDATE() (and vmstate_validate!()),
move the usage of hpet into post_load. To make it safer, loading the
timers with the num_timers, then only check against the wire number at
last.

In addition, drop the test_fn() in the VMStateField of HPETState.timers
- this was duplicated, but now the check in post_load is enough
(and test_fn should not be used for validation).

Originally-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
Copy Peter's commit message from his C HPET patch because now this patch
has the (almost) same logic.
---
 rust/hw/timer/hpet/src/device.rs | 45 ++++++++++++++++----------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/device.rs
index 89ba7a5c4d21..c7a2b7f6c2ec 100644
--- a/rust/hw/timer/hpet/src/device.rs
+++ b/rust/hw/timer/hpet/src/device.rs
@@ -934,10 +934,15 @@ fn pre_save(&self) -> Result<(), migration::Infallible> {
         Ok(())
     }
 
-    fn post_load(&self, _version_id: u8) -> Result<(), migration::Infallible> {
+    fn post_load(&self, _version_id: u8) -> Result<(), migration::InvalidError> {
         let mut regs = self.regs.borrow_mut();
         let cnt = regs.counter;
 
+        /* FIXME: use post_load_errp() to print error message. */
+        if !self.validate_num_timers() {
+            return Err(migration::InvalidError);
+        }
+
         for tn_regs in regs.tn_regs.iter_mut().take(self.num_timers) {
             tn_regs.update_cmp64(cnt);
             tn_regs.last = CLOCK_VIRTUAL.get_ns() - NANOSECONDS_PER_SECOND;
@@ -956,7 +961,7 @@ fn is_offset_needed(&self) -> bool {
         self.regs.borrow().is_hpet_enabled()
     }
 
-    fn validate_num_timers(&self, _version_id: u8) -> bool {
+    fn validate_num_timers(&self) -> bool {
         self.num_timers == self.num_timers_save.get().into()
     }
 }
@@ -1082,8 +1087,6 @@ fn restore_migrated_state(
 
 impl_vmstate_struct!(HPETTimerMigration, VMSTATE_HPET_TIMER);
 
-const VALIDATE_TIMERS_NAME: &CStr = c"num_timers must match";
-
 // HPETRegistersMigration is generated by ToMigrationState macro.
 impl_vmstate_struct!(
     HPETRegistersMigration,
@@ -1099,24 +1102,22 @@ fn restore_migrated_state(
         .build()
 );
 
-const VMSTATE_HPET: VMStateDescription<HPETState> =
-    VMStateDescriptionBuilder::<HPETState>::new()
-        .name(c"hpet")
-        .version_id(2)
-        .minimum_version_id(2)
-        .pre_save(&HPETState::pre_save)
-        .post_load(&HPETState::post_load)
-        .fields(vmstate_fields! {
-            vmstate_of!(HPETState, regs),
-            vmstate_of!(HPETState, num_timers_save),
-            vmstate_validate!(HPETState, VALIDATE_TIMERS_NAME, HPETState::validate_num_timers),
-            vmstate_of!(HPETState, timers[0 .. num_timers_save], HPETState::validate_num_timers).with_version_id(0),
-        })
-        .subsections(vmstate_subsections!(
-            VMSTATE_HPET_RTC_IRQ_LEVEL,
-            VMSTATE_HPET_OFFSET,
-        ))
-        .build();
+const VMSTATE_HPET: VMStateDescription<HPETState> = VMStateDescriptionBuilder::<HPETState>::new()
+    .name(c"hpet")
+    .version_id(2)
+    .minimum_version_id(2)
+    .pre_save(&HPETState::pre_save)
+    .post_load(&HPETState::post_load)
+    .fields(vmstate_fields! {
+        vmstate_of!(HPETState, regs),
+        vmstate_of!(HPETState, num_timers_save),
+        vmstate_of!(HPETState, timers[0 .. num_timers]).with_version_id(0),
+    })
+    .subsections(vmstate_subsections!(
+        VMSTATE_HPET_RTC_IRQ_LEVEL,
+        VMSTATE_HPET_OFFSET,
+    ))
+    .build();
 
 impl DeviceImpl for HPETState {
     const VMSTATE: Option<VMStateDescription<Self>> = Some(VMSTATE_HPET);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] rust/migration: Remove vmstate_validate!() macro and test
  2026-11-24  9:58 [PATCH 0/3] rust/migration: Remove vmstate_validate!() and VMS_MUST_EXIST Zhao Liu
  2026-11-24  9:58 ` [PATCH 1/3] rust/migration: Allow usize as the length of a varray Zhao Liu
  2026-11-24  9:58 ` [PATCH 2/3] rust/hpet: Move vmstate_validate!() check into post_load Zhao Liu
@ 2026-11-24  9:58 ` Zhao Liu
  2026-11-25 20:19 ` [PATCH 0/3] rust/migration: Remove vmstate_validate!() and VMS_MUST_EXIST Peter Xu
  3 siblings, 0 replies; 7+ messages in thread
From: Zhao Liu @ 2026-11-24  9:58 UTC (permalink / raw)
  To: Peter Xu, Peter Maydell, Fabiano Rosas, Paolo Bonzini,
	Manos Pitsidianakis
  Cc: qemu-devel, qemu-rust, Zhao Liu

We have moved all users (in Rust side) to other API, now they're never
used.

After the related test (originally FOOD) was removed, rename FOOE to
new FOOD test.

Suggested-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 rust/migration/src/prelude.rs     |  1 -
 rust/migration/src/vmstate.rs     | 17 ------
 rust/tests/tests/vmstate_tests.rs | 93 +++----------------------------
 3 files changed, 8 insertions(+), 103 deletions(-)

diff --git a/rust/migration/src/prelude.rs b/rust/migration/src/prelude.rs
index 797e7ec59d1b..e2cbbda43e0a 100644
--- a/rust/migration/src/prelude.rs
+++ b/rust/migration/src/prelude.rs
@@ -16,4 +16,3 @@
 pub use crate::vmstate_of;
 pub use crate::vmstate_subsections;
 pub use crate::vmstate_unused;
-pub use crate::vmstate_validate;
diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs
index 0b05db4e7049..ec8b712cbf86 100644
--- a/rust/migration/src/vmstate.rs
+++ b/rust/migration/src/vmstate.rs
@@ -384,23 +384,6 @@ macro_rules! vmstate_fields {
     }}
 }
 
-#[doc(alias = "VMSTATE_VALIDATE")]
-#[macro_export]
-macro_rules! vmstate_validate {
-    ($struct_name:ty, $test_name:expr, $test_fn:expr $(,)?) => {
-        $crate::bindings::VMStateField {
-            name: ::std::ffi::CStr::as_ptr($test_name),
-            field_exists: $crate::vmstate_exist_fn!($struct_name, $test_fn),
-            flags: $crate::bindings::VMStateFlags(
-                $crate::bindings::VMStateFlags::VMS_MUST_EXIST.0
-                    | $crate::bindings::VMStateFlags::VMS_NO_STATE.0,
-            ),
-            num: 0, // 0 elements: no data, only run test_fn callback
-            ..::common::zeroable::Zeroable::ZERO
-        }
-    };
-}
-
 /// Helper macro to allow using a struct in [`vmstate_of!`]
 ///
 /// # Safety
diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_tests.rs
index b680cfd3c783..9dbbb848b85c 100644
--- a/rust/tests/tests/vmstate_tests.rs
+++ b/rust/tests/tests/vmstate_tests.rs
@@ -411,106 +411,29 @@ fn test_vmstate_macro_array_of_pointer_wrapped() {
 // Test the use cases of the vmstate macro, corresponding to the following C
 // macro variants:
 //   * VMSTATE_FOOD:
-//     - VMSTATE_VALIDATE
-
-// Add more member fields when vmstate_of support "test" parameter.
-struct FooD;
-
-impl FooD {
-    fn validate_food_0(&self, _version_id: u8) -> bool {
-        true
-    }
-
-    fn validate_food_1(_state: &FooD, _version_id: u8) -> bool {
-        false
-    }
-}
-
-fn validate_food_2(_state: &FooD, _version_id: u8) -> bool {
-    true
-}
-
-static VMSTATE_FOOD: VMStateDescription<FooD> = VMStateDescriptionBuilder::<FooD>::new()
-    .name(c"foo_d")
-    .version_id(3)
-    .minimum_version_id(1)
-    .fields(vmstate_fields! {
-        vmstate_validate!(FooD, c"foo_d_0", FooD::validate_food_0),
-        vmstate_validate!(FooD, c"foo_d_1", FooD::validate_food_1),
-        vmstate_validate!(FooD, c"foo_d_2", validate_food_2),
-    })
-    .build();
-
-#[test]
-fn test_vmstate_validate() {
-    let foo_fields: &[VMStateField] =
-        unsafe { slice::from_raw_parts(VMSTATE_FOOD.as_ref().fields, 4) };
-    let mut foo_d = FooD;
-    let foo_d_p = std::ptr::addr_of_mut!(foo_d).cast::<c_void>();
-
-    // 1st VMStateField in VMSTATE_FOOD
-    assert_eq!(
-        unsafe { CStr::from_ptr(foo_fields[0].name) }.to_bytes_with_nul(),
-        b"foo_d_0\0"
-    );
-    assert_eq!(foo_fields[0].offset, 0);
-    assert_eq!(foo_fields[0].num_indirect.size, 0);
-    assert!(foo_fields[0].info.is_null());
-    assert_eq!(foo_fields[0].version_id, 0);
-    assert_eq!(foo_fields[0].size, 0);
-    assert_eq!(foo_fields[0].num, 0);
-    assert_eq!(
-        foo_fields[0].flags.0,
-        VMStateFlags::VMS_NO_STATE.0 | VMStateFlags::VMS_MUST_EXIST.0
-    );
-    assert!(foo_fields[0].vmsd.is_null());
-    assert!(unsafe { foo_fields[0].field_exists.unwrap()(foo_d_p, 0) });
-
-    // 2nd VMStateField in VMSTATE_FOOD
-    assert_eq!(
-        unsafe { CStr::from_ptr(foo_fields[1].name) }.to_bytes_with_nul(),
-        b"foo_d_1\0"
-    );
-    assert!(!unsafe { foo_fields[1].field_exists.unwrap()(foo_d_p, 1) });
-
-    // 3rd VMStateField in VMSTATE_FOOD
-    assert_eq!(
-        unsafe { CStr::from_ptr(foo_fields[2].name) }.to_bytes_with_nul(),
-        b"foo_d_2\0"
-    );
-    assert!(unsafe { foo_fields[2].field_exists.unwrap()(foo_d_p, 2) });
-
-    // The last VMStateField in VMSTATE_FOOD.
-    assert_eq!(foo_fields[3].flags, VMStateFlags::VMS_END);
-}
-
-// =========================== Test VMSTATE_FOOE ===========================
-// Test the use cases of the vmstate macro, corresponding to the following C
-// macro variants:
-//   * VMSTATE_FOOE:
 //     - VMSTATE_VARRAY with a `usize` length
 #[repr(C)]
 #[derive(Default)]
-struct FooE {
+struct FooD {
     arr: [u8; FOO_ARRAY_MAX],
     num: usize,
 }
 
-static VMSTATE_FOOE: VMStateDescription<FooE> = VMStateDescriptionBuilder::<FooE>::new()
-    .name(c"foo_e")
+static VMSTATE_FOOD: VMStateDescription<FooD> = VMStateDescriptionBuilder::<FooD>::new()
+    .name(c"foo_d")
     .version_id(1)
     .minimum_version_id(1)
     .fields(vmstate_fields! {
-        vmstate_of!(FooE, arr[0 .. num]),
+        vmstate_of!(FooD, arr[0 .. num]),
     })
     .build();
 
 #[test]
 fn test_vmstate_varray_usize() {
     let foo_fields: &[VMStateField] =
-        unsafe { slice::from_raw_parts(VMSTATE_FOOE.as_ref().fields, 2) };
+        unsafe { slice::from_raw_parts(VMSTATE_FOOD.as_ref().fields, 2) };
 
-    // 1st VMStateField ("arr") in VMSTATE_FOOE
+    // 1st VMStateField ("arr") in VMSTATE_FOOD
     assert_eq!(
         unsafe { CStr::from_ptr(foo_fields[0].name) }.to_bytes_with_nul(),
         b"arr\0"
@@ -518,7 +441,7 @@ fn test_vmstate_varray_usize() {
     assert_eq!(foo_fields[0].offset, 0);
     assert_eq!(
         foo_fields[0].num_indirect.offset,
-        std::mem::offset_of!(FooE, num) as u32
+        std::mem::offset_of!(FooD, num) as u32
     );
     assert_eq!(foo_fields[0].num_indirect.size, size_of::<usize>() as u8);
     assert_eq!(foo_fields[0].info, unsafe { &vmstate_info_uint8 });
@@ -529,6 +452,6 @@ fn test_vmstate_varray_usize() {
     assert!(foo_fields[0].vmsd.is_null());
     assert!(foo_fields[0].field_exists.is_none());
 
-    // The last VMStateField in VMSTATE_FOOE.
+    // The last VMStateField in VMSTATE_FOOD.
     assert_eq!(foo_fields[1].flags, VMStateFlags::VMS_END);
 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] rust/hpet: Move vmstate_validate!() check into post_load
  2026-11-24  9:58 ` [PATCH 2/3] rust/hpet: Move vmstate_validate!() check into post_load Zhao Liu
@ 2026-11-24 10:10   ` Philippe Mathieu-Daudé
  2026-11-24 10:22     ` Zhao Liu
  0 siblings, 1 reply; 7+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-24 10:10 UTC (permalink / raw)
  To: Zhao Liu, Peter Xu, Peter Maydell, Fabiano Rosas, Paolo Bonzini,
	Manos Pitsidianakis
  Cc: qemu-devel, qemu-rust

On 24/11/26 10:58, Zhao Liu wrote:
> To pave way for removing VMSTATE_VALIDATE() (and vmstate_validate!()),
> move the usage of hpet into post_load. To make it safer, loading the
> timers with the num_timers, then only check against the wire number at
> last.
> 
> In addition, drop the test_fn() in the VMStateField of HPETState.timers
> - this was duplicated, but now the check in post_load is enough
> (and test_fn should not be used for validation).
> 
> Originally-by: Peter Xu <peterx@redhat.com>
> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> ---
> Copy Peter's commit message from his C HPET patch because now this patch
> has the (almost) same logic.
> ---
>   rust/hw/timer/hpet/src/device.rs | 45 ++++++++++++++++----------------
>   1 file changed, 23 insertions(+), 22 deletions(-)


> -const VMSTATE_HPET: VMStateDescription<HPETState> =
> -    VMStateDescriptionBuilder::<HPETState>::new()
> -        .name(c"hpet")
> -        .version_id(2)
> -        .minimum_version_id(2)
> -        .pre_save(&HPETState::pre_save)
> -        .post_load(&HPETState::post_load)
> -        .fields(vmstate_fields! {
> -            vmstate_of!(HPETState, regs),
> -            vmstate_of!(HPETState, num_timers_save),
> -            vmstate_validate!(HPETState, VALIDATE_TIMERS_NAME, HPETState::validate_num_timers),
> -            vmstate_of!(HPETState, timers[0 .. num_timers_save], HPETState::validate_num_timers).with_version_id(0),
> -        })
> -        .subsections(vmstate_subsections!(
> -            VMSTATE_HPET_RTC_IRQ_LEVEL,
> -            VMSTATE_HPET_OFFSET,
> -        ))
> -        .build();
> +const VMSTATE_HPET: VMStateDescription<HPETState> = VMStateDescriptionBuilder::<HPETState>::new()
> +    .name(c"hpet")
> +    .version_id(2)
> +    .minimum_version_id(2)
> +    .pre_save(&HPETState::pre_save)
> +    .post_load(&HPETState::post_load)
> +    .fields(vmstate_fields! {
> +        vmstate_of!(HPETState, regs),
> +        vmstate_of!(HPETState, num_timers_save),
> +        vmstate_of!(HPETState, timers[0 .. num_timers]).with_version_id(0),
> +    })
> +    .subsections(vmstate_subsections!(
> +        VMSTATE_HPET_RTC_IRQ_LEVEL,
> +        VMSTATE_HPET_OFFSET,
> +    ))
> +    .build();

Doing the indentation change in a preliminary patch would ease review.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] rust/hpet: Move vmstate_validate!() check into post_load
  2026-11-24 10:10   ` Philippe Mathieu-Daudé
@ 2026-11-24 10:22     ` Zhao Liu
  0 siblings, 0 replies; 7+ messages in thread
From: Zhao Liu @ 2026-11-24 10:22 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Xu, Peter Maydell, Fabiano Rosas, Paolo Bonzini,
	Manos Pitsidianakis, qemu-devel, qemu-rust

> > -const VMSTATE_HPET: VMStateDescription<HPETState> =
> > -    VMStateDescriptionBuilder::<HPETState>::new()
> > -        .name(c"hpet")
> > -        .version_id(2)
> > -        .minimum_version_id(2)
> > -        .pre_save(&HPETState::pre_save)
> > -        .post_load(&HPETState::post_load)
> > -        .fields(vmstate_fields! {
> > -            vmstate_of!(HPETState, regs),
> > -            vmstate_of!(HPETState, num_timers_save),
> > -            vmstate_validate!(HPETState, VALIDATE_TIMERS_NAME, HPETState::validate_num_timers),
> > -            vmstate_of!(HPETState, timers[0 .. num_timers_save], HPETState::validate_num_timers).with_version_id(0),
> > -        })
> > -        .subsections(vmstate_subsections!(
> > -            VMSTATE_HPET_RTC_IRQ_LEVEL,
> > -            VMSTATE_HPET_OFFSET,
> > -        ))
> > -        .build();
> > +const VMSTATE_HPET: VMStateDescription<HPETState> = VMStateDescriptionBuilder::<HPETState>::new()
> > +    .name(c"hpet")
> > +    .version_id(2)
> > +    .minimum_version_id(2)
> > +    .pre_save(&HPETState::pre_save)
> > +    .post_load(&HPETState::post_load)
> > +    .fields(vmstate_fields! {
> > +        vmstate_of!(HPETState, regs),
> > +        vmstate_of!(HPETState, num_timers_save),
> > +        vmstate_of!(HPETState, timers[0 .. num_timers]).with_version_id(0),
> > +    })
> > +    .subsections(vmstate_subsections!(
> > +        VMSTATE_HPET_RTC_IRQ_LEVEL,
> > +        VMSTATE_HPET_OFFSET,
> > +    ))
> > +    .build();
> 
> Doing the indentation change in a preliminary patch would ease review.

Yeah, but this style change was from rustfmt's complaints about
this patch, so I've merged rustfmt's changes into this patch as
well... this ensures this individual patch could pass all checks.

Thanks,
Zhao



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/3] rust/migration: Remove vmstate_validate!() and VMS_MUST_EXIST
  2026-11-24  9:58 [PATCH 0/3] rust/migration: Remove vmstate_validate!() and VMS_MUST_EXIST Zhao Liu
                   ` (2 preceding siblings ...)
  2026-11-24  9:58 ` [PATCH 3/3] rust/migration: Remove vmstate_validate!() macro and test Zhao Liu
@ 2026-11-25 20:19 ` Peter Xu
  3 siblings, 0 replies; 7+ messages in thread
From: Peter Xu @ 2026-11-25 20:19 UTC (permalink / raw)
  To: Zhao Liu
  Cc: Peter Maydell, Fabiano Rosas, Paolo Bonzini, Manos Pitsidianakis,
	qemu-devel, qemu-rust

On Tue, Nov 24, 2026 at 05:58:11PM +0800, Zhao Liu wrote:
> Hi,
> 
> This simple series is based on Peter Xu's series [*] and mainly refines
> patch 5 — removing `vmstate_validate!()` from Rust HPET (while
> maintaining consistency logic with C HPET as much as possible).
> 
> I originally planned to use a single patch, but breaking it up this way
> makes it easier to review. I suppose these three small patches could
> also replace Peter's patch 5 :-).
> 
> There is also some cleanup work left (e.g., support post_load_errp() in
> Rust); I will address this in some separate patch later (without
> blocking the current effort to remove `vmstate_validate!()`).
> 
> [*]: https://lore.kernel.org/qemu-devel/20261120124923.1656220-6-peterx@redhat.com/

I'll carry this series too while reposting mine just to make it complete;
feel free to repost / address comments concurrently from other Rust
developers, we'll figure out how it lands.

Thanks again for sending!

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-25 20:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  9:58 [PATCH 0/3] rust/migration: Remove vmstate_validate!() and VMS_MUST_EXIST Zhao Liu
2026-11-24  9:58 ` [PATCH 1/3] rust/migration: Allow usize as the length of a varray Zhao Liu
2026-11-24  9:58 ` [PATCH 2/3] rust/hpet: Move vmstate_validate!() check into post_load Zhao Liu
2026-11-24 10:10   ` Philippe Mathieu-Daudé
2026-11-24 10:22     ` Zhao Liu
2026-11-24  9:58 ` [PATCH 3/3] rust/migration: Remove vmstate_validate!() macro and test Zhao Liu
2026-11-25 20:19 ` [PATCH 0/3] rust/migration: Remove vmstate_validate!() and VMS_MUST_EXIST Peter Xu

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.