linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] xhci fixes for usb-linus
@ 2025-10-13 22:55 Mathias Nyman
  2025-10-13 22:55 ` [PATCH 1/3] usb: xhci-pci: Fix USB2-only root hub registration Mathias Nyman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mathias Nyman @ 2025-10-13 22:55 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Hi Greg

A few fixes for usb-linus 6.18-rc
Solve an issue in the USB2 only PCI xHCI controller support added to 6.18
Solve two DbC cases that have been around since beginning of DbC support.

Thanks
Mathias

Mathias Nyman (2):
  xhci: dbc: fix bogus 1024 byte prefix if ttyDBC read races with stall
    event
  xhci: dbc: enable back DbC in resume if it was enabled before suspend

Michal Pecio (1):
  usb: xhci-pci: Fix USB2-only root hub registration

 drivers/usb/host/xhci-dbgcap.c | 15 ++++++++++++---
 drivers/usb/host/xhci-pci.c    |  3 ++-
 2 files changed, 14 insertions(+), 4 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] usb: xhci-pci: Fix USB2-only root hub registration
  2025-10-13 22:55 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
@ 2025-10-13 22:55 ` Mathias Nyman
  2025-10-13 22:55 ` [PATCH 2/3] xhci: dbc: fix bogus 1024 byte prefix if ttyDBC read races with stall event Mathias Nyman
  2025-10-13 22:55 ` [PATCH 3/3] xhci: dbc: enable back DbC in resume if it was enabled before suspend Mathias Nyman
  2 siblings, 0 replies; 4+ messages in thread
From: Mathias Nyman @ 2025-10-13 22:55 UTC (permalink / raw)
  To: gregkh
  Cc: linux-usb, Michal Pecio, Arisa Snowbell, Michal Kubecek,
	Mathias Nyman

From: Michal Pecio <michal.pecio@gmail.com>

A recent change to hide USB3 root hubs of USB2-only controllers broke
registration of USB2 root hubs - allow_single_roothub is set too late,
and by this time xhci_run() has already deferred root hub registration
until after the shared HCD is added, which will never happen.

This makes such controllers unusable, but testers didn't notice since
they were only bothered by warnings about empty USB3 root hubs. The bug
causes problems to other people who actually use such HCs and I was
able to confirm it on an ordinary HC by patching to ignore USB3 ports.

Setting allow_single_roothub during early setup fixes things.

Reported-by: Arisa Snowbell <arisa.snowbell@gmail.com>
Closes: https://lore.kernel.org/linux-usb/CABpa4MA9unucCoKtSdzJyOLjHNVy+Cwgz5AnAxPkKw6vuox1Nw@mail.gmail.com/
Reported-by: Michal Kubecek <mkubecek@suse.cz>
Closes: https://lore.kernel.org/linux-usb/lnb5bum7dnzkn3fc7gq6hwigslebo7o4ccflcvsc3lvdgnu7el@fvqpobbdoapl/
Fixes: 719de070f764 ("usb: xhci-pci: add support for hosts with zero USB3 ports")
Tested-by: Arisa Snowbell <arisa.snowbell@gmail.com>
Tested-by: Michal Kubecek <mkubecek@suse.cz>
Suggested-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 5c8ab519f497..f67a4d956204 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -582,6 +582,8 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
 	if (!usb_hcd_is_primary_hcd(hcd))
 		return 0;
 
+	xhci->allow_single_roothub = 1;
+
 	if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
 		xhci_pme_acpi_rtd3_enable(pdev);
 
@@ -637,7 +639,6 @@ int xhci_pci_common_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	xhci = hcd_to_xhci(hcd);
 	xhci->reset = reset;
 
