Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: xhci: limit number of ports to 127

The xHCI driver allocates various port-related structures based on the
maximum number of ports reported by the controller. The Number of Ports
(MaxPorts) field occupies bits 31:24 of the HCSPARAMS1 register and can
represent values up to 255. However, the 'HCS_MAX_PORTS()' macro currently
reads bits 30:24, effectively limiting the maximum to 127.

Fixing the macro increases the reported port limit to 255, which in turn
increases memory usage regardless of how many ports are actually used.

To maintain compatibility and control memory consumption, set
'xhci->max_ports' to the minimum of the value read from 'HCS_MAX_PORTS()'
and 127 (MAX_HC_PORTS). This preserves the existing limit while making
the restriction explicit and easier to adjust in the future.

Summary:
* Port allocations are now limited to 127.
* HC max ports macro now correctly reads the MaxPorts value.
* Macro 'MAX_HC_PORTS' can be modified to set the port limit.

Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://patch.msgid.link/20251119142417.2820519-17-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Niklas Neronin and committed by
Greg Kroah-Hartman
1668263a df089735

+7 -4
+2 -2
drivers/usb/host/xhci-caps.h
··· 12 12 #define HCS_SLOTS_MASK 0xff 13 13 /* bits 8:18, Max Interrupters */ 14 14 #define HCS_MAX_INTRS(p) (((p) >> 8) & 0x7ff) 15 - /* bits 24:31, Max Ports - max value is 0x7F = 127 ports */ 16 - #define HCS_MAX_PORTS(p) (((p) >> 24) & 0x7f) 15 + /* bits 31:24, Max Ports - max value is 255 */ 16 + #define HCS_MAX_PORTS(p) (((p) >> 24) & 0xff) 17 17 18 18 /* HCSPARAMS2 - hcs_params2 - bitmasks */ 19 19 /* bits 0:3, frames or uframes that SW needs to queue transactions
+1 -1
drivers/usb/host/xhci.c
··· 5448 5448 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); 5449 5449 5450 5450 xhci->max_slots = HCS_MAX_SLOTS(hcs_params1); 5451 - xhci->max_ports = HCS_MAX_PORTS(hcs_params1); 5451 + xhci->max_ports = min(HCS_MAX_PORTS(hcs_params1), MAX_HC_PORTS); 5452 5452 /* xhci-plat or xhci-pci might have set max_interrupters already */ 5453 5453 if ((!xhci->max_interrupters) || xhci->max_interrupters > HCS_MAX_INTRS(hcs_params1)) 5454 5454 xhci->max_interrupters = HCS_MAX_INTRS(hcs_params1);
+4 -1
drivers/usb/host/xhci.h
··· 34 34 35 35 /* Max number of USB devices for any host controller - limit in section 6.1 */ 36 36 #define MAX_HC_SLOTS 256 37 - /* Section 5.3.3 - MaxPorts */ 37 + /* 38 + * Max Number of Ports. xHCI specification section 5.3.3 39 + * Valid values are in the range of 1 to 255. 40 + */ 38 41 #define MAX_HC_PORTS 127 39 42 40 43 /*