[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aR84jHNj0rhNRbaK@earendel>
Date: Thu, 20 Nov 2025 10:49:32 -0500
From: Peter Colberg <pcolberg@...hat.com>
To: Zhi Wang <zhiw@...dia.com>
Cc: Danilo Krummrich <dakr@...nel.org>, Bjorn Helgaas <bhelgaas@...gle.com>,
Krzysztof Wilczyński <kwilczynski@...nel.org>,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Abdiel Janulgue <abdiel.janulgue@...il.com>,
Daniel Almeida <daniel.almeida@...labora.com>,
Robin Murphy <robin.murphy@....com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Dave Ertman <david.m.ertman@...el.com>,
Ira Weiny <ira.weiny@...el.com>, Leon Romanovsky <leon@...nel.org>,
linux-pci@...r.kernel.org, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org,
Alexandre Courbot <acourbot@...dia.com>,
Alistair Popple <apopple@...dia.com>,
Joel Fernandes <joelagnelf@...dia.com>,
John Hubbard <jhubbard@...dia.com>, Jason Gunthorpe <jgg@...pe.ca>
Subject: Re: [PATCH 8/8] samples: rust: add SR-IOV driver sample
On Thu, Nov 20, 2025 at 08:41:32AM +0200, Zhi Wang wrote:
> On Wed, 19 Nov 2025 17:19:12 -0500
> Peter Colberg <pcolberg@...hat.com> 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.
> >
>
> snip
>
> > +
> > + fn sriov_configure(pdev: &pci::Device<Core>, nr_virtfn: i32) ->
> > Result<i32> {
> > + assert!(pdev.is_physfn());
> > +
> > + if nr_virtfn == 0 {
> > + dev_info!(
> > + pdev.as_ref(),
> > + "Disable SR-IOV (PCI ID: {}, 0x{:x}).\n",
> > + pdev.vendor_id(),
> > + pdev.device_id()
> > + );
> > + pdev.disable_sriov();
> > + } else {
> > + dev_info!(
> > + pdev.as_ref(),
> > + "Enable SR-IOV (PCI ID: {}, 0x{:x}).\n",
> > + pdev.vendor_id(),
> > + pdev.device_id()
> > + );
> > + pdev.enable_sriov(nr_virtfn)?;
> > + }
> > +
>
> IMO, it would be nice to simply demostrate how to reach the driver data
> structure (struct SampleDriver) and its members (I think accessing one
> dummy member in the SampleDriver is good enough, not something fancy),
> which I believe quite many of the drivers need to do so and they can
> take this as the kernel recommended approach instead of inventing
> something new differently. :)
Thanks for the suggestion. I added a `private` member to SampleDriver,
similar to the rust_driver_auxiliary sample, and extended the VF-only
path of probe() to demonstrate how to reach the driver data of the PF
device from a VF device.
Peter
>
> Z.
>
> > + assert_eq!(pdev.num_vf(), nr_virtfn);
> > + Ok(nr_virtfn)
> > + }
> > +}
> > +
> > +#[pinned_drop]
> > +impl PinnedDrop for SampleDriver {
> > + fn drop(self: Pin<&mut Self>) {
> > + dev_info!(self.pdev.as_ref(), "Remove Rust SR-IOV driver
> > sample.\n");
> > + }
> > +}
> > +
> > +kernel::module_pci_driver! {
> > + type: SampleDriver,
> > + name: "rust_driver_sriov",
> > + authors: ["Peter Colberg"],
> > + description: "Rust SR-IOV driver",
> > + license: "GPL v2",
> > +}
> >
>
Powered by blists - more mailing lists