iommu/rockchip: prevent iommus dead loop when two masters share one IOMMU
Subsystems (3)
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
@@ -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
Quoted 6 lines · Simon Xue
When two masters share an IOMMU, calling
ops->of_xlateduring the second master's driver init may overwriteiommu->domainset by the first. This causes the check if (iommu->domain== domain) inrk_iommu_attach_device()to fail, resulting in the sameiommu->nodebeing added twice to&rk_domain->iommus, which can lead to an infinite loop in subsequent&rk_domain->iommusoperations.
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:
Thanks,
Robin.
Quoted 26 lines
Signed-off-by Simon Xue <[email protected]>--- drivers/iommu/rockchip-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iommu/rockchip-iommu.c +2
-1@@ -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 ;
Hi Robin,
Quoted 52 lines · Simon Xue
Quoted 19 lines
When two masters share an IOMMU, calling
ops->of_xlateduringthe second master's driver init may overwrite
iommu->domainsetby the first. This causes the check if (
iommu->domain== domain)in
rk_iommu_attach_device()to fail, resulting in the sameQuoted 5 lines
iommu->nodebeing added twice to&rk_domain->iommus, which canlead to an infinite loop in subsequent
&rk_domain->iommusoperations.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_FAULTimmediately after requesting the IRQ (e.g. in akdump 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
Reviewed-by Robin Murphy <[email protected]>And probably also:
Fixes 25c2325575cc ("iommu/rockchip: Add missing set_platform_dma_opscallback")
Thanks,
Robin.
Quoted 101 lines
Signed-off-by Simon Xue <[email protected]>---
drivers/iommu/rockchip-iommu.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)drivers/iommu/rockchip-iommu.c +0
-0index
22f74ba33a0e..e6bb3c784017100644---
a/drivers/iommu/rockchip-iommu.c+++
b/drivers/iommu/rockchip-iommu.cdrivers/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;
PATCH v2 1/1 iommu/rockchip: prevent iommus dead loop when two masters share one IOMMU
In reply to Simon XueWhen 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.
v2:
No functional changes.
--- drivers/iommu/rockchip-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/rockchip-iommu.c +2 -1
@@ -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
kernel test robot
build botFYI: 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
PATCH v3 1/1 iommu/rockchip: prevent iommus dead loop when two masters share one IOMMU
In reply to Simon XueWhen 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.
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
@@ -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
Joerg Roedel
maintainerQuoted 12 lines · Simon Xue
When two masters share an IOMMU, calling
ops->of_xlateduring the second master's driver init may overwriteiommu->domainset by the first. This causes the check if (iommu->domain== domain) inrk_iommu_attach_device()to fail, resulting in the sameiommu->nodebeing added twice to&rk_domain->iommus, which can lead to an infinite loop in subsequent&rk_domain->iommusoperations.Cc <[email protected]>Fixes 25c2325575cc ("iommu/rockchip: Add missing set_platform_dma_ops callback")Signed-off-by Simon Xue <[email protected]>Reviewed-by Robin Murphy <[email protected]>
Quoted 8 lines
v3:
Add missingCc: [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.