vfio-pci: Disable binding to PFs with SR-IOV enabled
Subsystems (3)
PATCH 1/1 vfio-pci: Disable binding to PFs with SR-IOV enabled
We expect to receive PFs with SR-IOV disabled, however some host drivers leave SR-IOV enabled at unbind. This puts us in a state where we can potentially assign both the PF and the VF, leading to both functionality as well as security concerns due to lack of managing the SR-IOV state as well as vendor dependent isolation from the PF to VF. If we were to attempt to actively disable SR-IOV on driver probe, we risk VF bound drivers blocking, potentially risking live lock scenarios. Therefore simply refuse to bind to PFs with SR-IOV enabled with a warning message indicating the issue. Users can resolve this by re-binding to the host driver and disabling SR-IOV before attempting to use the device with vfio-pci.
--- drivers/vfio/pci/vfio_pci.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/vfio/pci/vfio_pci.c +13 -0
@@ -1189,6 +1189,19 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (pdev->hdr_type !=PCI_HEADER_TYPE_NORMAL )return -EINVAL ; +/* +* Prevent binding to PFs with VFs enabled, this too easily allows +* userspace instance with VFs and PFs from the same device, which +* cannot work. Disabling SR-IOV here would initiate removing the +* VFs, which would unbind the driver, which is prone to blocking +* if that VF is also in use by vfio-pci. Just reject these PFs +* and let the user sort it out. +*/ +if (pci_num_vf (pdev)) { +pci_warn (pdev,"Cannot bind to PF with SR-IOV enabled\n" ); +return -EBUSY ; + } + group =vfio_iommu_group_get (&pdev->dev);if (!group)return -EINVAL ;
Quoted 12 lines · Alex Williamson
We expect to receive PFs with SR-IOV disabled, however some host drivers leave SR-IOV enabled at unbind. This puts us in a state where we can potentially assign both the PF and the VF, leading to both functionality as well as security concerns due to lack of managing the SR-IOV state as well as vendor dependent isolation from the PF to VF. If we were to attempt to actively disable SR-IOV on driver probe, we risk VF bound drivers blocking, potentially risking live lock scenarios. Therefore simply refuse to bind to PFs with SR-IOV enabled with a warning message indicating the issue. Users can resolve this by re-binding to the host driver and disabling SR-IOV before attempting to use the device with vfio-pci.
Quoted 1 line
Signed-off-by Alex Williamson <[email protected]>
Quoted 29 lines
--- drivers/vfio/pci/vfio_pci.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)drivers/vfio/pci/vfio_pci.c +13
-0@@ -1189,6 +1189,19 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (pdev->hdr_type !=PCI_HEADER_TYPE_NORMAL )return -EINVAL ; +/* +* Prevent binding to PFs with VFs enabled, this too easily allows +* userspace instance with VFs and PFs from the same device, which +* cannot work. Disabling SR-IOV here would initiate removing the +* VFs, which would unbind the driver, which is prone to blocking +* if that VF is also in use by vfio-pci. Just reject these PFs +* and let the user sort it out. +*/ +if (pci_num_vf (pdev)) { +pci_warn (pdev,"Cannot bind to PF with SR-IOV enabled\n" ); +return -EBUSY ; + } + group =vfio_iommu_group_get (&pdev->dev);if (!group)return -EINVAL ;
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 12 lines · Alex Williamson
We expect to receive PFs with SR-IOV disabled, however some host drivers leave SR-IOV enabled at unbind. This puts us in a state where we can potentially assign both the PF and the VF, leading to both functionality as well as security concerns due to lack of managing the SR-IOV state as well as vendor dependent isolation from the PF to VF. If we were to attempt to actively disable SR-IOV on driver probe, we risk VF bound drivers blocking, potentially risking live lock scenarios. Therefore simply refuse to bind to PFs with SR-IOV enabled with a warning message indicating the issue. Users can resolve this by re-binding to the host driver and disabling SR-IOV before attempting to use the device with vfio-pci.
Quoted 1 line
Signed-off-by Alex Williamson <[email protected]>
Signature · 1 line
Peter Xu