linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: xhci-ring: USB SSD may fail to unmount if disconnect during data transferring.
@ 2021-08-12 12:02 Tao Wang
  2021-08-13  1:44 ` wat
  0 siblings, 1 reply; 3+ messages in thread
From: Tao Wang @ 2021-08-12 12:02 UTC (permalink / raw)
  To: quic_wat, linyyuan, hongwus, zhijunw, wat
  Cc: Mathias Nyman, Greg Kroah-Hartman, open list:USB XHCI DRIVER, open list

From: Tao Wang <quic_wat@quicinc.com>

it stuck in usb_kill_urb() due to urb use_count will not become zero,
this means urb giveback is not happen.
in xhci_handle_cmd_set_deq() will giveback urb if td's cancel_status
equal to TD_CLEARING_CACHE,
but in xhci_invalidate_cancelled_tds(), only last canceled td's
cancel_status change to TD_CLEARING_CACHE,
thus giveback only happen to last urb.

this change set all cancelled_td's cancel_status to TD_CLEARING_CACHE
rather than the last one, so all urb can giveback.

Signed-off-by: Tao Wang <quic_wat@quicinc.com>
---
 drivers/usb/host/xhci-ring.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 8fea44b..c7dd7c0 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -960,19 +960,19 @@ static int xhci_invalidate_cancelled_tds(struct xhci_virt_ep *ep)
 			td_to_noop(xhci, ring, td, false);
 			td->cancel_status = TD_CLEARED;
 		}
-	}
-	if (cached_td) {
-		cached_td->cancel_status = TD_CLEARING_CACHE;
-
-		err = xhci_move_dequeue_past_td(xhci, slot_id, ep->ep_index,
-						cached_td->urb->stream_id,
-						cached_td);
-		/* Failed to move past cached td, try just setting it noop */
-		if (err) {
-			td_to_noop(xhci, ring, cached_td, false);
-			cached_td->cancel_status = TD_CLEARED;
+		if (cached_td) {
+			cached_td->cancel_status = TD_CLEARING_CACHE;
+
+			err = xhci_move_dequeue_past_td(xhci, slot_id, ep->ep_index,
+							cached_td->urb->stream_id,
+							cached_td);
+			/* Failed to move past cached td, try just setting it noop */
+			if (err) {
+				td_to_noop(xhci, ring, cached_td, false);
+				cached_td->cancel_status = TD_CLEARED;
+			}
+			cached_td = NULL;
 		}
-		cached_td = NULL;
 	}
 	return 0;
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: xhci-ring: USB SSD may fail to unmount if disconnect during data transferring.
  2021-08-12 12:02 [PATCH] usb: xhci-ring: USB SSD may fail to unmount if disconnect during data transferring Tao Wang
@ 2021-08-13  1:44 ` wat
  2021-08-13  2:03   ` wat
  0 siblings, 1 reply; 3+ messages in thread
From: wat @ 2021-08-13  1:44 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman, linux-usb, linux-kernel; +Cc: quic_wat, wat

Hi usb teams,

I have a patch about xhci-ring, can you help me to check?

you can contact me if you have any question.


On 2021-08-12 20:02, Tao Wang wrote:
> From: Tao Wang <quic_wat@quicinc.com>
> 
> it stuck in usb_kill_urb() due to urb use_count will not become zero,
> this means urb giveback is not happen.
> in xhci_handle_cmd_set_deq() will giveback urb if td's cancel_status
> equal to TD_CLEARING_CACHE,
> but in xhci_invalidate_cancelled_tds(), only last canceled td's
> cancel_status change to TD_CLEARING_CACHE,
> thus giveback only happen to last urb.
> 
> this change set all cancelled_td's cancel_status to TD_CLEARING_CACHE
> rather than the last one, so all urb can giveback.
> 
> Signed-off-by: Tao Wang <quic_wat@quicinc.com>
> ---
>  drivers/usb/host/xhci-ring.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-ring.c 
> b/drivers/usb/host/xhci-ring.c
> index 8fea44b..c7dd7c0 100644
> --- a/drivers/usb/host/xhci-ring.c
> +++ b/drivers/usb/host/xhci-ring.c
> @@ -960,19 +960,19 @@ static int xhci_invalidate_cancelled_tds(struct
> xhci_virt_ep *ep)
>  			td_to_noop(xhci, ring, td, false);
>  			td->cancel_status = TD_CLEARED;
>  		}
> -	}
> -	if (cached_td) {
> -		cached_td->cancel_status = TD_CLEARING_CACHE;
> -
> -		err = xhci_move_dequeue_past_td(xhci, slot_id, ep->ep_index,
> -						cached_td->urb->stream_id,
> -						cached_td);
> -		/* Failed to move past cached td, try just setting it noop */
> -		if (err) {
> -			td_to_noop(xhci, ring, cached_td, false);
> -			cached_td->cancel_status = TD_CLEARED;
> +		if (cached_td) {
> +			cached_td->cancel_status = TD_CLEARING_CACHE;
> +
> +			err = xhci_move_dequeue_past_td(xhci, slot_id, ep->ep_index,
> +							cached_td->urb->stream_id,
> +							cached_td);
> +			/* Failed to move past cached td, try just setting it noop */
> +			if (err) {
> +				td_to_noop(xhci, ring, cached_td, false);
> +				cached_td->cancel_status = TD_CLEARED;
> +			}
> +			cached_td = NULL;
>  		}
> -		cached_td = NULL;
>  	}
>  	return 0;
>  }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: xhci-ring: USB SSD may fail to unmount if disconnect during data transferring.
  2021-08-13  1:44 ` wat