-	xhci->allow_single_roothub = 1;
 	if (!xhci_has_one_roothub(xhci)) {
 		xhci->shared_hcd = usb_create_shared_hcd(&xhci_pci_hc_driver, &dev->dev,
 							 pci_name(dev), hcd);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] xhci: dbc: fix bogus 1024 byte prefix if ttyDBC read races with stall event
  2025-10-13 22:55 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
  2025-10-13 22:55 ` [PATCH 1/3] usb: xhci-pci: Fix USB2-only root hub registration Mathias Nyman
@ 2025-10-13 22:55 ` Mathias Nyman
  2025-10-13 22:55 ` [PATCH 3/3] xhci: dbc: enable back DbC in resume if it was enabled before suspend Mathias Nyman
  2 siblings, 0 replies; 4+ messages in thread
From: Mathias Nyman @ 2025-10-13 22:55 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman, stable, Łukasz Bartosik

DbC may add 1024 bogus bytes to the beginneing of the receiving endpoint
if DbC hw triggers a STALL event before any Transfer Blocks (TRBs) for
incoming data are queued, but driver handles the event after it queued
the TRBs.

This is possible as xHCI DbC hardware may trigger spurious STALL transfer
events even if endpoint is empty. The STALL event contains a pointer
to the stalled TRB, and "remaining" untransferred data length.

As there are no TRBs queued yet the STALL event will just point to first
TRB position of the empty ring, with '0' bytes remaining untransferred.

DbC driver is polling for events, and may not handle the STALL event
before /dev/ttyDBC0 is opened and incoming data TRBs are queued.

The DbC event handler will now assume the first queued TRB (length 1024)
has stalled with '0' bytes remaining untransferred, and copies the data

This race situation can be practically mitigated by making sure the event
handler handles all pending transfer events when DbC reaches configured
state, and only then create dev/ttyDbC0, and start queueing transfers.
The event handler can this way detect the STALL events on empty rings
and discard them before any transfers are queued.

This does in practice solve the issue, but still leaves a small possible
gap for the race to trigger.
We still need a way to distinguish spurious STALLs on empty rings with '0'
bytes remaing, from actual STALL events with all bytes transmitted.

Cc: stable@vger.kernel.org
Fixes: dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")
Tested-by: Łukasz Bartosik <ukaszb@chromium.org>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 63edf2d8f245..023a8ec6f305 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -892,7 +892,8 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 			dev_info(dbc->dev, "DbC configured\n");
 			portsc = readl(&dbc->regs->portsc);
 			writel(portsc, &dbc->regs->portsc);
-			return EVT_GSER;
+			ret = EVT_GSER;
+			break;
 		}
 
 		return EVT_DONE;
@@ -954,7 +955,8 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 			break;
 		case TRB_TYPE(TRB_TRANSFER):
 			dbc_handle_xfer_event(dbc, evt);
-			ret = EVT_XFER_DONE;
+			if (ret != EVT_GSER)
+				ret = EVT_XFER_DONE;
 			break;
 		default:
 			break;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] xhci: dbc: enable back DbC in resume if it was enabled before suspend
  2025-10-13 22:55 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
  2025-10-13 22:55 ` [PATCH 1/3] usb: xhci-pci: Fix USB2-only root hub registration Mathias Nyman
  2025-10-13 22:55 ` [PATCH 2/3] xhci: dbc: fix bogus 1024 byte prefix if ttyDBC read races with stall event Mathias Nyman
@ 2025-10-13 22:55 ` Mathias Nyman
  2 siblings, 0 replies; 4+ messages in thread
From: Mathias Nyman @ 2025-10-13 22:55 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman, stable, Łukasz Bartosik

DbC is currently only enabled back if it's in configured state during
suspend.

If system is suspended after DbC is enabled, but before the device is
properly enumerated by the host, then DbC would not be enabled back in
resume.

Always enable DbC back in resume if it's suspended in enabled,
connected, or configured state

Cc: stable@vger.kernel.org
Fixes: dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")
Tested-by: Łukasz Bartosik <ukaszb@chromium.org>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 023a8ec6f305..ecda964e018a 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -1392,8 +1392,15 @@ int xhci_dbc_suspend(struct xhci_hcd *xhci)
 	if (!dbc)
 		return 0;
 
-	if (dbc->state == DS_CONFIGURED)
+	switch (dbc->state) {
+	case DS_ENABLED:
+	case DS_CONNECTED:
+	case DS_CONFIGURED:
 		dbc->resume_required = 1;
+		break;
+	default:
+		break;
+	}
 
 	xhci_dbc_stop(dbc);
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-10-13 22:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-13 22:55 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
2025-10-13 22:55 ` [PATCH 1/3] usb: xhci-pci: Fix USB2-only root hub registration Mathias Nyman
2025-10-13 22:55 ` [PATCH 2/3] xhci: dbc: fix bogus 1024 byte prefix if ttyDBC read races with stall event Mathias Nyman
2025-10-13 22:55 ` [PATCH 3/3] xhci: dbc: enable back DbC in resume if it was enabled before suspend 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).