lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YAaipp7Srf6uUdFZ@aptenodytes>
Date:   Tue, 19 Jan 2021 10:13:10 +0100
From:   Paul Kocialkowski <paul.kocialkowski@...tlin.com>
To:     Robin Murphy <robin.murphy@....com>
Cc:     Yong Wu <yong.wu@...iatek.com>, Rob Herring <robh@...nel.org>,
        youlin.pei@...iatek.com, devicetree@...r.kernel.org,
        Nicolas Boichat <drinkcat@...omium.org>,
        srv_heupstream@...iatek.com, chao.hao@...iatek.com,
        Will Deacon <will@...nel.org>,
        Frank Rowand <frowand.list@...il.com>,
        linux-kernel@...r.kernel.org, Evan Green <evgreen@...omium.org>,
        Tomasz Figa <tfiga@...gle.com>,
        iommu@...ts.linux-foundation.org,
        linux-mediatek@...ts.infradead.org,
        Krzysztof Kozlowski <krzk@...nel.org>,
        Matthias Brugger <matthias.bgg@...il.com>,
        anan.sun@...iatek.com, linux-arm-kernel@...ts.infradead.org
Subject: Re: [PATCH v6 06/33] of/device: Move dma_range_map before
 of_iommu_configure

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.
> > > > 
> > > > CC: Rob Herring <robh+dt@...nel.org>
> > > > CC: Frank Rowand <frowand.list@...il.com>
> > > > Signed-off-by: Yong Wu <yong.wu@...iatek.com>
> > > > ---
> > > >   drivers/of/device.c | 3 ++-
> > > >   1 file changed, 2 insertions(+), 1 deletion(-)
> > > > 
> > > > 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, struct device_node *np,
> > > >   	dev_dbg(dev, "device is%sdma coherent\n",
> > > >   		coherent ? " " : " not ");
> > > > +	dev->dma_range_map = map;
> > > >   	iommu = of_iommu_configure(dev, np, id);
> > > >   	if (PTR_ERR(iommu) == -EPROBE_DEFER) {
> > > >   		kfree(map);
> > > > +		dev->dma_range_map = NULL;
> > > 
> > > Not really going to matter, but you should probably clear dma_range_map
> > > before what it points to is freed.
> > > 
> > > With that,
> > > 
> > > Reviewed-by: Rob Herring <robh@...nel.org>
> > 
> > Thanks for the review. I will move it before "kfree(map)" in next
> > version.
> 
> 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 sweeping
> my inbox now only goes to show I was right to think of it :)
> 
> 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 = map; under the if (!ret).

Then I think the error case for of_iommu_configure should be to set
dev->dma_range_map = NULL; only if map != NULL (otherwise we'd be overwriting
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.
> 
> [1] https://lore.kernel.org/linux-arm-kernel/5c7946f3-b56e-da00-a750-be097c7ceb32@arm.com/
> 
> > > 
> > > >   		return -EPROBE_DEFER;
> > > >   	}
> > > > @@ -181,7 +183,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
> > > >   	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
> > > > -	dev->dma_range_map = map;
> > > >   	return 0;
> > > >   }
> > > >   EXPORT_SYMBOL_GPL(of_dma_configure_id);
> > > > -- 
> > > > 2.18.0
> > > > 
> > 
> > _______________________________________________
> > iommu mailing list
> > iommu@...ts.linux-foundation.org
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu
> > 

-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