linux-stable/drivers/vfio/pci
Jason Gunthorpe 1ef3342a93 vfio/pci: Fix vf_token mechanism when device-specific VF drivers are used
get_pf_vdev() tries to check if a PF is a VFIO PF by looking at the driver:

       if (pci_dev_driver(physfn) != pci_dev_driver(vdev->pdev)) {

However now that we have multiple VF and PF drivers this is no longer
reliable.

This means that security tests realted to vf_token can be skipped by
mixing and matching different VFIO PCI drivers.

Instead of trying to use the driver core to find the PF devices maintain a
linked list of all PF vfio_pci_core_device's that we have called
pci_enable_sriov() on.

When registering a VF just search the list to see if the PF is present and
record the match permanently in the struct. PCI core locking prevents a PF
from passing pci_disable_sriov() while VF drivers are attached so the VFIO
owned PF becomes a static property of the VF.

In common cases where vfio does not own the PF the global list remains
empty and the VF's pointer is statically NULL.

This also fixes a lockdep splat from recursive locking of the
vfio_group::device_lock between vfio_device_get_from_name() and
vfio_device_get_from_dev(). If the VF and PF share the same group this
would deadlock.

Fixes: ff53edf6d6 ("vfio/pci: Split the pci_driver code out of vfio_pci_core.c")
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/0-v3-876570980634+f2e8-vfio_vf_token_jgg@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2022-04-13 11:37:44 -06:00
..
hisilicon hisi_acc_vfio_pci: Use its own PCI reset_done error handler 2022-03-15 11:41:32 -06:00
mlx5 vfio/mlx5: Fix to not use 0 as NULL pointer 2022-03-09 10:29:40 -07:00
Kconfig hisi_acc_vfio_pci: add new vfio_pci driver for HiSilicon ACC devices 2022-03-15 11:34:08 -06:00
Makefile hisi_acc_vfio_pci: add new vfio_pci driver for HiSilicon ACC devices 2022-03-15 11:34:08 -06:00
trace.h vfio/pci: Cleanup license mess 2019-01-22 11:06:05 -07:00
vfio_pci.c vfio: Have the core code decode the VFIO_DEVICE_FEATURE ioctl 2022-03-03 12:54:43 +02:00
vfio_pci_config.c vfio/pci: Introduce vfio_pci_core.ko 2021-08-26 10:36:51 -06:00
vfio_pci_core.c vfio/pci: Fix vf_token mechanism when device-specific VF drivers are used 2022-04-13 11:37:44 -06:00
vfio_pci_igd.c vfio/pci: Resolve sparse endian warnings in IGD support 2021-12-21 12:30:31 -07:00
vfio_pci_intrs.c vfio/pci: Introduce vfio_pci_core.ko 2021-08-26 10:36:51 -06:00
vfio_pci_rdwr.c vfio/pci: Stub vfio_pci_vga_rw when !CONFIG_VFIO_PCI_VGA 2022-02-22 13:45:02 -07:00
vfio_pci_zdev.c Merge branches 'v5.15/vfio/spdx-license-cleanups', 'v5.15/vfio/dma-valid-waited-v3', 'v5.15/vfio/vfio-pci-core-v5' and 'v5.15/vfio/vfio-ap' into v5.15/vfio/next 2021-08-26 11:08:50 -06:00