Skip to content

Commit 121f787

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 1ff415e commit 121f787

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
@@ -227,3 +227,17 @@ struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu)
227227

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

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,6 @@ struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu)
638638
{
639639
const struct device_node *np = smmu->dev->of_node;
640640
const struct of_device_id *match;
641-
static u8 tbu_registered;
642-
643-
if (!tbu_registered++)
644-
platform_driver_register(&qcom_smmu_tbu_driver);
645641

646642
#ifdef CONFIG_ACPI
647643
if (np == NULL) {
@@ -666,3 +662,13 @@ struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu)
666662

667663
return smmu;
668664
}
665+
666+
int __init qcom_smmu_module_init(void)
667+
{
668+
return platform_driver_register(&qcom_smmu_tbu_driver);
669+
}
670+
671+
void __exit qcom_smmu_module_exit(void)
672+
{
673+
platform_driver_unregister(&qcom_smmu_tbu_driver);
674+
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2386,7 +2386,29 @@ static struct platform_driver arm_smmu_driver = {
23862386
.remove_new = arm_smmu_device_remove,
23872387
.shutdown = arm_smmu_device_shutdown,
23882388
};
2389-
module_platform_driver(arm_smmu_driver);
2389+
2390+
static int __init arm_smmu_init(void)
2391+
{
2392+
int ret;
2393+
2394+
ret = platform_driver_register(&arm_smmu_driver);
2395+
if (ret)
2396+
return ret;
2397+
2398+
ret = arm_smmu_impl_module_init();
2399+
if (ret)
2400+
platform_driver_unregister(&arm_smmu_driver);
2401+
2402+
return ret;
2403+
}
2404+
module_init(arm_smmu_init);
2405+
2406+
static void __exit arm_smmu_exit(void)
2407+
{
2408+
arm_smmu_impl_module_exit();
2409+
platform_driver_unregister(&arm_smmu_driver);
2410+
}
2411+
module_exit(arm_smmu_exit);
23902412

23912413
MODULE_DESCRIPTION("IOMMU API for ARM architected SMMU implementations");
23922414
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
@@ -538,6 +538,11 @@ struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu);
538538
struct arm_smmu_device *nvidia_smmu_impl_init(struct arm_smmu_device *smmu);
539539
struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu);
540540

541+
int __init arm_smmu_impl_module_init(void);
542+
void __exit arm_smmu_impl_module_exit(void);
543+
int __init qcom_smmu_module_init(void);
544+
void __exit qcom_smmu_module_exit(void);
545+
541546
void arm_smmu_write_context_bank(struct arm_smmu_device *smmu, int idx);
542547
int arm_mmu500_reset(struct arm_smmu_device *smmu);
543548

0 commit comments

Comments
 (0)