Skip to contentSkip to conversation

iommu/rockchip: prevent iommus dead loop when two masters share one IOMMU

PATCH Superseded Simon Xue 4 participants 7 messages Jun 20, 2025 – Jun 27, 2025

Subsystems (3)
lore
Share & tools
lore

Simon Xue

author
#0 lore raw

PATCH 1/1 iommu/rockchip: prevent iommus dead loop when two masters share one IOMMU

When two masters share an IOMMU, calling ops->of_xlate during the second master's driver init may overwrite iommu->domain set by the first. This causes the check if (iommu->domain == domain) in rk_iommu_attach_device() to fail, resulting in the same iommu->node being added twice to &rk_domain->iommus, which can lead to an infinite loop in subsequent &rk_domain->iommus operations.

---
 drivers/iommu/rockchip-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/rockchip-iommu.c +2 -1
index 22f74ba33a0e..e6bb3c784017 100644
@@ -1157,7 +1157,6 @@ static int rk_iommu_of_xlate(struct device *dev,
 		return -ENOMEM;
 
 	data->iommu = platform_get_drvdata(iommu_dev);
-	data->iommu->domain = &rk_identity_domain;
 	dev_iommu_priv_set(dev, data);
 
 	platform_device_put(iommu_dev);
@@ -1195,6 +1194,8 @@ static int rk_iommu_probe(struct platform_device *pdev)
 	if (!iommu)
 		return -ENOMEM;
 
+	iommu->domain = &rk_identity_domain;
+
 	platform_set_drvdata(pdev, iommu);
 	iommu->dev = dev;
 	iommu->num_mmu = 0;
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Simon Xue

When two masters share an IOMMU, calling ops->of_xlate during the second master's driver init may overwrite iommu->domain set by the first. This causes the check if (iommu->domain == domain) in rk_iommu_attach_device() to fail, resulting in the same iommu->node being added twice to &rk_domain->iommus, which can lead to an infinite loop in subsequent &rk_domain->iommus operations.

Indeed this is a property of the IOMMU instance itself so it really should be initialised before registration, irrespective of client devices. FWIW, if it's possible to take an unexpected RK_MMU_IRQ_PAGE_FAULT immediately after requesting the IRQ (e.g. in a kdump kernel after a crash with the hardware still running) then I think the current code could probably end up dereferencing NULL in report_iommu_fault() as well.

And probably also:

Fixes 25c2325575cc ("iommu/rockchip: Add missing set_platform_dma_ops callback")

Thanks,
Robin.

Quoted 26 lines
---
  drivers/iommu/rockchip-iommu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/rockchip-iommu.c +2 -1
index 22f74ba33a0e..e6bb3c784017 100644
@@ -1157,7 +1157,6 @@ static int rk_iommu_of_xlate(struct device *dev,
  		return -ENOMEM;
 
  	data->iommu = platform_get_drvdata(iommu_dev);
-	data->iommu->domain = &rk_identity_domain;
  	dev_iommu_priv_set(dev, data);
 
  	platform_device_put(iommu_dev);
@@ -1195,6 +1194,8 @@ static int rk_iommu_probe(struct platform_device *pdev)
  	if (!iommu)
  		return -ENOMEM;
 
+	iommu->domain = &rk_identity_domain;
+
  	platform_set_drvdata(pdev, iommu);
  	iommu->dev = dev;
  	iommu->num_mmu = 0;
#2 lore raw

Hi Robin,

Quoted 52 lines · Simon Xue
Quoted 19 lines

When two masters share an IOMMU, calling ops->of_xlate during

the second master's driver init may overwrite iommu->domain set

by the first. This causes the check if (iommu->domain == domain)

in rk_iommu_attach_device() to fail, resulting in the same

Quoted 5 lines

iommu->node being added twice to &rk_domain->iommus, which can

lead to an infinite loop in subsequent &rk_domain->iommus operations.

Indeed this is a property of the IOMMU instance itself so it really

should be initialised before registration, irrespective of client

devices. FWIW, if it's possible to take an unexpected

RK_MMU_IRQ_PAGE_FAULT immediately after requesting the IRQ (e.g. in a

kdump kernel after a crash with the hardware still running) then I think

Quoted 5 lines

the current code could probably end up dereferencing NULL in

report_iommu_fault() as well.

Thanks for your review and clear explanation, I will add the information as you suggested.

Simon Xue

Quoted 157 lines

And probably also:

Fixes 25c2325575cc ("iommu/rockchip: Add missing set_platform_dma_ops

callback")

Thanks,

Robin.

Quoted 101 lines

---

   drivers/iommu/rockchip-iommu.c | 3 ++-

   1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/rockchip-iommu.c +0 -0

index 22f74ba33a0e..e6bb3c784017 100644

--- a/drivers/iommu/rockchip-iommu.c

+++ b/drivers/iommu/rockchip-iommu.c

drivers/iommu/rockchip-iommu.c +0 -0
@@ -1157,7 +1157,6 @@ static int rk_iommu_of_xlate(struct device *dev,
 
 
 
    		return -ENOMEM;
 
 

   data->iommu = platform_get_drvdata(iommu_dev);

drivers/iommu/rockchip-iommu.c +0 -1
-	data->iommu->domain = &rk_identity_domain;

   dev_iommu_priv_set(dev, data);

   platform_device_put(iommu_dev);

drivers/iommu/rockchip-iommu.c +0 -0
@@ -1195,6 +1194,8 @@ static int rk_iommu_probe(struct platform_device *pdev)
 
 
 
    	if (!iommu)
 
 

   return -ENOMEM;

drivers/iommu/rockchip-iommu.c +2 -0
+	iommu->domain = &rk_identity_domain;
 
 
 
+

   platform_set_drvdata(pdev, iommu);

   iommu->dev = dev;

   iommu->num_mmu = 0;

author
#3 lore raw

PATCH v2 1/1 iommu/rockchip: prevent iommus dead loop when two masters share one IOMMU

In reply to Simon Xue

When two masters share an IOMMU, calling ops->of_xlate during the second master's driver init may overwrite iommu->domain set by the first. This causes the check if (iommu->domain == domain) in rk_iommu_attach_device() to fail, resulting in the same iommu->node being added twice to &rk_domain->iommus, which can lead to an infinite loop in subsequent &rk_domain->iommus operations.

Fixes 25c2325575cc ("iommu/rockchip: Add missing set_platform_dma_ops callback")

v2:
No functional changes.

---
 drivers/iommu/rockchip-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/rockchip-iommu.c +2 -1
index 22f74ba33a0e..e6bb3c784017 100644
@@ -1157,7 +1157,6 @@ static int rk_iommu_of_xlate(struct device *dev,
 		return -ENOMEM;
 
 	data->iommu = platform_get_drvdata(iommu_dev);
-	data->iommu->domain = &rk_identity_domain;
 	dev_iommu_priv_set(dev, data);
 
 	platform_device_put(iommu_dev);
@@ -1195,6 +1194,8 @@ static int rk_iommu_probe(struct platform_device *pdev)
 	if (!iommu)
 		return -ENOMEM;
 
+	iommu->domain = &rk_identity_domain;
+
 	platform_set_drvdata(pdev, iommu);
 	iommu->dev = dev;
 	iommu->num_mmu = 0;
Signature · 7 lines
2.34.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
#4 lore raw
FYI: kernel test robot notices the stable kernel rule is not satisfied.

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1

Rule: add the tag "Cc: [email protected]" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH v2] iommu/rockchip: prevent iommus dead loop when two masters share one IOMMU

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#5 lore raw

PATCH v3 1/1 iommu/rockchip: prevent iommus dead loop when two masters share one IOMMU

In reply to Simon Xue

When two masters share an IOMMU, calling ops->of_xlate during the second master's driver init may overwrite iommu->domain set by the first. This causes the check if (iommu->domain == domain) in rk_iommu_attach_device() to fail, resulting in the same iommu->node being added twice to &rk_domain->iommus, which can lead to an infinite loop in subsequent &rk_domain->iommus operations.

Fixes 25c2325575cc ("iommu/rockchip: Add missing set_platform_dma_ops callback")

v3:
Add missing Cc: [email protected] in commit message. No functional changes.
v2:
No functional changes.

---
 drivers/iommu/rockchip-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/rockchip-iommu.c +2 -1
index 22f74ba33a0e..e6bb3c784017 100644
@@ -1157,7 +1157,6 @@ static int rk_iommu_of_xlate(struct device *dev,
 		return -ENOMEM;
 
 	data->iommu = platform_get_drvdata(iommu_dev);
-	data->iommu->domain = &rk_identity_domain;
 	dev_iommu_priv_set(dev, data);
 
 	platform_device_put(iommu_dev);
@@ -1195,6 +1194,8 @@ static int rk_iommu_probe(struct platform_device *pdev)
 	if (!iommu)
 		return -ENOMEM;
 
+	iommu->domain = &rk_identity_domain;
+
 	platform_set_drvdata(pdev, iommu);
 	iommu->dev = dev;
 	iommu->num_mmu = 0;
Signature · 1 line
2.34.1
maintainer
#6 lore raw
Quoted 12 lines · Simon Xue

When two masters share an IOMMU, calling ops->of_xlate during the second master's driver init may overwrite iommu->domain set by the first. This causes the check if (iommu->domain == domain) in rk_iommu_attach_device() to fail, resulting in the same iommu->node being added twice to &rk_domain->iommus, which can lead to an infinite loop in subsequent &rk_domain->iommus operations.

Fixes 25c2325575cc ("iommu/rockchip: Add missing set_platform_dma_ops callback")
Quoted 8 lines

v3:
Add missing Cc: [email protected] in commit message. No functional changes.
v2:
No functional changes.

---
 drivers/iommu/rockchip-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied for -rc, thanks.