Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Zhi Wang <zhiw@nvidia.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: Alexandre Courbot <acourbot@nvidia.com>,
	<rust-for-linux@vger.kernel.org>, <linux-pci@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <aliceryhl@google.com>,
	<bhelgaas@google.com>, <kwilczynski@kernel.org>,
	<ojeda@kernel.org>, <boqun@kernel.org>, <gary@garyguo.net>,
	<bjorn3_gh@protonmail.com>, <lossin@kernel.org>,
	<a.hindborg@kernel.org>, <tmgross@umich.edu>,
	<markus.probst@posteo.de>, <cjia@nvidia.com>, <smitra@nvidia.com>,
	<ankita@nvidia.com>, <aniketa@nvidia.com>, <kwankhede@nvidia.com>,
	<targupta@nvidia.com>, <kjaju@nvidia.com>, <alkumar@nvidia.com>,
	<joelagnelf@nvidia.com>, <jhubbard@nvidia.com>,
	<zhiwang@kernel.org>, <daniel.almeida@collabora.com>,
	<tamird@kernel.org>, <work@onurozkan.dev>
Subject: Re: [PATCH v8 1/1] rust: pci: add extended capability and SR-IOV support
Date: Wed, 26 Aug 2026 21:53:51 +0300	[thread overview]
Message-ID: <20260826215351.07940b1d@inno-dell> (raw)
In-Reply-To: <DKX57FPE7DKY.1MVQBHYXKFAWT@kernel.org>

On Mon, 24 Aug 2026 13:38:05 +0200
"Danilo Krummrich" <dakr@kernel.org> wrote:

> On Mon Aug 24, 2026 at 10:12 AM CEST, Alexandre Courbot wrote:

snip.

> >> +/// SR-IOV register layout per PCIe spec (64 bytes starting at
> >> cap offset). +#[repr(C)]
> >> +#[derive(FromBytes, IntoBytes)]
> >> +pub struct ExtSriovRegs {
> >> +    /// Extended capability header.
> >> +    _header: u32,
> >> +    /// SR-IOV capabilities.
> >> +    pub cap: u32,
> >> +    /// SR-IOV control.
> >> +    pub ctrl: u16,  
> 
> Why is this public?
> 

This is identical to register definition layout in the PCI spec.
And it is a straight-forward idea.

Do we prefer to:

a. keep the complete register definition layout here, while only expose
the ones that allow the user to access.

or

b. only keep the allowlist of registers in a enum(offset)?

> >> +    /// SR-IOV status.
> >> +    pub status: u16,  
> 
> Why do drivers need to read this directly?
> 
> >> +    /// Initial VFs.
> >> +    pub initial_vfs: u16,
> >> +    /// Total VFs.
> >> +    pub total_vfs: u16,
> >> +    /// Number of VFs.
> >> +    pub num_vfs: u16,  
> 
> Why do we need to mess with this? This should only ever be written
> through pci_enable_sriov()?
> 
> >> +    /// Function dependency link.
> >> +    pub func_dep_link: u8,
> >> +    _reserved_0: u8,
> >> +    /// First VF offset.
> >> +    pub vf_offset: u16,
> >> +    /// VF stride.
> >> +    pub vf_stride: u16,  
> 
> Those two are read by the PCI core in pci_iov_set_numvfs() and uses
> them internally. Why do we need a driver API for those?
> 
> Why can't we use pci_iov_virtfn_devfn()?
> 

GSP VF_INFO requires the first VF offset to be
filled [1], it requires the raw value from the registers instead of the
calculated one in pci_iov_virtfn_devfn().

[1] https://lore.kernel.org/all/20260804170045.902069-2-zhiw@nvidia.com/

> >> +    _reserved_1: u16,
> >> +    /// VF device ID.
> >> +    pub vf_device_id: u16,
> >> +    /// Supported page sizes.
> >> +    pub supported_page_sizes: u32,
> >> +    /// System page size.
> >> +    pub system_page_size: u32,  
> 
> Isn't this already taken care of by the PCI core? Do we need to
> expose this?
> 
> >> +    /// VF BARs (BAR0–BAR5).
> >> +    pub vf_bar: [u32; NUM_VF_BARS],  
> >
> > Now that we have an iterator method, we can make this member
> > private. I'd even say we should as making this public enables the
> > kinds of invalid accesses we built the iterator to avoid.  
> 
> Agreed.
> 
> >> +    /// VF migration state array offset.
> >> +    pub migration_state: u32,  
> 
> Do we need this? Isn't this obsolete?
> 
> >     pub fn vf_bars(&self) -> Result<impl Iterator<Item =
> > ExtSriovVfBar>> { let slots: [u32; NUM_VF_BARS] =
> >             core::array::from_fn(|slot| crate::io_read!(*self,
> > .vf_bar[panic: slot])); let mut slots = slots.into_iter();
> >         let mut bars = [None; NUM_VF_BARS];
> >         let mut count = 0;
> >
> >         while let Some(low) = slots.next().map(VfBarLow::from) {
> >             if low.io_space() {
> >                 return Err(EINVAL);
> >             }
> >
> >             let low_address = u64::from(low.address()) <<
> > VfBarLow::ADDRESS_SHIFT; let bar = match low.memory_type()? {
> >                 VfBarMemoryType::Bits64 => ExtSriovVfBar {
> >                     address:
> > (u64::from(slots.next().ok_or(EINVAL)?) << 32) | low_address,
> > is_64bit: true, },
> >                 VfBarMemoryType::Bits32 => ExtSriovVfBar {
> >                     address: low_address,
> >                     is_64bit: false,
> >                 },
> >             };
> >
> >             bars[count] = Some(bar);
> >             count += 1;
> >         }
> >
> >         Ok(bars.into_iter().flatten())
> >     }
> >
> > With this you don't need `ExtSriovVfBars` at all, which removes a
> > bit (almost 50 LoCs!) of code.  
> 
> LGTM, thanks for improving this.


  reply	other threads:[~2026-08-26 18:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18  8:46 [PATCH v8 0/1] Rust PCI capability infrastructure and SR-IOV support Zhi Wang
2026-08-18  8:46 ` [PATCH v8 1/1] rust: pci: add extended capability " Zhi Wang
2026-08-18  8:55   ` sashiko-bot
2026-08-24  8:12   ` Alexandre Courbot
2026-08-24 10:48     ` Gary Guo
2026-08-24 11:14       ` Alexandre Courbot
2026-08-24 11:59         ` Gary Guo
2026-08-24 15:21           ` Alexandre Courbot
2026-08-24 15:46             ` Gary Guo
2026-08-24 16:25               ` Gary Guo
2026-08-25  2:57                 ` Alexandre Courbot
2026-08-24 11:38     ` Danilo Krummrich
2026-08-26 18:53       ` Zhi Wang [this message]
2026-08-26 11:24   ` Alexandre Courbot
2026-08-26 11:32     ` Danilo Krummrich
2026-08-26 11:44       ` Miguel Ojeda
2026-08-26 13:36         ` Danilo Krummrich
2026-08-26 14:09           ` Miguel Ojeda
2026-08-26 13:32       ` Alexandre Courbot
2026-08-26 11:33     ` Zhi Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260826215351.07940b1d@inno-dell \
    --to=zhiw@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=alkumar@nvidia.com \
    --cc=aniketa@nvidia.com \
    --cc=ankita@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=cjia@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=kjaju@nvidia.com \
    --cc=kwankhede@nvidia.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=markus.probst@posteo.de \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=smitra@nvidia.com \
    --cc=tamird@kernel.org \
    --cc=targupta@nvidia.com \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    --cc=zhiwang@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox