All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/26] rust: bundle of prerequisites for HPET implementation
@ 2024-12-09 12:36 Paolo Bonzini
  2024-12-09 12:36 ` [PATCH 01/26] bql: check that the BQL is not dropped within marked sections Paolo Bonzini
                   ` (26 more replies)
  0 siblings, 27 replies; 81+ messages in thread
From: Paolo Bonzini @ 2024-12-09 12:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust, Zhao Liu, Junjie Mao

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

-- 
2.47.1



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

end of thread, other threads:[~2024-12-18 16:01 UTC | newest]

Thread overview: 81+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-09 12:36 [PATCH 00/26] rust: bundle of prerequisites for HPET implementation Paolo Bonzini
2024-12-09 12:36 ` [PATCH 01/26] bql: check that the BQL is not dropped within marked sections Paolo Bonzini
2024-12-09 12:36 ` [PATCH 02/26] rust: cell: add BQL-enforcing Cell variant Paolo Bonzini
2024-12-09 12:36 ` [PATCH 03/26] rust: cell: add BQL-enforcing RefCell variant Paolo Bonzini
2024-12-09 12:36 ` [PATCH 04/26] rust: define prelude Paolo Bonzini
2024-12-10  7:19   ` Zhao Liu
2024-12-09 12:36 ` [PATCH 05/26] rust: add bindings for interrupt sources Paolo Bonzini
2024-12-10  7:25   ` Zhao Liu
2024-12-09 12:36 ` [PATCH 06/26] rust: add a bit operation module Paolo Bonzini
2024-12-10  8:13   ` Zhao Liu
2024-12-10  9:30     ` Paolo Bonzini
2024-12-09 12:36 ` [PATCH 07/26] rust: qom: add default definitions for ObjectImpl Paolo Bonzini
2024-12-10  8:21   ` Zhao Liu
2024-12-09 12:36 ` [PATCH 08/26] rust: qom: rename Class trait to ClassInitImpl Paolo Bonzini
2024-12-10  8:24   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 09/26] rust: qom: convert type_info! macro to an associated const Paolo Bonzini
2024-12-10  8:30   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 10/26] rust: qom: move ClassInitImpl to the instance side Paolo Bonzini
2024-12-10 16:03   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 11/26] rust: qdev: move device_class_init! body to generic function, ClassInitImpl implementation to macro Paolo Bonzini
2024-12-10 16:06   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 12/26] rust: qdev: move bridge for realize and reset functions out of pl011 Paolo Bonzini
2024-12-10 16:07   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 13/26] rust: qom: automatically use Drop trait to implement instance_finalize Paolo Bonzini
2024-12-10 16:16   ` Zhao Liu
2024-12-11 12:42     ` Paolo Bonzini
2024-12-11 15:37       ` Zhao Liu
2024-12-09 12:37 ` [PATCH 14/26] rust: qom: move bridge for TypeInfo functions out of pl011 Paolo Bonzini
2024-12-10 15:50   ` Zhao Liu
2024-12-10 17:38     ` Paolo Bonzini
2024-12-11  7:59       ` Zhao Liu
2024-12-11  9:11         ` Paolo Bonzini
2024-12-11 16:56           ` Zhao Liu
2024-12-12  9:24             ` Paolo Bonzini
2024-12-13  8:53               ` Zhao Liu
2024-12-10 16:02   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 15/26] rust: qom: split ObjectType from ObjectImpl trait Paolo Bonzini
2024-12-11  8:41   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 16/26] rust: qom: change the parent type to an associated type Paolo Bonzini
2024-12-11  8:47   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 17/26] rust: qom: put class_init together from multiple ClassInitImpl<> Paolo Bonzini
2024-12-12  9:15   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 18/26] rust: qom: add possibility of overriding unparent Paolo Bonzini
2024-12-12  9:40   ` Zhao Liu
2024-12-12 11:15     ` Paolo Bonzini
2024-12-09 12:37 ` [PATCH 19/26] rust: rename qemu-api modules to follow C code a bit more Paolo Bonzini
2024-12-12  9:52   ` Zhao Liu
2024-12-12 11:28     ` Paolo Bonzini
2024-12-13  9:19       ` Zhao Liu
2024-12-13 11:24         ` Paolo Bonzini
2024-12-09 12:37 ` [PATCH 20/26] rust: re-export C types from qemu-api submodules Paolo Bonzini
2024-12-12  9:55   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 21/26] rust: tests: allow writing more than one test Paolo Bonzini
2024-12-12 10:04   ` Zhao Liu
2024-12-16 15:07     ` Paolo Bonzini
2024-12-09 12:37 ` [PATCH 22/26] rust: qom: add casting functionality Paolo Bonzini
2024-12-16 12:53   ` Zhao Liu
2024-12-16 15:17     ` Paolo Bonzini
2024-12-09 12:37 ` [PATCH 23/26] rust: qom: add initial subset of methods on Object Paolo Bonzini
2024-12-16 15:18   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 24/26] rust: qom: move device_id to PL011 class side Paolo Bonzini
2024-12-17  3:58   ` Zhao Liu
2024-12-17 16:50     ` Paolo Bonzini
2024-12-18  6:57       ` Zhao Liu
2024-12-18  7:14         ` Paolo Bonzini
2024-12-18 10:26           ` Paolo Bonzini
2024-12-18 14:46             ` Zhao Liu
2024-12-18 16:01               ` Paolo Bonzini
2024-12-18 14:30           ` Zhao Liu
2024-12-18 14:47   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 25/26] rust: qemu-api: add a module to wrap functions and zero-sized closures Paolo Bonzini
2024-12-17 15:03   ` Zhao Liu
2024-12-09 12:37 ` [PATCH 26/26] rust: callbacks: allow passing optional callbacks as () Paolo Bonzini
2024-12-17 16:13   ` Zhao Liu
2024-12-17 16:40     ` Paolo Bonzini
2024-12-18  7:09       ` Zhao Liu
2024-12-18  7:32         ` Paolo Bonzini
2024-12-18 15:09           ` Zhao Liu
2024-12-09 16:24 ` [PATCH 00/26] rust: bundle of prerequisites for HPET implementation Philippe Mathieu-Daudé
2024-12-09 17:23   ` Paolo Bonzini
2024-12-10  2:38     ` Zhao Liu

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.