The VMStateDescription of Migratable<T> missed the name field, and this
casused segmentation fault in vmstate_save_state_v() when it tries to
write name field by json_writer_str().

Due to the limitation of const, a custom name based on type would be
more difficult. Instead, a straightforward and simple approach is to
have all Migratable<T> instances use the same VMSD name -
"migratable-wrapper".

This is availiable because Migratable<T> is always a field within a
VMSD, and its parent VMSD should have a distinct name.

Signed-off-by: Zhao Liu <[email protected]>
---
 rust/migration/src/migratable.rs | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/rust/migration/src/migratable.rs b/rust/migration/src/migratable.rs
index 5c47c7d1c2fa..76e524774a3c 100644
--- a/rust/migration/src/migratable.rs
+++ b/rust/migration/src/migratable.rs
@@ -421,7 +421,11 @@ impl<T: 'static + ToMigrationStateShared> Migratable<T> {
         Migratable::<T>::FIELD
     };
 
+    // All Migratable<T> instances share the same name. This is fine because
+    // Migratable<T> is always a field within a VMSD. The parent VMSD has the
+    // different name to distinguish child Migratable<T>.
     const VMSD: &'static bindings::VMStateDescription = 
VMStateDescriptionBuilder::<Self>::new()
+        .name(c"migratable-wrapper")
         .version_id(1)
         .minimum_version_id(1)
         .pre_save(&Self::pre_save)
-- 
2.34.1


Reply via email to