mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Wahren <stefan.wahren@i2se.com>
To: Doug Anderson <dianders@chromium.org>,
	Guenter Roeck <linux@roeck-us.net>
Cc: "Minas Harutyunyan" <hminas@synopsys.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Antti Seppälä" <a.seppala@gmail.com>,
	"Boris ARZUR" <boris@konbu.org>,
	linux-usb@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	"Felipe Balbi" <balbi@kernel.org>,
	"Martin Schiller" <ms@dev.tdt.de>,
	"Nicolas Saenz Julienne" <nsaenzjulienne@suse.de>
Subject: Re: [RFT PATCH 1/4] usb: dwc2: Simplify and fix DMA alignment code
Date: Fri, 28 Feb 2020 17:26:47 +0100	[thread overview]
Message-ID: <ea445ef5-3e8a-1e58-d264-0d7dad064fc8@i2se.com> (raw)
In-Reply-To: <CAD=FV=WDd4E-zDW73kb-qHo1QYQrD3BTgVpE70rzowpgeXVy7w@mail.gmail.com>

Hi Doug,

[add Nicolas the new BCM2835 maintainer]

Am 27.02.20 um 23:06 schrieb Doug Anderson:
> Hi,
>
> On Wed, Feb 26, 2020 at 1:04 PM Guenter Roeck <linux@roeck-us.net> wrote:
>> The code to align buffers for DMA was first introduced with commit
>> 3bc04e28a030 ("usb: dwc2: host: Get aligned DMA in a more supported way").
>> It was updated with commit 56406e017a88 ("usb: dwc2: Fix DMA alignment
>> to start at allocated boundary") because it did not really align buffers to
>> DMA boundaries but to word offsets. This was then optimized in commit
>> 1e111e885238 ("usb: dwc2: Fix inefficient copy of unaligned buffers")
>> to only copy actual data rather than the whole buffer. Commit 4a4863bf2e79
>> ("usb: dwc2: Fix DMA cache alignment issues") changed this further to add
>> a padding at the end of the buffer to ensure that the old data pointer is
>> not in the same cache line as the buffer.
>>
>> This last commit states "Otherwise, the stored_xfer_buffer gets corrupted
>> for IN URBs on non-cache-coherent systems". However, such corruptions are
>> still observed. This suggests that the commit may have been hiding a
>> problem rather than fixing it. Further analysis shows that this is indeed
>> the case: The code in dwc2_hc_start_transfer() assumes that the transfer
>> size is a multiple of wMaxPacketSize, and rounds up the transfer size
>> communicated to the chip accordingly. Added debug code confirms that
>> the chip does under some circumstances indeed send more data than requested
>> in the urb receive buffer size.
>>
>> On top of that, it turns out that buffers are still not guaranteed to be
>> aligned to dma_get_cache_alignment(), but to DWC2_USB_DMA_ALIGN (4).
>> Further debugging shows that packets aligned to DWC2_USB_DMA_ALIGN
>> but not to dma_get_cache_alignment() are indeed common and work just fine.
>> This suggests that commit 56406e017a88 was not really necessary because
>> even without it packets were already aligned to DWC2_USB_DMA_ALIGN.
>>
>> To simplify the code, move the old data pointer back to the beginning of
>> the new buffer, restoring most of the original commit. Stop aligning the
>> buffer to dma_get_cache_alignment() since it isn't needed and only makes
>> the code more complex. Instead, ensure that the allocated buffer is a
>> multiple of wMaxPacketSize to ensure that the chip does not write beyond
>> the end of the buffer.
> I do like the cleanliness of being able to easily identify the old
> buffer (AKA by putting it first) and I agree that the existing code
> was only really guaranteeing 4-byte alignment and if we truly needed
> more alignment then we'd be allocating a lot more bounce buffers
> (which is pretty expensive).
>
> ...but the argument in commit 56406e017a88 ("usb: dwc2: Fix DMA
> alignment to start at allocated boundary") is still a compelling one.
> Maybe at least put a comment in the code next to the "#define
> DWC2_USB_DMA_ALIGN" saying that we think that this is enough alignment
> for anyone using dwc2's built-in DMA logic?
>
>
>> Cc: Douglas Anderson <dianders@chromium.org>
>> Cc: Boris Arzur <boris@konbu.org>
>> Fixes: 56406e017a88 ("usb: dwc2: Fix DMA alignment to start at allocated boundary")
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>>  drivers/usb/dwc2/hcd.c | 67 ++++++++++++++++++++++--------------------
>>  1 file changed, 35 insertions(+), 32 deletions(-)
> Sorry for such a mess and thank you for all the work tracking down and
> documenting all the problems.  Clearly deep understanding of DMA is
> not something I can claim.  :(
>
> A few points of order first:
> * Although get_maintainer doesn't identify him, it has seemed like
> Felipe Balbi lands most of the dwc2 things.  Probably a good idea to
> CC him.
> * I have historically found Stefan Wahren interested in dwc2 fixes and
> willing to test them on Raspberry Pi w/ various peripherals.

i'm not the BCM2835 maintainer anymore, but will give it a try.

Regards
Stefan


  parent reply	other threads:[~2020-02-28 16:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26 21:04 [RFT PATCH 0/4] usb: dwc2: Fixes and improvements Guenter Roeck
2020-02-26 21:04 ` [RFT PATCH 1/4] usb: dwc2: Simplify and fix DMA alignment code Guenter Roeck
2020-02-27 22:06   ` Doug Anderson
2020-02-27 22:27     ` Guenter Roeck
2020-02-28  4:28       ` Guenter Roeck
2020-02-28 16:14         ` Doug Anderson
2020-02-28 17:59           ` Guenter Roeck
2020-02-29  7:46             ` Antti Seppälä
2020-02-29 15:25               ` Guenter Roeck
2020-02-29 16:33                 ` Antti Seppälä
2020-03-01 15:51                   ` Antti Seppälä
2020-03-01 16:24                     ` Guenter Roeck
2020-03-01 16:51                       ` Antti Seppälä
2020-03-01 17:13                         ` Guenter Roeck
2020-02-28 16:26     ` Stefan Wahren [this message]
2020-02-26 21:04 ` [RFT PATCH 2/4] usb: dwc2: Do not update data length if it is 0 on inbound transfers Guenter Roeck
2020-02-27 22:06   ` Doug Anderson
2020-02-28  0:32     ` Guenter Roeck
2020-02-26 21:04 ` [RFT PATCH 3/4] usb: dwc2: Abort transaction after errors with unknown reason Guenter Roeck
2020-02-27 22:06   ` Doug Anderson
2020-02-28  0:36     ` Guenter Roeck
2020-02-26 21:04 ` [RFT PATCH 4/4] usb: dwc2: Make "trimming xfer length" a debug message Guenter Roeck
2020-02-27 22:07   ` Doug Anderson
2020-02-28  0:38     ` Guenter Roeck
2020-02-29  1:50 ` [RFT PATCH 0/4] usb: dwc2: Fixes and improvements Boris ARZUR
2021-01-12 19:40 ` Nicolas Saenz Julienne
2021-01-12 19:44 ` Nicolas Saenz Julienne
2021-01-13  4:48   ` Guenter Roeck

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=ea445ef5-3e8a-1e58-d264-0d7dad064fc8@i2se.com \
    --to=stefan.wahren@i2se.com \
    --cc=a.seppala@gmail.com \
    --cc=balbi@kernel.org \
    --cc=boris@konbu.org \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hminas@synopsys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=ms@dev.tdt.de \
    --cc=nsaenzjulienne@suse.de \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®