All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@kernel.org>
To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Wesley Cheng <wcheng@codeaurora.org>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"jackp@codeaurora.org" <jackp@codeaurora.org>
Subject: Re: [PATCH v2] usb: dwc3: gadget: Avoid canceling current request for queuing error
Date: Wed, 05 May 2021 15:59:27 +0300	[thread overview]
Message-ID: <87zgx9gwuo.fsf@kernel.org> (raw)
In-Reply-To: <aca00596-11db-398f-e0c3-4a4d50efbed5@synopsys.com>

[-- Attachment #1: Type: text/plain, Size: 3373 bytes --]


Hi,

Thinh Nguyen <Thinh.Nguyen@synopsys.com> writes:
>>>>>> allocate io_data (ffs)
>>>>>>  --> usb_ep_queue()
>>>>>>    --> __dwc3_gadget_kick_transfer()
>>>>>>    --> dwc3_send_gadget_ep_cmd(EINVAL)
>>>>>>    --> dwc3_gadget_ep_cleanup_cancelled_requests()
>>>>>>    --> dwc3_gadget_giveback(ECONNRESET)
>>>>>> ffs completion callback
>>>>>> queue work item within io_data
>>>>>>  --> usb_ep_queue returns EINVAL
>>>>>> ffs frees io_data
>>>>>> ...
>>>>>>
>>>>>> work scheduled
>>>>>>  --> NULL pointer/memory fault as io_data is freed
>>>>
>>>> Hi Thinh,
>>>>
>>>>>
>>>>> sounds like a race issue.
>>>>>
>>>>
>>>> It'll always happen if usb_ep_queue() fails with an error. Sorry for not
>>>> clarifying, but the "..." represents executing in a different context
>>>> :). Anything above the "..." is in the same context.
>>>>>>
>>>>>>> BTW, what kinds of command and error do you see in your setup and for
>>>>>>> what type endpoint? I'm thinking of letting the function driver to
>>>>>>> dequeue the requests instead of letting dwc3 automatically
>>>>>>> ending/cancelling the queued requests. However, it's a bit tricky to do
>>>>>>> that if the error is -ETIMEDOUT since we're not sure if the controller
>>>>>>> had already cached the TRBs.
>>>>>>>
>>>>>>
>>>>>> Happens on bulk EPs so far, but I think it wouldn't matter as long as
>>>>>> its over the FFS interface. (and using async IO transfers)
>>>>>
>>>>> Do you know which command and error code? It's strange if
>>>>> UPDATE_TRANSFER command failed.
>>>>>
>>>>
>>>> Sorry for missing that part of the question.  It is a no xfer resource
>>>> error on a start transfer command.  So far this happens on low system
>>>> memory test cases, so there may be some sequences that were missed,
>>>> which led to this particular command error.
>>>>
>>>> Thanks
>>>> Wesley Cheng
>> 
>> Hi Thinh,
>> 
>>>
>>> No xfer resource usually means that the driver attempted to send
>>> START_TRANSFER without waiting for END_TRANSFER command to complete.
>>> This may be a dwc3 driver issue. Did you check this?
>>>
>>> Thanks,
>>> Thinh
>>>
>>>
>> 
>> Yes, we know the reason why this happens, and its due to one of the
>> downstream changes we had that led to the scenario above.  Although,
>> that has been fixed, I still believe the error path is a potential
>> scenario we'd still want to address.
>> 
>> I think the returning success always on dwc3_gadget_ep_queue(), and
>> allowing the error in the completion handler/giveback at the function
>> driver level to do the cleanup is a feasible solution.  Doesn't change
>> the flow of the DWC3 gadget, and so far all function drivers we've used
>> handle this in the correct manner.
>> 
>> Thanks
>> Wesley Cheng
>
> Right. I think for now we should do that (return success always except
> for cases of disconnect or already in-flight etc). This helps keeping it

no, let's not lie to our users ;-)

> simple and avoid some pitfalls dealing with giving back the request.
> Currently we return the error status to dwc3_gadget_ep_queue if we
> failed to send a command that may not even related to the same request
> being queued.

I think the fix should be simple, but we're trying to patch it in the
wrong way. Can y'all comment on my suggestion on the other subthread?

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 511 bytes --]

  parent reply	other threads:[~2021-05-05 12:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04  1:21 [PATCH v2] usb: dwc3: gadget: Avoid canceling current request for queuing error Wesley Cheng
2021-05-04  2:20 ` Thinh Nguyen
2021-05-04  2:45   ` Wesley Cheng
2021-05-04  3:12     ` Thinh Nguyen
2021-05-04  3:27       ` Wesley Cheng
2021-05-04  5:22         ` Thinh Nguyen
2021-05-04  8:24           ` Wesley Cheng
2021-05-05  1:50             ` Thinh Nguyen
2021-05-05  3:37               ` Wesley Cheng
2021-05-05 12:59               ` Felipe Balbi [this message]
2021-05-05 12:57     ` Felipe Balbi
2021-05-05 15:19       ` Alan Stern
2021-05-05 18:01         ` Wesley Cheng
2021-05-05 18:31         ` Thinh Nguyen
2021-05-05 18:46           ` Alan Stern
2021-05-06  9:04           ` Felipe Balbi
2021-05-06 18:06             ` Thinh Nguyen
2021-05-05 17:59       ` Wesley Cheng
2021-05-06  9:00         ` Felipe Balbi
2021-05-05 19:06       ` Thinh Nguyen
2021-05-05 12:50 ` Felipe Balbi

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=87zgx9gwuo.fsf@kernel.org \
    --to=balbi@kernel.org \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jackp@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=wcheng@codeaurora.org \
    /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.