[PATCH 00/14] Add Rust PCI SR-IOV support

Zhi Wang posted 14 patches 1 week, 2 days ago
There is a newer version of this series
Documentation/rust/index.rst             |   1 +
Documentation/rust/pci-sriov-pf-data.rst | 330 +++++++++++++++++++++
MAINTAINERS                              |   4 +
drivers/gpu/nova-core/driver.rs          |  34 ++-
drivers/pci/iov.c                        | 103 ++++++-
drivers/pci/pci-driver.c                 |   3 +-
drivers/pci/pci.h                        |   2 +
include/linux/pci.h                      |  44 +++
include/linux/rust_ffi.h                 |  88 ++++++
rust/bindings/bindings_helper.h          |   5 +
rust/kernel/interop.rs                   |   5 +-
rust/kernel/interop/ffi.rs               | 252 ++++++++++++++++
rust/kernel/pci.rs                       | 126 ++++++++
rust/kernel/pci/sriov.rs                 | 355 +++++++++++++++++++++++
rust/macros/ffi_vtable.rs                | 148 ++++++++++
rust/macros/lib.rs                       |  90 ++++++
samples/rust/Kconfig                     |  26 ++
samples/rust/Makefile                    |   2 +
samples/rust/rust_dma.rs                 |   1 +
samples/rust/rust_driver_auxiliary.rs    |   1 +
samples/rust/rust_driver_pci.rs          |   1 +
samples/rust/rust_driver_sriov.h         |  27 ++
samples/rust/rust_driver_sriov.rs        | 270 +++++++++++++++++
samples/rust/rust_driver_sriov_c_vf.c    |  61 ++++
24 files changed, 1972 insertions(+), 7 deletions(-)
create mode 100644 Documentation/rust/pci-sriov-pf-data.rst
create mode 100644 include/linux/rust_ffi.h
create mode 100644 rust/kernel/interop/ffi.rs
create mode 100644 rust/kernel/pci/sriov.rs
create mode 100644 rust/macros/ffi_vtable.rs
create mode 100644 samples/rust/rust_driver_sriov.h
create mode 100644 samples/rust/rust_driver_sriov.rs
create mode 100644 samples/rust/rust_driver_sriov_c_vf.c
[PATCH 00/14] Add Rust PCI SR-IOV support
Posted by Zhi Wang 1 week, 2 days ago
Rust PCI drivers need to enable and disable SR-IOV and share selected
PF-owned functionality with their VF drivers. The shared data must remain
valid while a VF driver is bound, including when the VF driver is in C.

This series builds on Peter Colberg's Rust PCI SR-IOV v3 series [1],
extending it with typed PF registration data and C FFI support. The
registration design follows Danilo Krummrich's Rust vGPU/VFIO PoC [2].
As the discussion on Rust/VFIO support is still ongoing [3], this series
supports both C and Rust sample VF drivers.

Add the PCI SR-IOV operations and callback, managed VF removal during PF
unbind, and typed PF registration data. A pinned registration publishes
the PF payload. Rust VFs borrow the typed data directly; C VFs use an
ABI-checked descriptor and generated C-to-Rust trampolines.

Include Rust and C VF samples and integrate the registration into
nova-core. Nova implements sriov_configure() and publishes PF-readiness
data before VFs are enabled. Document the sharing interface, its borrow
lifetimes and teardown ordering.

[1] https://lore.kernel.org/rust-for-linux/20260303-rust-pci-sriov-v3-0-4443c35f0c88@redhat.com/
[2] https://lore.kernel.org/nova-gpu/DLCRZLO06SIO.LS7TWQXIPZSQ@kernel.org/
[3] https://lore.kernel.org/nova-gpu/20260914121217.70fa0d93@shazbot.org/

John Hubbard (1):
  rust: pci: add is_virtfn(), to check for VFs

Peter Colberg (7):
  PCI: add driver flag to opt into disabling SR-IOV on remove()
  rust: pci: add {enable,disable}_sriov(), to control SR-IOV capability
  rust: pci: add vtable attribute to pci::Driver trait
  rust: pci: add bus callback sriov_configure(), to control SR-IOV from
    sysfs
  rust: pci: add is_physfn(), to check for PFs
  rust: pci: add num_vf(), to return number of VFs
  samples: rust: add Rust SR-IOV VF driver sample

