From: Felipe Balbi <balbi@kernel.org>
To: John Stultz <john.stultz@linaro.org>
Cc: "Yang\, Fei" <fei.yang@intel.com>,
Andrzej Pietrasiewicz <andrzej.p@collabora.com>,
lkml <linux-kernel@vger.kernel.org>,
Felipe Balbi <felipe.balbi@linux.intel.com>,
Thinh Nguyen <thinhn@synopsys.com>,
Tejas Joglekar <tejas.joglekar@synopsys.com>,
Jack Pham <jackp@codeaurora.org>, Todd Kjos <tkjos@google.com>,
Greg KH <gregkh@linuxfoundation.org>,
Linux USB List <linux-usb@vger.kernel.org>,
stable <stable@vger.kernel.org>, Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@infradead.org>
Subject: Re: [RFC][PATCH 0/2] Avoiding DWC3 transfer stalls/hangs when using adb over f_fs
Date: Thu, 06 Feb 2020 08:23:48 +0200 [thread overview]
Message-ID: <87lfpg5j4b.fsf@kernel.org> (raw)
In-Reply-To: <CALAqxLUQ0ciJTLrmEAu9WKCJHAbpY9szuVm=+VapN2QWWGnNjA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4072 bytes --]
Hi,
John Stultz <john.stultz@linaro.org> writes:
> On Thu, Jan 23, 2020 at 9:46 AM Felipe Balbi <balbi@kernel.org> wrote:
>> >>>>>
>> >>>>> Since ~4.20, when the functionfs gadget enabled scatter-gather
>> >>>>> support, we have seen problems with adb connections stalling and
>> >>>>> stopping to function on hardware with dwc3 usb controllers.
>> >>>>> Specifically, HiKey960, Dragonboard 845c, and Pixel3 devices.
> ...
>> >>
>> >> I'm pretty sure this should be solved at the DMA API level, just want to confirm.
>> >
>> > I have sent you the tracepoints long time ago. Also my analysis of the
>> > problem (BTW, I don't think the tracepoints helped much). It's
>> > basically a logic problem in function dwc3_gadget_ep_reclaim_trb_sg().
>>
>> AFAICT, this is caused by DMA API merging pages together when map an
>> sglist for DMA. While doing that, it does *not* move the SG_END flag
>> which sg_is_last() checks.
>>
>> I consider that an overlook on the DMA API, wouldn't you? Why should DMA
>> API users care if pages were merged or not while mapping the sglist? We
>> have for_each_sg() and sg_is_last() for a reason.
>>
>
> From an initial look, I agree this is pretty confusing. dma_map_sg()
> can coalesce entries in the sg list, modifying the sg entires
> themselves, however, in doing so it doesn't modify the number of
> entries in the sglist (nor the end state bit). That's pretty subtle!
>
> My initial naive attempt to fix the dma-iommu path to set the end bit
> at the tail of __finalize_sg() which does the sg entry modifications,
> only caused trouble elsewhere, as there's plenty of logic that expects
> the number of entries to not change, so having sg_next() return NULL
> before that point results in lots of null pointer traversals.
>
> Further, looking at the history, while apparently quirky, this has
> been the documented behavior in DMA-API.txt for over almost 14 years
> (at least). It clearly states that that dma_map_api can return fewer
> mapped entries then sg entries, and one should loop only that many
> times (for_each_sg() having a max number of entries to iterate over
> seems specifically for this purpose). Additionally, it says one must
> preserve the original number of entries (not # mapped entries) for
> dma_unmap_sg().
>
> So I'm not sure that sg_is_last() is really valid for iterating on
> mapped sg lists.
>
> Should it be? Probably (at least with my unfamiliar eyes), but
> sg_is_last() has been around for almost as long coexisting with this
> behavioral quirk, so I'm also not sure this is the best hill for the
> dwc3 driver to die on. :)
>
> The fix here:
> https://lore.kernel.org/lkml/20200122222645.38805-3-john.stultz@linaro.org/
> Or maybe the slightly cleaner varient here:
> https://git.linaro.org/people/john.stultz/android-dev.git/commit/?h=dev/db845c-mainline-WIP&id=61a5816aa71ec719e77df9f2260dbbf6bcec7c99
in that case, we don't need to use sg_is_last() at all, since i will
always encode the last entry in the list.
> seems like it would correctly address things following the
> documentation and avoid the failures we're seeing.
>
> As to if dma_map_sg() should fixup the state bits or properly shrink
> the sg list when it coalesces entries, that seems like it would be a
> much more intrusive change across quite a bit of the kernel that was
> written to follow the documented method. So my confidence that such a
> change would make it upstream in a reasonable amount of time isn't
> very high, and it seems like a bad idea to block the driver from
> working properly in the meantime.
>
> Pulling in Christoph and Jens as I suspect they have more context on
> this, and maybe can explain thats its not so quirky with the right
> perspective?
>
> Thoughts? Maybe there is an easier way to make it less quirky then
> what I imagine?
it just seems very counter-intuitive to me that DMA api can coalesce
entries but they're actually still there and drivers have to cope with
this behavior.
--
balbi
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
next prev parent reply other threads:[~2020-02-06 6:24 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-22 22:26 [RFC][PATCH 0/2] Avoiding DWC3 transfer stalls/hangs when using adb over f_fs John Stultz
2020-01-22 22:26 ` [RFC][PATCH 1/2] usb: dwc3: gadget: Check for IOC/LST bit in both event->status and TRB->ctrl fields John Stultz
2020-01-23 7:24 ` Felipe Balbi
2020-01-23 18:54 ` Yang, Fei
[not found] ` <CALAqxLUeBf2Jx2tLW1yzJk6JHM0RP9cJbTt7m19Qdz-rWMw2mQ@mail.gmail.com>
2020-01-24 7:45 ` Felipe Balbi
2020-01-24 22:10 ` John Stultz
2020-01-25 11:02 ` Felipe Balbi
2020-01-27 18:48 ` John Stultz
2020-01-22 22:26 ` [RFC][PATCH 2/2] usb: dwc3: gadget: Correct the logic for finding last SG entry John Stultz
2020-01-23 7:25 ` Felipe Balbi
2020-01-23 15:50 ` Anurag Kumar Vulisha
2020-01-23 7:18 ` [RFC][PATCH 0/2] Avoiding DWC3 transfer stalls/hangs when using adb over f_fs Felipe Balbi
2020-01-23 8:43 ` Andrzej Pietrasiewicz
2020-01-23 16:29 ` Yang, Fei
2020-01-23 17:31 ` Felipe Balbi
2020-01-23 17:37 ` Yang, Fei
2020-01-23 17:46 ` Felipe Balbi
2020-01-23 18:28 ` Yang, Fei
2020-02-05 21:03 ` John Stultz
2020-02-06 6:23 ` Felipe Balbi [this message]
2020-02-06 7:40 ` Christoph Hellwig
2020-02-06 18:29 ` Felipe Balbi
2020-02-06 18:41 ` Christoph Hellwig
2020-02-07 6:00 ` Felipe Balbi
2020-01-23 19:58 ` John Stultz
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=87lfpg5j4b.fsf@kernel.org \
--to=balbi@kernel.org \
--cc=andrzej.p@collabora.com \
--cc=axboe@kernel.dk \
--cc=fei.yang@intel.com \
--cc=felipe.balbi@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@infradead.org \
--cc=jackp@codeaurora.org \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tejas.joglekar@synopsys.com \
--cc=thinhn@synopsys.com \
--cc=tkjos@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.