From: liulongfang <liulongfang@huawei.com> To: Will Deacon <will@kernel.org> Cc: <robin.murphy@arm.com>, <linux-arm-kernel@lists.infradead.org>, <iommu@lists.linux.dev> Subject: Re: [PATCH 2/2] iommu: fix smmu initialization memory leak problem Date: Fri, 18 Nov 2022 17:28:36 +0800 [thread overview] Message-ID: <26e8c338-7e4b-b35e-c68a-78a7cbdf2d45@huawei.com> (raw) In-Reply-To: <20221114180821.GC31476@willie-the-truck> On 2022/11/15 2:08, Will Deacon Wrote: > On Fri, Oct 21, 2022 at 11:51:47AM +0800, Longfang Liu wrote: >> When iommu_device_register() in arm_smmu_device_probe() fails, >> in addition to sysfs needs to be deleted, device should also >> be disabled, and the memory of iopf needs to be released to >> prevent memory leak of iopf. >> >> Signed-off-by: Longfang Liu <liulongfang@huawei.com> >> --- >> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 9 +++++++-- >> 1 file changed, 7 insertions(+), 2 deletions(-) >> >> 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 a1db07bed6a9..c70defb0c866 100644 >> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c >> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c >> @@ -3816,11 +3816,16 @@ static int arm_smmu_device_probe(struct platform_device *pdev) >> ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); >> if (ret) { >> dev_err(dev, "Failed to register iommu\n"); >> - iommu_device_sysfs_remove(&smmu->iommu); >> - return ret; >> + goto err_sysfs_remove; >> } >> >> return 0; >> + >> +err_sysfs_remove: >> + iommu_device_sysfs_remove(&smmu->iommu); >> + arm_smmu_device_disable(smmu); >> + iopf_queue_free(smmu->evtq.iopf); >> + return ret; > > Doesn't this miss the cases where iommu_device_sysfs_add() or > arm_smmu_device_reset() fail? > > We'd probably be better off using something like devres_alloc() to track > the iopf queue here. > This is actually not a problem found by the test, but a problem found by the code logic analysis. When an error exits, the memory allocated by the iopf queue is not released during the entire exit process. In addition, it can also be seen from arm_smmu_device_remove() that the missing operation when the probe error exits. Thanks Longfang. > Will > . >
WARNING: multiple messages have this Message-ID (diff)
From: liulongfang <liulongfang@huawei.com> To: Will Deacon <will@kernel.org> Cc: <robin.murphy@arm.com>, <linux-arm-kernel@lists.infradead.org>, <iommu@lists.linux.dev> Subject: Re: [PATCH 2/2] iommu: fix smmu initialization memory leak problem Date: Fri, 18 Nov 2022 17:28:36 +0800 [thread overview] Message-ID: <26e8c338-7e4b-b35e-c68a-78a7cbdf2d45@huawei.com> (raw) In-Reply-To: <20221114180821.GC31476@willie-the-truck> On 2022/11/15 2:08, Will Deacon Wrote: > On Fri, Oct 21, 2022 at 11:51:47AM +0800, Longfang Liu wrote: >> When iommu_device_register() in arm_smmu_device_probe() fails, >> in addition to sysfs needs to be deleted, device should also >> be disabled, and the memory of iopf needs to be released to >> prevent memory leak of iopf. >> >> Signed-off-by: Longfang Liu <liulongfang@huawei.com> >> --- >> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 9 +++++++-- >> 1 file changed, 7 insertions(+), 2 deletions(-) >> >> 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 a1db07bed6a9..c70defb0c866 100644 >> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c >> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c >> @@ -3816,11 +3816,16 @@ static int arm_smmu_device_probe(struct platform_device *pdev) >> ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); >> if (ret) { >> dev_err(dev, "Failed to register iommu\n"); >> - iommu_device_sysfs_remove(&smmu->iommu); >> - return ret; >> + goto err_sysfs_remove; >> } >> >> return 0; >> + >> +err_sysfs_remove: >> + iommu_device_sysfs_remove(&smmu->iommu); >> + arm_smmu_device_disable(smmu); >> + iopf_queue_free(smmu->evtq.iopf); >> + return ret; > > Doesn't this miss the cases where iommu_device_sysfs_add() or > arm_smmu_device_reset() fail? > > We'd probably be better off using something like devres_alloc() to track > the iopf queue here. > This is actually not a problem found by the test, but a problem found by the code logic analysis. When an error exits, the memory allocated by the iopf queue is not released during the entire exit process. In addition, it can also be seen from arm_smmu_device_remove() that the missing operation when the probe error exits. Thanks Longfang. > Will > . > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-11-18 9:28 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-21 3:51 [PATCH 0/2] fix the memory leak of iopf Longfang Liu 2022-10-21 3:51 ` Longfang Liu 2022-10-21 3:51 ` [PATCH 1/2] iommu: fix " Longfang Liu 2022-10-21 3:51 ` Longfang Liu 2022-11-02 1:36 ` liulongfang 2022-11-02 1:36 ` liulongfang 2022-10-21 3:51 ` [PATCH 2/2] iommu: fix smmu initialization memory leak problem Longfang Liu 2022-10-21 3:51 ` Longfang Liu 2022-11-14 18:08 ` Will Deacon 2022-11-14 18:08 ` Will Deacon 2022-11-18 9:28 ` liulongfang [this message] 2022-11-18 9:28 ` liulongfang 2022-11-18 11:54 ` Robin Murphy 2022-11-18 11:54 ` Robin Murphy 2022-11-21 2:09 ` liulongfang 2022-11-21 2:09 ` liulongfang
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=26e8c338-7e4b-b35e-c68a-78a7cbdf2d45@huawei.com \ --to=liulongfang@huawei.com \ --cc=iommu@lists.linux.dev \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=robin.murphy@arm.com \ --cc=will@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.