Re: [PATCH v9 3/6] iommufd: Allow binding to a noiommu device
From: Pranjal Shrivastava
Date: Tue Jun 16 2026 - 16:38:36 EST
On Thu, Jun 11, 2026 at 10:26:55AM -0700, Jacob Pan wrote:
> From: Jason Gunthorpe <jgg@xxxxxxxxxx>
>
> Allow iommufd to bind devices without an IOMMU (noiommu mode) by creating
> a dummy igroup for such devices and skipping hwpt operations.
>
> This enables noiommu devices to operate through the same iommufd API as IOMMU-
> capable devices.
>
> Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>
> Reviewed-by: Yi Liu <yi.l.liu@xxxxxxxxx>
> Reviewed-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
> Signed-off-by: Jacob Pan <jacob.pan@xxxxxxxxxxxxxxxxxxx>
[...]
> +/*
> + * Detect a noiommu device for the cdev path. We check dev->iommu rather than
> + * using device_iommu_mapped() (which checks dev->iommu_group) because when
> + * both group and cdev interfaces coexist, the group path assigns a fake
> + * noiommu iommu_group to the device. That would cause device_iommu_mapped()
> + * to return true and hide the noiommu case from the cdev path. dev->iommu is
> + * reliably NULL when no IOMMU driver is managing the device.
> + */
> +static bool iommufd_device_is_noiommu(struct iommufd_device *idev)
> +{
> + return IS_ENABLED(CONFIG_IOMMUFD_NOIOMMU) && !idev->dev->iommu;
> +}
> +
Helpful comment! Thanks :)
> static void iommufd_group_release(struct kref *kref)
> {
> struct iommufd_group *igroup =
> @@ -30,9 +43,11 @@ static void iommufd_group_release(struct kref *kref)
>
> WARN_ON(!xa_empty(&igroup->pasid_attach));
>
> - xa_cmpxchg(&igroup->ictx->groups, iommu_group_id(igroup->group), igroup,
> - NULL, GFP_KERNEL);
> - iommu_group_put(igroup->group);
> + if (igroup->group) {
> + xa_cmpxchg(&igroup->ictx->groups, iommu_group_id(igroup->group),
> + igroup, NULL, GFP_KERNEL);
> + iommu_group_put(igroup->group);
> + }
> mutex_destroy(&igroup->lock);
> kfree(igroup);
> }
Reviewed-by: Pranjal Shrivastava <praan@xxxxxxxxxx>
Thanks,
Praan