RustInQemu: Difference between revisions

From QEMU
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 5: Line 5:
* [Current state|ChangeLog/9.2#Rust]
* [Current state|ChangeLog/9.2#Rust]
* [https://lore.kernel.org/all/cc40943e-dec1-4890-a1d9-579350ce296f@pbonzini.local/ December 2024 Roadmap]
* [https://lore.kernel.org/all/cc40943e-dec1-4890-a1d9-579350ce296f@pbonzini.local/ December 2024 Roadmap]
!--
<!--
* <code>Subject: [RFC 0/6] scripts: Rewrite simpletrace printer in Rust</code><br /><code>Date: Mon, 27 May 2024 16:14:15 +0800</code><br />[https://lore.kernel.org/qemu-devel/20240527081421.2258624-1-zhao1.liu@intel.com/ RFC v1]
* <code>Subject: [RFC 0/6] scripts: Rewrite simpletrace printer in Rust</code><br /><code>Date: Mon, 27 May 2024 16:14:15 +0800</code><br />[https://lore.kernel.org/qemu-devel/20240527081421.2258624-1-zhao1.liu@intel.com/ RFC v1]
* ARM PL011 UART device model in Rust<br /><code>Subject: [RFC PATCH v1 0/6] Implement ARM PL011 in Rust</code><br /><code>Date: Mon, 10 Jun 2024 21:22:35 +0300</code><br />[https://lore.kernel.org/qemu-devel/cover.rust-pl011-rfc-v1.git.manos.pitsidianakis@linaro.org/ RFC v1] [https://lore.kernel.org/qemu-devel/rust-pl011-rfc-v6.git.manos.pitsidianakis@linaro.org/ v6]
* ARM PL011 UART device model in Rust<br /><code>Subject: [RFC PATCH v1 0/6] Implement ARM PL011 in Rust</code><br /><code>Date: Mon, 10 Jun 2024 21:22:35 +0300</code><br />[https://lore.kernel.org/qemu-devel/cover.rust-pl011-rfc-v1.git.manos.pitsidianakis@linaro.org/ RFC v1] [https://lore.kernel.org/qemu-devel/rust-pl011-rfc-v6.git.manos.pitsidianakis@linaro.org/ v6]
Line 29: Line 29:
Bindgen 0.60.x has --allowlist-file. Of the supported distributions only Ubuntu 22.04 has an older version (0.59.x).
Bindgen 0.60.x has --allowlist-file. Of the supported distributions only Ubuntu 22.04 has an older version (0.59.x).


== Posted ==
* [https://lore.kernel.org/qemu-devel/20241108180139.117112-1-pbonzini@redhat.com/T/ improved integration with cargo]
** automatically generate rustc flags from Cargo.toml
** Perform clippy checks and reformat code ("ninja clippy", "ninja rustfmt") - TODO: rustfmt configuration currently requires nightly due to use of unstable features
** Rustfmt, clippy, rustdoc in CI
* [https://lore.kernel.org/qemu-devel/20241104085159.76841-1-pbonzini@redhat.com/T/ qemu_irq + interior mutability]
== Work in progress ==
== Work in progress ==
=== Paolo ===
=== Paolo ===
* Posted: [https://gitlab.com/bonzini/qemu/-/commits/rust-next irq + QOM + callbacks + documentation for public APIs]
* In progress: interior mutability for PL011
* In progress: bugfixes and interior mutability for PL011
* Planned: errno, chardev, pinned_init, vmstate, MemoryRegion
* Planned: errno, chardev, pinned_init, vmstate, MemoryRegion
* Upstream Meson support for clippy, rustfmt, rustdoc
* Upstream Meson support for clippy, rustfmt, rustdoc
Line 55: Line 47:


== TODO ==
== TODO ==
=== Bugs ===
* Integration tests are linked with libqemuutil as link_whole, which does not work when modules are enabled
** [https://github.com/mesonbuild/meson/pull/14026 meson seems to be buggy and does not allow using link_with instead?]
** probably best to require meson 1.7.0 anyway as it has nicer integration with clippy and rustfmt
* Add BQL abstraction for tests - avoid running them with "--test-threads 1"
* vmstate is not type safe
=== Nice things to have ===
* [https://github.com/mesonbuild/meson/pull/13933 run doctests with meson test]
* Remove need for manual "meson subprojects update --reset" when updating packagefiles/
* Remove need for manual "meson subprojects update --reset" when updating packagefiles/
* Improve tool integration
* Improve tool integration
Line 60: Line 61:
* rustfmt currently requires nightly, decide what to do about it
* rustfmt currently requires nightly, decide what to do about it
* Place rustdoc output for master somewhere?
* Place rustdoc output for master somewhere?
* more QOM procedural macros (currently <tt>#[derive(Object)]</tt>)
** generate qdev properties?
** generate parts of TypeInfo?
=== New code to write===
* [https://docs.google.com/presentation/d/12quXHIUtnjEZy0fwR2Fuka7KDKwW94oyJqXHfOd6hfg/edit#slide=id.g313dc2156a5_0_5 Roadmap]
* [https://docs.google.com/presentation/d/12quXHIUtnjEZy0fwR2Fuka7KDKwW94oyJqXHfOd6hfg/edit#slide=id.g313dc2156a5_0_5 Roadmap]
** feature parity for pl011
** feature parity for pl011
Line 69: Line 75:
* HPET device
* HPET device
** includes error/timer/gpio bindings.
** includes error/timer/gpio bindings.
* more QOM procedural macros (currently <tt>#[derive(Object)]</tt>)
** generate qdev properties?
** generate parts of TypeInfo?


== Ideas for lints without breaking CI ==
== Ideas for lints without breaking CI ==

Latest revision as of 00:01, 20 December 2024

For the old RustInQemu page, see RustInQemu/2022

Active effort

Past efforts

  • [RFC v3 00/32] Rust binding for QAPI and qemu-ga QMP handler examples
    on patchew on lore

Minimum supported versions

Required versions:

  • 1.59.0 has const CStr::from_bytes_with_nul_unchecked, not really possible to go below that. Of the supported distributions only Debian bullseye has an older version.
  • 1.63.0 is available on Debian bookworm (though it also rustc-web, which is 1.70.0 on mips64el and 1.78.0 on all other platforms).
  • 1.75.0 is available on Ubuntu 22.04 and 24.04. It can return "impl Trait" in traits. This is important when using the pinned_init crate in traits (e.g. to implement QOM instance_init).
  • 1.83.0 will allow const_refs_statics and nested offset_of (useful to make vmstate type-safe).

Bindgen 0.60.x has --allowlist-file. Of the supported distributions only Ubuntu 22.04 has an older version (0.59.x).

Work in progress

Paolo

  • In progress: interior mutability for PL011
  • Planned: errno, chardev, pinned_init, vmstate, MemoryRegion
  • Upstream Meson support for clippy, rustfmt, rustdoc

Manos

  • Documentation

Kevin

  • Executing async code
  • Block driver implementations

Work in progress

  • hpet timer device
    • timer/bitops/memattrs bindings

TODO

Bugs

  • Integration tests are linked with libqemuutil as link_whole, which does not work when modules are enabled
  • Add BQL abstraction for tests - avoid running them with "--test-threads 1"
  • vmstate is not type safe

Nice things to have

  • run doctests with meson test
  • Remove need for manual "meson subprojects update --reset" when updating packagefiles/
  • Improve tool integration
    • Run code checks a la "meson test --suite codecheck"? (clippy and rustfmt)
  • rustfmt currently requires nightly, decide what to do about it
  • Place rustdoc output for master somewhere?
  • more QOM procedural macros (currently #[derive(Object)])
    • generate qdev properties?
    • generate parts of TypeInfo?

New code to write

Ideas for lints without breaking CI

See https://github.com/bonzini/rust-qemu/commit/95b25f7c5f4e2694a85a5503050cc98da7562c7c

  • run clippy as part of "make check", possibly only if Rust is newer than some version (1.74.0 so that clippy can be configured in Cargo.toml?)
  • deny many individual lints, do not deny groups (complexity, perf, style, suspicious) on regular builds. allow unknown_lints.
  • add to CI a fallible job that runs on nightly clippy with -Dclippy::complexity -Dclippy::perf -Dclippy::suspicious -Dclippy::style -Dunknown_lints. the job should generally pass, and if a new lint triggers it probably should be added to Cargo.toml as either "allow" (rare) or "deny" (possibly after adding #[allow()] to the source).

Possible project targets

Miscellanea

- qemu-bridge-helper.c Re-write SUID C executable with useful features.

Devices

  • hw/block/pflash_cfi01.c, hw/block/pflash_cfi02.c (claimed, WIP)
    • needs block bindings
  • hw/timer/hpet.c, hw/timer/i8254.c (claimed, WIP)
    • needs timer/memattrs/bitops/error/irq/trace bindgings
  • hw/mem/nvdimm.c (suggested by Manos)