* [PATCH] iommu/arm-smmu-v3: Free MSIs in case of ENOMEM
@ 2024-03-29 9:51 Aleksandr Aprelkov
2024-04-01 16:40 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Aleksandr Aprelkov @ 2024-03-29 9:51 UTC (permalink / raw)
To: Will Deacon
Cc: Aleksandr Aprelkov, Robin Murphy, Joerg Roedel, Jason Gunthorpe,
Nicolin Chen, Michael Shavit, Lu Baolu, Marc Zyngier,
linux-arm-kernel, iommu, linux-kernel
If devm_add_action() returns ENOMEM, then MSIs allocated but
not freed on teardown.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 166bdbd23161 ("iommu/arm-smmu: Add support for MSI on SMMUv3")
Signed-off-by: Aleksandr Aprelkov <aaprelkov@usergate.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 41f93c3ab160..136d0cdce6a9 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -3402,7 +3402,12 @@ static void arm_smmu_setup_msis(struct arm_smmu_device *smmu)
smmu->priq.q.irq = msi_get_virq(dev, PRIQ_MSI_INDEX);
/* Add callback to free MSIs on teardown */
- devm_add_action(dev, arm_smmu_free_msis, dev);
+ ret = devm_add_action(dev, arm_smmu_free_msis, dev);
+ if (ret) {
+ dev_warn(dev, "failed to add free MSIs callback - falling back to wired irqs\n");
+ arm_smmu_free_msis(dev);
+ return;
+ }
}
static void arm_smmu_setup_unique_irqs(struct arm_smmu_device *smmu)
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iommu/arm-smmu-v3: Free MSIs in case of ENOMEM
2024-03-29 9:51 [PATCH] iommu/arm-smmu-v3: Free MSIs in case of ENOMEM Aleksandr Aprelkov
@ 2024-04-01 16:40 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2024-04-01 16:40 UTC (permalink / raw)
To: Aleksandr Aprelkov
Cc: Will Deacon, Robin Murphy, Joerg Roedel, Jason Gunthorpe,
Nicolin Chen, Michael Shavit, Lu Baolu, Marc Zyngier,
linux-arm-kernel, iommu, linux-kernel
On Fri, 29 Mar 2024 16:51:33 +0700
Aleksandr Aprelkov <aaprelkov@usergate.com> wrote:
> If devm_add_action() returns ENOMEM, then MSIs allocated but
> not freed on teardown.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 166bdbd23161 ("iommu/arm-smmu: Add support for MSI on SMMUv3")
> Signed-off-by: Aleksandr Aprelkov <aaprelkov@usergate.com>
I've not checked this is an actual bug (though it looks like one from
the context of the patch - the comment below is just about
how you fix it.
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index 41f93c3ab160..136d0cdce6a9 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -3402,7 +3402,12 @@ static void arm_smmu_setup_msis(struct arm_smmu_device *smmu)
> smmu->priq.q.irq = msi_get_virq(dev, PRIQ_MSI_INDEX);
>
> /* Add callback to free MSIs on teardown */
> - devm_add_action(dev, arm_smmu_free_msis, dev);
> + ret = devm_add_action(dev, arm_smmu_free_msis, dev);
Use devm_add_action_or_reset() which exists to solve the case of devm registration failing.
> + if (ret) {
> + dev_warn(dev, "failed to add free MSIs callback - falling back to wired irqs\n");
> + arm_smmu_free_msis(dev);
> + return;
> + }
> }
>
> static void arm_smmu_setup_unique_irqs(struct arm_smmu_device *smmu)
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-01 16:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-29 9:51 [PATCH] iommu/arm-smmu-v3: Free MSIs in case of ENOMEM Aleksandr Aprelkov
2024-04-01 16:40 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).