On 2020-06-27 04:15, Lu Baolu wrote:
The hardware assistant vfio mediated device is a use case of iommu
aux-domain. The interactions between vfio/mdev and iommu during mdev
creation and passthr are:
- Create a group for mdev with iommu_group_alloc();
- Add the device to the group with
ÂÂÂÂÂÂÂÂ group = iommu_group_alloc();
ÂÂÂÂÂÂÂÂ if (IS_ERR(group))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return PTR_ERR(group);
ÂÂÂÂÂÂÂÂ ret = iommu_group_add_device(group, &mdev->dev);
ÂÂÂÂÂÂÂÂ if (!ret)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_info(&mdev->dev, "MDEV: group_id = %d\n",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ iommu_group_id(group));
- Allocate an aux-domain
ÂÂÂÂiommu_domain_alloc()
- Attach the aux-domain to the physical device from which the mdev is
ÂÂ created.
ÂÂÂÂiommu_aux_attach_device()
In the whole process, an iommu group was allocated for the mdev and an
iommu domain was attached to the group, but the group->domain leaves
NULL. As the result, iommu_get_domain_for_dev() doesn't work anymore.
This adds iommu_group_get/set_domain() so that group->domain could be
managed whenever a domain is attached or detached through the aux-domain
api's.
Letting external callers poke around directly in the internals of iommu_group doesn't look right to me.
If a regular device is attached to one or more aux domains for PASID use, iommu_get_domain_for_dev() is still going to return the primary domain, so why should it be expected to behave differently for mediated
devices? AFAICS it's perfectly legitimate to have no primary domain if traffic-without-PASID is invalid.
Robin.