public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Peter Chen <hzpeterchen@gmail.com>, Greg KH <gregkh@linuxfoundation.org>
Cc: "WeitaoWang-oc@zhaoxin.com" <WeitaoWang-oc@zhaoxin.com>,
	mathias.nyman@intel.com, Alan Stern <stern@rowland.harvard.edu>,
	USB list <linux-usb@vger.kernel.org>,
	lkml <linux-kernel@vger.kernel.org>,
	CobeChen@zhaoxin.com, TimGuo@zhaoxin.com, tonywwang@zhaoxin.com,
	weitaowang@zhaoxin.com
Subject: Re: [PATCH] USB: Fix xhci ERDP update issue
Date: Wed, 16 Mar 2022 14:45:27 +0200	[thread overview]
Message-ID: <d95ca5f6-221b-1a22-abbe-10621e2fb219@linux.intel.com> (raw)
In-Reply-To: <CAL411-o_2PSndEVXfa+ciLukSr5u5w8G9T63d2MpSm2Fpn5QTQ@mail.gmail.com>

On 16.3.2022 13.57, Peter Chen wrote:
> On Mon, Mar 14, 2022 at 10:34 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>>
>> On Mon, Mar 14, 2022 at 03:25:23PM +0800, WeitaoWang-oc@zhaoxin.com wrote:
>>> On some situations, software handles TRB events slower than adding TRBs,
>>> xhci_irq will not exit until all events are handled. If xhci_irq just
>>> handles 256 TRBs and exit, the temp variable(event_ring_deq) driver records
>>> in xhci irq is equal to driver current dequeue pointer. It will cause driver
>>> not update ERDP and software dequeue pointer lost sync with ERDP. On the
>>> next xhci_irq, the event ring is full but driver will not update ERDP as
>>> software dequeue pointer is equal to ERDP.
> 
> At the current driver, the ERDP is updated at most 128 TRBs, how is
> the above condition
> triggered?
> 
> Peter
> 

Before, and during _one_ interrupt handling xHC hardware writes exactly 256 events
to event ring. ring buffer size is 256 so buffer position 0 and 256 point
to the same place.

Interrupt handler stores software dequeue in a local variable "event_ring_deq".
Handler start handling events, it updates software dequeue, but not local variable.
After 128 events handler updates hardware ERDP.

So at event 128 we got:
Hardware ERDP = 128
software dequeue = 128
event_ring_deq = 0

Handler continue handling events, at event 256 try to update HW ERDP again, but fail due
to this condition in update_erst_dequeue():
      if (event_ring_deq != xhci->event_ring->dequeue)

This fails because event_ring_deq is still 0, and software deq is 256,
pointing to the same place in the event ring.

So at the end of the interrupt handler we have:
HW ERDP = 128
software dequeue = 256 (same as 0)

So in this specific case we fail to update ERDP correctly

-Mathias

  reply	other threads:[~2022-03-16 12:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14  7:25 [PATCH] USB: Fix xhci ERDP update issue WeitaoWang-oc
2022-03-14  7:39 ` Greg KH
2022-03-16 11:57   ` Peter Chen
2022-03-16 12:45     ` Mathias Nyman [this message]
2022-03-17  1:51       ` Peter Chen
2022-03-16 12:47     ` WeitaoWang-oc
2022-03-15  8:08 ` Mathias Nyman
2022-03-15 12:44   ` WeitaoWang-oc
2022-03-16 13:20     ` Mathias Nyman
2022-03-17  2:43       ` WeitaoWang-oc
2022-03-17  1:56 ` Peter Chen
  -- strict thread matches above, loose matches on Subject: below --
2022-03-18  7:32 WeitaoWang-oc
2022-03-18  7:45 ` Greg KH
2022-03-18 12:17 WeitaoWang-oc
2022-03-18 12:34 ` Greg KH

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=d95ca5f6-221b-1a22-abbe-10621e2fb219@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=CobeChen@zhaoxin.com \
    --cc=TimGuo@zhaoxin.com \
    --cc=WeitaoWang-oc@zhaoxin.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hzpeterchen@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=stern@rowland.harvard.edu \
    --cc=tonywwang@zhaoxin.com \
    --cc=weitaowang@zhaoxin.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox