* Fwd: [PATCH] usb: xhci: dbc: advance transfer ring dequeue pointer on completion [not found] ` <CAD858L_iB6zkTXk4czOfen3+PbGc2VjBNHio4y42L0k73vk0Uw@mail.gmail.com> @ 2026-12-02 16:32 ` matthew Boyle 2026-12-03 3:52 ` Greg Kroah-Hartman 2026-12-03 10:48 ` Mathias Nyman 0 siblings, 2 replies; 4+ messages in thread From: matthew Boyle @ 2026-12-02 16:32 UTC (permalink / raw) To: Mathias Nyman, Greg Kroah-Hartman, Niklas Neronin Cc: linux-usb, linux-kernel, stable, Michal Pecio [-- Attachment #1: Type: text/plain, Size: 2667 bytes --] Good Morning, Commit 7ee645963075 ("usb: xhci: remove legacy 'num_trbs_free' tracking") removed ring->num_trbs_free and switched xhci_dbc_queue_bulk_tx() to xhci_num_trbs_free(ring), which computes free space from ring->enqueue and ring->dequeue. However, DbC transfer rings never updated ring->dequeue on transfer completion; previously only ring->num_trbs_free was incremented in dbc_handle_xfer_event(). As a result, ring->dequeue remains stuck at the start of the single-segment ring while ring->enqueue advances. After exactly 254 TRBs (254 * 1024 B = 260,096 B on a 256-TRB segment with one link TRB and the xhci_num_trbs_free(ring) <= num_trbs guard), xhci_num_trbs_free() drops to 1 and every subsequent bulk transfer fails permanently with -EBUSY ("failed to queue trbs"). Add a dbc_inc_deq() helper mirroring xhci_dbc_queue_trb()'s link-TRB wraparound and call it in dbc_handle_xfer_event() before giving back completed and stale stalled requests (while dbc->lock is still held, before completion callbacks can re-queue new TRBs). Fixes: 7ee645963075 ("usb: xhci: remove legacy 'num_trbs_free' tracking") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222348 Cc: stable@vger.kernel.org Signed-off-by: Matthew Boyle <mcboyle1865@gmail.com> --- (Note: sent via Gmail web; the clean git format-patch file with preserved tabs is also attached as 0001-usb-xhci-dbc-advance-transfer-ring-dequeue-pointer-o.patch.) drivers/usb/host/xhci-dbgcap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index 48ee6a4f9..39a501002 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -812,6 +812,15 @@ dbc_handle_port_status(struct xhci_dbc *dbc, union xhci_trb *event) writel(portsc & ~DBC_PORTSC_RESET_CHANGE, &dbc->regs->portsc); } +static void dbc_inc_deq(struct xhci_ring *ring) +{ + union xhci_trb *next; + + next = ++ring->dequeue; + if (TRB_TYPE_LINK_LE32(next->link.control)) + ring->dequeue = ring->deq_seg->trbs; +} + static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event) { struct dbc_ep *dep; @@ -840,6 +849,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event) } if (r->status == -COMP_STALL_ERROR) { dev_warn(dbc->dev, "Give back stale stalled req\n"); + dbc_inc_deq(ring); xhci_dbc_giveback(r, 0); } } @@ -904,6 +914,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event) break; } + dbc_inc_deq(ring); req->actual = req->length - remain_length; xhci_dbc_giveback(req, status); } -- 2.53.0 Very respectfully, Matthew Boyle [-- Attachment #2: 0002-usb-xhci-dbc-increase-request-queue-depth-and-write-.patch --] [-- Type: application/octet-stream, Size: 2150 bytes --] From 67799c0d0d98868bd712ae3ae515a1d83d6d6e4a Mon Sep 17 00:00:00 2001 From: Matthew Boyle <mcboyle1865@gmail.com> Date: Wed, 2 Dec 2026 15:32:09 +0000 Subject: [PATCH usb-next] usb: xhci: dbc: increase request queue depth and write buffer size The xHCI DbC tty driver currently allocates only DBC_QUEUE_SIZE (16) 1024-byte requests per endpoint and an 8 KiB TX kfifo (DBC_WRITE_BUF_SIZE). Because dbc_tty_write() enforces per-write boundaries via port->tx_boundary and DbC events are serviced via a polled workqueue (event_work), these small limits cap in-flight pipelining to 8 KiB on TX and 16 KiB on RX per poll cycle, severely underutilizing SuperSpeed (5 Gbps) and SuperSpeedPlus (10 Gbps) bulk links. Increase DBC_QUEUE_SIZE from 16 to 64 and DBC_WRITE_BUF_SIZE from 8192 to 65536 so that: - TX kfifo capacity matches the full 64 * 1024 B request pool (64 KiB), eliminating 8 KiB write stalls on bulk transfers; - RX and TX hardware pipelining increases 4x (16 KiB -> 64 KiB in flight per endpoint) while staying well within the 255-TRB single-segment transfer ring (~25% utilization); - Per-request buffer size stays at DBC_MAX_PACKET (1024 B), preserving USB bulk short-packet semantics on RX and the single-TRB DMA mapping invariant (count_trbs() == 1). Memory overhead per active DbC tty port increases by ~152 KiB (96 KiB for 48 additional 1 KiB requests on each endpoint plus 56 KiB for the larger TX kfifo). Signed-off-by: Matthew Boyle <mcboyle1865@gmail.com> --- drivers/usb/host/xhci-dbgcap.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h index 5b18efb2c..ab7a2b6b6 100644 --- a/drivers/usb/host/xhci-dbgcap.h +++ b/drivers/usb/host/xhci-dbgcap.h @@ -108,8 +108,8 @@ struct dbc_ep { unsigned int halted:1; }; -#define DBC_QUEUE_SIZE 16 -#define DBC_WRITE_BUF_SIZE 8192 +#define DBC_QUEUE_SIZE 64 +#define DBC_WRITE_BUF_SIZE 65536 #define DBC_POLL_INTERVAL_DEFAULT 64 /* milliseconds */ #define DBC_POLL_INTERVAL_MAX 5000 /* milliseconds */ #define DBC_XFER_INACTIVITY_TIMEOUT 10 /* milliseconds */ -- 2.53.0 [-- Attachment #3: 0001-usb-xhci-dbc-advance-transfer-ring-dequeue-pointer-o.patch --] [-- Type: application/octet-stream, Size: 2708 bytes --] From 8f093ed55ba809b03e67b76cfd0b8e553627e340 Mon Sep 17 00:00:00 2001 From: Matthew Boyle <mcboyle1865@gmail.com> Date: Wed, 2 Dec 2026 15:30:43 +0000 Subject: [PATCH] usb: xhci: dbc: advance transfer ring dequeue pointer on completion Commit 7ee645963075 ("usb: xhci: remove legacy 'num_trbs_free' tracking") removed ring->num_trbs_free and switched xhci_dbc_queue_bulk_tx() to xhci_num_trbs_free(ring), which computes free space from ring->enqueue and ring->dequeue. However, DbC transfer rings never updated ring->dequeue on transfer completion; previously only ring->num_trbs_free was incremented in dbc_handle_xfer_event(). As a result, ring->dequeue remains stuck at the start of the single-segment ring while ring->enqueue advances. After exactly 254 TRBs (254 * 1024 B = 260,096 B on a 256-TRB segment with one link TRB and the xhci_num_trbs_free(ring) <= num_trbs guard), xhci_num_trbs_free() drops to 1 and every subsequent bulk transfer fails permanently with -EBUSY ("failed to queue trbs"). Add a dbc_inc_deq() helper mirroring xhci_dbc_queue_trb()'s link-TRB wraparound and call it in dbc_handle_xfer_event() before giving back completed and stale stalled requests (while dbc->lock is still held, before completion callbacks can re-queue new TRBs). Fixes: 7ee645963075 ("usb: xhci: remove legacy 'num_trbs_free' tracking") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222348 Cc: stable@vger.kernel.org Signed-off-by: Matthew Boyle <mcboyle1865@gmail.com> --- drivers/usb/host/xhci-dbgcap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index 48ee6a4f9..39a501002 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -812,6 +812,15 @@ dbc_handle_port_status(struct xhci_dbc *dbc, union xhci_trb *event) writel(portsc & ~DBC_PORTSC_RESET_CHANGE, &dbc->regs->portsc); } +static void dbc_inc_deq(struct xhci_ring *ring) +{ + union xhci_trb *next; + + next = ++ring->dequeue; + if (TRB_TYPE_LINK_LE32(next->link.control)) + ring->dequeue = ring->deq_seg->trbs; +} + static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event) { struct dbc_ep *dep; @@ -840,6 +849,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event) } if (r->status == -COMP_STALL_ERROR) { dev_warn(dbc->dev, "Give back stale stalled req\n"); + dbc_inc_deq(ring); xhci_dbc_giveback(r, 0); } } @@ -904,6 +914,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event) break; } + dbc_inc_deq(ring); req->actual = req->length - remain_length; xhci_dbc_giveback(req, status); } -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: Fwd: [PATCH] usb: xhci: dbc: advance transfer ring dequeue pointer on completion 2026-12-02 16:32 ` Fwd: [PATCH] usb: xhci: dbc: advance transfer ring dequeue pointer on completion matthew Boyle @ 2026-12-03 3:52 ` Greg Kroah-Hartman 2026-12-03 10:48 ` Mathias Nyman 1 sibling, 0 replies; 4+ messages in thread From: Greg Kroah-Hartman @ 2026-12-03 3:52 UTC (permalink / raw) To: matthew Boyle Cc: Mathias Nyman, Niklas Neronin, linux-usb, linux-kernel, stable, Michal Pecio On Wed, Dec 02, 2026 at 11:32:19AM -0500, matthew Boyle wrote: > Good Morning, > Commit 7ee645963075 ("usb: xhci: remove legacy 'num_trbs_free' > tracking") removed ring->num_trbs_free and switched > xhci_dbc_queue_bulk_tx() to xhci_num_trbs_free(ring), which computes > free space from ring->enqueue and ring->dequeue. > > However, DbC transfer rings never updated ring->dequeue on transfer > completion; previously only ring->num_trbs_free was incremented in > dbc_handle_xfer_event(). As a result, ring->dequeue remains stuck at > the start of the single-segment ring while ring->enqueue advances. > After exactly 254 TRBs (254 * 1024 B = 260,096 B on a 256-TRB segment > with one link TRB and the xhci_num_trbs_free(ring) <= num_trbs guard), > xhci_num_trbs_free() drops to 1 and every subsequent bulk transfer > fails permanently with -EBUSY ("failed to queue trbs"). > > Add a dbc_inc_deq() helper mirroring xhci_dbc_queue_trb()'s link-TRB > wraparound and call it in dbc_handle_xfer_event() before giving back > completed and stale stalled requests (while dbc->lock is still held, > before completion callbacks can re-queue new TRBs). > > Fixes: 7ee645963075 ("usb: xhci: remove legacy 'num_trbs_free' tracking") > Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222348 > Cc: stable@vger.kernel.org > Signed-off-by: Matthew Boyle <mcboyle1865@gmail.com> > --- > (Note: sent via Gmail web; the clean git format-patch file with > preserved tabs is also attached as > 0001-usb-xhci-dbc-advance-transfer-ring-dequeue-pointer-o.patch.) > > drivers/usb/host/xhci-dbgcap.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > Hi, This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree. You are receiving this message because of the following common error(s) as indicated below: - Your patch is malformed (tabs converted to spaces, linewrapped, etc.) and can not be applied. Please read the file, Documentation/process/email-clients.rst in order to fix this. - Your patch was attached, please place it inline so that it can be applied directly from the email message itself. If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers. thanks, greg k-h's patch email bot ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Fwd: [PATCH] usb: xhci: dbc: advance transfer ring dequeue pointer on completion 2026-12-02 16:32 ` Fwd: [PATCH] usb: xhci: dbc: advance transfer ring dequeue pointer on completion matthew Boyle 2026-12-03 3:52 ` Greg Kroah-Hartman @ 2026-12-03 10:48 ` Mathias Nyman 2026-12-03 11:05 ` Michal Pecio 1 sibling, 1 reply; 4+ messages in thread From: Mathias Nyman @ 2026-12-03 10:48 UTC (permalink / raw) To: matthew Boyle, Greg Kroah-Hartman, Niklas Neronin Cc: linux-usb, linux-kernel, stable, Michal Pecio On 12/2/26 18:32, matthew Boyle wrote: > Good Morning, > Commit 7ee645963075 ("usb: xhci: remove legacy 'num_trbs_free' > tracking") removed ring->num_trbs_free and switched > xhci_dbc_queue_bulk_tx() to xhci_num_trbs_free(ring), which computes > free space from ring->enqueue and ring->dequeue. > > However, DbC transfer rings never updated ring->dequeue on transfer > completion; previously only ring->num_trbs_free was incremented in > dbc_handle_xfer_event(). As a result, ring->dequeue remains stuck at > the start of the single-segment ring while ring->enqueue advances. > After exactly 254 TRBs (254 * 1024 B = 260,096 B on a 256-TRB segment > with one link TRB and the xhci_num_trbs_free(ring) <= num_trbs guard), > xhci_num_trbs_free() drops to 1 and every subsequent bulk transfer > fails permanently with -EBUSY ("failed to queue trbs"). nice catch, thanks > > Add a dbc_inc_deq() helper mirroring xhci_dbc_queue_trb()'s link-TRB > wraparound and call it in dbc_handle_xfer_event() before giving back > completed and stale stalled requests (while dbc->lock is still held, > before completion callbacks can re-queue new TRBs). The transfer event contains the dequeue TRB DMA address, how about setting the ring->dequeue directly based on it instead. Does this work for you: diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index 48ee6a4f9e1c..a9c011194cd8 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -835,6 +835,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event) /* Match the pending request: */ list_for_each_entry(r, &dep->list_pending, list_pending) { if (r->trb_dma == event->trans_event.buffer) { + ring->dequeue = xhci_dma_to_trb(ring->deq_seg, r->trb_dma, NULL); req = r; break; } diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 7ccd89a4b995..bc9a162617dd 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -85,7 +85,7 @@ dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, return seg->dma + (segment_offset * sizeof(*trb)); } -static union xhci_trb *xhci_dma_to_trb(struct xhci_segment *start_seg, +union xhci_trb *xhci_dma_to_trb(struct xhci_segment *start_seg, dma_addr_t dma, struct xhci_segment **match_seg) { diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 6201b6b24252..42cc7e592ccd 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1963,6 +1963,8 @@ void xhci_cleanup_command_queue(struct xhci_hcd *xhci); void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring); unsigned int count_trbs(u64 addr, u64 len); unsigned int xhci_num_trbs_free(struct xhci_ring *ring); +union xhci_trb *xhci_dma_to_trb(struct xhci_segment *start_seg, dma_addr_t dma, + struct xhci_segment **match_seg); void xhci_process_cancelled_tds(struct xhci_hcd *xhci, struct xhci_virt_ep *ep); void xhci_update_erst_dequeue(struct xhci_hcd *xhci, struct xhci_interrupter *ir, Thanks Mathias ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: xhci: dbc: advance transfer ring dequeue pointer on completion 2026-12-03 10:48 ` Mathias Nyman @ 2026-12-03 11:05 ` Michal Pecio 0 siblings, 0 replies; 4+ messages in thread From: Michal Pecio @ 2026-12-03 11:05 UTC (permalink / raw) To: Mathias Nyman Cc: matthew Boyle, Greg Kroah-Hartman, Niklas Neronin, linux-usb, linux-kernel, stable On Thu, 3 Dec 2026 12:48:55 +0200, Mathias Nyman wrote: > On 12/2/26 18:32, matthew Boyle wrote: > > Good Morning, > > Commit 7ee645963075 ("usb: xhci: remove legacy 'num_trbs_free' > > tracking") removed ring->num_trbs_free and switched > > xhci_dbc_queue_bulk_tx() to xhci_num_trbs_free(ring), which computes > > free space from ring->enqueue and ring->dequeue. > > > > However, DbC transfer rings never updated ring->dequeue on transfer > > completion; previously only ring->num_trbs_free was incremented in > > dbc_handle_xfer_event(). As a result, ring->dequeue remains stuck at > > the start of the single-segment ring while ring->enqueue advances. > > After exactly 254 TRBs (254 * 1024 B = 260,096 B on a 256-TRB segment > > with one link TRB and the xhci_num_trbs_free(ring) <= num_trbs guard), > > xhci_num_trbs_free() drops to 1 and every subsequent bulk transfer > > fails permanently with -EBUSY ("failed to queue trbs"). > > nice catch, thanks > > > > > Add a dbc_inc_deq() helper mirroring xhci_dbc_queue_trb()'s link-TRB > > wraparound and call it in dbc_handle_xfer_event() before giving back > > completed and stale stalled requests (while dbc->lock is still held, > > before completion callbacks can re-queue new TRBs). > > The transfer event contains the dequeue TRB DMA address, how about setting > the ring->dequeue directly based on it instead. > > Does this work for you: > > diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c > index 48ee6a4f9e1c..a9c011194cd8 100644 > --- a/drivers/usb/host/xhci-dbgcap.c > +++ b/drivers/usb/host/xhci-dbgcap.c > @@ -835,6 +835,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event) > /* Match the pending request: */ > list_for_each_entry(r, &dep->list_pending, list_pending) { > if (r->trb_dma == event->trans_event.buffer) { > + ring->dequeue = xhci_dma_to_trb(ring->deq_seg, r->trb_dma, NULL); > req = r; > break; > } Not familiar with DBC, but I suspect you actually want: ring->dequeue = xhci_dma_to_trb(ring->deq_seg, r->trb_dma, &ring->deq_seg); Regards, Michal ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-03 11:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CAD858L_rFUTS_63uBFb=HytY+U1DKSVtNTttKqXWSPf0Ba4TRA@mail.gmail.com>
[not found] ` <CAD858L_iB6zkTXk4czOfen3+PbGc2VjBNHio4y42L0k73vk0Uw@mail.gmail.com>
2026-12-02 16:32 ` Fwd: [PATCH] usb: xhci: dbc: advance transfer ring dequeue pointer on completion matthew Boyle
2026-12-03 3:52 ` Greg Kroah-Hartman
2026-12-03 10:48 ` Mathias Nyman
2026-12-03 11:05 ` Michal Pecio
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox