[PATCH] iommu/arm-smmu-v3: Allow stream table to have nodes with the same ID

Nicolin Chen nicolinc at nvidia.com
Sat Apr 12 10:03:42 PDT 2025


On Sat, Apr 12, 2025 at 10:55:14AM -0300, Jason Gunthorpe wrote:
> On Fri, Apr 11, 2025 at 08:39:36PM -0700, Nicolin Chen wrote:
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index b4c21aaed1266a..97b9f8d7fb3340 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -3389,6 +3389,7 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,
>  	for (i = 0; i < fwspec->num_ids; i++) {
>  		struct arm_smmu_stream *new_stream = &master->streams[i];
>  		u32 sid = fwspec->ids[i];
> +		struct rb_node *existing;
>  
>  		new_stream->id = sid;
>  		new_stream->master = master;
> @@ -3398,10 +3399,20 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,
>  			break;
>  
>  		/* Insert into SID tree */
> -		if (rb_find_add(&new_stream->node, &smmu->streams,
> -				arm_smmu_streams_cmp_node)) {
> -			dev_warn(master->dev, "stream %u already in tree\n",
> -				 sid);
> +		existing = rb_find_add(&new_stream->node, &smmu->streams,
> +				       arm_smmu_streams_cmp_node);

Oh right, it does find() already.

> +		if (existing) {
> +			struct arm_smmu_master *existing_master =
> +				rb_entry(existing, struct arm_smmu_stream, node)
> +					->master;
> +
> +			/* Bridged PCI devices may end up with duplicated IDs */
> +			if (existing_master == master)
> +				continue;
> +
> +			dev_warn(master->dev,
> +				 "stream %u already in tree from dev %s\n", sid,
> +				 dev_name(existing_master->dev));
>  			ret = -EINVAL;
>  			break;
>  		}
> 
> It seems like a reasonable rc fix, and if nobody has cared about DMA
> Alias support since it was broken in 2021 maybe we just leave it.

I will wrap it up and make a note with that.

Thanks!
Nicolin



More information about the linux-arm-kernel mailing list