Re: [PATCH v2 1/2] rust: pci: skip probing VFs if driver doesn't support VFs

Jason Gunthorpe
2025-10-02T18:56:29Z

On Thu, Oct 02, 2025 at 08:42:58PM +0200, Danilo Krummrich wrote:
> On 10/2/25 8:31 PM, Jason Gunthorpe wrote:
> > This exactly how this function is used.
> >
> > The core PF driver provides an API:
> >
> > struct mlx5_core_dev *mlx5_vf_get_core_dev(struct pci_dev *pdev)
> >
> > Which takes in the VF as pdev and internally it invokes:
> >
> > mdev = pci_iov_get_pf_drvdata(pdev, &mlx5_core_driver);
>
> Oh, I see, that makes sense then. Thanks for clarifying. I think I already had
> in mind how this would look like in the Rust abstraction, and there we don't
> need pci_iov_get_pf_drvdata() to achieve the same thing.

I'm skeptical, there is nothing about rust that should avoid having to
us pci_iov_get_pf_drvdata().. It does a number of safety checks
related to the linux driver model that are not optional.

Don't forget in linux you actually can bind VFIO to the PF, start
SRIOV and then bind VFs to other drivers which then fail
pci_iov_get_pf_drvdata(). Blindly converting a struct device to an
instance memory without this check will be buggy.

> Yes, I already thought about this. In the context of adding support for SR-IOV
> in the Rust abstractions I'm planning on sending an RFC to let the subsystem
> provide this guarantee instead (at least under certain conditions).

Certain conditions may be workable, some drivers seem to have
preferences not to call disable, though I think that is wrong :\

Jason