@ 2021-08-13  2:03   ` wat
  0 siblings, 0 replies; 3+ messages in thread
From: wat @ 2021-08-13  2:03 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman, linux-usb, linux-kernel

sorry, This email is invalid because some reason, I will submit another 
email for it.


On 2021-08-13 09:44, wat@codeaurora.org wrote:
> Hi usb teams,
> 
> I have a patch about xhci-ring, can you help me to check?
> 
> you can contact me if you have any question.
> 
> 
> On 2021-08-12 20:02, Tao Wang wrote:
>> From: Tao Wang <quic_wat@quicinc.com>
>> 
>> it stuck in usb_kill_urb() due to urb use_count will not become zero,
>> this means urb giveback is not happen.
>> in xhci_handle_cmd_set_deq() will giveback urb if td's cancel_status
>> equal to TD_CLEARING_CACHE,
>> but in xhci_invalidate_cancelled_tds(), only last canceled td's
>> cancel_status change to TD_CLEARING_CACHE,
>> thus giveback only happen to last urb.
>> 
>> this change set all cancelled_td's cancel_status to TD_CLEARING_CACHE
>> rather than the last one, so all urb can giveback.
>> 
>> Signed-off-by: Tao Wang <quic_wat@quicinc.com>
>> ---
>>  drivers/usb/host/xhci-ring.c | 24 ++++++++++++------------
>>  1 file changed, 12 insertions(+), 12 deletions(-)
>> 
>> diff --git a/drivers/usb/host/xhci-ring.c 
>> b/drivers/usb/host/xhci-ring.c
>> index 8fea44b..c7dd7c0 100644
>> --- a/drivers/usb/host/xhci-ring.c
>> +++ b/drivers/usb/host/xhci-ring.c
>> @@ -960,19 +960,19 @@ static int xhci_invalidate_cancelled_tds(struct
>> xhci_virt_ep *ep)
>>  			td_to_noop(xhci, ring, td, false);
>>  			td->cancel_status = TD_CLEARED;
>>  		}
>> -	}
>> -	if (cached_td) {
>> -		cached_td->cancel_status = TD_CLEARING_CACHE;
>> -
>> -		err = xhci_move_dequeue_past_td(xhci, slot_id, ep->ep_index,
>> -						cached_td->urb->stream_id,
>> -						cached_td);
>> -		/* Failed to move past cached td, try just setting it noop */
>> -		if (err) {
>> -			td_to_noop(xhci, ring, cached_td, false);
>> -			cached_td->cancel_status = TD_CLEARED;
>> +		if (cached_td) {
>> +			cached_td->cancel_status = TD_CLEARING_CACHE;
>> +
>> +			err = xhci_move_dequeue_past_td(xhci, slot_id, ep->ep_index,
>> +							cached_td->urb->stream_id,
>> +							cached_td);
>> +			/* Failed to move past cached td, try just setting it noop */
>> +			if (err) {
>> +				td_to_noop(xhci, ring, cached_td, false);
>> +				cached_td->cancel_status = TD_CLEARED;
>> +			}
>> +			cached_td = NULL;
>>  		}
>> -		cached_td = NULL;
>>  	}
>>  	return 0;
>>  }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-13  2:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 12:02 [PATCH] usb: xhci-ring: USB SSD may fail to unmount if disconnect during data transferring Tao Wang
2021-08-13  1:44 ` wat
2021-08-13  2:03   ` wat

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).