* 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
0 siblings, 1 reply; 2+ 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] 2+ messages in thread