[PATCH] iommu/arm-smmu-v3: fix probe device bug due to duplicated stream IDS.

Reaper Li posted 1 patch 2 months, 1 week ago
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 11 +++++++++++
1 file changed, 11 insertions(+)
[PATCH] iommu/arm-smmu-v3: fix probe device bug due to duplicated stream IDS.
Posted by Reaper Li 2 months, 1 week ago
From: Reaper <reaperlioc@glenfly.com>

Commit 9246b487ab3c ("PCI: Add function 0 DMA alias quirk for Glenfly Arise
chip ") add quirk to fix hda dma request issue, but IORT logic populaties
two identical IDs into the fwspec->ids array via DMA aliasing in
iort_pci_iommu_init() called by pci_for_each_dma_alias().

Signed-off-by: ReaperLi <reaperlioc@glenfly.com>
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

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 2a8b46b94..996d3c0f8 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -3476,10 +3476,21 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,
 				rb_entry(existing, struct arm_smmu_stream, node)
 					->master;
 
+			struct device *mdev = master->dev;
+			struct device *existing_mdev = existing_master->dev;
+
 			/* Bridged PCI devices may end up with duplicated IDs */
 			if (existing_master == master)
 				continue;
 
+			/* Dma alias PCI devices may end up with duplicated IDs */
+			if (existing_mdev != mdev &&
+				dev_is_pci(existing_mdev) && dev_is_pci(mdev) &&
+				to_pci_dev(existing_mdev)->bus == to_pci_dev(mdev)->bus &&
+				pci_devs_are_dma_aliases(to_pci_dev(existing_mdev),
+										 to_pci_dev(mdev)))
+				continue;
+
 			dev_warn(master->dev,
 				 "Aliasing StreamID 0x%x (from %s) unsupported, expect DMA to be broken\n",
 				 sid, dev_name(existing_master->dev));
-- 
2.34.1
Re: [PATCH] iommu/arm-smmu-v3: fix probe device bug due to duplicated stream IDS.
Posted by Jason Gunthorpe 1 month, 3 weeks ago
On Sat, Oct 11, 2025 at 10:30:03AM +0800, Reaper Li wrote:
> From: Reaper <reaperlioc@glenfly.com>
> 
> Commit 9246b487ab3c ("PCI: Add function 0 DMA alias quirk for Glenfly Arise
> chip ") add quirk to fix hda dma request issue, but IORT logic populaties
> two identical IDs into the fwspec->ids array via DMA aliasing in
> iort_pci_iommu_init() called by pci_for_each_dma_alias().

I'd rather we not have duplicate IDs in the same fwspec, can we avoid
that at the source?

Jason
Re: [PATCH] iommu/arm-smmu-v3: fix probe device bug due to duplicated stream IDS.
Posted by Robin Murphy 1 month, 3 weeks ago
On 2025-10-23 7:12 pm, Jason Gunthorpe wrote:
> On Sat, Oct 11, 2025 at 10:30:03AM +0800, Reaper Li wrote:
>> From: Reaper <reaperlioc@glenfly.com>
>>
>> Commit 9246b487ab3c ("PCI: Add function 0 DMA alias quirk for Glenfly Arise
>> chip ") add quirk to fix hda dma request issue, but IORT logic populaties
>> two identical IDs into the fwspec->ids array via DMA aliasing in
>> iort_pci_iommu_init() called by pci_for_each_dma_alias().
> 
> I'd rather we not have duplicate IDs in the same fwspec, can we avoid
> that at the source?

The original reason for not doing that is that there are multiple 
sources - the drivers' own .of_xlate routines for DT, but the 
IORT/VIOT/RIMT/whatever code for ACPI. Yes, iommu_fwspec_add_ids() is in 
a common path there, but that's only responsible for appending an opaque 
block of data to another opaque block of data - only the producer or 
consumer of that data know how to interpret it (e.g. for SMMUv2, 
[0x00000002, 0x00000003] may or may not be considered equivalent to 
[0x00010002]).

Anyway, this patch is wrong regardless, and it is definitely not fixing 
any bug. SMMUv3 has explicitly never supported StreamID aliasing between 
*different* devices, because doing that correctly is a challenge. It 
needs custom group assignment based on StreamID-to-group lookup (like 
SMMUv2) - we can't just assume it's OK for PCI devices, since as soon as 
we allow aliasing at all then we also allow it outside the PCI hierarchy 
where pci_device_group() can't see it (like on the Arm Juno platform). 
These days we do have arm_smmu_find_master() which makes *that* 
feasible, but conversely means we now also have to be concerned with 
disallowing ATS/PRI and working out what to do with anything else that 
is subtly broken by no longer having the assumed 1:1 correspondence of 
StreamID:device.

Thanks,
Robin.