From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A475CC54EBC for ; Tue, 10 Jan 2023 12:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=v7EiiErpkMNWNRwvQrQhh/0W/CrzI04CyiUcyqqeN/s=; b=afxgZANomlZmq8 YG8JjxsiOzBCymQyRxkHC5KXBMx8zakpFpnTxWpZt3e6s19C/lZBOCPfp8Jw0ZAAxl1ogXCQNBJm1 S+A+Njm6H/12Tksr6g9fGNa5R//dg5nO49x2ByI/l5mHHZsanGCkpVLDwtKLGE4keNsjwa8cSpDOv FgZhMVYm6Oc3Hbso3ixsbYz5U7GDW9Tm4LG1nBwkkib7TFI+fpyY6/3NJBx1X4Sz6+8CsUSX7QmoA Y0XAFwnRPq90vJBh4HgEM4IA1976G9R8csnOx5F2eSmxGwUiMuM0EgPGVjWF8tVPl2hmRMgZwOyRT jMd7XT7+HYp5CNsLUGyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFDJX-006jrC-H4; Tue, 10 Jan 2023 12:01:11 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFDJP-006jq4-Rw for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2023 12:01:09 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 63D7761645; Tue, 10 Jan 2023 12:01:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 772AFC433D2; Tue, 10 Jan 2023 12:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673352062; bh=dJUumUaWZHmrgtk7/xY3OEo27gkthFqWeeR6gHs6HOc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=L4WC9jfJMLxaxiqNcsXCvwkNvFxPM6bIvkbosFonTMJvAQiqNYYSF9tVUjh/DEDco xaDXUYg8cNkNueOfVlZQc0+9qYPMrkudzoazJa3q75pZJ7c5sEhaLZwhnZakMbaW1o /bqsnQDNHhyxJHfMtPgB34xKe2NyxggjhZtsyo0mHLbv8w9esN3KQQ3vgcID7sP/Tg jAeNPrOsRcv1l5TNJU/wAzoyPJ6jWRopbt5DSBHj04uaa95zEm9gC6COIpCsH5CCNY cQeTXBkwp8LXHZs2Dfs80mMy1nmMdNI0DPRNCW1GVsxgB9SRDum4BJJc153gqxtlxr 4AmQs83fq388w== Date: Tue, 10 Jan 2023 12:00:57 +0000 From: Will Deacon To: Marion & Christophe JAILLET Cc: liulongfang , Robin Murphy , iommu@lists.linux.dev, "linux-arm-kernel@lists.infradead.org" Subject: Re: [PATCH v2] iommu: fix smmu initialization memory leak problem Message-ID: <20230110120056.GA9119@willie-the-truck> References: <20221121030421.19295-1-liulongfang@huawei.com> <20221121180552.GB7645@willie-the-truck> <20221129152452.GB26561@willie-the-truck> <20221201133118.GA28489@willie-the-truck> <4fb97e88-92df-2738-a078-f8269aa76870@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_040105_032123_EF2B54D2 X-CRM114-Status: GOOD ( 28.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Dec 20, 2022 at 10:37:51PM +0100, Marion & Christophe JAILLET wrote: > = > Le 20/12/2022 =E0 04:17, liulongfang a =E9crit=A0: > > On 2022/12/1 21:31, Will Deacon Wrote: > > > On Thu, Dec 01, 2022 at 08:42:02PM +0800, liulongfang wrote: > > > > On 2022/11/29 23:24, Will Deacon wrote: > > > > > On Tue, Nov 22, 2022 at 08:00:39PM +0800, liulongfang wrote: > > > > > > On 2022/11/22 2:05, Will Deacon wrote: > > > > > > > On Mon, Nov 21, 2022 at 11:04:21AM +0800, Longfang Liu wrote: > > Hi Christophe: > > "[PATCH] iommu/arm-smmu-v3: Fix an error handling path in arm_smmu_devi= ce_probe()" > > = > > the patch you sent is the same as mine. The maintainer hopes to optimiz= e the queue > > application part of iopf with devres_alloc(). > = > You also added a arm_smmu_device_disable() call in the error handling pat= h. > Looks good to me, but should be confirmed by s.o who knows the hardware. > = > That said, I think that what has been suggested by Will Deacon would be > something like: > = > = > 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 ab160198edd6..1994990decb8 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -2930,6 +2930,11 @@ static int arm_smmu_cmdq_init(struct arm_smmu_devi= ce > *smmu) > =A0=A0=A0=A0 return 0; > =A0} > = > +static void arm_smmu_free_queues(void *ptr) > +{ > +=A0=A0=A0 iopf_queue_free(ptr); > +} > + > =A0static int arm_smmu_init_queues(struct arm_smmu_device *smmu) > =A0{ > =A0=A0=A0=A0 int ret; > @@ -2957,6 +2962,11 @@ static int arm_smmu_init_queues(struct > arm_smmu_device *smmu) > =A0=A0=A0=A0 =A0=A0=A0 smmu->evtq.iopf =3D iopf_queue_alloc(dev_name(smmu= ->dev)); > =A0=A0=A0=A0 =A0=A0=A0 if (!smmu->evtq.iopf) > =A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 return -ENOMEM; > + > +=A0=A0=A0 =A0=A0=A0 ret =3D devm_add_action_or_reset(smmu->dev, arm_smmu= _free_queues, > +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=A0=A0 smm= u->evtq.iopf); > +=A0=A0=A0 =A0=A0=A0 if (ret) > +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 return ret; > =A0=A0=A0=A0 } > = > =A0=A0=A0=A0 /* priq */ > @@ -3832,16 +3842,21 @@ static int arm_smmu_device_probe(struct > platform_device *pdev) > =A0=A0=A0=A0 ret =3D iommu_device_sysfs_add(&smmu->iommu, dev, NULL, > =A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0 "smmu3.%pa", &ioa= ddr); > =A0=A0=A0=A0 if (ret) > -=A0=A0=A0 =A0=A0=A0 return ret; > +=A0=A0=A0 =A0=A0=A0 goto err_reset; > = > =A0=A0=A0=A0 ret =3D iommu_device_register(&smmu->iommu, &arm_smmu_ops, d= ev); > =A0=A0=A0=A0 if (ret) { > =A0=A0=A0=A0 =A0=A0=A0 dev_err(dev, "Failed to register iommu\n"); > -=A0=A0=A0 =A0=A0=A0 iommu_device_sysfs_remove(&smmu->iommu); > -=A0=A0=A0 =A0=A0=A0 return ret; > +=A0=A0=A0 =A0=A0=A0 goto err_sysfs_add; > =A0=A0=A0=A0 } > = > =A0=A0=A0=A0 return 0; > + > +err_sysfs_add: > +=A0=A0=A0 iommu_device_sysfs_remove(&smmu->iommu); > +err_reset: > +=A0=A0=A0 arm_smmu_device_disable(smmu); > +=A0=A0=A0 return ret; > =A0} I don't see the need for this hunk -- we presently call iommu_device_sysfs_remove() if iommu_device_register() fails, so that can stay as-is. If it's necessary to call arm_smmu_device_disable() then I think that should be a separate patch because it doesn't seem related to the freeing of the iopf queue at all. Otherwise, I'm happy to queue something like this using devm_add_action_or_reset(), thanks. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel