Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH v7 0/1] rust: introduce abstractions for fwctl
@ 2026-07-08 15:59 Zhi Wang
  2026-07-08 15:59 ` [PATCH v7 1/1] " Zhi Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Zhi Wang @ 2026-07-08 15:59 UTC (permalink / raw)
  To: rust-for-linux, linux-kernel
  Cc: dakr, jgg, dave.jiang, saeedm, jic23, gary, joelagnelf, aliceryhl,
	kwilczynski, ojeda, alex.gaynor, boqun.feng, bjorn3_gh, lossin,
	a.hindborg, tmgross, cjia, smitra, ankita, aniketa, kwankhede,
	targupta, kjaju, alkumar, acourbot, jhubbard, zhiwang,
	daniel.almeida, Zhi Wang

In the NVIDIA vGPU RFC [1], the vGPU type blobs must be provided to the GSP
before userspace can enumerate available vGPU types and create vGPU
instances. The original design relied on the firmware loading interface,
but fwctl is a more natural fit for this use case, as it is designed for
uploading configuration or firmware data required before the device becomes
operational.

This series introduces a Rust abstraction over the fwctl subsystem,
providing safe and idiomatic bindings.

The series is a single patch. `Registration` owns the callback-visible
driver data and ties it to the parent device binding lifetime using a GAT
on `Operations`. `Device<T>` remains the refcounted fwctl object, while
callbacks borrow registration data for the callback lifetime.

The Rust fwctl module provides:

  - `Operations`: driver-specific `open()`, `close()`, `info()`, and
    `fw_rpc()` callbacks. The implementing type is the per-FD user context.

  - `RegistrationData<'a>`: a GAT associated type owned by `Registration`
    and borrowed by callbacks under the fwctl registration lock.

  - `Device<T>`: a refcounted wrapper around `struct fwctl_device`.

  - `Registration<T>`: registration and automatic unregistration, including
    verification that the supplied bound parent is the device's actual
    parent.

  - `RpcScope` and `FwRpcResponse`: type-safe RPC scope and response
    handling. The safe callback receives the userspace output-buffer size
    as a numeric value, while raw output-length pointer handling remains
    confined to the abstraction.

`DeviceType` intentionally models every valid, non-error
`fwctl_device_type` UAPI value rather than the set of existing Rust
drivers. This preserves a typed interface while making
`FWCTL_DEVICE_TYPE_ERROR` and arbitrary integers unrepresentable.
Device-specific Rust consumers can add new variants together with their
UAPI allocation.

`rust/kernel/lib.rs` conditionally includes the module under
`CONFIG_RUST_FWCTL_ABSTRACTIONS`.

This series is based on drm-rust-next commit d85845b64c00
("gpu: nova-core: build SetRegistry entries dynamically"), so Nova can
build on it directly. Danilo suggested taking it through the DRM tree;
Jason, please let us know if you would prefer it to go through the fwctl
tree.

v7:

- Rebase onto the latest drm-rust-next.
- Pad fwctl allocation sizes for Rust alignment. (Danilo, Alexandre)
- Validate the actual parent in `Registration::new()`. (Alexandre, Danilo)
- Add an HRTB helper and remove the lifetime transmute. (Alexandre)
- Pass `max_output_len` to safe RPC callbacks. (Alexandre, Joel)
- Write `out_len` once. (Alexandre)
- Return `NULL` for empty RPC replies. (Danilo)
- Convert allocation results to `NonNull` immediately. (Alexandre, Gary)
- Simplify callback lifetimes and raw pointer use. (Danilo, Alexandre)
- Make `VTable` and `VTABLE` private. (Danilo)
- Remove manual `Registration` `Send`/`Sync` impls. (Alexandre)
- Tighten the rustdoc and safety comments. (Alexandre)
- Document `DeviceType` as the non-error UAPI domain. (Danilo)
- Update the FWCTL `MAINTAINERS` entry. (Miguel, Danilo)
- Add Danilo's `Signed-off-by` trailer. (Danilo)

Link to v6: [2]
Links to the v6 reviews: [8] [9] [10]

v6:

