Re: [RFC 5/5] vfio/qat: Add vfio_pci driver for Intel QAT VF devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/30/2023 6:13 AM, Xin Zeng wrote:
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.


Add vfio pci driver for Intel QAT VF devices.

This driver uses vfio_pci_core to register to the VFIO subsystem. It
acts as a vfio agent and interacts with the QAT PF driver to implement
VF live migration.

Co-developed-by: Yahui Cao <yahui.cao@xxxxxxxxx>
Signed-off-by: Yahui Cao <yahui.cao@xxxxxxxxx>
Signed-off-by: Xin Zeng <xin.zeng@xxxxxxxxx>
---
  drivers/vfio/pci/Kconfig                 |   2 +
  drivers/vfio/pci/Makefile                |   1 +
  drivers/vfio/pci/qat/Kconfig             |  13 +
  drivers/vfio/pci/qat/Makefile            |   4 +
  drivers/vfio/pci/qat/qat_vfio_pci_main.c | 518 +++++++++++++++++++++++
  5 files changed, 538 insertions(+)
  create mode 100644 drivers/vfio/pci/qat/Kconfig
  create mode 100644 drivers/vfio/pci/qat/Makefile
  create mode 100644 drivers/vfio/pci/qat/qat_vfio_pci_main.c


[...]

+
+static int
+qat_vf_vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+       struct device *dev = &pdev->dev;
+       struct qat_vf_core_device *qat_vdev;
+       int ret;
+
+       qat_vdev = vfio_alloc_device(qat_vf_core_device, core_device.vdev, dev, &qat_vf_pci_ops);
+       if (IS_ERR(qat_vdev))
+               return PTR_ERR(qat_vdev);
+
+       qat_vdev->vf_id = pci_iov_vf_id(pdev);
+       qat_vdev->parent = pdev->physfn;
+       if (!qat_vdev->parent || qat_vdev->vf_id < 0)
+               return -EINVAL;

Since vfio_alloc_device() was successful you need to call vfio_put_device() in this error case as well.

+
+       pci_set_drvdata(pdev, &qat_vdev->core_device);
+       ret = vfio_pci_core_register_device(&qat_vdev->core_device);
+       if (ret)
+               goto out_put_device;
+
+       return 0;
+
+out_put_device:
+       vfio_put_device(&qat_vdev->core_device.vdev);
+       return ret;
+}
+
+static struct qat_vf_core_device *qat_vf_drvdata(struct pci_dev *pdev)
+{
+       struct vfio_pci_core_device *core_device = pci_get_drvdata(pdev);
+
+       return container_of(core_device, struct qat_vf_core_device, core_device);
+}
+
+static void qat_vf_vfio_pci_remove(struct pci_dev *pdev)
+{
+       struct qat_vf_core_device *qat_vdev = qat_vf_drvdata(pdev);
+
+       vfio_pci_core_unregister_device(&qat_vdev->core_device);
+       vfio_put_device(&qat_vdev->core_device.vdev);
+}
+
+static const struct pci_device_id qat_vf_vfio_pci_table[] = {
+       /* Intel QAT GEN4 4xxx VF device */
+       { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_INTEL, 0x4941) },
+       {}
+};
+MODULE_DEVICE_TABLE(pci, qat_vf_vfio_pci_table);
+
+static struct pci_driver qat_vf_vfio_pci_driver = {
+       .name = "qat_vfio_pci",
+       .id_table = qat_vf_vfio_pci_table,
+       .probe = qat_vf_vfio_pci_probe,
+       .remove = qat_vf_vfio_pci_remove,
+       .driver_managed_dma = true,
+};
+module_pci_driver(qat_vf_vfio_pci_driver)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Intel Corporation");
+MODULE_DESCRIPTION("QAT VFIO PCI - VFIO PCI driver with live migration support for Intel(R) QAT device family");
--
2.18.2




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux