A Alex Williamson #
Message details and related content
On Mon, 29 Aug 2016 21:52:20 -0600 Alex Williamson [off-list ref] wrote:
On Mon, 29 Aug 2016 21:23:25 -0600 Alex Williamson [off-list ref] wrote:quoted
On Tue, 30 Aug 2016 05:27:17 +0300 "Michael S. Tsirkin" [off-list ref] wrote:quoted
Modern virtio pci devices can set VIRTIO_F_IOMMU_PLATFORM to signal they are safe to use with an IOMMU. Without this bit, exposing the device to userspace is unsafe, so probe and fail VFIO initialization unless noiommu is enabled. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> --- drivers/vfio/pci/vfio_pci_private.h | 1 + drivers/vfio/pci/vfio_pci.c | 14 ++++ drivers/vfio/pci/vfio_pci_virtio.c | 140 ++++++++++++++++++++++++++++++++++++ drivers/vfio/pci/Makefile | 1 + 4 files changed, 156 insertions(+) create mode 100644 drivers/vfio/pci/vfio_pci_virtio.cdiff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index 2128de8..2bd5616 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h@@ -139,4 +139,5 @@ static inline int vfio_pci_igd_init(struct vfio_pci_device *vdev) return -ENODEV; } #endif +extern int vfio_pci_virtio_quirk(struct vfio_pci_device *vdev, bool noiommu); #endif /* VFIO_PCI_PRIVATE_H */diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index d624a52..e93bf0c 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c@@ -1236,6 +1236,20 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) return ret; } + if (pdev->vendor == PCI_VENDOR_ID_REDHAT_QUMRANET) {
I think something like this would do it.
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c@@ -1214,6 +1214,22 @@ static int vfio_pci_probe(struct pci_dev *pdev, const str if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL) return -EINVAL; + /* + * Filter out virtio devices that do not honor the iommu, + * but only for real iommu groups. + */ + if (vfio_pci_is_virtio(pdev)) { + struct iommu_group *tmp = iommu_group_get(&pdev->dev); + + if (tmp) { + iommu_group_put(tmp); + + ret = vfio_pci_virtio_quirk(pdev); + if (ret) + return ret; + } + } + group = vfio_iommu_group_get(&pdev->dev); if (!group) return -EINVAL;
Thanks, Alex
quoted
quoted
+ + ret = vfio_pci_virtio_quirk(vdev, noiommu); + if (ret) { + dev_warn(&vdev->pdev->dev, + "Failed to setup Virtio for VFIO\n"); + vfio_del_group_dev(&pdev->dev); + vfio_iommu_group_put(group, &pdev->dev); + kfree(vdev); + return ret; + } + } + if (vfio_pci_is_vga(pdev)) { vga_client_register(pdev, vdev, NULL, vfio_pci_set_vga_decode); vga_set_legacy_decoding(pdev,diff --git a/drivers/vfio/pci/vfio_pci_virtio.c b/drivers/vfio/pci/vfio_pci_virtio.c new file mode 100644 index 0000000..e1ecffd --- /dev/null +++ b/drivers/vfio/pci/vfio_pci_virtio.c@@ -0,0 +1,140 @@ +/* + * VFIO PCI Intel Graphics support^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^quoted
+ * + * Copyright (C) 2016 Red Hat, Inc. All rights reserved. + * Author: Alex Williamson <alex.williamson@redhat.com>Update.quoted
+ * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Register a device specific region through which to provide read-only + * access to the Intel IGD opregion. The register defining the opregion + * address is also virtualized to prevent user modification. + */ +