- Use a GAT lifetime for `Operations::RegistrationData<'a>` instead of
  requiring `ForLt`. (Danilo)
- Require `FWCTL=y` for `RUST_FWCTL_ABSTRACTIONS`.
- Add `#[inline]` to small forwarding helpers.
- Return `EINVAL` for an unrecognized RPC scope.

Link to Danilo's GAT diff: [3]
Link to v5: [4]

v5:

- Rebase on top of drm-rust-next.
- Adopt Danilo's higher-ranked lifetime model for callback-visible
  registration data.
- Drop the fwctl core release hook patch.
- Reject `FwRpcResponse::InPlace(len)` when `len` exceeds the input buffer.
- Add the missing BNXT fwctl device type.
- Document the registration exclusivity requirements.

Link to v4: [5]

v4:

- Rebase on top of drm-rust-next.
- Split out the fwctl core release hook.
- Drop the already-merged fwctl init-ordering change.
- Add compile-time layout checks. (Jason)
- Use `const_assert!()` for generic layout assertions.
- Require `Operations` and its data to be `Send + Sync`. (Danilo)
- Pass pinned shared references to `info()` and `fw_rpc()`. (Danilo)
- Return an initializer directly from `open()`. (Danilo)
- Fix clippy and rustdoc warnings. (Danilo)

Link to v3: [6]

v3:

- Use an enum for the RPC response. (Joel)
- Remove the test UAPI and sample driver. (Jason, John)
- Remove `DeviceType::Error` and add fwctl reference helpers. (Gary)
- Refine device-private data ownership. (Danilo)
- Separate allocation and registration. (Jason)
- Tie registration to a bound parent device. (Danilo)
- Make the implementing type the per-FD context. (Danilo)

An example nova-core fwctl consumer is available at [7].

v2:

- Use a Rust helper for `fwctl_put()`. (Jason, Danilo)
- Guarantee registration lifetime management. (Jason, Danilo)
- Rename the main abstraction types and use a typed device identifier.
  (Danilo)
- Improve pointer casts, reference counting, safety comments, and clippy
  cleanliness.

v1:

- Initial submission introducing fwctl Rust abstractions.

[1] https://lore.kernel.org/all/20250903221111.3866249-1-zhiw@nvidia.com/
[2] https://lore.kernel.org/r/20260629150156.3169384-1-zhiw@nvidia.com/
[3] https://lore.kernel.org/r/DJJW7X4ESDSM.QCVYK2FC7ZR3@kernel.org/
[4] https://lore.kernel.org/r/20260629103946.3117152-1-zhiw@nvidia.com/
[5] https://lore.kernel.org/r/20260624091758.1678092-1-zhiw@nvidia.com/
[6] https://lore.kernel.org/r/20260217204909.211793-1-zhiw@nvidia.com/
[7] https://lore.kernel.org/r/20260305190936.398590-1-zhiw@nvidia.com/
[8] https://lore.kernel.org/r/DJQ1KX0O60J7.Q3RUZ46V153O@kernel.org/
[9] https://lore.kernel.org/r/DJR76RV8NEKN.2MP5M9Z66U4TY@nvidia.com/
[10] https://lore.kernel.org/r/DJRH022OWTTK.1KPQDQHKG7CTF@garyguo.net/

Zhi Wang (1):
  rust: introduce abstractions for fwctl

 MAINTAINERS                     |   2 +
 drivers/fwctl/Kconfig           |  12 +
 rust/bindings/bindings_helper.h |   1 +
 rust/helpers/fwctl.c            |  17 +
 rust/helpers/helpers.c          |   3 +-
 rust/kernel/fwctl.rs            | 578 ++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs              |   2 +
 7 files changed, 614 insertions(+), 1 deletion(-)
 create mode 100644 rust/helpers/fwctl.c
 create mode 100644 rust/kernel/fwctl.rs


base-commit: d85845b64c0020b2812243a22fa79d57cc1c1e38
-- 
2.51.0

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

end of thread, other threads:[~2026-07-08 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 15:59 [PATCH v7 0/1] rust: introduce abstractions for fwctl Zhi Wang
2026-07-08 15:59 ` [PATCH v7 1/1] " Zhi Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox