Re: [PATCH 3/3] usbip: Limit maximum number of virtual host controllers to 31.

From: Greg Kroah-Hartman
Date: Tue Nov 04 2025 - 09:33:53 EST


On Tue, Nov 04, 2025 at 12:32:48PM +0100, Jakub Lecki wrote:
> When loading the vhci-hcd module with number of virtual host controllers
> configured to max value of 128, the module initialization fails due to
> insufficient number of available IDs for USB busses.
>
> Each virtual host controller registers two usb hubs (USB2.0 & USB3.0) to
> the usb core, each with a unique bus number. The number of USB busses is
> limited by ID allocation range [1 .. USB_MAXBUS - 1] (defined in
> usb_register_bus()). Therefore, VHCI_MAX_NR_HCS must not be greater than
> (USB_MAXBUS - 1) / 2 = 31.
>
> In real world scenarios the maximum number of virtual host controllers
> possible to create may be even lower as other USB host controllers may
> be registered. In this case, the module initialization failure is
> correct as the number of virtual host controllers must be adjusted by
> a user to a given use-case.
>
> Signed-off-by: Jakub Lecki <lec.jakub@xxxxxxxxx>
> ---
> drivers/usb/usbip/vhci.h | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
> index 2772d923a8cb..3b0ea4038e51 100644
> --- a/drivers/usb/usbip/vhci.h
> +++ b/drivers/usb/usbip/vhci.h
> @@ -76,8 +76,17 @@ enum hub_speed {
> #define VHCI_DEFAULT_HC_PORTS 8
> #define VHCI_MAX_HC_PORTS USB_SS_MAXPORTS
>
> +/*
> + * Number of supported virtual host controllers. Value has upperbound of
> + * maximum possible usb busses.
> + * It is limited by a bus ID allocation in [1 .. USB_MAXBUS - 1] range,
> + * resulting in maximum of USB_MAXBUS - 1 usb busses allocated.
> + * Additionally, each virtual host controller registers 2 usb hubs (USB2.0
> + * & USB3.0), therefore maximum number of virtual host controllers is:
> + * (USB_MAXBUS - 1) / 2
> + */
> #define VHCI_DEFAULT_NR_HCS 1
> -#define VHCI_MAX_NR_HCS 128
> +#define VHCI_MAX_NR_HCS 31

Why have any max at all? Why not just dynamically allocate them when
asked for?

thanks,

greg k-h