On 9/17/2021 10:35 AM, Christoph Hellwig wrote:
On Fri, Sep 17, 2021 at 04:49:41AM +0000, Tian, Kevin wrote:
You just use the new style mdev API and directly call
vfio_register_group_dev and it will pick up the
parent->dev->iommu_group naturally like everything else using physical
iommu groups.
Directly calling vfio_register_group_dev() doesn't work without linking
mdev->dev->iommu_group to mdev->type->parent->dev->iommu_group.
When mdev device is created, mdev->dev->iommu_group is NULL. Then if
called vfio_register_group_dev with mdev->dev as vfio device, it fails
because mdev->dev->iommu_group is NULL. So create vfio_device with mdev
parent's dev as below:
if (IOMMU backed mdev)
vfio_init_group_dev(&vfio_dev, &mdev->type->parent->dev, &fops);
else
vfio_init_group_dev(&vfio_dev, &mdev->dev, &fops);
if (IOMMU backed mdev)
vfio_register_group_dev(&vfio_dev);
else
vfio_register_emulated_iommu_dev(&vfio_dev);
But still mdev->dev->iommu_group is NULL and
/sys/bus/mdev/devices/<mdev_uuid>/iommu_group is not present.
For QEMU, input parameter is mdev device's UUID. QEMU checks
/sys/bus/mdev/devices/<mdev_uuid>/iommu_group path and fails with error
"no iommu_group found".
There has to be symlink /mdev/devices/<mdev_uuid>/iommu_group to it's
parent device's iommu_group.
iommu_group_add_device(parent_iommu_group, mdev->dev) fails because mdev
device is not pci device or ACPI device. Can it be allowed to add mdev
device to its parent's iommu group here?
For above usage (wrap pdev into mdev), isn't the right way to directly add
vendor vfio-pci driver since vfio-pci-core has been split out now? It's not
necessary to fake a mdev just for adding some mediation in the r/w path...
Exactly.
vfio-pci doesn't provide way to configure the device as mdev framework
provide using mdev_types.
Thanks,
Kirti