linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@kernel.org>
To: Sriharsha Allenki <sallenki@codeaurora.org>,
	gregkh@linuxfoundation.org, linux-usb@vger.kernel.org
Cc: jackp@codeaurora.org, mgautam@codeaurora.org
Subject: Re: [PATCH] usb: dwc3: Do not process request if HWO is set for its TRB
Date: Tue, 03 Dec 2019 14:30:06 +0200	[thread overview]
Message-ID: <871rtla8xd.fsf@gmail.com> (raw)
In-Reply-To: <0101016ec6294c21-99711286-dbda-4d62-b8c7-e9f28e99b261-000000@us-west-2.amazonses.com>

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


Hi,

Sriharsha Allenki <sallenki@codeaurora.org> writes:
>>> If the HWO bit is set for the TRB (or the first TRB if scatter-gather
>>> is used) of a request, it implies that core is still processing it.
>>> In that case do not reclaim that TRB and do not giveback the
>>> request to the function driver, else it will result in a SMMU
>>> translation fault when core tries to access the buffer
>>> corresponding to this TRB.
>> This is not entirely true. There are cases where driver *must* clear HWO
>> bit manually and driver currently accounts for that. Care to explain
>
> Based on my understanding I am trying to list down the two cases where
> driver must clear HWO bit manually and how the patch would not regress 
> these.
>
> Additionally, I want to add that this patch is checking for req->trb
> (not the TRB pointed by the *trb_dequeue*) which will be pointing to
> the first TRB in the case of SG and in the case of linear it point to
> the TRB containing the data (not theextra_trb or the trb to handle
> zero length packet).
>
> *Case-1*:
>
> We are in the middle of series of chained TRBs and we received a short
> transfer along the way. Here is the code handling this case:
>
>          /*
>           * If we're in the middle of series of chained TRBs and we
>           * receive a short transfer along the way, DWC3 will skip
>           * through all TRBs including the last TRB in the chain (the
>           * where CHN bit is zero. DWC3 will also avoid clearing HWO
>           * bit and SW has to do it manually.
>           *
>           * We're going to do that here to avoid problems of HW trying
>           * to use bogus TRBs for transfers.
>           */
>          if (chain && (trb->ctrl & DWC3_TRB_CTRL_HWO))
>                  trb->ctrl &= ~DWC3_TRB_CTRL_HWO;
>
>
> This case occurs only after the first TRB of the chain is processed,
> which we arechecking in the patch. Although, this piece of code has
> been no-op after introducingthe function
> "dwc3_gadget_ep_reclaim_trb_sg".This function checks for the HWO and
> does notcall the "dwc3_gadget_ep_reclaim_completed_trb" if it is
> set.Hence this condition mostly likely will never hit.

You're missing one important detail: If we have e.g. 200 TRBs in a
single SG-list and we receive a short packet on TRB 10, we will have 190
TRBs with HWO bit left set and your patch prevents the driver from
clearing that bit. Yes, you are regressing a very special case.

> *Case-2*:
> The second case is wherewe append the actual data buffer TRB with an 
> extra_trb
> for unaligned OUT transfer. Code handling this is:
>
>          /*
>           * If we're dealing with unaligned size OUT transfer, we will 
> be left
>           * with one TRB pending in the ring. We need to manually clear 
> HWO bit
>           * from that TRB.
>           */
>
>          if (req->needs_extra_trb && !(trb->ctrl & DWC3_TRB_CTRL_CHN)) {
>                  trb->ctrl &= ~DWC3_TRB_CTRL_HWO;
>                  return 1;
>          }
>
> This also requires that the actual data buffer TRB should be processed
> and then we areexpected to reclaim this extra_trb. If the TRB
> corresponding to the actual data (req->trb)is not processed we are not
> expecting this extra_trb to be reclaimed.

if you read dwc3_gadget_ep_reclaim_complete_trb() carefully, you will
see that we *never* touch the next TRB from inside that function. We
rely on the fact that this function will be called AGAIN to clear HWO
bit on both of these special cases and you're causing a regression to
both of them.

> So, both these cases occurs and valid only if the first TRB/TRB
> containing the dataof the request(req->trb) is processed.

yes, and your patch makes no distinction of what type of TRB we're
dealing with. In the case of unaligned transfers, we would giveback the
first TRB with the unaligned length and never clear HWO from the chained
TRB following it because your patch would prevent
dwc3_gadget_ep_reclaim_trb*() from even being called.

> The proposed change is looking for thecompletion of this TRB, soI
> don't think this change will regress the above mentioned cases.

it will

>> what problem you actually found? Preferrably with tracepoint data
>> showing the fault.
>
> Test case here involves f_fs driver in AIO mode and we see ~8 TRBs in
> the queue with HWO set and UPDATE_XFER done. In the failure case I see
> thatas part of processingthe interrupt generated by the core for the
> completion of the first TRB, the driver isgoing ahead and giving

we shouldn't get completion interrupt for the first TRB, only the
last. Care to share tracepoint data?

> backthe requests of all theother queued TRBs, whichinvolves removing
> the SMMU mapping of the buffers associated with the requests.  But
> these are still active and when core processesthese TRBs and their
> correspondingun-mapped buffers, I see a translationfaultraised by the
> SMMU.
>
> I hope I have answered your queries, please let me know if I am still 
> missing something here.

yes, tracepoint data showing the problem. Thank you

-- 
balbi

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

  reply	other threads:[~2019-12-03 12:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1574946055-3788-1-git-send-email-sallenki@codeaurora.org>
2019-12-02  7:12 ` [PATCH] usb: dwc3: Do not process request if HWO is set for its TRB Sriharsha Allenki
     [not found] ` <1575270714-29994-1-git-send-email-sallenki@codeaurora.org>
2019-12-02  7:36   ` Felipe Balbi
2019-12-02 10:30     ` Sriharsha Allenki
2019-12-03 12:30       ` Felipe Balbi [this message]
2019-12-10  6:50         ` Sriharsha Allenki
     [not found]         ` <4c34d724-6a45-dc21-2d10-337f358015ce@codeaurora.org>
2019-12-10 11:46           ` 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=871rtla8xd.fsf@gmail.com \
    --to=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jackp@codeaurora.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mgautam@codeaurora.org \
    --cc=sallenki@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).