usbip: Convert vhci-hcd Kconfig related to number of ports to module parameters
Subsystems (2)
cover usbip: Convert vhci-hcd Kconfig related to number of ports to module parameters
In workflows involving a greater number of remote
USB/IP devices, the default number of available virtual ports may be insufficient, forcing user to recompile the module with greater number of configured virtual host controllers and/or number of ports.
Allow a user to configure the number of USB/IP virtual host controllers and number of its ports using module parameters to simplify the usage of this module.
Jakub Lecki (3):
usbip: Convert CONFIG_USBIP_VHCI_NR_HCS to a module parameter.
usbip: Convert CONFIG_USBIP_VHCI_HC_PORTS to a module parameter.
usbip: Limit maximum number of virtual host controllers to 31.
drivers/usb/usbip/Kconfig | 21 ------------ drivers/usb/usbip/vhci.h | 42 +++++++++++++----------- drivers/usb/usbip/vhci_hcd.c | 59 +++++++++++++++++++++++++--------- drivers/usb/usbip/vhci_sysfs.c | 18 +++++------ 4 files changed, 75 insertions(+), 65 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 usbip: Convert CONFIG_USBIP_VHCI_NR_HCS to a module parameter.
In workflows involving a greater number of remote
USB/IP devices, the default number of available virtual ports may be insufficient, forcing user to recompile the module with greater number of configured virtual host controllers and/or number of ports.
Allow a user to configure the number of USB/IP virtual host controllers via a new 'num_controllers' module parameter to simplify the usage of this module.
VHCI controller structures are already dynamically allocated during module initialization, so the only change is switch from assigning 'vhci_num_controllers' via Kconfig to using the module parameter framework.
- Remove the USBIP_VHCI_NR_HCS Kconfig option and replace it with a module parameter.
- Trim the value of the configured 'num_controllers' parameter if it exceeds bounds, and emit a warning.
--- drivers/usb/usbip/Kconfig | 11 ----------- drivers/usb/usbip/vhci.h | 9 +++------ drivers/usb/usbip/vhci_hcd.c | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 19 deletions(-)
drivers/usb/usbip/Kconfig +0 -11
@@ -38,17 +38,6 @@ config USBIP_VHCI_HC_PORTS host controller driver, this defines number of ports per USB/IP virtual host controller. -config USBIP_VHCI_NR_HCS - int "Number of USB/IP virtual host controllers" - range 1 128 - default 1 - depends on USBIP_VHCI_HCD - help - To increase number of ports available for USB/IP virtual - host controller driver, this defines number of USB/IP - virtual host controllers as if adding physical host - controllers. - config USBIP_HOST tristate "Host driver" depends on USBIP_CORE && USB
drivers/usb/usbip/vhci.h +3 -6
@@ -82,11 +82,8 @@ enum hub_speed {/* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */ #define VHCI_PORTS (VHCI_HC_PORTS*2) -#ifdef CONFIG_USBIP_VHCI_NR_HCS -#define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS -#else -#define VHCI_NR_HCS 1 -#endif +#define VHCI_DEFAULT_NR_HCS 1 +#define VHCI_MAX_NR_HCS 128#define MAX_STATUS_NAME 16
@@ -118,7 +115,7 @@ struct vhci_hcd {struct vhci_device vdev[VHCI_HC_PORTS ]; }; -extern int vhci_num_controllers; +extern unsigned int vhci_num_controllers;extern struct vhci *vhcis;extern struct attribute_group vhci_attr_group;
drivers/usb/usbip/vhci_hcd.c +14 -2
@@ -10,6 +10,7 @@#include <linux/kthread.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/printk.h> #include <linux/slab.h> #include <linux/string_choices.h>
@@ -44,7 +45,12 @@ static int vhci_get_frame_number(struct usb_hcd *hcd);static const char driver_name[] ="vhci_hcd" ;static const char driver_desc[] ="USB/IP Virtual Host Controller" ; -int vhci_num_controllers =VHCI_NR_HCS ; +unsigned int vhci_num_controllers =VHCI_DEFAULT_NR_HCS ; +module_param_named (num_controllers, vhci_num_controllers, uint,0444 ); +MODULE_PARM_DESC(num_controllers, "Number of USB/IP virtual host controllers (range: 0-" + __MODULE_STRING(VHCI_MAX_NR_HCS) ", default: " + __MODULE_STRING(VHCI_DEFAULT_NR_HCS) ")"); +struct vhci *vhcis;static const char *const bit_desc[] = {
@@ -1510,8 +1516,14 @@ static int __init vhci_hcd_init(void)if (usb_disabled ())return -ENODEV ; -if (vhci_num_controllers <1 ) +if (vhci_num_controllers <1 ) { +pr_warn ("num_controllers less than 1, setting to 1\n" ); vhci_num_controllers =1 ; + }else if (vhci_num_controllers >VHCI_MAX_NR_HCS ) { +pr_warn ("num_controllers too high, limiting to %d\n" , +VHCI_MAX_NR_HCS ); + vhci_num_controllers =VHCI_MAX_NR_HCS ; + } vhcis =kcalloc (vhci_num_controllers,sizeof (struct vhci ),GFP_KERNEL );if (vhcis ==NULL )
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerRe: [PATCH 1/3] usbip: Convert CONFIG_USBIP_VHCI_NR_HCS to a module parameter.
Quoted 88 lines · Jakub Lecki
In workflows involving a greater number of remote
USB/IP devices, the default number of available virtual ports may be insufficient, forcing user to recompile the module with greater number of configured virtual host controllers and/or number of ports.Allow a user to configure the number of USB/IP virtual host controllers via a new '
num_controllers' module parameter to simplify the usage of this module.VHCI controller structures are already dynamically allocated during module initialization, so the only change is switch from assigning '
vhci_num_controllers' viaKconfigto using the module parameter framework.- Remove the
USBIP_VHCI_NR_HCSKconfigoption and replace it with a module parameter.
- Trim the value of the configured 'num_controllers' parameter if it exceeds bounds, and emit a warning.Signed-off-by Jakub Lecki <[email protected]>--- drivers/usb/usbip/Kconfig | 11 ----------- drivers/usb/usbip/vhci.h | 9 +++------ drivers/usb/usbip/vhci_hcd.c | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 19 deletions(-)drivers/usb/usbip/Kconfig +0
-11@@ -38,17 +38,6 @@ config USBIP_VHCI_HC_PORTS host controller driver, this defines number of ports per USB/IP virtual host controller. -config USBIP_VHCI_NR_HCS - int "Number of USB/IP virtual host controllers" - range 1 128 - default 1 - depends on USBIP_VHCI_HCD - help - To increase number of ports available for USB/IP virtual - host controller driver, this defines number of USB/IP - virtual host controllers as if adding physical host - controllers. - config USBIP_HOST tristate "Host driver" depends on USBIP_CORE && USBdrivers/usb/usbip/vhci.h +3
-6@@ -82,11 +82,8 @@ enum hub_speed {/* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */ #define VHCI_PORTS (VHCI_HC_PORTS*2) -#ifdef CONFIG_USBIP_VHCI_NR_HCS -#define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS -#else -#define VHCI_NR_HCS 1 -#endif +#define VHCI_DEFAULT_NR_HCS 1 +#define VHCI_MAX_NR_HCS 128#define MAX_STATUS_NAME 16@@ -118,7 +115,7 @@ struct vhci_hcd {struct vhci_device vdev[VHCI_HC_PORTS ]; }; -extern int vhci_num_controllers; +extern unsigned int vhci_num_controllers;extern struct vhci *vhcis;extern struct attribute_group vhci_attr_group;drivers/usb/usbip/vhci_hcd.c +1
-0@@ -10,6 +10,7 @@#include <linux/kthread.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/printk.h> #include <linux/slab.h> #include <linux/string_choices.h>
drivers/usb/usbip/vhci_hcd.c static int vhci_get_frame_number(struct usb_hcd *hcd); · line 52
Quoted 9 lines
drivers/usb/usbip/vhci_hcd.c +5
-1@@ -44,7 +45,12 @@ static int vhci_get_frame_number(struct usb_hcd *hcd);static const char driver_name[] ="vhci_hcd" ;static const char driver_desc[] ="USB/IP Virtual Host Controller" ; -int vhci_num_controllers =VHCI_NR_HCS ; +unsigned int vhci_num_controllers =VHCI_DEFAULT_NR_HCS ; +module_param_named (num_controllers, vhci_num_controllers, uint,0444 ); +MODULE_PARM_DESC(num_controllers, "Number of USB/IP virtual host controllers (range: 0-" + __MODULE_STRING(VHCI_MAX_NR_HCS) ", default: " + __MODULE_STRING(VHCI_DEFAULT_NR_HCS) ")");
I'm all for making this dynamic, but this is not the 1990's, please do not add new module parameters. Use the "proper" api for this, either sysfs or configfs, instead.
thanks,
greg k-h
PATCH 2/3 usbip: Convert CONFIG_USBIP_VHCI_HC_PORTS to a module parameter.
In reply to Jakub LeckiIn workflows involving a greater number of remote
USB/IP devices, the default number of available virtual ports may be insufficient, forcing user to recompile the module with greater number of configured virtual host controllers and/or number of ports.
Allow a user to configure the number of ports per USB/IP virtual host controller via a new 'hc_ports' module parameter to simplify the usage of this module.
- Remove the USBIP_VHCI_HC_PORTS Kconfig option and replace it with a module parameter.
- Fix the omitted BUILD_BUG_ON check for the upper limit of 'vhci_hc_ports' when switching from USB_MAXCHILDREN to USB_SS_MAXPORTS.
- Resize related arrays to match VHCI_MAX_HC_PORTS = USB_SS_MAXPORTS to support a dynamically configurable number of ports.
- Trim the value of the configured 'hc_ports' parameter if it exceeds bounds, and emit a warning.
--- drivers/usb/usbip/Kconfig | 10 -------- drivers/usb/usbip/vhci.h | 22 ++++++++--------- drivers/usb/usbip/vhci_hcd.c | 43 +++++++++++++++++++++++----------- drivers/usb/usbip/vhci_sysfs.c | 18 +++++++------- 4 files changed, 48 insertions(+), 45 deletions(-)
drivers/usb/usbip/Kconfig +0 -10
@@ -28,16 +28,6 @@ config USBIP_VHCI_HCD To compile this driver as a module, choose M here: the module will be called vhci-hcd. -config USBIP_VHCI_HC_PORTS - int "Number of ports per USB/IP virtual host controller" - range 1 15 - default 8 - depends on USBIP_VHCI_HCD - help - To increase number of ports available for USB/IP virtual - host controller driver, this defines number of ports per - USB/IP virtual host controller. - config USBIP_HOST tristate "Host driver" depends on USBIP_CORE && USB
drivers/usb/usbip/vhci.h +10 -12
@@ -72,15 +72,9 @@ enum hub_speed { HUB_SPEED_SUPER, }; -/* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */ -#ifdef CONFIG_USBIP_VHCI_HC_PORTS -#define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS -#else -#define VHCI_HC_PORTS 8 -#endif - -/* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */ -#define VHCI_PORTS (VHCI_HC_PORTS*2) +/* Number of supported ports. Value has an upperbound of USB_SS_MAXPORTS */ +#define VHCI_DEFAULT_HC_PORTS 8 +#define VHCI_MAX_HC_PORTS USB_SS_MAXPORTS#define VHCI_DEFAULT_NR_HCS 1#define VHCI_MAX_NR_HCS 128
@@ -100,7 +94,7 @@ struct vhci {struct vhci_hcd {struct vhci *vhci; -u32 port_status[VHCI_HC_PORTS ]; +u32 port_status[VHCI_MAX_HC_PORTS ];unsigned resuming:1 ;unsigned long re_timeout;
@@ -112,13 +106,17 @@ struct vhci_hcd {* wIndex shows the port number and begins from 1. * But, the index of this array begins from 0. */ -struct vhci_device vdev[VHCI_HC_PORTS ]; +struct vhci_device vdev[VHCI_MAX_HC_PORTS ]; };extern unsigned int vhci_num_controllers; +extern unsigned int vhci_hc_ports;extern struct vhci *vhcis;extern struct attribute_group vhci_attr_group; +/* Each VHCI has 2 hubs (USB2 and USB3), each has vhci_hc_ports ports */ +#define VHCI_PORTS (vhci_hc_ports * 2) +/* vhci_hcd.c */ void rh_port_connect (struct vhci_device *vdev,enum usb_device_speed speed);
@@ -135,7 +133,7 @@ int vhci_tx_loop(void *data);static inline __u32 port_to_rhport (__u32 port) { -return port %VHCI_HC_PORTS ; +return port % vhci_hc_ports; }static inline int port_to_pdev_nr (__u32 port)
drivers/usb/usbip/vhci_hcd.c +29 -14
122 lines not on this page · raw message
drivers/usb/usbip/vhci_sysfs.c +9 -9
@@ -81,7 +81,7 @@ static ssize_t status_show_vhci(int pdev_nr, char *out)spin_lock_irqsave (&vhci->lock, flags); -for (i =0 ; i <VHCI_HC_PORTS ; i++) { +for (i =0 ; i < vhci_hc_ports; i++) {struct vhci_device *vdev = &vhci->vhci_hcd_hs->vdev[i];spin_lock (&vdev->ud.lock);
@@ -90,12 +90,12 @@ static ssize_t status_show_vhci(int pdev_nr, char *out)spin_unlock (&vdev->ud.lock); } -for (i =0 ; i <VHCI_HC_PORTS ; i++) { +for (i =0 ; i < vhci_hc_ports; i++) {struct vhci_device *vdev = &vhci->vhci_hcd_ss->vdev[i];spin_lock (&vdev->ud.lock);port_show_vhci (&out,HUB_SPEED_SUPER , - pdev_nr *VHCI_PORTS +VHCI_HC_PORTS + i, vdev); + pdev_nr *VHCI_PORTS + vhci_hc_ports + i, vdev);spin_unlock (&vdev->ud.lock); }
@@ -109,7 +109,7 @@ static ssize_t status_show_not_ready(int pdev_nr, char *out)char *s = out;int i =0 ; -for (i =0 ; i <VHCI_HC_PORTS ; i++) { +for (i =0 ; i < vhci_hc_ports; i++) { out +=sprintf (out,"hs %04u %03u " , (pdev_nr *VHCI_PORTS ) + i,VDEV_ST_NOTASSIGNED );
@@ -117,9 +117,9 @@ static ssize_t status_show_not_ready(int pdev_nr, char *out) out +=sprintf (out,"\n" ); } -for (i =0 ; i <VHCI_HC_PORTS ; i++) { +for (i =0 ; i < vhci_hc_ports; i++) { out +=sprintf (out,"ss %04u %03u " , - (pdev_nr *VHCI_PORTS ) +VHCI_HC_PORTS + i, + (pdev_nr *VHCI_PORTS ) + vhci_hc_ports + i,VDEV_ST_NOTASSIGNED ); out +=sprintf (out,"000 00000000 0000000000000000 0-0" ); out +=sprintf (out,"\n" );
@@ -221,11 +221,11 @@ static int valid_port(__u32 *pdev_nr, __u32 *rhport) } *pdev_nr =array_index_nospec (*pdev_nr, vhci_num_controllers); -if (*rhport >=VHCI_HC_PORTS ) { +if (*rhport >= vhci_hc_ports) {pr_err ("rhport %u\n" , *rhport);return 0 ; } - *rhport =array_index_nospec (*rhport,VHCI_HC_PORTS ); + *rhport =array_index_nospec (*rhport, vhci_hc_ports);return 1 ; }
@@ -255,7 +255,7 @@ static ssize_t detach_store(struct device *dev, struct device_attribute *attr,usbip_dbg_vhci_sysfs ("rhport %d\n" , rhport); -if ((port /VHCI_HC_PORTS ) %2 ) +if ((port / vhci_hc_ports) %2 ) vhci_hcd =hcd_to_vhci_hcd (hcd)->vhci->vhci_hcd_ss;else vhci_hcd =hcd_to_vhci_hcd (hcd)->vhci->vhci_hcd_hs;
Signature · 1 line
2.43.0
PATCH 3/3 usbip: Limit maximum number of virtual host controllers to 31.
In reply to Jakub LeckiWhen 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.
--- drivers/usb/usbip/vhci.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/usb/usbip/vhci.h +10 -1
@@ -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#define MAX_STATUS_NAME 16
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerRe: [PATCH 3/3] usbip: Limit maximum number of virtual host controllers to 31.
Quoted 31 lines · Jakub Lecki
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 inusb_register_bus()). Therefore,VHCI_MAX_NR_HCSmust 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 <[email protected]>--- drivers/usb/usbip/vhci.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/usb/usbip/vhci.h +2
-0@@ -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
drivers/usb/usbip/vhci.h enum hub_speed { · line 89
Quoted 10 lines
drivers/usb/usbip/vhci.h +8
-1+* 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