public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/arm-smmu-v3: fix probe device bug due to duplicated stream IDS.
@ 2025-10-11  2:30 Reaper Li
  2025-10-23 18:12 ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Reaper Li @ 2025-10-11  2:30 UTC (permalink / raw)
  To: will, robin.murphy
  Cc: joro, linux-arm-kernel, iommu, linux-kernel, reaperlioc

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu/arm-smmu-v3: fix probe device bug due to duplicated stream IDS.
  2025-10-11  2:30 [PATCH] iommu/arm-smmu-v3: fix probe device bug due to duplicated stream IDS Reaper Li
@ 2025-10-23 18:12 ` Jason Gunthorpe
  2025-10-24 10:20   ` Robin Murphy
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 18:12 UTC (permalink / raw)
  To: Reaper Li; +Cc: will, robin.murphy, joro, linux-arm-kernel, iommu, linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu/arm-smmu-v3: fix probe device bug due to duplicated stream IDS.
  2025-10-23 18:12 ` Jason Gunthorpe
@ 2025-10-24 10:20   ` Robin Murphy
  0 siblings, 0 replies; 3+ messages in thread
From: Robin Murphy @ 2025-10-24 10:20 UTC (permalink / raw)
  To: Jason Gunthorpe, Reaper Li
  Cc: will, joro, linux-arm-kernel, iommu, linux-kernel

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-24 10:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-11  2:30 [PATCH] iommu/arm-smmu-v3: fix probe device bug due to duplicated stream IDS Reaper Li
2025-10-23 18:12 ` Jason Gunthorpe
2025-10-24 10:20   ` Robin Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox