Skip to content

rust: bundle of prerequisites for HPET implementation

Paolo Bonzini qemu-devel qemu-rust 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest26 patches 54 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/26bql: check that the BQL is not dropped within marked sectionsinclude/qemu/main-loop.h stubs/iothread-lock.c system/cpus.c+45 -00 replies
2/26rust: cell: add BQL-enforcing Cell variantrust/qemu-api/meson.build rust/qemu-api/src/cell.rs rust/qemu-api/src/lib.rs+300 -00 replies
3/26rust: cell: add BQL-enforcing RefCell variantrust/qemu-api/Cargo.toml rust/qemu-api/meson.build rust/qemu-api/src/cell.rs+539 -110 replies
4/26rust: define preluderust/qemu-api/meson.build rust/qemu-api/src/lib.rs rust/qemu-api/src/prelude.rs+12 -01 reply
5/26rust: add bindings for interrupt sourcesrust/hw/char/pl011/src/device.rs rust/qemu-api/meson.build rust/qemu-api/src/irq.rs +2 more+134 -101 reply
6/26rust: add a bit operation modulerust/qemu-api/meson.build rust/qemu-api/src/bitops.rs rust/qemu-api/src/lib.rs +1 more+123 -02 replies
7/26rust: qom: add default definitions for ObjectImplrust/hw/char/pl011/src/device.rs rust/qemu-api/src/definitions.rs rust/qemu-api/tests/tests.rs+4 -141 reply
8/26rust: qom: rename Class trait to ClassInitImplrust/hw/char/pl011/src/device.rs rust/qemu-api/src/definitions.rs rust/qemu-api/tests/tests.rs+26 -71 reply
9/26rust: qom: convert type_info! macro to an associated construst/hw/char/pl011/src/device.rs rust/qemu-api/src/definitions.rs rust/qemu-api/tests/tests.rs+24 -331 reply
10/26rust: qom: move ClassInitImpl to the instance siderust/hw/char/pl011/src/device.rs rust/qemu-api/src/definitions.rs rust/qemu-api/tests/tests.rs+7 -71 reply
11/26rust: qdev: move device_class_init! body to generic function, ClassInitImpl implementation to macrorust/hw/char/pl011/src/device.rs rust/hw/char/pl011/src/device_class.rs rust/qemu-api/src/device_class.rs +1 more+103 -561 reply
12/26rust: qdev: move bridge for realize and reset functions out of pl011rust/hw/char/pl011/src/device.rs rust/hw/char/pl011/src/device_class.rs rust/qemu-api/src/definitions.rs +1 more+33 -361 reply
13/26rust: qom: automatically use Drop trait to implement instance_finalizerust/qemu-api/src/definitions.rs+8 -23 replies
14/26rust: qom: move bridge for TypeInfo functions out of pl011rust/hw/char/pl011/src/device.rs rust/qemu-api/src/definitions.rs+69 -328 replies
15/26rust: qom: split ObjectType from ObjectImpl traitrust/hw/char/pl011/src/device.rs rust/qemu-api/src/definitions.rs rust/qemu-api/src/device_class.rs +3 more+43 -181 reply
16/26rust: qom: change the parent type to an associated typerust/hw/char/pl011/src/device.rs rust/qemu-api/src/definitions.rs rust/qemu-api/tests/tests.rs+7 -101 reply
17/26rust: qom: put class_init together from multiple ClassInitImpl<>rust/hw/char/pl011/src/device.rs rust/qemu-api/src/definitions.rs rust/qemu-api/src/device_class.rs +2 more+101 -801 reply
18/26rust: qom: add possibility of overriding unparentrust/qemu-api/src/definitions.rs rust/qemu-api/src/device_class.rs+45 -52 replies
19/26rust: rename qemu-api modules to follow C code a bit morerust/hw/char/pl011/src/device.rs rust/qemu-api-macros/src/lib.rs rust/qemu-api/meson.build +7 more+92 -544 replies
20/26rust: re-export C types from qemu-api submodulesrust/qemu-api/src/qdev.rs rust/qemu-api/src/qom.rs rust/qemu-api/src/sysbus.rs +2 more+20 -121 reply
21/26rust: tests: allow writing more than one testrust/qemu-api/tests/tests.rs+61 -482 replies
22/26rust: qom: add casting functionalityrust/Cargo.toml rust/hw/char/pl011/src/device.rs rust/qemu-api/src/prelude.rs +4 more+362 -112 replies
23/26rust: qom: add initial subset of methods on Objectrust/qemu-api/src/prelude.rs rust/qemu-api/src/qom.rs rust/qemu-api/tests/tests.rs+66 -31 reply
24/26rust: qom: move device_id to PL011 class siderust/hw/char/pl011/src/device.rs+28 -319 replies
25/26rust: qemu-api: add a module to wrap functions and zero-sized closuresrust/qemu-api/meson.build rust/qemu-api/src/callbacks.rs rust/qemu-api/src/lib.rs+146 -01 reply
26/26rust: callbacks: allow passing optional callbacks as ()rust/qemu-api/src/callbacks.rs+97 -05 replies

