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: <CAK8P3a0j=vowKpdJxt-GBsFuwqNJZv-dB-XoZihg=XHey1VoCg@mail.gmail.com>
Date:   Mon, 7 Jun 2021 10:22:55 +0200
From:   Arnd Bergmann <arnd@...db.de>
To:     Sven Peter <sven@...npeter.dev>
Cc:     USB list <linux-usb@...r.kernel.org>,
        Felipe Balbi <balbi@...nel.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3] usb: dwc3: support 64 bit DMA in platform driver

On Mon, Jun 7, 2021 at 10:01 AM Sven Peter <sven@...npeter.dev> wrote:
> On Mon, Jun 7, 2021, at 09:25, Arnd Bergmann wrote:
> > On Mon, Jun 7, 2021 at 8:18 AM Sven Peter <sven@...npeter.dev> wrote:
> > >
> > > Currently, the dwc3 platform driver does not explicitly ask for
> > > a DMA mask. This makes it fall back to the default 32-bit mask which
> > > breaks the driver on systems that only have RAM starting above the
> > > first 4G like the Apple M1 SoC.
> > >
> > > Fix this by calling dma_set_mask_and_coherent with a 64bit mask.
> > >
> > > Signed-off-by: Sven Peter <sven@...npeter.dev>
> > > ---
> > >
> > > Third time's a charm I hope - this time much simpler :)
> >
> > I think this is almost good, but there is still one small issue:
> >
> > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> > > index b6e53d8212cd..ba4792b6a98f 100644
> > > --- a/drivers/usb/dwc3/core.c
> > > +++ b/drivers/usb/dwc3/core.c
> > > @@ -1545,6 +1545,10 @@ static int dwc3_probe(struct platform_device *pdev)
> > >
> > >         dwc3_get_properties(dwc);
> > >
> > > +       ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64));
> > > +       if (ret)
> > > +               return ret;
> >
> > This will now  fail on machines with dwc3 connected to a 32-bit bus (or a
> > bus that is accidentally not annotated as supporting 64-bit) when there is
> > some memory that is not addressable through that bus.
> >
> > If dma_set_mask_and_coherent() fails, the platform should just fall back to
> > 32-bit addressing as it did before your change. dma_alloc_*() will do that
> > implicitly by allocating from ZONE_DMA32, while dma_map_*() fails
> > on any non-addressable memory, or falls back to swiotlb if that is available.
>
>
> Makes sense, but just to make sure I understand this correctly:
> All that needs to be done is call dma_set_mask_and_coherent with a 64 bit
> mask and then just ignore the return value?

If the driver never calls dma_map_*() on the device, that is correct, otherwise
it has to be careful about what pointers it passes in there to avoid
failing later.
Since it is already working without the dma_set_mask(), I don't expect a
problem there.

I suppose in theory, the dwc3_alloc_scratch_buffers() should use GFP_DMA32
if dma_set_mask_and_coherent() failed. On arm32, it won't matter since
all kernel pointers are generall within ZONE_DMA32, and on arm64 we always
build with SWIOTLB enabled. Not sure where else you'd typically find dwc3,
or if any of them are broken without changing this.

        Arnd

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