[PATCH 03/10] iommu: Add generic_single_device_group()

Tian, Kevin kevin.tian at intel.com
Fri Jul 21 00:17:39 PDT 2023


> From: Jason Gunthorpe <jgg at nvidia.com>
> Sent: Wednesday, July 19, 2023 3:06 AM
> 
> This implements the common pattern seen in drivers of a single
> iommu_group for the entire iommu driver. Implement this in core code
> so the drivers that want this can select it from their ops.

strictly speaking it's per-iommu-instance group. 😊

> +/*
> + * Generic device_group call-back function. It just allocates one
> + * iommu-group per iommu driver.
> + */
> +struct iommu_group *generic_single_device_group(struct device *dev)
> +{
> +	struct iommu_device *iommu = dev->iommu->iommu_dev;
> +
> +	lockdep_assert_held(&dev_iommu_group_lock);
> +
> +	if (!iommu->singleton_group) {
> +		struct iommu_group *group;
> +
> +		group = iommu_group_alloc();
> +		if (IS_ERR(group))
> +			return group;
> +		iommu->singleton_group = group;
> +	}
> +	return iommu_group_ref_get(iommu->singleton_group);

'singleton' is a bit confusing whether it means a single
group per instance or a group having only a single device.

I don't know a better name, but probably just using
iommu->group is not worse than the 'singleton_' prefix...


More information about the linux-arm-kernel mailing list