Reviews trailers per patch

21 of 26 patches have a Reviewed-by or Acked-by.

PatchPaolo BonziniZhao Liu
SeriesCo-authored-by
1/26
2/26
3/26
4/26R-b
5/26R-b
6/26Co-authored-by R-b
7/26R-b
8/26R-b
9/26R-b
10/26R-b
11/26Rviewed-by
12/26R-b
13/26R-b
14/26R-b
15/26R-b
16/26R-b
17/26R-b
18/26R-b
19/26R-b
20/26R-b
21/26R-b
22/26R-b
23/26R-b
24/26R-b
25/26R-b
26/26

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 00/26] rust: bundle of prerequisites for HPET implementation

These are the initial set of bindings and support code that are needed to apply Zhao's posted HPET implementation, and for him to apply my review comments. They include:

- QOM cleanups (already posted)

- interrupts sources and cells (posted and reviewed)

- bit deposit and extract operations (new)

- QOM generalization beyond DeviceState (new)

- callbacks system (new)

This is the code that I aim at integrating in QEMU 10.0, and is also what is needed to develop additional bindings (for e.g. timers) more or less independently. I'll focus here on the changes to QOM because they represent the bulk of the patches. The bit operations and callbacks are just one or two patches each, and better explained by the doc comments in the patch itself.

With respect to qdev, some of this was already explained in the "Rust in QEMU roadmap". The patches are split in two series, corresponding to patches 7-14 and 15-24.

The first and previously posted part mostly removes code duplication, while keeping the focus very much on four elements of DeviceClass (realize, legacy reset, properties, vmstate).

The second instead starts to establish a correspondence between the QOM class hierarchy and the Rust trait system. The hierarchy of classes is visible as an ObjectImpl::ParentType associated type, and also present in the implementation of the ClassInitImpl<ClassType> trait. The ClassInitImpl trait is implemented for each Rust-defined QOM class as before, but now its implementation is split over multiple blanket impls, one for each superclass. This allows code reuse of the class_init wrappers, and is implemented in patches 15-18.

After a brief cleanup intermission in patches 19-21, patches 22-23 provide the method invocation infrastructure. Taking inspiration from glib-rs's GObject bindings, an IsA<> trait declares what is a subclass of what, which allows two things:

- safe and efficient typecasts, which are compile-time checked so that it is an error if the destination type is not a superclass.

