lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251120084132.40f72ba4.zhiw@nvidia.com>
Date: Thu, 20 Nov 2025 08:41:32 +0200
From: Zhi Wang <zhiw@...dia.com>
To: Peter Colberg <pcolberg@...hat.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 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. :)

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

Powered by Openwall GNU/*/Linux Powered by OpenVZ