Re: [PATCH 7/8] rust: pci: add physfn(), to return PF device for VF device

Jason Gunthorpe
2025-11-24T14:00:02Z

On Sun, Nov 23, 2025 at 11:43:08AM +1300, Danilo Krummrich wrote:
> On Sun Nov 23, 2025 at 5:16 AM NZDT, Jason Gunthorpe wrote:
> > I think to make progress along this line you need to still somehow
> > validate that the PF driver is working right, either by checking that
> > the driver is bound to a rust driver somehow or using the same
> > approach as the core helper.
>
> Do you refer to the
>
> if (pf_dev->driver != pf_driver)
>
> check? If so, that's (in a slightly different form) already part of the generic
> Device::drvdata() accessor.

Yeah, but by that point it has already returned a bound device pointer
without proving it is safe to do so..

If you check the flag you are proposing below then it would be OK:

> > I'm not sure the idea to force all drivers to do disable sriov is
> > going to be easy, and I'd rather see rust bindings progress without
> > opening such a topic..
>
> I'm sorry, I should have mentioned what I actually propose:
>
> My idea would be to provide a bool in struct pci_driver, which, if set,
> guarantees that all VFs are unbound when the PF is unbound.
>
> With this bool being set, the PCI bus can provide the guarantee that VF bound
> implies PF bound; the Rust accessor can then leverage this guarantee.
>
> This can also be leveraged by the C code, where we could have a separate
> accessor that checks the bool rather than askes the driver to promise that the
> PF is bound, which pci_iov_get_pf_drvdata() does.
>
> (Although I have to admit that without the additional type system capabilities
> we have in Rust, it is not that big of an improvement.)

This seems like it has a decent chance of succeeding..

Though as I said in my other email, you'd probably want a version
where there is WARN_ON if that common code is actually triggered as it
would be a driver bug to misorder its destruction.

Jason