[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <zqogmf4mnadxkthhzyfhzesk3pdafnr7jqf5i22ahkdo5ugt63@gvb5xhgjylku>
Date: Wed, 1 Oct 2025 10:30:43 +1000
From: Alistair Popple <apopple@...dia.com>
To: John Hubbard <jhubbard@...dia.com>
Cc: Danilo Krummrich <dakr@...nel.org>,
Alexandre Courbot <acourbot@...dia.com>, Joel Fernandes <joelagnelf@...dia.com>,
Timur Tabi <ttabi@...dia.com>, Zhi Wang <zhiw@...dia.com>, Surath Mitra <smitra@...dia.com>,
David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
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>, nouveau@...ts.freedesktop.org, linux-pci@...r.kernel.org,
rust-for-linux@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 1/2] rust: pci: add is_virtfn(), to check for VFs
On 2025-10-01 at 08:07 +1000, John Hubbard <jhubbard@...dia.com> wrote...
> Add a method to check if a PCI device is a Virtual Function (VF). This
> allows Rust drivers to determine whether a device is a VF created
> through SR-IOV. This is required in order to implement VFIO, because
> drivers such as NovaCore must only bind to Physical Functions (PFs) or
> regular PCI devices. The VFs must be left unclaimed, so that a VFIO
> kernel module can claim them.
>
> is_virtfn() returns true if the device's is_virtfn flag is set, matching
> the behavior of the C code.
Seems fine to me so please add:
Reviewed-by: Alistair Popple <apopple@...dia.com>
> Signed-off-by: John Hubbard <jhubbard@...dia.com>
> ---
> rust/kernel/pci.rs | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> index 7fcc5f6022c1..476b80f05905 100644
> --- a/rust/kernel/pci.rs
> +++ b/rust/kernel/pci.rs
> @@ -496,6 +496,12 @@ pub fn resource_start(&self, bar: u32) -> Result<bindings::resource_size_t> {
> Ok(unsafe { bindings::pci_resource_start(self.as_raw(), bar.try_into()?) })
> }
>
> + /// Returns true if this device is a Virtual Function (VF).
> + pub fn is_virtfn(&self) -> bool {
> + // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
> + unsafe { (*self.as_raw()).is_virtfn() != 0 }
> + }
> +
> /// Returns the size of the given PCI bar resource.
> pub fn resource_len(&self, bar: u32) -> Result<bindings::resource_size_t> {
> if !Bar::index_is_valid(bar) {
> --
> 2.51.0
>
Powered by blists - more mailing lists