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 X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37519C433DB for ; Tue, 19 Jan 2021 09:14:39 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BA9A623135 for ; Tue, 19 Jan 2021 09:14:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA9A623135 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LDx684R5DssQQ2NJMYRbYvyG6ywj4fpBnjokRtxF+HQ=; b=1JgoN/nywjC0GPPt02+prAIQT Gh+mnJS/mhHpKzVtWuBhh934m1pJ0GhXfnP2rRUNu9rEUun9eM26/ENuCWp2WZ48bkQWRJlbHda1v 3ZkyO90Nlj+foc0jGl3P+wsqCz8RWlZB3HfIYHMcRmhazyq/A9ULNCBsACJ0sU8ZsUr1glF2dyEH9 ntUGOYHV/cL8b1aJrlw13I/B3v3AZtxYL8RZA+Wx5NGWumb+6yKqhOGg+uQc2pVYqn/Xk6E5+c79k 9yTFj6QP+Dg6Lg2iW5OdW8dEGder6rnnVpI2wK+/YAzwTBs39GdRND4CqVfdE9XtCiHiAbpt/qdQm W4qBufYAA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l1n4h-0006nM-5X; Tue, 19 Jan 2021 09:13:19 +0000 Received: from relay2-d.mail.gandi.net ([217.70.183.194]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l1n4e-0006m1-5r; Tue, 19 Jan 2021 09:13:17 +0000 X-Originating-IP: 93.29.109.196 Received: from aptenodytes (196.109.29.93.rev.sfr.net [93.29.109.196]) (Authenticated sender: paul.kocialkowski@bootlin.com) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 702B24001D; Tue, 19 Jan 2021 09:13:11 +0000 (UTC) Date: Tue, 19 Jan 2021 10:13:10 +0100 From: Paul Kocialkowski To: Robin Murphy Subject: Re: [PATCH v6 06/33] of/device: Move dma_range_map before of_iommu_configure Message-ID: References: <20210111111914.22211-1-yong.wu@mediatek.com> <20210111111914.22211-7-yong.wu@mediatek.com> <20210114192732.GA3401278@robh.at.kernel.org> <1610688626.4578.1.camel@mhfsdcap03> <1853732d-0efd-171e-9e1f-7ee7ed72a98f@arm.com> MIME-Version: 1.0 In-Reply-To: <1853732d-0efd-171e-9e1f-7ee7ed72a98f@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210119_041316_392050_D8C40278 X-CRM114-Status: GOOD ( 30.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: youlin.pei@mediatek.com, Nicolas Boichat , srv_heupstream@mediatek.com, devicetree@vger.kernel.org, Frank Rowand , linux-kernel@vger.kernel.org, Evan Green , chao.hao@mediatek.com, Tomasz Figa , iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org, Krzysztof Kozlowski , Matthias Brugger , anan.sun@mediatek.com, Will Deacon , Yong Wu , linux-arm-kernel@lists.infradead.org Content-Type: multipart/mixed; boundary="===============1369490893914454951==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============1369490893914454951== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="9JUkddB3RODiIlTw" Content-Disposition: inline --9JUkddB3RODiIlTw Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Mon 18 Jan 21, 15:49, Robin Murphy wrote: > On 2021-01-15 05:30, Yong Wu wrote: > > On Thu, 2021-01-14 at 13:27 -0600, Rob Herring wrote: > > > On Mon, Jan 11, 2021 at 07:18:47PM +0800, Yong Wu wrote: > > > > "dev->dma_range_map" contains the devices' dma_ranges information, > > > > This patch moves dma_range_map before of_iommu_configure. The iommu > > > > driver may need to know the dma_address requirements of its iommu > > > > consumer devices. > > > >=20 > > > > CC: Rob Herring > > > > CC: Frank Rowand > > > > Signed-off-by: Yong Wu > > > > --- > > > > drivers/of/device.c | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > >=20 > > > > diff --git a/drivers/of/device.c b/drivers/of/device.c > > > > index aedfaaafd3e7..1d84636149df 100644 > > > > --- a/drivers/of/device.c > > > > +++ b/drivers/of/device.c > > > > @@ -170,9 +170,11 @@ int of_dma_configure_id(struct device *dev, st= ruct device_node *np, > > > > dev_dbg(dev, "device is%sdma coherent\n", > > > > coherent ? " " : " not "); > > > > + dev->dma_range_map =3D map; > > > > iommu =3D of_iommu_configure(dev, np, id); > > > > if (PTR_ERR(iommu) =3D=3D -EPROBE_DEFER) { > > > > kfree(map); > > > > + dev->dma_range_map =3D NULL; > > >=20 > > > Not really going to matter, but you should probably clear dma_range_m= ap > > > before what it points to is freed. > > >=20 > > > With that, > > >=20 > > > Reviewed-by: Rob Herring > >=20 > > Thanks for the review. I will move it before "kfree(map)" in next > > version. >=20 > Paul noticed that we already have a bug in assigning to this > unconditionally[1] - I'd totally forgotten about this series when I > theorised about IOMMU drivers wanting the information earlier, but sweepi= ng > my inbox now only goes to show I was right to think of it :) >=20 > We should really get something in as a fix independent of this series, > taking both angles into account. Okay, I can also fix this while fixing my case. So we'd go for setting dev->dma_range_map =3D map; under the if (!ret). Then I think the error case for of_iommu_configure should be to set dev->dma_range_map =3D NULL; only if map !=3D NULL (otherwise we'd be overw= riting and leaking the previously-set map). I think a comment to remind that dev->dma_range_map can be set prior to this function would be useful too. What do you think? Cheers, Paul > Robin. >=20 > [1] https://lore.kernel.org/linux-arm-kernel/5c7946f3-b56e-da00-a750-be09= 7c7ceb32@arm.com/ >=20 > > >=20 > > > > return -EPROBE_DEFER; > > > > } > > > > @@ -181,7 +183,6 @@ int of_dma_configure_id(struct device *dev, str= uct device_node *np, > > > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > > > - dev->dma_range_map =3D map; > > > > return 0; > > > > } > > > > EXPORT_SYMBOL_GPL(of_dma_configure_id); > > > > --=20 > > > > 2.18.0 > > > >=20 > >=20 > > _______________________________________________ > > iommu mailing list > > iommu@lists.linux-foundation.org > > https://lists.linuxfoundation.org/mailman/listinfo/iommu > >=20 --=20 Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com --9JUkddB3RODiIlTw Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEJZpWjZeIetVBefti3cLmz3+fv9EFAmAGoqYACgkQ3cLmz3+f v9GonQf/efUk6Macghd2ipStYZpoRfxYwHOuemUNFudMoUEZ3WfF8oq65Qp+I6jx 5f0iHYTgcPXsTDkMgyPINgSmcuagEYEDUH+IkPoJBvZZ8T2/oI5E0y4xGbbpLtfK hGfAg1spG4E0akpjq/2wNSYkiUiVIdXsFHPXrMNez3j0Z8VJKTBoETeb88QoAOaJ KtcJHmcIW3Gi2fYp/EMBbe+oMbairUCcnnqXZLZjYRSfHl+4EpH9T/FmaI2rtgoE xXedTQFz7axYSXPqHR0WWkg0P876yNO+jkd387VvBvC9AxZYMyFngHVDYM4e4Edx eE2MYAMyuHp/V4AlneqACADHWyS/oQ== =2EGZ -----END PGP SIGNATURE----- --9JUkddB3RODiIlTw-- --===============1369490893914454951== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============1369490893914454951==--