- automatically making methods available to all subclasses. This is done through another blanket implementation of a trait, as in glib-rs (see
https://gtk-rs.org/gtk4-rs/stable/latest/docs/src/gtk4/auto/widget.rs.html#5377),
though the details are a bit different.

The differences with glib-rs are not small, but fortunately it is the QEMU version that is simpler. QEMU does not use a complicated macro like glib's
(https://gtk-rs.org/gtk-rs-core/git/docs/glib/macro.wrapper.html) to wrap all subclasses of GObject with an opaque Rust type. While macros in general, and procedural macros in particular, may be a useful tool(*), for now I prefer to ensure that the infrastructure is usable and readable even without any macro magic.

The two pieces allow defining QOM class hierarchies entirely in Rust; patch 24 for example gives TYPE_PL011 its own class type PL011Class, and stores the device id in PL011Class instead of PL011State.

I understand that this is a lot of code, and a lot of added lines in particular. Fortunately about 40% of it is docs, which is definitely a change for QEMU's standards. :) Also all except the last two patches have already been used by Zhao, who did not report any particular problem adopting them.

Excepting the docs, the bulk of the new code is in the BqlCell and BqlRefCell implementations, as well as in patch 22. Fortunately these patches are also relatively boring. The more interesting patches to review are patch 15-18 for QOM, and 25 for the callbacks. Patch 25 is also the trickiest to explain from the point of view of using advanced language features; (**) I tried to explain that in the doc comments and commit messages but please ask for more if necessary.

This series is available at branch rust-next of
https://gitlab.com/bonzini/qemu.git.
Thanks,

Paolo

(*) For example they could automate the declaration of various traits, many of which are "unsafe" as a reminder that they interact with C code. This should be pretty easy, considering that the amount of code required to write QOM types is already smaller in Rust than in C. qdev properties are also a useful target, as exemplified by Manos's previously posted series.

(**) In particular, zero-sized types and the Fn trait.

Paolo Bonzini (26):
bql: check that the BQL is not dropped within marked sections
rust: cell: add BQL-enforcing Cell variant
rust: cell: add BQL-enforcing RefCell variant
rust: define prelude
rust: add bindings for interrupt sources
rust: add a bit operation module
rust: qom: add default definitions for ObjectImpl
rust: qom: rename Class trait to ClassInitImpl
rust: qom: convert type_info! macro to an associated const
rust: qom: move ClassInitImpl to the instance side
rust: qdev: move device_class_init! body to generic function,
ClassInitImpl implementation to macro
rust: qdev: move bridge for realize and reset functions out of pl011
rust: qom: automatically use Drop trait to implement instance_finalize
rust: qom: move bridge for TypeInfo functions out of pl011
rust: qom: split ObjectType from ObjectImpl trait
rust: qom: change the parent type to an associated type
rust: qom: put class_init together from multiple ClassInitImpl<>
rust: qom: add possibility of overriding unparent
rust: rename qemu-api modules to follow C code a bit more
rust: re-export C types from qemu-api submodules
rust: tests: allow writing more than one test
rust: qom: add casting functionality
rust: qom: add initial subset of methods on Object
rust: qom: move device_id to PL011 class side
rust: qemu-api: add a module to wrap functions and zero-sized closures
rust: callbacks: allow passing optional callbacks as ()

 include/qemu/main-loop.h               |  15 +
 stubs/iothread-lock.c                  |  15 +
 system/cpus.c                          |  15 +
 rust/Cargo.toml                        |   1 +
 rust/hw/char/pl011/src/device.rs       | 156 ++---
 rust/hw/char/pl011/src/device_class.rs |  34 -
 rust/qemu-api-macros/src/lib.rs        |   2 +-
 rust/qemu-api/Cargo.toml               |   3 +-
 rust/qemu-api/meson.build              |  14 +-
 rust/qemu-api/src/bitops.rs            | 119 ++++
 rust/qemu-api/src/callbacks.rs         | 238 +++++++
 rust/qemu-api/src/cell.rs              | 822 +++++++++++++++++++++++++
 rust/qemu-api/src/definitions.rs       |  91 ---
 rust/qemu-api/src/device_class.rs      |  74 ---
 rust/qemu-api/src/irq.rs               |  91 +++
 rust/qemu-api/src/lib.rs               |  15 +-
 rust/qemu-api/src/module.rs            |  43 ++
 rust/qemu-api/src/prelude.rs           |  18 +
 rust/qemu-api/src/qdev.rs              | 146 +++++
 rust/qemu-api/src/qom.rs               | 556 +++++++++++++++++
 rust/qemu-api/src/sysbus.rs            |  51 ++
 rust/qemu-api/src/vmstate.rs           |   9 +-
 rust/qemu-api/tests/tests.rs           | 208 +++++--
 23 files changed, 2374 insertions(+), 362 deletions(-)
 create mode 100644 rust/qemu-api/src/bitops.rs
 create mode 100644 rust/qemu-api/src/callbacks.rs
 create mode 100644 rust/qemu-api/src/cell.rs
 delete mode 100644 rust/qemu-api/src/definitions.rs
 delete mode 100644 rust/qemu-api/src/device_class.rs
 create mode 100644 rust/qemu-api/src/irq.rs
 create mode 100644 rust/qemu-api/src/module.rs
 create mode 100644 rust/qemu-api/src/prelude.rs
 create mode 100644 rust/qemu-api/src/qdev.rs
 create mode 100644 rust/qemu-api/src/qom.rs
 create mode 100644 rust/qemu-api/src/sysbus.rs
Signature · 1 line
2.47.1