Skip to content

Commit f611daf

Browse files
Danilo Krummrichgregkh
authored andcommitted
iommu/arm-smmu-qcom: do not register driver in probe()
commit ed1ac3c upstream. Commit 0b4eeee ("iommu/arm-smmu-qcom: Register the TBU driver in qcom_smmu_impl_init") intended to also probe the TBU driver when CONFIG_ARM_SMMU_QCOM_DEBUG is disabled, but also moved the corresponding platform_driver_register() call into qcom_smmu_impl_init() which is called from arm_smmu_device_probe(). However, it neither makes sense to register drivers from probe() callbacks of other drivers, nor does the driver core allow registering drivers with a device lock already being held. The latter was revealed by commit dc23806 ("driver core: enforce device_lock for driver_match_device()") leading to a deadlock condition described in [1]. Additionally, it was noted by Robin that the current approach is potentially racy with async probe [2]. Hence, fix this by registering the qcom_smmu_tbu_driver from module_init(). Unfortunately, due to the vendoring of the driver, this requires an indirection through arm-smmu-impl.c. Reported-by: Mark Brown <broonie@kernel.org> Closes: https://lore.kernel.org/lkml/7ae38e31-ef31-43ad-9106-7c76ea0e8596@sirena.org.uk/ Link: https://lore.kernel.org/lkml/DFU7CEPUSG9A.1KKGVW4HIPMSH@kernel.org/ [1] Link: https://lore.kernel.org/lkml/0c0d3707-9ea5-44f9-88a1-a65c62e3df8d@arm.com/ [2] Fixes: dc23806 ("driver core: enforce device_lock for driver_match_device()") Fixes: 0b4eeee ("iommu/arm-smmu-qcom: Register the TBU driver in qcom_smmu_impl_init") Acked-by: Robin Murphy <robin.murphy@arm.com> Tested-by: Bjorn Andersson <andersson@kernel.org> Reviewed-by: Bjorn Andersson <andersson@kernel.org> Acked-by: Konrad Dybcio <konradybcio@kernel.org> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Tested-by: Ioana Ciornei <ioana.ciornei@nxp.com> #LX2160ARDB Tested-by: Wang Jiayue <akaieurus@gmail.com> Reviewed-by: Wang Jiayue <akaieurus@gmail.com> Tested-by: Mark Brown <broonie@kernel.org> Acked-by: Joerg Roedel <joerg.roedel@amd.com> Link: https://patch.msgid.link/20260121141215.29658-1-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0415ae5 commit f611daf

4 files changed

Lines changed: 52 additions & 5 deletions

File tree

drivers/iommu/arm/arm-smmu/arm-smmu-impl.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,17 @@ struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu)
228228

229229
return smmu;
230230
}
231+
232+
int __init arm_smmu_impl_module_init(void)
233+
{
234+
if (IS_ENABLED(CONFIG_ARM_SMMU_QCOM))
235+
return qcom_smmu_module_init();
236+
237+
return 0;
238+
}
239+
240+
void __exit arm_smmu_impl_module_exit(void)
241+
{
242+
if (IS_ENABLED(CONFIG_ARM_SMMU_QCOM))
243+
qcom_smmu_module_exit();
244+
}

drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,6 @@ struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu)
773773
{
774774
const struct device_node *np = smmu->dev->of_node;
775775
const struct of_device_id *match;
776-
static u8 tbu_registered;
777-
778-
if (!tbu_registered++)
779-
platform_driver_register(&qcom_smmu_tbu_driver);
780776

781777
#ifdef CONFIG_ACPI
782778
if (np == NULL) {
@@ -801,3 +797,13 @@ struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu)
801797

802798
return smmu;
803799
}
800+
801+
int __init qcom_smmu_module_init(void)
802+
{
803+
return platform_driver_register(&qcom_smmu_tbu_driver);
804+
}
805+
806+
void __exit qcom_smmu_module_exit(void)
807+
{
808+
platform_driver_unregister(&qcom_smmu_tbu_driver);
809+
}

drivers/iommu/arm/arm-smmu/arm-smmu.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,29 @@ static struct platform_driver arm_smmu_driver = {
23622362
.remove = arm_smmu_device_remove,
23632363
.shutdown = arm_smmu_device_shutdown,
23642364
};
2365-
module_platform_driver(arm_smmu_driver);
2365+
2366+
static int __init arm_smmu_init(void)
2367+
{
2368+
int ret;
2369+
2370+
ret = platform_driver_register(&arm_smmu_driver);
2371+
if (ret)
2372+
return ret;
2373+
2374+
ret = arm_smmu_impl_module_init();
2375+
if (ret)
2376+
platform_driver_unregister(&arm_smmu_driver);
2377+
2378+
return ret;
2379+
}
2380+
module_init(arm_smmu_init);
2381+
2382+
static void __exit arm_smmu_exit(void)
2383+
{
2384+
arm_smmu_impl_module_exit();
2385+
platform_driver_unregister(&arm_smmu_driver);
2386+
}
2387+
module_exit(arm_smmu_exit);
23662388

23672389
MODULE_DESCRIPTION("IOMMU API for ARM architected SMMU implementations");
23682390
MODULE_AUTHOR("Will Deacon <will@kernel.org>");

drivers/iommu/arm/arm-smmu/arm-smmu.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@ struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu);
540540
struct arm_smmu_device *nvidia_smmu_impl_init(struct arm_smmu_device *smmu);
541541
struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu);
542542

543+
int __init arm_smmu_impl_module_init(void);
544+
void __exit arm_smmu_impl_module_exit(void);
545+
int __init qcom_smmu_module_init(void);
546+
void __exit qcom_smmu_module_exit(void);
547+
543548
void arm_smmu_write_context_bank(struct arm_smmu_device *smmu, int idx);
544549
int arm_mmu500_reset(struct arm_smmu_device *smmu);
545550

0 commit comments

Comments
 (0)