[PATCH RFC v6 3/5] iommu/arm-smmu-v3: Support shared SIDs in insert/remove_master

Nicolin Chen nicolinc at nvidia.com
Mon Oct 12 13:48:43 PDT 2026


On Sun, Oct 11, 2026 at 07:31:27PM +0800, Peng Fan (OSS) wrote:
>  static void arm_smmu_remove_master(struct arm_smmu_master *master)
>  {
> +	int i;
>  	struct arm_smmu_device *smmu = master->smmu;
>  
>  	if (!smmu || !master->streams)
>  		return;
>  
>  	mutex_lock(&smmu->streams_mutex);
> -	arm_smmu_free_master_streams(master);
> +	for (i = 0; i < master->num_streams; i++) {
> +		struct arm_smmu_stream *stream = master->streams[i];
> +
> +		if (!list_empty(&stream->shared_masters)) {
> +			struct arm_smmu_master *next;
> +
> +			list_del_init(&master->shared_masters_elm);
> +			next = list_first_entry(&stream->shared_masters,
> +						struct arm_smmu_master,
> +						shared_masters_elm);
> +			if (stream->master == master)
> +				stream->master = next;
> +			if (list_is_singular(&stream->shared_masters))
> +				list_del_init(&next->shared_masters_elm);
> +			continue;
> +		}
> +		rb_erase(&stream->node, &smmu->streams);
> +		kfree(stream);
> +	}

Rather than removing arm_smmu_free_master_streams(), just fold all
of these into arm_smmu_free_master_streams(). The rollback path in
arm_smmu_insert_master() can still use the same helper:

arm_smmu_insert_master:
	[...]
	if (ret) {
		arm_smmu_free_master_streams(master);
		mutex_unlock(&smmu->streams_mutex);
		kfree(master->streams);
		[...]

arm_smmu_remove_master:
	[...]
	mutex_lock(&smmu->streams_mutex);
	arm_smmu_free_master_streams(master);
	mutex_unlock(&smmu->streams_mutex);
	[...]

> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> index 56ed6ad1dd523..95da4ad354829 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> @@ -1020,6 +1020,8 @@ struct arm_smmu_stream {
>  	u32				id;
>  	struct arm_smmu_master		*master;
>  	struct rb_node			node;
> +	bool				ste_installed;

ste_installed is unused; better move to the patch that uses it.

With these addressed,

Reviewed-by: Nicolin Chen <nicolinc at nvidia.com>



More information about the linux-arm-kernel mailing list