590faa03 | 17-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: bindings for MemoryRegionOps
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
d449d29a | 13-Dec-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: bindings: add Send and Sync markers for types that have bindings
This is needed for the MemoryRegionOps<T> to be declared as static; Rust requires static elements to be Sync.
Reviewed-by: Zha
rust: bindings: add Send and Sync markers for types that have bindings
This is needed for the MemoryRegionOps<T> to be declared as static; Rust requires static elements to be Sync.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
5472a38c | 17-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qdev: switch from legacy reset to Resettable
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
68da5402 | 07-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qdev: make ObjectImpl a supertrait of DeviceImpl
In practice it has to be implemented always in order to access an implementation of ClassInitImpl<ObjectClass>. Make the relationship explicit
rust: qdev: make ObjectImpl a supertrait of DeviceImpl
In practice it has to be implemented always in order to access an implementation of ClassInitImpl<ObjectClass>. Make the relationship explicit in the code.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
688c6741 | 17-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qom: allow initializing interface vtables
Unlike regular classes, interface vtables can only be obtained via object_class_dynamic_cast. Provide a wrapper that allows accessing the vtable and
rust: qom: allow initializing interface vtables
Unlike regular classes, interface vtables can only be obtained via object_class_dynamic_cast. Provide a wrapper that allows accessing the vtable and pass it to a ClassInitImpl implementation, for example ClassInitImpl<ResettableClass>.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
201ef001 | 17-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qdev: add clock creation
Add a Rust version of qdev_init_clock_in, which can be used in instance_init. There are a couple differences with the C version:
- in Rust the object keeps its own r
rust: qdev: add clock creation
Add a Rust version of qdev_init_clock_in, which can be used in instance_init. There are a couple differences with the C version:
- in Rust the object keeps its own reference to the clock (in addition to the one embedded in the NamedClockList), and the reference is dropped automatically by instance_finalize(); this is encoded in the signature of DeviceClassMethods::init_clock_in, which makes the lifetime of the clock independent of that of the object it holds. This goes unnoticed in the C version and is due to the existence of aliases.
- also, anything that happens during instance_init uses the pinned_init framework to operate on a partially initialized object, and is done through class methods (i.e. through DeviceClassMethods rather than DeviceMethods) because the device does not exist yet. Therefore, Rust code *must* create clocks from instance_init, which is stricter than C.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
66bcc554 | 06-Dec-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: callbacks: allow passing optional callbacks as ()
In some cases, callbacks are optional. Using "Some(function)" and "None" does not work well, because when someone writes "None" the compiler
rust: callbacks: allow passing optional callbacks as ()
In some cases, callbacks are optional. Using "Some(function)" and "None" does not work well, because when someone writes "None" the compiler does not know what to use for "F" in "Option<F>".
Therefore, adopt () to mean a "null" callback. It is possible to enforce that a callback is valid by adding a "let _: () = F::ASSERT_IS_SOME" before the invocation of F::call.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
ec3eba98 | 31-Oct-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qom: add object creation functionality
The basic object lifecycle test can now be implemented using safe code!
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzi
rust: qom: add object creation functionality
The basic object lifecycle test can now be implemented using safe code!
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
0fcccf3f | 17-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qom: add reference counting functionality
Add a smart pointer that allows to add and remove references from QOM objects. It's important to note that while all QOM objects have a reference cou
rust: qom: add reference counting functionality
Add a smart pointer that allows to add and remove references from QOM objects. It's important to note that while all QOM objects have a reference count, in practice not all of them have their lifetime guarded by it. Embedded objects, specifically, are confined to the lifetime of the owner.
When writing Rust bindings this is important, because embedded objects are *never* used through the "Owned<>" smart pointer that is introduced here.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
476d6e4c | 07-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: restrict missing_const_for_fn to qemu_api crate
missing_const_for_fn is not necessarily useful or good. For example in a private API you can always add const later, and in a public API it can
rust: restrict missing_const_for_fn to qemu_api crate
missing_const_for_fn is not necessarily useful or good. For example in a private API you can always add const later, and in a public API it can be unnecessarily restrictive to annotate everything with const (blocking further improvements to the API).
Nevertheless, QEMU turns it on because qemu_api uses const quite aggressively and therefore it can be handy to have as much as possible annotated with const. Outside qemu_api though, not so much: devices are self contained consumers and if there is nothing that could use their functions in const contexts that were not anticipated.
Since missing_const_for_fn can be a bit noisy and trigger on trivial functions that no one would ever call in const context, do not turn it on everywhere and only keep it in qemu_api as a special case.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
aaf3778b | 23-Jan-2025 |
Zhao Liu <zhao1.liu@intel.com> |
rust/zeroable: Implement Zeroable with const_zero macro
The `const_zero` crate provides a nice macro to zero type-specific constants, which doesn't need to enumerates the fields one by one.
Introdu
rust/zeroable: Implement Zeroable with const_zero macro
The `const_zero` crate provides a nice macro to zero type-specific constants, which doesn't need to enumerates the fields one by one.
Introduce the `const_zero` macro to QEMU (along with its documentation), and use it to simplify the implementation of `Zeroable` trait.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250123163143.679841-1-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
af7edb1d | 02-Dec-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qdev: make reset take a shared reference
Because register reset is within a borrow_mut() call, reset does not need anymore a mut reference to the PL011State.
Reviewed-by: Zhao Liu <zhao1.liu@
rust: qdev: make reset take a shared reference
Because register reset is within a borrow_mut() call, reset does not need anymore a mut reference to the PL011State.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
7d052039 | 23-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: prefer NonNull::new to assertions
Do not use new_unchecked; the effect is the same, but the code is easier to read and unsafe regions become smaller. Likewise, NonNull::new can be used instead
rust: prefer NonNull::new to assertions
Do not use new_unchecked; the effect is the same, but the code is easier to read and unsafe regions become smaller. Likewise, NonNull::new can be used instead of assertion and followed by as_ref() or as_mut() instead of dereferencing the pointer.
Suggested-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
24f0e8d8 | 07-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: vmstate: make order of parameters consistent in vmstate_clock
Place struct_name before field_name, similar to offset_of.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
9d489949 | 07-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: vmstate: remove translation of C vmstate macros
Keep vmstate_clock!; because it uses a field of type VMStateDescription, it cannot be converted to the VMState trait without access to the const
rust: vmstate: remove translation of C vmstate macros
Keep vmstate_clock!; because it uses a field of type VMStateDescription, it cannot be converted to the VMState trait without access to the const_refs_static feature.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
9a2ba488 | 21-Dec-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qemu_api: add vmstate_struct
It is not type safe, but it's the best that can be done without const_refs_static. It can also be used with BqlCell and BqlRefCell.
Signed-off-by: Paolo Bonzini
rust: qemu_api: add vmstate_struct
It is not type safe, but it's the best that can be done without const_refs_static. It can also be used with BqlCell and BqlRefCell.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
00f89716 | 21-Dec-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: vmstate: add public utility macros to implement VMState
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
f2cb78bd | 29-Dec-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: vmstate: implement VMState for scalar types
Scalar types are those that have their own VMStateInfo. This poses a problem in that references to VMStateInfo can only be included in associated c
rust: vmstate: implement VMState for scalar types
Scalar types are those that have their own VMStateInfo. This poses a problem in that references to VMStateInfo can only be included in associated consts starting with Rust 1.83.0, when the const_refs_static was stabilized. Removing the requirement is done by placing a limited list of VMStateInfos in an enum, and going from enum to &VMStateInfo only when building the VMStateField.
The same thing cannot be done with VMS_STRUCT because the set of VMStateDescriptions extends to structs defined by the devices. Therefore, structs and cells cannot yet use vmstate_of!.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
2537f830 | 29-Dec-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: vmstate: implement Zeroable for VMStateField
This shortens a bit the constants. Do not bother using it in the vmstate macros since most of them will go away soon.
Reviewed-by: Zhao Liu <zhao
rust: vmstate: implement Zeroable for VMStateField
This shortens a bit the constants. Do not bother using it in the vmstate macros since most of them will go away soon.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
5b024b4e | 19-Dec-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: vmstate: add varray support to vmstate_of!
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
80aa3045 | 29-Dec-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: vmstate: implement VMState for non-leaf types
Arrays, pointers and cells use a VMStateField that is based on that for the inner type. The implementation therefore delegates to the VMState imp
rust: vmstate: implement VMState for non-leaf types
Arrays, pointers and cells use a VMStateField that is based on that for the inner type. The implementation therefore delegates to the VMState implementation of the inner type.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
0d43ddae | 08-Dec-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: vmstate: add new type safe implementation
The existing translation of the C macros for vmstate does not make any attempt to type-check vmstate declarations against the struct, so introduce a n
rust: vmstate: add new type safe implementation
The existing translation of the C macros for vmstate does not make any attempt to type-check vmstate declarations against the struct, so introduce a new system that computes VMStateField based on the actual struct declaration.
Macros do not have full access to the type system, therefore a full implementation of this scheme requires a helper trait to analyze the type and produce a VMStateField from it; a macro "vmstate_of!" accepts arguments similar to "offset_of!" and tricks the compiler into looking up the trait for the right type.
The patch introduces not just vmstate_of!, but also the slightly too clever enabling macro call_func_with_field!. The particular trick used here was proposed on the users.rust-lang.org forum, so I take no merit and all the blame.
Introduce the trait and some functions to access it; the actual implementation comes later.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
0f9eb0ff | 21-Jan-2025 |
Zhao Liu <zhao1.liu@intel.com> |
rust/qdev: Make REALIZE safe
A safe REALIZE accepts immutable reference.
Since current PL011's realize() only calls a char binding function ( qemu_chr_fe_set_handlers), it is possible to convert mu
rust/qdev: Make REALIZE safe
A safe REALIZE accepts immutable reference.
Since current PL011's realize() only calls a char binding function ( qemu_chr_fe_set_handlers), it is possible to convert mutable reference (&mut self) to immutable reference (&self), which only needs to convert the pointers passed to C to mutable pointers.
Thus, make REALIZE accept immutable reference.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250121140457.84631-2-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
559a779c | 29-Nov-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qdev: expose inherited methods to subclasses of SysBusDevice
The ObjectDeref trait now provides all the magic that is required to fake inheritance. Replace the "impl SysBusDevice" block of qe
rust: qdev: expose inherited methods to subclasses of SysBusDevice
The ObjectDeref trait now provides all the magic that is required to fake inheritance. Replace the "impl SysBusDevice" block of qemu_api::sysbus with a trait, so that sysbus_init_irq() can be invoked as "self.init_irq()" without any intermediate upcast.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
22a18f0a | 29-Nov-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qom: make INSTANCE_POST_INIT take a shared reference
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |