Skip to content

Commit 7487d8d

Browse files
Alex Williamsonawilliam
authored andcommitted
vfio/pci: Require vfio_device_ops.name
vfio-pci-core code makes use of the vfio_device_ops.name field in order to set a default driver_override for VFs created on a user-owned PF. This avoids default driver matching, which might otherwise bind those VFs to native drivers. The mechanism for this currently uses kasprintf(), which will set driver_override to the literal "(null)" if name is NULL. This is effective in sequestering the device, but presents a challenging debug situation to differentiate driver_override being set to "(null)" versus being NULL and interpreted as "(null)" via the sysfs show attribute. There's also a tree-wide effort to convert to generic driver_override support, where passing NULL will generate an error, resulting in a WARN_ON without setting any driver_override. All drivers making use of vfio-pci-core already set a driver name, therefore by requiring this behavior, all of these corner cases are rendered moot. This is expected to have no impact on current in-kernel drivers. Suggested-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Alex Williamson <alex.williamson@nvidia.com> Reviewed-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20260331202443.2598404-1-alex.williamson@nvidia.com Signed-off-by: Alex Williamson <alex@shazbot.org>
1 parent ad6ed97 commit 7487d8d

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/vfio/pci/vfio_pci_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,10 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev)
21392139
if (WARN_ON(vdev != dev_get_drvdata(dev)))
21402140
return -EINVAL;
21412141

2142+
/* Drivers must set a name. Required for sequestering SR-IOV VFs */
2143+
if (WARN_ON(!vdev->vdev.ops->name))
2144+
return -EINVAL;
2145+
21422146
if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL)
21432147
return -EINVAL;
21442148

0 commit comments

Comments
 (0)