]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
vfio/pci: Fix vf_token mechanism when device-specific VF drivers are used
authorJason Gunthorpe <jgg@nvidia.com>
Wed, 13 Apr 2022 13:10:36 +0000 (10:10 -0300)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 27 Apr 2022 10:00:52 +0000 (12:00 +0200)
commit1a5a55cd76291929577e7934e2ab314d40999a3d
tree6bdd6503dae2564e88f025714d0ee22e43455053
parent2297eae15bae6c6e3bf28ee6415f487c1d7a7c5c
vfio/pci: Fix vf_token mechanism when device-specific VF drivers are used

BugLink: https://bugs.launchpad.net/bugs/1969857
[ Upstream commit 1ef3342a934e235aca72b4bcc0d6854d80a65077 ]

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: ff53edf6d6ab ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/vfio/pci/vfio_pci_core.c
include/linux/vfio_pci_core.h