Zhi Wang (6):
  rust: pci: add typed SR-IOV PF registration data
  rust: add C-to-Rust FFI descriptors and trampolines
  rust: pci: add C FFI support to typed SR-IOV PF registration data
  samples: rust: add C SR-IOV VF driver that calls into a Rust PF driver
  gpu: nova-core: publish typed SR-IOV PF data for VF drivers
  Documentation: rust: explain SR-IOV PF data sharing with VFs

 Documentation/rust/index.rst             |   1 +
 Documentation/rust/pci-sriov-pf-data.rst | 330 +++++++++++++++++++++
 MAINTAINERS                              |   4 +
 drivers/gpu/nova-core/driver.rs          |  34 ++-
 drivers/pci/iov.c                        | 103 ++++++-
 drivers/pci/pci-driver.c                 |   3 +-
 drivers/pci/pci.h                        |   2 +
 include/linux/pci.h                      |  44 +++
 include/linux/rust_ffi.h                 |  88 ++++++
 rust/bindings/bindings_helper.h          |   5 +
 rust/kernel/interop.rs                   |   5 +-
 rust/kernel/interop/ffi.rs               | 252 ++++++++++++++++
 rust/kernel/pci.rs                       | 126 ++++++++
 rust/kernel/pci/sriov.rs                 | 355 +++++++++++++++++++++++
 rust/macros/ffi_vtable.rs                | 148 ++++++++++
 rust/macros/lib.rs                       |  90 ++++++
 samples/rust/Kconfig                     |  26 ++
 samples/rust/Makefile                    |   2 +
 samples/rust/rust_dma.rs                 |   1 +
 samples/rust/rust_driver_auxiliary.rs    |   1 +
 samples/rust/rust_driver_pci.rs          |   1 +
 samples/rust/rust_driver_sriov.h         |  27 ++
 samples/rust/rust_driver_sriov.rs        | 270 +++++++++++++++++
 samples/rust/rust_driver_sriov_c_vf.c    |  61 ++++
 24 files changed, 1972 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/rust/pci-sriov-pf-data.rst
 create mode 100644 include/linux/rust_ffi.h
 create mode 100644 rust/kernel/interop/ffi.rs
 create mode 100644 rust/kernel/pci/sriov.rs
 create mode 100644 rust/macros/ffi_vtable.rs
 create mode 100644 samples/rust/rust_driver_sriov.h
 create mode 100644 samples/rust/rust_driver_sriov.rs
 create mode 100644 samples/rust/rust_driver_sriov_c_vf.c


base-commit: 34a8ecc902e907d7b0596a8d38b437e90eac0701
Re: [PATCH 00/14] Add Rust PCI SR-IOV support
Posted by Danilo Krummrich 1 week, 1 day ago
On Tue Sep 15, 2026 at 10:56 PM CEST, Zhi Wang wrote:
> Rust PCI drivers need to enable and disable SR-IOV and share selected
> PF-owned functionality with their VF drivers. The shared data must remain
> valid while a VF driver is bound, including when the VF driver is in C.
>
> This series builds on Peter Colberg's Rust PCI SR-IOV v3 series [1],
> extending it with typed PF registration data and C FFI support. The
> registration design follows Danilo Krummrich's Rust vGPU/VFIO PoC [2].
> As the discussion on Rust/VFIO support is still ongoing [3], this series
> supports both C and Rust sample VF drivers.

[...]

> [1] https://lore.kernel.org/rust-for-linux/20260303-rust-pci-sriov-v3-0-4443c35f0c88@redhat.com/
> [2] https://lore.kernel.org/nova-gpu/DLCRZLO06SIO.LS7TWQXIPZSQ@kernel.org/
> [3] https://lore.kernel.org/nova-gpu/20260914121217.70fa0d93@shazbot.org/
>
>  drivers/pci/iov.c                        | 103 ++++++-
>  drivers/pci/pci-driver.c                 |   3 +-
>  drivers/pci/pci.h                        |   2 +
>  include/linux/pci.h                      |  44 +++
>  include/linux/rust_ffi.h                 |  88 ++++++
>  rust/kernel/interop/ffi.rs               | 252 ++++++++++++++++
>  rust/kernel/pci.rs                       | 126 ++++++++
>  rust/kernel/pci/sriov.rs                 | 355 +++++++++++++++++++++++
>  rust/macros/ffi_vtable.rs                | 148 ++++++++++
>  rust/macros/lib.rs                       |  90 ++++++

Thanks for all the effort, Zhi! It is good to have a reference to see how this
turns out.

Unfortunately, this raises the same concerns I already shared in the other
thread in [2], plus additional ones:

  (1) This FFI layer is already more code than would be needed to abstract the
      vfio-pci driver API surface in Rust. In addition, it is also much more
      complex and error prone.

  (2) By creating a generic FFI layer to connect PF and VF drivers (which are
      technically the same driver project), we incentivise writing cross
      language drivers.

      When the panthor DRM driver was considering to (re-)write parts in Rust I
      very much objected to this, as it would have created an arbitrary FFI
      boundary within DRM (which for obvious reasons would be a maintainance
      nightmare).

      Now, this is not exactly the same, as it is not an arbitrary FFI boundary;
      it is well defined. But, it is still a workaround for a single driver
      project being split up in a Rust and in a C portion.

      The FFI surface is best kept at the subsystem level abstracting the driver
      facing APIs, which provides a defined and comparatively stable API
      surface.

For those reasons I don't want to add this to the PCI (Rust and C) core code,
i.e. I don't want to support a generic FFI layer between PF and VF drivers.

I really hope that we can find a way forward not having to end up doing this;
but if we really have to, we should stick to a nova project internal FFI layer
for this.

Thanks,
Danilo