All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Pecio <michal.pecio@gmail.com>
To: Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] usb: xhci: Simplify moving HW Dequeue Pointer past cancelled TDs
Date: Thu, 6 Aug 2026 13:58:54 +0200	[thread overview]
Message-ID: <20260806135854.2441ac51.michal.pecio@gmail.com> (raw)
In-Reply-To: <fd8ed109-2183-4160-af9e-4a74bda8c020@linux.intel.com>

On Mon, 1 Jun 2026 13:45:37 +0300, Mathias Nyman wrote:
> On 5/29/26 13:53, Michal Pecio wrote:
> > And one more problem: unconditionally advancing enqueue past a link
> > TRB creates risk that enqueue will enter deq_seg if the queued
> > command fails, which breaks ring expansion later. If we care...  
> 
> Enqueue is only advanced past link TRB if ring is empty, and both are
> then set to the beginning of the next segment. Ring expansion isn't
> an issue here. This is done to avoid moving dequeue to a link TRB.

This is the code:

+       if (list_empty(&ring->td_list)) {
+               if (trb_is_link(ring->enqueue))
+                       inc_enq_past_link(xhci, ring, 0);
+               ep->queued_deq_seg = ring->enq_seg;
+               ep->queued_deq_ptr = ring->enqueue;

This checks for empty td_list, but not for dequeue position,
so it can move enqueue to the beginning of ep_ring->deq_seg.
New URBs may be submitted before the command completes and
ep_ring->dequeue is updated, so ring expansion check may run
under abnormal conditions.

Now, I looked at xhci_ring_expansion_needed() and I think it
would consider the whole ring empty, but somebody could submit
a patch to optimize this function (use segment numbers and
TRB offsets to quickly calculate enq-deq distance) and nobody
will expect that this patch may cause ring expansions when
Set TR Dequeue is pending on a ring with no TDs.

And if the command fails, the xHC would progress to the newly
linked segment. Though to be honest, Set Deq failure is always
a complete disaster anyway, so I don't know if it's a big deal.

But any potential issues can be trivially prevented:

+               if (trb_is_link(ring->enqueue) && ring->enq_seg->next != ring->deq_seg)
+                       inc_enq_past_link(xhci, ring, 0);

Regards,
Michal

  reply	other threads:[~2026-08-06 11:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-25 11:57 [PATCH v2 0/3] xhci: ring queuing cleanups plus a quirk Michal Pecio
2025-02-25 11:58 ` [PATCH v2 1/3] usb: xhci: Apply the link chain quirk on NEC isoc endpoints Michal Pecio
2025-02-25 11:59 ` [PATCH v2 2/3] usb: xhci: Simplify moving HW Dequeue Pointer past cancelled TDs Michal Pecio
2025-02-25 14:55   ` Mathias Nyman
2025-02-25 22:17     ` Michał Pecio
2026-05-29 10:53     ` Michal Pecio
2026-06-01 10:45       ` Mathias Nyman
2026-08-06 11:58         ` Michal Pecio [this message]
2025-02-25 12:00 ` [PATCH v2 3/3] usb: xhci: Unify duplicate inc_enq() code Michal Pecio
2025-02-26 12:39 ` [PATCH v2 0/3] xhci: ring queuing cleanups plus a quirk Mathias Nyman

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=20260806135854.2441ac51.michal.pecio@gmail.com \
    --to=michal.pecio@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=mathias.nyman@linux.intel.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.