aboutsummaryrefslogtreecommitdiff
path: root/rust/migration
AgeCommit message (Collapse)AuthorFilesLines
4 daysrust: migration: implement ToMigrationState as part of impl_vmstate_bitsizedPaolo Bonzini1-0/+19
This is most likely desirable, and is the easiest way to migrate a bit-sized value without peeking at the innards of the bilge crate. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5 daysrust: qemu-macros: add ToMigrationState derive macroPaolo Bonzini4-3/+14
Add a macro that recursively builds the "migrated" version of a struct. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5 daysrust: migration: add high-level migration wrappersPaolo Bonzini3-0/+438
Instead of dealing with pre/post callbacks, allow devices to implement a snapshot/restore mechanism; this has two main advantages: - it can be easily implemented via procedural macros - there can be generic implementations to deal with various kinds of interior-mutable containers, from BqlRefCell to Mutex, so that C code does not see Rust concepts such as Mutex<>. Using it is easy; you can implement the snapshot/restore trait ToMigrationState and declare your state like: regs: Migratable<Mutex<MyDeviceRegisters>> Migratable<> allows dereferencing to the underlying object with no run-time cost. Note that Migratable<> actually does not accept ToMigrationState, only the similar ToMigrationStateShared trait that the user will mostly not care about. This is required by the fact that pre/post callbacks take a &self, and ensures that the argument is a Mutex or BqlRefCell (including an array or Arc<> thereof). Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5 daysrust: move VMState from bql to migrationPaolo Bonzini3-2/+5
The high-level wrapper Migratable<T> will contain a BqlCell, which would introduce a circular dependency betwen the bql and migration crates. Move the implementation of VMState for cells to "migration", together with the implementation for std types. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5 daysrust: migration: extract vmstate_fields_refPaolo Bonzini1-6/+17
This is useful when building a VMState for generic structs, because you have to avoid nested statics. Using vmstate_fields! will fail in the likely case where the _FIELDS static uses Self from an outer item, because that is forbidden. The separate macros are needed because you cannot just do .fields(vmstate_fields_ref! { vmstate_of!(PL011State, clock), }) The value returned by vmstate_fields_ref! is not promoted to static, which is unfortunate but intentional (https://github.com/rust-lang/rust/issues/60502): error[E0716]: temporary value dropped while borrowed --> rust/hw/char/pl011/libpl011.rlib.p/structured/device.rs:743:17 | 738 | / VMStateDescriptionBuilder::<PL011State>::new() 739 | | .name(c"pl011/clock") 740 | | .version_id(1) 741 | | .minimum_version_id(1) 742 | | .needed(&PL011State::clock_needed) 743 | | .fields(vmstate_fields_ref! { | | _________________^ 744 | || vmstate_of!(PL011State, clock), 745 | || }) | ||_________^- argument requires that borrow lasts for `'static` | |_________| | creates a temporary value which is freed while still in use 746 | .build(); | - temporary value is freed at the end of this statement Thus it is necessary to use the "static", whether explicitly or hidden by vmstate_fields. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5 daysrust: migration: validate termination of subsection arraysPaolo Bonzini1-0/+3
For consistency with fields(), validate the value (at least to some extent) before passing it to C. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5 daysrust: migration: do not store raw pointers into VMStateSubsectionsWrapperPaolo Bonzini1-20/+9
Raw pointers were used to insert a NULL one at the end of the array. However, Option<&...> has the same layout and does not remove Sync from the type of the array. As an extra benefit, this enables validation of the terminator of the subsection array, because is_null() in const context would not be stable until Rust 1.84. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5 daysrust: migration: do not pass raw pointer to VMStateDescription::fieldsPaolo Bonzini1-3/+6
Pass a slice instead; a function that accepts a raw pointer should arguably be declared as unsafe. But since it is now much easier to forget vmstate_fields!, validate the value (at least to some extent) before passing it to C. (Unfortunately, doing the same for subsections would require const ptr::is_null(), which is only stable in Rust 1.84). Suggested-by: Zhao Liu <zhao1.liu@intel.com> Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5 daysrust: migration: hide more warnings from call_func_with_field!Paolo Bonzini1-0/+1
The call_func_with_field! macro uses dead code willingly to infer the appropriate type. This has started adding a new warning: error: unused variable: `value__` 79 | break phantom__(&{ let value__: $typ; value__.$($field).+ }) So shut it up together with the existing unreachable_code warning. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-03rust: use glib-sysMarc-André Lureau3-1/+3
Don't generate FFI for glib, rely on glib-sys crate. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-09-30build-sys: pass -fvisibility=default for wasm bindgenMarc-André Lureau1-1/+2
Otherwise, no functions are generated: https://github.com/rust-lang/rust-bindgen/issues/2989 Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Kohei Tokunaga <ktokunaga.mail@gmail.com> Message-ID: <20250924120426.2158655-27-marcandre.lureau@redhat.com>
2025-09-22rust: build: remove "protocol: rust: from doctestsPaolo Bonzini1-1/+0
It is added already by rust.doctest. Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-09-22rust: vmstate: use "cast()" instead of "as"Paolo Bonzini1-1/+1
Reported by clippy, fix it. Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-09-17rust: re-export qemu macros from common/qom/hwcoreMarc-André Lureau1-1/+0
This is just a bit nicer. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20250827104147.717203-22-marcandre.lureau@redhat.com Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-09-17rust: rename qemu_api_macros -> qemu_macrosMarc-André Lureau1-1/+1
Since "qemu_api" is no longer the unique crate to provide APIs. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20250827104147.717203-17-marcandre.lureau@redhat.com Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-09-17rust: split "qom" crateMarc-André Lureau1-1/+1
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250827104147.717203-13-marcandre.lureau@redhat.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-09-17rust: split "bql" crateMarc-André Lureau1-2/+2
Unfortunately, an example had to be compile-time disabled, since it relies on higher level crates (qdev, irq etc). The alternative is probably to move that code to an example in qemu-api or elsewere and make a link to it, or include_str. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20250827104147.717203-12-marcandre.lureau@redhat.com Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-09-17rust: split "migration" crateMarc-André Lureau7-0/+895
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20250827104147.717203-11-marcandre.lureau@redhat.com Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>