public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] rust: introduce abstractions for fwctl
@ 2026-01-22 20:42 Zhi Wang
  2026-01-22 20:42 ` [PATCH v2 1/2] " Zhi Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Zhi Wang @ 2026-01-22 20:42 UTC (permalink / raw)
  To: rust-for-linux, linux-pci, linux-kernel
  Cc: dakr, aliceryhl, bhelgaas, kwilczynski, ojeda, alex.gaynor,
	boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, tmgross,
	markus.probst, helgaas, cjia, smitra, ankita, aniketa, kwankhede,
	targupta, acourbot, joelagnelf, 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 patch introduces a Rust abstraction over the fwctl subsystem,
providing safe and idiomatic bindings.

The new `fwctl` module allows Rust drivers to integrate with the existing
C-side fwctl core through a typed trait interface. It provides:

  - `Operations` trait — defines driver-specific operations such as
    `open_uctx()`, `close_uctx()`, `info()`, and `fw_rpc()`.  
    Each Rust driver implements this trait to describe its own per-FD
    user-context behavior and RPC handling.

  - `UserCtx<T>` — a generic wrapper around `struct fwctl_uctx`
    embedding driver-specific context data, providing safe conversion
    from raw C pointers and access to the parent device.

  - `Registration<T>` — safe registration and automatic unregistration
    of `struct fwctl_device` objects using the kernel's device model.

  - `VTable<T>` — a static vtable bridging C callbacks and Rust
    trait methods, ensuring type safety across the FFI boundary.

`rust/kernel/lib.rs` is updated to conditionally include this module
under `CONFIG_FWCTL`.

The repo with the patches can be found at [2].

v2:

- Don't open fwctl_put(). Add a rust helper. (Jason/Danilo)
- Wrap Registration with Devres to guarantee proper lifetime management.
  (Jason/Danilo)
- Rename FwctlOps to Operations, FwctlUserCtx to UserCtx, FwctlDevice to
  Device. (Danilo)
- Use fwctl::DeviceType enum instead of raw u32 for DEVICE_TYPE. (Danilo)
- Change fwctl_uctx field in UserCtx to Opaque<bindings::fwctl_uctx> and
  make it private. (Danilo)
- Provide Deref and DerefMut implementations for UserCtx::uctx. (Danilo)
- Add UserCtx::parent_device_from_raw() to simplify parent device access.
- Use cast() and cast_mut() instead of manual pointer casts. (Danilo)
- Implement AlwaysRefCounted for Device and use ARef<Device> in
  Registration. (Danilo)
- Add rust_helper_fwctl_get() for reference counting.
- Improve safety comments for slice::from_raw_parts_mut() in
  fw_rpc_callback. (Danilo)
- Convert imports to vertical style.
- Fix all clippy warnings.

v1:

- Initial submission introducing fwctl Rust abstractions.

[1] https://lore.kernel.org/all/20250903221111.3866249-1-zhiw@nvidia.com/
[2] https://github.com/zhiwang-nvidia/driver-core/tree/fwctl-rust-abstraction-v2

Zhi Wang (2):
  rust: introduce abstractions for fwctl
  samples: rust: fwctl: add sample code for fwctl

 drivers/fwctl/Kconfig             |  12 +
 include/uapi/fwctl/fwctl.h        |   1 +
 rust/bindings/bindings_helper.h   |   1 +
 rust/helpers/fwctl.c              |  17 ++
 rust/helpers/helpers.c            |   3 +-
 rust/kernel/fwctl.rs              | 456 ++++++++++++++++++++++++++++++
 rust/kernel/lib.rs                |   2 +
 samples/rust/Kconfig              |  11 +
 samples/rust/Makefile             |   1 +
 samples/rust/rust_driver_fwctl.rs | 136 +++++++++
 10 files changed, 639 insertions(+), 1 deletion(-)
 create mode 100644 rust/helpers/fwctl.c
 create mode 100644 rust/kernel/fwctl.rs
 create mode 100644 samples/rust/rust_driver_fwctl.rs

-- 
2.51.0


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

end of thread, other threads:[~2026-01-28 17:40 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-22 20:42 [PATCH v2 0/2] rust: introduce abstractions for fwctl Zhi Wang
2026-01-22 20:42 ` [PATCH v2 1/2] " Zhi Wang
2026-01-22 21:17   ` Joel Fernandes
2026-01-23 10:25     ` Zhi Wang
2026-01-26 17:48   ` Gary Guo
2026-01-27 19:59     ` Zhi Wang
2026-01-26 18:19   ` Jason Gunthorpe
2026-01-27 19:57     ` Zhi Wang
2026-01-27 20:07       ` Danilo Krummrich
2026-01-28  0:04         ` Jason Gunthorpe
2026-01-28  1:21           ` Danilo Krummrich
2026-01-28 13:20             ` [PATCH v2 1/2] rust: introduce abstractions for fwctlg Jason Gunthorpe
2026-01-28 14:01               ` Danilo Krummrich
2026-01-28 14:59                 ` Jason Gunthorpe
2026-01-28 15:49                   ` Danilo Krummrich
2026-01-28 15:56                     ` Jason Gunthorpe
2026-01-28 16:35                       ` Danilo Krummrich
2026-01-28 16:39                         ` Jason Gunthorpe
2026-01-28 17:26                           ` Zhi Wang
2026-01-28 17:30                         ` Zhi Wang
2026-01-28 17:39                           ` Jason Gunthorpe
2026-01-28 17:40                           ` Danilo Krummrich
2026-01-28 11:36         ` [PATCH v2 1/2] rust: introduce abstractions for fwctl Zhi Wang
2026-01-28 11:41           ` Danilo Krummrich
2026-01-27 20:09       ` Danilo Krummrich
2026-01-22 20:42 ` [PATCH v2 2/2] samples: rust: fwctl: add sample code " Zhi Wang
2026-01-22 20:58   ` Jason Gunthorpe
2026-01-22 21:06     ` Danilo Krummrich
2026-01-22 21:16       ` John Hubbard
2026-01-23 10:23         ` Zhi Wang
2026-01-26 17:59   ` Gary Guo
2026-01-22 21:32 ` [PATCH v2 0/2] rust: introduce abstractions " Danilo Krummrich
2026-01-23 10:14   ` Zhi Wang

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