From: "Danilo Krummrich" <dakr@kernel.org>
To: "Jason Gunthorpe" <jgg@nvidia.com>
Cc: "John Hubbard" <jhubbard@nvidia.com>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
"Timur Tabi" <ttabi@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Zhi Wang" <zhiw@nvidia.com>, "Surath Mitra" <smitra@nvidia.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Alex Williamson" <alex.williamson@redhat.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
nouveau@lists.freedesktop.org, linux-pci@vger.kernel.org,
rust-for-linux@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] rust: pci: skip probing VFs if driver doesn't support VFs
Date: Fri, 03 Oct 2025 02:57:53 +0200 [thread overview]
Message-ID: <DD8A27ESH61G.306ZAIGZCMJ97@kernel.org> (raw)
In-Reply-To: <20251002234010.GI3299207@nvidia.com>
On Fri Oct 3, 2025 at 1:40 AM CEST, Jason Gunthorpe wrote:
> On Thu, Oct 02, 2025 at 11:32:44PM +0200, Danilo Krummrich wrote:
>
>> So, when we call pdev.physfn().drvdata_borrow::<NovaCore>() the checks are
>> included already.
>
> I'm not keen on hiding this reasoning inside an physfn() accessor like
> this. ie one that returns a Device<Bound>. The reasoning for this is
> tricky and special. We have enough cases where physfn won't be a bound
> driver. I think it is big stretch just to declare that unconditionally
> safe.
In this example physfn() would return a &pci::Device<Bound>.
This is what I mentioned previously; I want the subsystem to guarantee (at least
under certain circumstances) that if the VF device is bound that the PF device
must be bound as well.
> There is a reason pci_iov_get_pf_drvdata() has such a big comment..
>
> So I'd rather see you follow the C design and have an explicit helper
> function to convert a VF bound device to a PF bound device
Well, this is exactly what physfn() does (with the precondition that we can get
the guarantee from the subsystem).
> and check
> the owner, basically split up pci_iov_get_pf_drvdata() into a part to
> get the struct device and an inline to get the drvdata. Rust still has an
> ops pointer it can pass in so it can be consistent with the C code
Which ops pointer are you referring to? Do you mean the struct pci_driver
pointer? If so, no we can't access this one. We could make it accessible, but it
would result into horrible code, wouldn't make it possible to implement the
check generically for any device (which we need anyways) and would have some
other bad implications.
I try to be as consistent as possible with C code, but sometimes it just doesn't
fit at all and would even hurt. This is one of those cases.
To give at least some background: A driver structure (like struct pci_driver) is
embedded in a module structure, which is a global static and intentionally not
directly accessible for drivers.
Even if we'd make it accessible, the driver field within a module structure
depends on the exact implementation, i.e. it depends on whether a module is
declared "by hand", or whether it is generated by a module_driver!() macro (e.g.
module_pci_driver!().
It probably also helps to have a look at samples/rust/rust_driver_auxiliary.rs,
which open codes driver registrations, since it registers two drivers in the
same module for the purpose of illustrating an auxiliary connection, i.e. it
doesn't use a module_driver!() macro.
The struct struct auxiliary_driver resides within the
driver::Registration<auxiliary::Adapter<T>>, where driver::Registration is a
generic type for registering drivers, auxiliary::Adapter defines the auxiliary
specific bits for this registration and T is the driver specific type that
implements the auxiliary::Driver trait, containing the bus callbacks etc.
> even if it does another check inside its drvdata_borrow.
It's the exact same check; just a better fitting implementation.
I.e. instead of checking a pointer which is hard to access, we check if the type
ID we gave to the device matches the driver specific type (the T in
driver::Registration<auxiliary::Adapter<T>>).
Semantically, there is no difference, but it results in less cumbersome and more
flexible code.
next prev parent reply other threads:[~2025-10-03 0:58 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-02 2:00 [PATCH v2 0/2] rust: pci: don't probe() VFs in nova-core John Hubbard
2025-10-02 2:00 ` [PATCH v2 1/2] rust: pci: skip probing VFs if driver doesn't support VFs John Hubbard
2025-10-02 11:49 ` Danilo Krummrich
2025-10-02 12:11 ` Jason Gunthorpe
2025-10-02 12:18 ` Danilo Krummrich
2025-10-02 12:39 ` Jason Gunthorpe
2025-10-02 13:03 ` Danilo Krummrich
2025-10-02 13:56 ` Jason Gunthorpe
2025-10-02 15:11 ` Danilo Krummrich
2025-10-02 15:23 ` Jason Gunthorpe
2025-10-02 16:05 ` Danilo Krummrich
2025-10-02 17:05 ` Jason Gunthorpe
2025-10-02 17:37 ` Danilo Krummrich
2025-10-02 17:40 ` Danilo Krummrich
2025-10-02 17:49 ` John Hubbard
2025-10-02 18:05 ` Jason Gunthorpe
2025-10-02 18:09 ` John Hubbard
2025-10-02 18:32 ` Jason Gunthorpe
2025-10-02 18:17 ` Danilo Krummrich
2025-10-02 18:31 ` Jason Gunthorpe
2025-10-02 18:42 ` Danilo Krummrich
2025-10-02 18:56 ` Jason Gunthorpe
2025-10-02 19:36 ` Danilo Krummrich
2025-10-02 21:04 ` Jason Gunthorpe
2025-10-02 21:14 ` Danilo Krummrich
2025-10-02 21:32 ` Danilo Krummrich
2025-10-02 23:40 ` Jason Gunthorpe
2025-10-03 0:57 ` Danilo Krummrich [this message]
2025-10-03 11:52 ` Jason Gunthorpe
2025-10-02 17:56 ` Jason Gunthorpe
2025-10-02 18:55 ` Danilo Krummrich
2025-10-02 2:00 ` [PATCH v2 2/2] gpu: nova-core: declare that VFs are not (yet) supported John Hubbard
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=DD8A27ESH61G.306ZAIGZCMJ97@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=alex.williamson@redhat.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=joelagnelf@nvidia.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=smitra@nvidia.com \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=zhiw@nvidia.com \
/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;
as well as URLs for NNTP newsgroup(s).