* [PATCH 0/3] xhci fixes for usb-linus
@ 2025-09-02 10:53 Mathias Nyman
2025-09-02 10:53 ` [PATCH 1/3] xhci: dbc: decouple endpoint allocation from initialization Mathias Nyman
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Mathias Nyman @ 2025-09-02 10:53 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A couple xhci fixes for usb-linus
Fixing a xhci memory leak regression in 6.17-rc3, and a DbC issue
triggered when re-connecting DbC cable ~10 times without data transfers
in between
Thanks
Mathias
Mathias Nyman (3):
xhci: dbc: decouple endpoint allocation from initialization
xhci: dbc: Fix full DbC transfer ring after several reconnects
xhci: fix memory leak regression when freeing xhci vdev devices depth
first
drivers/usb/host/xhci-dbgcap.c | 94 ++++++++++++++++++++++++----------
drivers/usb/host/xhci-mem.c | 2 +-
2 files changed, 68 insertions(+), 28 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/3] xhci: dbc: decouple endpoint allocation from initialization
2025-09-02 10:53 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
@ 2025-09-02 10:53 ` Mathias Nyman
2025-09-02 10:53 ` [PATCH 2/3] xhci: dbc: Fix full DbC transfer ring after several reconnects Mathias Nyman
2025-09-02 10:53 ` [PATCH 3/3] xhci: fix memory leak regression when freeing xhci vdev devices depth first Mathias Nyman
2 siblings, 0 replies; 11+ messages in thread
From: Mathias Nyman @ 2025-09-02 10:53 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman, stable
Decouple allocation of endpoint ring buffer from initialization
of the buffer, and initialization of endpoint context parts from
from the rest of the contexts.
It allows driver to clear up and reinitialize endpoint rings
after disconnect without reallocating everything.
This is a prerequisite for the next patch that prevents the transfer
ring from filling up with cancelled (no-op) TRBs if a debug cable is
reconnected several times without transferring anything.
Cc: stable@vger.kernel.org
Fixes: dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-dbgcap.c | 71 ++++++++++++++++++++++------------
1 file changed, 46 insertions(+), 25 deletions(-)
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 06a2edb9e86e..d0faff233e3e 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -101,13 +101,34 @@ static u32 xhci_dbc_populate_strings(struct dbc_str_descs *strings)
return string_length;
}
+static void xhci_dbc_init_ep_contexts(struct xhci_dbc *dbc)
+{
+ struct xhci_ep_ctx *ep_ctx;
+ unsigned int max_burst;
+ dma_addr_t deq;
+
+ max_burst = DBC_CTRL_MAXBURST(readl(&dbc->regs->control));
+
+ /* Populate bulk out endpoint context: */
+ ep_ctx = dbc_bulkout_ctx(dbc);
+ deq = dbc_bulkout_enq(dbc);
+ ep_ctx->ep_info = 0;
+ ep_ctx->ep_info2 = dbc_epctx_info2(BULK_OUT_EP, 1024, max_burst);
+ ep_ctx->deq = cpu_to_le64(deq | dbc->ring_out->cycle_state);
+
+ /* Populate bulk in endpoint context: */
+ ep_ctx = dbc_bulkin_ctx(dbc);
+ deq = dbc_bulkin_enq(dbc);
+ ep_ctx->ep_info = 0;
+ ep_ctx->ep_info2 = dbc_epctx_info2(BULK_IN_EP, 1024, max_burst);
+ ep_ctx->deq = cpu_to_le64(deq | dbc->ring_in->cycle_state);
+}
+
static void xhci_dbc_init_contexts(struct xhci_dbc *dbc, u32 string_length)
{
struct dbc_info_context *info;
- struct xhci_ep_ctx *ep_ctx;
u32 dev_info;
- dma_addr_t deq, dma;
- unsigned int max_burst;
+ dma_addr_t dma;
if (!dbc)
return;
@@ -121,20 +142,8 @@ static void xhci_dbc_init_contexts(struct xhci_dbc *dbc, u32 string_length)
info->serial = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH * 3);
info->length = cpu_to_le32(string_length);
- /* Populate bulk out endpoint context: */
- ep_ctx = dbc_bulkout_ctx(dbc);
- max_burst = DBC_CTRL_MAXBURST(readl(&dbc->regs->control));
- deq = dbc_bulkout_enq(dbc);
- ep_ctx->ep_info = 0;
- ep_ctx->ep_info2 = dbc_epctx_info2(BULK_OUT_EP, 1024, max_burst);
- ep_ctx->deq = cpu_to_le64(deq | dbc->ring_out->cycle_state);
-
- /* Populate bulk in endpoint context: */
- ep_ctx = dbc_bulkin_ctx(dbc);
- deq = dbc_bulkin_enq(dbc);
- ep_ctx->ep_info = 0;
- ep_ctx->ep_info2 = dbc_epctx_info2(BULK_IN_EP, 1024, max_burst);
- ep_ctx->deq = cpu_to_le64(deq | dbc->ring_in->cycle_state);
+ /* Populate bulk in and out endpoint contexts: */
+ xhci_dbc_init_ep_contexts(dbc);
/* Set DbC context and info registers: */
lo_hi_writeq(dbc->ctx->dma, &dbc->regs->dccp);
@@ -436,6 +445,23 @@ dbc_alloc_ctx(struct device *dev, gfp_t flags)
return ctx;
}
+static void xhci_dbc_ring_init(struct xhci_ring *ring)
+{
+ struct xhci_segment *seg = ring->first_seg;
+
+ /* clear all trbs on ring in case of old ring */
+ memset(seg->trbs, 0, TRB_SEGMENT_SIZE);
+
+ /* Only event ring does not use link TRB */
+ if (ring->type != TYPE_EVENT) {
+ union xhci_trb *trb = &seg->trbs[TRBS_PER_SEGMENT - 1];
+
+ trb->link.segment_ptr = cpu_to_le64(ring->first_seg->dma);
+ trb->link.control = cpu_to_le32(LINK_TOGGLE | TRB_TYPE(TRB_LINK));
+ }
+ xhci_initialize_ring_info(ring);
+}
+
static struct xhci_ring *
xhci_dbc_ring_alloc(struct device *dev, enum xhci_ring_type type, gfp_t flags)
{
@@ -464,15 +490,10 @@ xhci_dbc_ring_alloc(struct device *dev, enum xhci_ring_type type, gfp_t flags)
seg->dma = dma;
- /* Only event ring does not use link TRB */
- if (type != TYPE_EVENT) {
- union xhci_trb *trb = &seg->trbs[TRBS_PER_SEGMENT - 1];
-
- trb->link.segment_ptr = cpu_to_le64(dma);
- trb->link.control = cpu_to_le32(LINK_TOGGLE | TRB_TYPE(TRB_LINK));
- }
INIT_LIST_HEAD(&ring->td_list);
- xhci_initialize_ring_info(ring);
+
+ xhci_dbc_ring_init(ring);
+
return ring;
dma_fail:
kfree(seg);
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/3] xhci: dbc: Fix full DbC transfer ring after several reconnects
2025-09-02 10:53 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
2025-09-02 10:53 ` [PATCH 1/3] xhci: dbc: decouple endpoint allocation from initialization Mathias Nyman
@ 2025-09-02 10:53 ` Mathias Nyman
2025-09-02 10:53 ` [PATCH 3/3] xhci: fix memory leak regression when freeing xhci vdev devices depth first Mathias Nyman
2 siblings, 0 replies; 11+ messages in thread
From: Mathias Nyman @ 2025-09-02 10:53 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman, stable
Pending requests will be flushed on disconnect, and the corresponding
TRBs will be turned into No-op TRBs, which are ignored by the xHC
controller once it starts processing the ring.
If the USB debug cable repeatedly disconnects before ring is started
then the ring will eventually be filled with No-op TRBs.
No new transfers can be queued when the ring is full, and driver will
print the following error message:
"xhci_hcd 0000:00:14.0: failed to queue trbs"
This is a normal case for 'in' transfers where TRBs are always enqueued
in advance, ready to take on incoming data. If no data arrives, and
device is disconnected, then ring dequeue will remain at beginning of
the ring while enqueue points to first free TRB after last cancelled
No-op TRB.
s
Solve this by reinitializing the rings when the debug cable disconnects
and DbC is leaving the configured state.
Clear the whole ring buffer and set enqueue and dequeue to the beginning
of ring, and set cycle bit to its initial state.
Cc: stable@vger.kernel.org
Fixes: dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-dbgcap.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index d0faff233e3e..63edf2d8f245 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -462,6 +462,25 @@ static void xhci_dbc_ring_init(struct xhci_ring *ring)
xhci_initialize_ring_info(ring);
}
+static int xhci_dbc_reinit_ep_rings(struct xhci_dbc *dbc)
+{
+ struct xhci_ring *in_ring = dbc->eps[BULK_IN].ring;
+ struct xhci_ring *out_ring = dbc->eps[BULK_OUT].ring;
+
+ if (!in_ring || !out_ring || !dbc->ctx) {
+ dev_warn(dbc->dev, "Can't re-init unallocated endpoints\n");
+ return -ENODEV;
+ }
+
+ xhci_dbc_ring_init(in_ring);
+ xhci_dbc_ring_init(out_ring);
+
+ /* set ep context enqueue, dequeue, and cycle to initial values */
+ xhci_dbc_init_ep_contexts(dbc);
+
+ return 0;
+}
+
static struct xhci_ring *
xhci_dbc_ring_alloc(struct device *dev, enum xhci_ring_type type, gfp_t flags)
{
@@ -885,7 +904,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
dev_info(dbc->dev, "DbC cable unplugged\n");
dbc->state = DS_ENABLED;
xhci_dbc_flush_requests(dbc);
-
+ xhci_dbc_reinit_ep_rings(dbc);
return EVT_DISC;
}
@@ -895,7 +914,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
writel(portsc, &dbc->regs->portsc);
dbc->state = DS_ENABLED;
xhci_dbc_flush_requests(dbc);
-
+ xhci_dbc_reinit_ep_rings(dbc);
return EVT_DISC;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/3] xhci: fix memory leak regression when freeing xhci vdev devices depth first
2025-09-02 10:53 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
2025-09-02 10:53 ` [PATCH 1/3] xhci: dbc: decouple endpoint allocation from initialization Mathias Nyman
2025-09-02 10:53 ` [PATCH 2/3] xhci: dbc: Fix full DbC transfer ring after several reconnects Mathias Nyman
@ 2025-09-02 10:53 ` Mathias Nyman
2 siblings, 0 replies; 11+ messages in thread
From: Mathias Nyman @ 2025-09-02 10:53 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman, David Wang, Michal Pecio, stable
Suspend-resume cycle test revealed a memory leak in 6.17-rc3
Turns out the slot_id race fix changes accidentally ends up calling
xhci_free_virt_device() with an incorrect vdev parameter.
The vdev variable was reused for temporary purposes right before calling
xhci_free_virt_device().
Fix this by passing the correct vdev parameter.
The slot_id race fix that caused this regression was targeted for stable,
so this needs to be applied there as well.
Fixes: 2eb03376151b ("usb: xhci: Fix slot_id resource race conflict")
Reported-by: David Wang <00107082@163.com>
Closes: https://lore.kernel.org/linux-usb/20250829181354.4450-1-00107082@163.com
Suggested-by: Michal Pecio <michal.pecio@gmail.com>
Suggested-by: David Wang <00107082@163.com>
Cc: stable@vger.kernel.org
Tested-by: David Wang <00107082@163.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-mem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 81eaad87a3d9..c4a6544aa107 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -962,7 +962,7 @@ static void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_i
out:
/* we are now at a leaf device */
xhci_debugfs_remove_slot(xhci, slot_id);
- xhci_free_virt_device(xhci, vdev, slot_id);
+ xhci_free_virt_device(xhci, xhci->devs[slot_id], slot_id);
}
int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2023-03-30 14:30 Mathias Nyman
0 siblings, 0 replies; 11+ messages in thread
From: Mathias Nyman @ 2023-03-30 14:30 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few small patches for usb-linus.
Reverting xhci-pci asynchronous probe due to Renesas host regression, and
fixing a memory leak.
Thanks
Mathias
D Scott Phillips (1):
xhci: also avoid the XHCI_ZERO_64B_REGS quirk with a passthrough iommu
Mathias Nyman (2):
Revert "usb: xhci-pci: Set PROBE_PREFER_ASYNCHRONOUS"
xhci: Free the command allocated for setting LPM if we return early
drivers/usb/host/xhci-pci.c | 7 +++----
drivers/usb/host/xhci.c | 7 ++++++-
2 files changed, 9 insertions(+), 5 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2022-08-25 15:08 Mathias Nyman
0 siblings, 0 replies; 11+ messages in thread
From: Mathias Nyman @ 2022-08-25 15:08 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few xhci fixes for usb-linus.
USB3 devices aren't visible immediately after xHC reset, so don't
stop polling the roothub and suspend too early after xHC reset.
Also Revert the port poweroff patch due to regression,
and fix a null pointer issue for xHC hosts with just one roothub.
-Mathias
Mathias Nyman (3):
xhci: Fix null pointer dereference in remove if xHC has only one
roothub
xhci: Add grace period after xHC start to prevent premature runtime
suspend.
Revert "xhci: turn off port power in shutdown"
drivers/usb/host/xhci-hub.c | 13 ++++++++++++-
drivers/usb/host/xhci-plat.c | 11 ++++++++---
drivers/usb/host/xhci.c | 19 +++++--------------
drivers/usb/host/xhci.h | 4 +---
4 files changed, 26 insertions(+), 21 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2022-04-08 13:48 Mathias Nyman
0 siblings, 0 replies; 11+ messages in thread
From: Mathias Nyman @ 2022-04-08 13:48 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few small xhci fixes for usb-linus
Fixes USB 3 link resume for tunneled USB 3 devices, timers left running
after shutdown, and a bug in how we handle a full event ring.
Thanks
-Mathias
Henry Lin (1):
xhci: stop polling roothubs after shutdown
Mathias Nyman (1):
xhci: increase usb U3 -> U0 link resume timeout from 100ms to 500ms
Weitao Wang (1):
USB: Fix xhci event ring dequeue pointer ERDP update issue
drivers/usb/host/xhci-hub.c | 2 +-
drivers/usb/host/xhci-ring.c | 1 +
drivers/usb/host/xhci.c | 11 +++++++++++
3 files changed, 13 insertions(+), 1 deletion(-)
--
2.25.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2020-10-28 20:31 Mathias Nyman
0 siblings, 0 replies; 11+ messages in thread
From: Mathias Nyman @ 2020-10-28 20:31 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few xhci patches for usb-linus, including a fix for the xhci lockdep
oops in 5.10-rc1
-Mathias
Colin Ian King (1):
xhci: Fix sizeof() mismatch
Mathias Nyman (1):
xhci: Don't create stream debugfs files with spinlock held.
Sandeep Singh (1):
usb: xhci: Workaround for S3 issue on AMD SNPS 3.0 xHC
drivers/usb/host/xhci-mem.c | 4 ++--
drivers/usb/host/xhci-pci.c | 17 +++++++++++++++++
drivers/usb/host/xhci.c | 5 ++++-
drivers/usb/host/xhci.h | 1 +
4 files changed, 24 insertions(+), 3 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2020-08-21 9:15 Mathias Nyman
0 siblings, 0 replies; 11+ messages in thread
From: Mathias Nyman @ 2020-08-21 9:15 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few xhci fixes for usb-linus.
This series makes sure we don't ignore devices attached during suspend that
are stuck in a resume "cold attach status" state, and makes sure xhci driver
doesn't prevent queuing urbs to a endpoint only because driver previously
refused to manually clear the data toggle of a non-empty endpoint.
-Mathias
Ding Hui (1):
xhci: Always restore EP_SOFT_CLEAR_TOGGLE even if ep reset failed
Kai-Heng Feng (1):
xhci: Do warm-reset when both CAS and XDEV_RESUME are set
Li Jun (1):
usb: host: xhci: fix ep context print mismatch in debugfs
drivers/usb/host/xhci-debugfs.c | 8 ++++----
drivers/usb/host/xhci-hub.c | 19 ++++++++++---------
drivers/usb/host/xhci.c | 3 ++-
3 files changed, 16 insertions(+), 14 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2020-04-21 14:08 Mathias Nyman
0 siblings, 0 replies; 11+ messages in thread
From: Mathias Nyman @ 2020-04-21 14:08 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
These xhci fixes for usb-linus sort out halted empty endpoint handling,
protocol stall handling, and overcurrent handling.
Theses issues have caused usb devices to appear as if they stop working
suddenly, failed to enumerate LS/FS devices behind HS hubs (seen on some
audio devices), and host from freezing in case of suspend on over-current.
-Mathias
Mathias Nyman (3):
xhci: Fix handling halted endpoint even if endpoint ring appears empty
xhci: prevent bus suspend if a roothub port detected a over-current
condition
xhci: Don't clear hub TT buffer on ep0 protocol stall
drivers/usb/host/xhci-hub.c | 9 +++++++
drivers/usb/host/xhci-ring.c | 46 +++++++++++++++++++++++++++++++-----
drivers/usb/host/xhci.c | 14 +++++------
drivers/usb/host/xhci.h | 5 ++--
4 files changed, 59 insertions(+), 15 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2019-10-25 14:30 Mathias Nyman
0 siblings, 0 replies; 11+ messages in thread
From: Mathias Nyman @ 2019-10-25 14:30 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few xhci fixes for usb-linus, solving a couple endianness issues, and a
use-after-free regression reported by Johan Hovold
-Mathias
Ben Dooks (Codethink) (1):
usb: xhci: fix __le32/__le64 accessors in debugfs code
Mathias Nyman (1):
xhci: Fix use-after-free regression in xhci clear hub TT
implementation
Samuel Holland (1):
usb: xhci: fix Immediate Data Transfer endianness
drivers/usb/host/xhci-debugfs.c | 24 +++++++++---------
drivers/usb/host/xhci-ring.c | 2 ++
drivers/usb/host/xhci.c | 54 ++++++++++++++++++++++++++++++++++-------
3 files changed, 59 insertions(+), 21 deletions(-)
--
2.7.4
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-09-02 10:53 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-02 10:53 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
2025-09-02 10:53 ` [PATCH 1/3] xhci: dbc: decouple endpoint allocation from initialization Mathias Nyman
2025-09-02 10:53 ` [PATCH 2/3] xhci: dbc: Fix full DbC transfer ring after several reconnects Mathias Nyman
2025-09-02 10:53 ` [PATCH 3/3] xhci: fix memory leak regression when freeing xhci vdev devices depth first Mathias Nyman
-- strict thread matches above, loose matches on Subject: below --
2023-03-30 14:30 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
2022-08-25 15:08 Mathias Nyman
2022-04-08 13:48 Mathias Nyman
2020-10-28 20:31 Mathias Nyman
2020-08-21 9:15 Mathias Nyman
2020-04-21 14:08 Mathias Nyman
2019-10-25 14:30 Mathias Nyman
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).