Re: [PATCH v2 10/10] samples: rust: add SR-IOV driver sample

From: Peter Colberg

Date: Tue Feb 17 2026 - 21:04:05 EST


Hi Dirk,

On Mon, Feb 16, 2026 at 09:27:44AM +0100, Dirk Behme wrote:
> Hi Peter,
>
> On 05.02.2026 21:59, Peter Colberg wrote:
> > Add a new SR-IOV driver sample that demonstrates how to enable and
> > disable the Single Root I/O Virtualization capability for a PCI device.
> >
> > The sample may be exercised using QEMU's 82576 (igb) emulation.
> >
> > Link: https://www.qemu.org/docs/master/system/devices/igb.html
> > Signed-off-by: Peter Colberg <pcolberg@xxxxxxxxxx>
> > ---
> > Changes in v2:
> > - Use "kernel vertical" style on imports.
> > - Demonstrate how to reach driver data of PF device from VF device.
> > ---
> > MAINTAINERS | 1 +
> > samples/rust/Kconfig | 11 ++++
> > samples/rust/Makefile | 1 +
> > samples/rust/rust_driver_sriov.rs | 127 ++++++++++++++++++++++++++++++++++++++
> > 4 files changed, 140 insertions(+)
> >
> ...
> > diff --git a/samples/rust/rust_driver_sriov.rs b/samples/rust/rust_driver_sriov.rs
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..84d057629c7b03d743179a4e05ccc092f814bf6b
> > --- /dev/null
> > +++ b/samples/rust/rust_driver_sriov.rs
> > @@ -0,0 +1,127 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +//! Rust SR-IOV driver sample based on QEMU's 82576 ([igb]) emulation.
> > +//!
> > +//! To make this driver probe, QEMU must be run with `-device igb`.
> > +//!
> > +//! Further, enable [vIOMMU] with interrupt remapping using, e.g.,
> > +//!
> > +//! `-M q35,accel=kvm,kernel-irqchip=split -device intel-iommu,intremap=on,caching-mode=on`
> > +//!
> > +//! and append `intel_iommu=on` to the guest kernel arguments.
> > +//!
> > +//! [igb]: https://www.qemu.org/docs/master/system/devices/igb.html
> > +//! [vIOMMU]: https://wiki.qemu.org/Features/VT-d
> > +
> > +use kernel::{
> > + device::Core,
> > + pci,
> > + prelude::*,
> > + sync::aref::ARef, //
> > +};
> > +
> > +use core::any::TypeId;
> > +
> > +#[pin_data(PinnedDrop)]
> > +struct SampleDriver {
> > + pdev: ARef<pci::Device>,
> > + private: TypeId,
> > +}
> > +
> > +kernel::pci_device_table!(
> > + PCI_TABLE,
> > + MODULE_PCI_TABLE,
> > + <SampleDriver as pci::Driver>::IdInfo,
> > + [
> > + // E1000_DEV_ID_82576
> > + (pci::DeviceId::from_id(pci::Vendor::INTEL, 0x10c9), ()),
> > + // E1000_DEV_ID_82576_VF
> > + (pci::DeviceId::from_id(pci::Vendor::INTEL, 0x10ca), ())
> > + ]
> > +);
> > +
> > +#[vtable]
> > +impl pci::Driver for SampleDriver {
> > + type IdInfo = ();
> > +
> > + const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
> > +
> > + fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {
> > + pin_init::pin_init_scope(move || {
> > + dev_info!(
> > + pdev.as_ref(),
>
> The `as_ref()` in the `dev_*()` prints can be dropped. Example:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/samples/rust/rust_driver_pci.rs?id=600de1c008b2302b56d69ff27d12a9d8d14892ac

Thank you for the pointer, dropped in v3.

Peter

>
> Best regards
>
> Dirk
>