aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2018-07-12 18:33:04 -0400
committerAlex Williamson <alex.williamson@redhat.com>2018-08-06 14:23:19 -0400
commit0dd0e297f0ec780b6b3484ba38b27d18c8ca7af9 (patch)
tree7ca25cc8284c0a53355f710582cc3b66f2f1905a
parent544c05a60aef7de34ef60eebaf46582ca2bf05f9 (diff)
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. Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
-rw-r--r--drivers/vfio/pci/vfio_pci.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 7fe2748ba101..9979d3ba9e52 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -1193,6 +1193,19 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1193 if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL) 1193 if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL)
1194 return -EINVAL; 1194 return -EINVAL;
1195 1195
1196 /*
1197 * Prevent binding to PFs with VFs enabled, this too easily allows
1198 * userspace instance with VFs and PFs from the same device, which
1199 * cannot work. Disabling SR-IOV here would initiate removing the
1200 * VFs, which would unbind the driver, which is prone to blocking
1201 * if that VF is also in use by vfio-pci. Just reject these PFs
1202 * and let the user sort it out.
1203 */
1204 if (pci_num_vf(pdev)) {
1205 pci_warn(pdev, "Cannot bind to PF with SR-IOV enabled\n");
1206 return -EBUSY;
1207 }
1208
1196 group = vfio_iommu_group_get(&pdev->dev); 1209 group = vfio_iommu_group_get(&pdev->dev);
1197 if (!group) 1210 if (!group)
1198 return -EINVAL; 1211 return -EINVAL;