Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: xhci: fix maximum event ring segments calculation
@ 2026-08-28 10:59 oushixiong1025
  2026-08-30  3:12 ` Pierre-David Belanger
  2026-08-31  9:10 ` Mathias Nyman
  0 siblings, 2 replies; 9+ messages in thread
From: oushixiong1025 @ 2026-08-28 10:59 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Shixiong Ou

From: Shixiong Ou <oushixiong@kylinos.cn>

Commit 6d45e9556d4a ("usb: xhci: standardize multi bit-field macros")
converted BIT(HCS_ERST_MAX(hcs_params2)) into
FIELD_GET(HCS_ERST_MAX, hcs_params2) << 2. The ERST Max field is a
power-of-two exponent, so the maximum number of segments is 2^n, not
n * 4.

With an ERST Max of 0 (as reported by e.g. QEMU xHCI) max_segs becomes
0, the event ring is allocated with 0 segments, and the resulting
zero-sized ERST allocation trips the page allocator:

  WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0x11d0/0x1548, CPU#0: swapper/0/1
  Call trace:
   __alloc_frozen_pages_noprof+0x11d0/0x1548 (P)
   alloc_pages_node_noprof+0xa0/0x108
   __dma_direct_alloc_pages.isra.0+0x178/0x260
   dma_direct_alloc+0x1e4/0x460
   dma_alloc_attrs+0xb4/0x2e8
   xhci_alloc_interrupter+0xdc/0x1c8
   xhci_mem_init+0x250/0xe70
   xhci_gen_setup+0x35c/0x4f0
   xhci_pci_setup+0x68/0x138
   usb_add_hcd+0x31c/0x640
   usb_hcd_pci_probe+0x1fc/0x3d8
   ...
  xhci_hcd 0000:02:00.0: Failed to allocate interrupter erst
  xhci_hcd 0000:02:00.0: can't setup: -12

Restore the BIT() based calculation.

Fixes: 6d45e9556d4a ("usb: xhci: standardize multi bit-field macros")
Signed-off-by: Shixiong Ou <oushixiong@kylinos.cn>
---
 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 7a21ac81f9c8..af8d4b74c4ba 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2301,7 +2301,7 @@ xhci_alloc_interrupter(struct xhci_hcd *xhci, unsigned int segs, gfp_t flags)
 	if (!segs)
 		segs = ERST_DEFAULT_SEGS;
 
-	max_segs = FIELD_GET(HCS_ERST_MAX, xhci->hcs_params2) << 2;
+	max_segs = BIT(FIELD_GET(HCS_ERST_MAX, xhci->hcs_params2));
 	segs = min(segs, max_segs);
 
 	ir = kzalloc_node(sizeof(*ir), flags, dev_to_node(dev));
-- 
2.25.1


No virus found
		Checked by Hillstone Network AntiVirus


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

end of thread, other threads:[~2026-09-01  8:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-28 10:59 [PATCH] usb: xhci: fix maximum event ring segments calculation oushixiong1025
2026-08-30  3:12 ` Pierre-David Belanger
2026-08-31  6:55   ` Thorsten Leemhuis
2026-08-31  9:21     ` Mathias Nyman
2026-08-31 11:28       ` Thorsten Leemhuis
2026-08-31 11:36         ` Thorsten Leemhuis
2026-08-31 14:28           ` Mathias Nyman
2026-09-01  8:16             ` Thorsten Leemhuis
2026-08-31  9:10 ` Mathias Nyman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox