[PATCH] iommu/exynos: Initialize lock before requesting IRQ

Runyu Xiao posted 1 patch 3 weeks, 3 days ago
drivers/iommu/exynos-iommu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] iommu/exynos: Initialize lock before requesting IRQ
Posted by Runyu Xiao 3 weeks, 3 days ago
The SysMMU interrupt handler can run as soon as devm_request_irq() is
called. Initialize the driver lock before registering the handler so an
early interrupt cannot use an uninitialized lock.

Fixes: 2a96536e77b4 ("iommu/exynos: Add iommu driver for EXYNOS Platforms")
Cc: stable@vger.kernel.org
Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
Assisted-by: Codex:GPT-5
---
 drivers/iommu/exynos-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index 874d05f4b..e9feb83b3 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -735,6 +735,8 @@ static int exynos_sysmmu_probe(struct platform_device *pdev)
 	if (!data)
 		return -ENOMEM;
 
+	spin_lock_init(&data->lock);
+
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	data->sfrbase = devm_ioremap_resource(dev, res);
 	if (IS_ERR(data->sfrbase))
@@ -773,7 +775,6 @@ static int exynos_sysmmu_probe(struct platform_device *pdev)
 		return PTR_ERR(data->clk_master);
 
 	data->sysmmu = dev;
-	spin_lock_init(&data->lock);
 
 	__sysmmu_get_version(data);
 
-- 
2.34.1
Re: [PATCH] iommu/exynos: Initialize lock before requesting IRQ
Posted by Runyu Xiao 4 days, 23 hours ago
Hello Robin and Marek,

Thanks for the reviews.

I agree that the current patch is incomplete. The interrupt handler does
not only access data->lock; it also depends on the clocks, variant data,
device pointers, and the SYSMMU hardware state, which are not fully
initialized at the current devm_request_irq() point.

Moving only spin_lock_init() before devm_request_irq() therefore does not
make the handler safe. I will withdraw this patch and will not send a v2
of the current change.

If this issue is pursued further, I will review the complete probe ordering
and the SYSMMU hardware disable/reset sequence before preparing a new patch.

Please disregard the submitted patch.

Regards,
Runyu
Re: [PATCH] iommu/exynos: Initialize lock before requesting IRQ
Posted by Marek Szyprowski 3 weeks, 3 days ago
On 01.09.2026 15:05, Runyu Xiao wrote:
> The SysMMU interrupt handler can run as soon as devm_request_irq() is
> called. Initialize the driver lock before registering the handler so an
> early interrupt cannot use an uninitialized lock.
>
> Fixes: 2a96536e77b4 ("iommu/exynos: Add iommu driver for EXYNOS Platforms")
> Cc: stable@vger.kernel.org
> Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
> Assisted-by: Codex:GPT-5


Sorry, but this patch doesn't make much sense. There are other things that have
to be properly initialized before the interrupts can be handled. To ensure that
interrupt doesn't fire before handler has been registered one should enable
clocks and reset the hw:
        writel(CTRL_DISABLE, data->sfrbase + REG_MMU_CTRL);
        writel(0, data->sfrbase + REG_MMU_CFG);

> ---
>  drivers/iommu/exynos-iommu.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
> index 874d05f4b..e9feb83b3 100644
> --- a/drivers/iommu/exynos-iommu.c
> +++ b/drivers/iommu/exynos-iommu.c
> @@ -735,6 +735,8 @@ static int exynos_sysmmu_probe(struct platform_device *pdev)
>  	if (!data)
>  		return -ENOMEM;
>  
> +	spin_lock_init(&data->lock);
> +
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	data->sfrbase = devm_ioremap_resource(dev, res);
>  	if (IS_ERR(data->sfrbase))
> @@ -773,7 +775,6 @@ static int exynos_sysmmu_probe(struct platform_device *pdev)
>  		return PTR_ERR(data->clk_master);
>  
>  	data->sysmmu = dev;
> -	spin_lock_init(&data->lock);
>  
>  	__sysmmu_get_version(data);
>  

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland

Re: [PATCH] iommu/exynos: Initialize lock before requesting IRQ
Posted by Robin Murphy 3 weeks, 3 days ago
On 01/09/2026 2:05 pm, Runyu Xiao wrote:
> The SysMMU interrupt handler can run as soon as devm_request_irq() is
> called. Initialize the driver lock before registering the handler so an
> early interrupt cannot use an uninitialized lock.

And what about all the _other_ data the handler unconditionally 
dereferences which is also still uninitialised at this point? If you 
think this (clearly theoretical) race is worth fixing then at least 
actually fix it...

Thanks,
Robin.

> Fixes: 2a96536e77b4 ("iommu/exynos: Add iommu driver for EXYNOS Platforms")
> Cc: stable@vger.kernel.org
> Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
> Assisted-by: Codex:GPT-5
> ---
>   drivers/iommu/exynos-iommu.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
> index 874d05f4b..e9feb83b3 100644
> --- a/drivers/iommu/exynos-iommu.c
> +++ b/drivers/iommu/exynos-iommu.c
> @@ -735,6 +735,8 @@ static int exynos_sysmmu_probe(struct platform_device *pdev)
>   	if (!data)
>   		return -ENOMEM;
>   
> +	spin_lock_init(&data->lock);
> +
>   	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>   	data->sfrbase = devm_ioremap_resource(dev, res);
>   	if (IS_ERR(data->sfrbase))
> @@ -773,7 +775,6 @@ static int exynos_sysmmu_probe(struct platform_device *pdev)
>   		return PTR_ERR(data->clk_master);
>   
>   	data->sysmmu = dev;
> -	spin_lock_init(&data->lock);
>   
>   	__sysmmu_get_version(data);
>