From nobody Fri Dec 19 09:24:04 2025 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D05DD2E03EC for ; Tue, 4 Nov 2025 11:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762255979; cv=none; b=Ea8cOGei1paxok0XGclkPW9usoCxxReZHfdiy0Jz5PQCTGp/rpLJ6NSxo+zfvLxxlLEdvC3/h5A/2NttivDW1RodXOx1ed7l/EYCeupyPXT/Hk4wgQr9QE52L18Q2ZEsNk5vNJUzsCV85FdWzpLrwXqEuB3znpHTz4b07KV2pK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762255979; c=relaxed/simple; bh=BrmEyFX5UaDMOI+HZP7uLh1hwRFA3aEfIDrRqMAcmaM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aixgywpTH2HMJIXtm4UCxkpfp8cahYKsFNNPjMgiLiOeLdDwr6556Zgf9TdqYuEOBj0QalvM8HStba5C2tU04oCauwEhO0GdX+CLAcuD0QiOd2aAle6adevNfuzZk9Dr01nSLB2Pud1o/wj69NptDi82eSdv+XVlWvsUcYdvPEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AzERjgCF; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AzERjgCF" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-b719ca8cb8dso166022766b.0 for ; Tue, 04 Nov 2025 03:32:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762255976; x=1762860776; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zB5oUHRN+sjBEDImJtxc/YP5+xfGRdtBoe5sSbvsoHs=; b=AzERjgCFEMkGNhA5vEUfCmDCa+1His+ZGgLVb7cUNuvaNfhFKDdg70CpHR9Wbdnmx8 HSJHWCC02UrZzF2e7xWvX30PqUSV6aH+bqKkYb3wqEj7Me7VpHTh1i2EglKyFqnWe6Mk +b3hJjbiQC1N6NR0ldiNJgmLVqbJR/e1gmTZcGwOEenQn7Jxg4yP1eA9EUU81EqMNl3W s2XM9qVNfpXWyquM3jBaxczGrFq251pxC5cGrMMYL8M+k/a6sR/2h7lJTA+16znDoFwe 56Ies0O9lmeE9DqxNsG3H5OqA4MWmcwxf9cykleMN4vFB4jCmeIzaZC/PwttP0Nq2kcG 78hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762255976; x=1762860776; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zB5oUHRN+sjBEDImJtxc/YP5+xfGRdtBoe5sSbvsoHs=; b=meqK5Sb6+C8F9dXnLHEpZgRhbHbM+RGFuOiatglOA5OoiZ077rb05uAKL4uD6/WI2C alJlSnXPxPr8MQL704Huh4i92EVtUTnk0toPlbrxWnKdT0yUY8nLJOdmR33qrjDx/tev nXWBURtc7l7UmNLLklPEmJ5RA47/7mlgj77mcm/6x3QJiuJhbV5D4Wswn2frhbUiHxTG CZdRds+N27Maa2VmbbhKGI/QU1kA5Z1tYfh3nCyrilc38qHeq/NAgz43n/HDhxJqDwJz cV+HeWeNjyWb4P45rWYMMvSIO+3RRaIStklyLbb1svqUZZEZuNMfb71MzU8rqDfMk7NE dInA== X-Forwarded-Encrypted: i=1; AJvYcCVi7F0TQYHqEN4stW0VidJKP9laiZm8gEN7EU9wu2KE+VW57zZd1wyin/g5UDHT/LK00qJFYC/UHSG3wgs=@vger.kernel.org X-Gm-Message-State: AOJu0YwT9W8SmN488ii+7jff4dqJUG7I1jiMXQ8dFd0iW7LbSNVcemJM sfBV9yrdad5MDXVZxNGyhAmOaWb70lTGIQAafpZYAIFqlZPrG6tOzBGg X-Gm-Gg: ASbGncsC4tuxNr5VmDZIOF1tlANHIX+udji4Y3vp+85Qy4TCfJcDpjwdT4fqyVoFzRe xs2tzMazVFx1gXlvYWbdmE6ePVb5qEJV1/5zHiFNSysaJqvXZFjtaOGJZkdFdji2zHya+r9OA3w Appz81Ta2k19xztofJfZEL4FsFwcUbCM3C4+RKKLJSXHc1IxGU0/giLEli1eYvLnXta3XDYxvG2 pPIwTtghJFoVUpNWBBIogV8jX2A5jW+AirqdpC8T2dAZsiwTX7mrkQj7gnu+nMYpcFq1/9hNoXt qe8Q6KgQh1HSI4ZPMwDHgrKTduh1XL4EHQUr2hcTKn7hvOfCyYG7AC5ZrJ/jCtYhW24A3hgt5oM jKkRLnJsk6zmhbmL4HJMUJTUaxGiAaARrq1IsUecvDvlwq4eEV5QBHtVQeF3MtSQiIBOLZfJgFk Q3puoo+dq7cYaaiCpX5PnHL9VbYVRUYSFKPWsElqCLNGr9vDYiutYNoz/zP3TdgZjy73cxpmvG X-Google-Smtp-Source: AGHT+IFOV3Ps8Sz7eT1jCBUyreP4B59BwW2YbE+VTDC+/GsVpvA9CcWro96lBn32vwcYP5LatlPrLg== X-Received: by 2002:a17:907:961e:b0:b2d:e514:5348 with SMTP id a640c23a62f3a-b70704c4014mr1830235466b.33.1762255976028; Tue, 04 Nov 2025 03:32:56 -0800 (PST) Received: from jale-pg.. ([2a02:2a40:17ee:2900:8627:17a2:2166:4084]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b72404470e9sm182469766b.70.2025.11.04.03.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 03:32:55 -0800 (PST) From: Jakub Lecki To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Valentina Manea , Shuah Khan , Hongren Zheng , Greg Kroah-Hartman , Jakub Lecki Subject: [PATCH 1/3] usbip: Convert CONFIG_USBIP_VHCI_NR_HCS to a module parameter. Date: Tue, 4 Nov 2025 12:32:46 +0100 Message-ID: <20251104113248.223594-2-lec.jakub@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251104113248.223594-1-lec.jakub@gmail.com> References: <20251104113248.223594-1-lec.jakub@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Jakub Lecki --- 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(-) diff --git a/drivers/usb/usbip/Kconfig b/drivers/usb/usbip/Kconfig index b9f94e2e278d..bdcb6f4fdbec 100644 --- a/drivers/usb/usbip/Kconfig +++ b/drivers/usb/usbip/Kconfig @@ -38,17 +38,6 @@ config USBIP_VHCI_HC_PORTS host controller driver, this defines number of ports per USB/IP virtual host controller. =20 -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 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h index 5659dce1526e..30b8540e0b49 100644 --- a/drivers/usb/usbip/vhci.h +++ b/drivers/usb/usbip/vhci.h @@ -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) =20 -#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 =20 #define MAX_STATUS_NAME 16 =20 @@ -118,7 +115,7 @@ struct vhci_hcd { struct vhci_device vdev[VHCI_HC_PORTS]; }; =20 -extern int vhci_num_controllers; +extern unsigned int vhci_num_controllers; extern struct vhci *vhcis; extern struct attribute_group vhci_attr_group; =20 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c index e70fba9f55d6..93c3fa3e1c53 100644 --- a/drivers/usb/usbip/vhci_hcd.c +++ b/drivers/usb/usbip/vhci_hcd.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include =20 @@ -44,7 +45,12 @@ static int vhci_get_frame_number(struct usb_hcd *hcd); static const char driver_name[] =3D "vhci_hcd"; static const char driver_desc[] =3D "USB/IP Virtual Host Controller"; =20 -int vhci_num_controllers =3D VHCI_NR_HCS; +unsigned int vhci_num_controllers =3D 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 controlle= rs (range: 0-" + __MODULE_STRING(VHCI_MAX_NR_HCS) ", default: " + __MODULE_STRING(VHCI_DEFAULT_NR_HCS) ")"); + struct vhci *vhcis; =20 static const char * const bit_desc[] =3D { @@ -1510,8 +1516,14 @@ static int __init vhci_hcd_init(void) if (usb_disabled()) return -ENODEV; =20 - if (vhci_num_controllers < 1) + if (vhci_num_controllers < 1) { + pr_warn("num_controllers less than 1, setting to 1\n"); vhci_num_controllers =3D 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 =3D VHCI_MAX_NR_HCS; + } =20 vhcis =3D kcalloc(vhci_num_controllers, sizeof(struct vhci), GFP_KERNEL); if (vhcis =3D=3D NULL) --=20 2.43.0 From nobody Fri Dec 19 09:24:04 2025 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56A9E2E9EA0 for ; Tue, 4 Nov 2025 11:32:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762255981; cv=none; b=iOqf0YWxCtUPFiywpqpdYWPQsSUnPLsVGR/eoOW1JFGvcdCXYQHqcgWzspjMSGzL1gfbGxyECrjW7jI9d+Au4zgHFcCJUYB7d+EJ3a0DQiUMREx5iCnA08O0y+S2lmghyub0kgGufSzysHkhPqzZiJNlQZ9ohO4hhvBzHNhIRPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762255981; c=relaxed/simple; bh=awdUCLb638duOsloxz8F9nYD6abSXejtgV2z/HFImZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fOpTfPfuXzrjd9ZCkZwWhMQQeFgRElkOtv1xUMd32DRvnnMJub9NwHm1qCladu0He/NKXDPxJY2JGMYBY+KbK7zsxsLeLdAV7lSkPyrDTh0KafaLQM+vdGTUup9cBW9LeXR4lIzdT469s1BkIAJJNFUJh3Tiii5nTKQCrKO5PbQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H/sNhBN3; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H/sNhBN3" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-640f4b6836bso430038a12.3 for ; Tue, 04 Nov 2025 03:32:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762255977; x=1762860777; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3d+YJijRpL8w9LCQNHN0V7As8Dqz/jO5NzA/qgZx3ko=; b=H/sNhBN3h34oAQdiKJH13bFNujfVrrLS8qHwGdsExgP/WlO+RrJesTIzvC9aL6Dfdl YpDFvsoMGIxiQ6KKw3QD4QgH77refqTaKD6KGh4ov14fHhec0GvOmWLwmL3/d/UGbhZV h1Sgo2P2JxGiKJpxh9dSKV7S4ZgwRv41Z4na8H3clerS7EePZCSyDRLzEaSNMiwUYS6C ipRMNMMDVHYIXnRnXFTsBVe7U78AK6x32kcbH53TzS3eU+/p1j5VODJnGIYv9SmRoNje koCwwNV46hLVXxjt+OpdX+JVb3C0oAJov+uFP4nta+BPVODKcNSVeurp/ExI9K1h3AMi L0vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762255977; x=1762860777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3d+YJijRpL8w9LCQNHN0V7As8Dqz/jO5NzA/qgZx3ko=; b=r3Rhqwrg8voc89D6kOSg6ZG+4X+6n9hINxOBuABvCXiJMfNSs6v8ZnUsVzh48X6HK7 OK18GBh50kGgjKQ3UxuvjWdySC7fYfeB5S7pyENHkAlRk7pBp8lnUHi6zS+PKixGTY7y cr4dSY/F2ORWtd9Z6z1PB8CXlLmVfEAfysGobRptPZ6inS6edwknozdBev2NLeQGdF3/ s8KB7c7hxACEKBF6KX94d8rSDbaOE4g41M1TPQif/t5wvVDkUlvdz6WaH52RfUC0M2u+ BoqwRlLOQUEhxoWj9D47PxvXfGkvouwGCBE/zXNAJlq0TeARUEPJuUBtX/mn53PsMBXH mVeg== X-Forwarded-Encrypted: i=1; AJvYcCWl6TC6z7hA06ZvF1YIhW250p9Hn9EgXsRo8Y4SZ5VN2UpdL/rMThlaTEdLMP9NuES9w8EYWtEtLYfJuK0=@vger.kernel.org X-Gm-Message-State: AOJu0YzWwxDHItXNRBCNE/Uz+scWXLpCZu4cck1Z7eOn6x9FYoTL0oNg relVKE+w2Q+O4ELrt3deKKTLYXK7d6rJuvE3p6kEhlrwNJsn3YVMj3FM X-Gm-Gg: ASbGncsBIxF+eLci2o/Ml7ypJmYMh9lfjJE0aieJuypu3YCOKCqaf4LMXs9cgJy6IGO NQ5/2p4+XOyZiR9AEkVRgevnNTKUi966ajVXtNUL0+kmaoY8y2G0TAtOZS6YwAyg6ykmdJ4Cps7 gEskwuRiJ9QtCQx+KEEsYajP8lKGXPEgiGfA6mbx1NHOJtZwBYw4EcYNI/8KuIsW56NPM2fv12s WnDWpX8ZzeYxxI2PVx5uFm9w6apIicT0PBrwxcWo4mEDO2zWSpkbp5L7va4Nlw1xNscx0UB3ZIs c+L+6PQ0K+pt64koUMyULOw5Hy3Uw3CHY5o0RlRnOCzDqlo8Ti90CZKTlZ1un/GB58076SMoywo ldOWt0ODLBHIR0RwogpSHTfY1W802Ga0i9NB9DAW718UPJ3Sxg2d6reGSC656eY5PQ/EnqRqZ9l uISy+Sc0Lt6sB+iQ6LnZIRD7Bqh8NmZ2hksO6udovEnInFS9aYCFqDGnDoRaXZdA== X-Google-Smtp-Source: AGHT+IHJelObIKzSQ1BbonnrHT1wYm4ffG4m1pg0tzoVEBs/baKPVWM3+Ur8xp6eb6w940PKIGOAWg== X-Received: by 2002:a17:906:730a:b0:b41:b0c4:e74c with SMTP id a640c23a62f3a-b70704b27d3mr1745393866b.33.1762255977438; Tue, 04 Nov 2025 03:32:57 -0800 (PST) Received: from jale-pg.. ([2a02:2a40:17ee:2900:8627:17a2:2166:4084]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b72404470e9sm182469766b.70.2025.11.04.03.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 03:32:56 -0800 (PST) From: Jakub Lecki To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Valentina Manea , Shuah Khan , Hongren Zheng , Greg Kroah-Hartman , Jakub Lecki Subject: [PATCH 2/3] usbip: Convert CONFIG_USBIP_VHCI_HC_PORTS to a module parameter. Date: Tue, 4 Nov 2025 12:32:47 +0100 Message-ID: <20251104113248.223594-3-lec.jakub@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251104113248.223594-1-lec.jakub@gmail.com> References: <20251104113248.223594-1-lec.jakub@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 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 =3D 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. Signed-off-by: Jakub Lecki --- 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(-) diff --git a/drivers/usb/usbip/Kconfig b/drivers/usb/usbip/Kconfig index bdcb6f4fdbec..e178867fb5ef 100644 --- a/drivers/usb/usbip/Kconfig +++ b/drivers/usb/usbip/Kconfig @@ -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. =20 -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 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h index 30b8540e0b49..2772d923a8cb 100644 --- a/drivers/usb/usbip/vhci.h +++ b/drivers/usb/usbip/vhci.h @@ -72,15 +72,9 @@ enum hub_speed { HUB_SPEED_SUPER, }; =20 -/* 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 =20 #define VHCI_DEFAULT_NR_HCS 1 #define VHCI_MAX_NR_HCS 128 @@ -100,7 +94,7 @@ struct vhci { struct vhci_hcd { struct vhci *vhci; =20 - u32 port_status[VHCI_HC_PORTS]; + u32 port_status[VHCI_MAX_HC_PORTS]; =20 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]; }; =20 extern unsigned int vhci_num_controllers; +extern unsigned int vhci_hc_ports; extern struct vhci *vhcis; extern struct attribute_group vhci_attr_group; =20 +/* 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= ); =20 @@ -135,7 +133,7 @@ int vhci_tx_loop(void *data); =20 static inline __u32 port_to_rhport(__u32 port) { - return port % VHCI_HC_PORTS; + return port % vhci_hc_ports; } =20 static inline int port_to_pdev_nr(__u32 port) diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c index 93c3fa3e1c53..1989a6f59107 100644 --- a/drivers/usb/usbip/vhci_hcd.c +++ b/drivers/usb/usbip/vhci_hcd.c @@ -51,6 +51,12 @@ MODULE_PARM_DESC(num_controllers, "Number of USB/IP virt= ual host controllers (ra __MODULE_STRING(VHCI_MAX_NR_HCS) ", default: " __MODULE_STRING(VHCI_DEFAULT_NR_HCS) ")"); =20 +unsigned int vhci_hc_ports =3D VHCI_DEFAULT_HC_PORTS; +module_param_named(hc_ports, vhci_hc_ports, uint, 0444); +MODULE_PARM_DESC(hc_ports, "Number of ports per USB/IP virtual host contro= ller (range: 1-" + __MODULE_STRING(VHCI_MAX_HC_PORTS) ", default: " + __MODULE_STRING(VHCI_DEFAULT_HC_PORTS) ")"); + struct vhci *vhcis; =20 static const char * const bit_desc[] =3D { @@ -236,7 +242,7 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *b= uf) { struct vhci_hcd *vhci_hcd =3D hcd_to_vhci_hcd(hcd); struct vhci *vhci =3D vhci_hcd->vhci; - int retval =3D DIV_ROUND_UP(VHCI_HC_PORTS + 1, 8); + int retval =3D DIV_ROUND_UP(vhci_hc_ports + 1, 8); int rhport; int changed =3D 0; unsigned long flags; @@ -250,7 +256,7 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *b= uf) } =20 /* check pseudo status register for each port */ - for (rhport =3D 0; rhport < VHCI_HC_PORTS; rhport++) { + for (rhport =3D 0; rhport < vhci_hc_ports; rhport++) { if ((vhci_hcd->port_status[rhport] & PORT_C_MASK)) { /* The status of a port has been changed, */ usbip_dbg_vhci_rh("port %d status changed\n", rhport); @@ -297,7 +303,7 @@ ss_hub_descriptor(struct usb_hub_descriptor *desc) desc->bDescLength =3D 12; desc->wHubCharacteristics =3D cpu_to_le16( HUB_CHAR_INDV_PORT_LPSM | HUB_CHAR_COMMON_OCPM); - desc->bNbrPorts =3D VHCI_HC_PORTS; + desc->bNbrPorts =3D vhci_hc_ports; desc->u.ss.bHubHdrDecLat =3D 0x04; /* Worst case: 0.4 micro sec*/ desc->u.ss.DeviceRemovable =3D 0xffff; } @@ -311,8 +317,7 @@ static inline void hub_descriptor(struct usb_hub_descri= ptor *desc) desc->wHubCharacteristics =3D cpu_to_le16( HUB_CHAR_INDV_PORT_LPSM | HUB_CHAR_COMMON_OCPM); =20 - desc->bNbrPorts =3D VHCI_HC_PORTS; - BUILD_BUG_ON(VHCI_HC_PORTS > USB_MAXCHILDREN); + desc->bNbrPorts =3D vhci_hc_ports; width =3D desc->bNbrPorts / 8 + 1; desc->bDescLength =3D USB_DT_HUB_NONVAR_SIZE + 2 * width; memset(&desc->u.hs.DeviceRemovable[0], 0, width); @@ -329,7 +334,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 ty= peReq, u16 wValue, unsigned long flags; bool invalid_rhport =3D false; =20 - u32 prev_port_status[VHCI_HC_PORTS]; + u32 prev_port_status[VHCI_MAX_HC_PORTS]; =20 if (!HCD_HW_ACCESSIBLE(hcd)) return -ETIMEDOUT; @@ -344,17 +349,18 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 = typeReq, u16 wValue, =20 /* * wIndex can be 0 for some request types (typeReq). rhport is - * in valid range when wIndex >=3D 1 and < VHCI_HC_PORTS. + * in valid range when wIndex >=3D 1 and < vhci_hc_ports. * * Reference port_status[] only with valid rhport when * invalid_rhport is false. */ - if (wIndex < 1 || wIndex > VHCI_HC_PORTS) { + if (wIndex < 1 || wIndex > vhci_hc_ports) { invalid_rhport =3D true; - if (wIndex > VHCI_HC_PORTS) + if (wIndex > vhci_hc_ports) pr_err("invalid port number %d\n", wIndex); - } else + } else { rhport =3D wIndex - 1; + } =20 vhci_hcd =3D hcd_to_vhci_hcd(hcd); vhci =3D vhci_hcd->vhci; @@ -707,7 +713,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct= urb *urb, gfp_t mem_flag struct vhci_device *vdev; unsigned long flags; =20 - if (portnum > VHCI_HC_PORTS) { + if (portnum > vhci_hc_ports) { pr_err("invalid port number %d\n", portnum); return -ENODEV; } @@ -1188,7 +1194,7 @@ static int vhci_start(struct usb_hcd *hcd) =20 /* initialize private data of usb_hcd */ =20 - for (rhport =3D 0; rhport < VHCI_HC_PORTS; rhport++) { + for (rhport =3D 0; rhport < vhci_hc_ports; rhport++) { struct vhci_device *vdev =3D &vhci_hcd->vdev[rhport]; =20 vhci_device_init(vdev); @@ -1244,7 +1250,7 @@ static void vhci_stop(struct usb_hcd *hcd) } =20 /* 2. shutdown all the ports of vhci_hcd */ - for (rhport =3D 0; rhport < VHCI_HC_PORTS; rhport++) { + for (rhport =3D 0; rhport < vhci_hc_ports; rhport++) { struct vhci_device *vdev =3D &vhci_hcd->vdev[rhport]; =20 usbip_event_add(&vdev->ud, VDEV_EVENT_REMOVED); @@ -1441,7 +1447,7 @@ static int vhci_hcd_suspend(struct platform_device *p= dev, pm_message_t state) =20 spin_lock_irqsave(&vhci->lock, flags); =20 - for (rhport =3D 0; rhport < VHCI_HC_PORTS; rhport++) { + for (rhport =3D 0; rhport < vhci_hc_ports; rhport++) { if (vhci->vhci_hcd_hs->port_status[rhport] & USB_PORT_STAT_CONNECTION) connected +=3D 1; @@ -1525,6 +1531,15 @@ static int __init vhci_hcd_init(void) vhci_num_controllers =3D VHCI_MAX_NR_HCS; } =20 + if (vhci_hc_ports < 1) { + pr_warn("hc_ports less than 1, setting to 1\n"); + vhci_hc_ports =3D 1; + } else if (vhci_hc_ports > VHCI_MAX_HC_PORTS) { + pr_warn("hc_ports too high, limiting to %d\n", + VHCI_MAX_HC_PORTS); + vhci_hc_ports =3D VHCI_MAX_HC_PORTS; + } + vhcis =3D kcalloc(vhci_num_controllers, sizeof(struct vhci), GFP_KERNEL); if (vhcis =3D=3D NULL) return -ENOMEM; diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c index d5865460e82d..19d67717180e 100644 --- a/drivers/usb/usbip/vhci_sysfs.c +++ b/drivers/usb/usbip/vhci_sysfs.c @@ -81,7 +81,7 @@ static ssize_t status_show_vhci(int pdev_nr, char *out) =20 spin_lock_irqsave(&vhci->lock, flags); =20 - for (i =3D 0; i < VHCI_HC_PORTS; i++) { + for (i =3D 0; i < vhci_hc_ports; i++) { struct vhci_device *vdev =3D &vhci->vhci_hcd_hs->vdev[i]; =20 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); } =20 - for (i =3D 0; i < VHCI_HC_PORTS; i++) { + for (i =3D 0; i < vhci_hc_ports; i++) { struct vhci_device *vdev =3D &vhci->vhci_hcd_ss->vdev[i]; =20 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); } =20 @@ -109,7 +109,7 @@ static ssize_t status_show_not_ready(int pdev_nr, char = *out) char *s =3D out; int i =3D 0; =20 - for (i =3D 0; i < VHCI_HC_PORTS; i++) { + for (i =3D 0; i < vhci_hc_ports; i++) { out +=3D 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 +=3D sprintf(out, "\n"); } =20 - for (i =3D 0; i < VHCI_HC_PORTS; i++) { + for (i =3D 0; i < vhci_hc_ports; i++) { out +=3D 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 +=3D sprintf(out, "000 00000000 0000000000000000 0-0"); out +=3D sprintf(out, "\n"); @@ -221,11 +221,11 @@ static int valid_port(__u32 *pdev_nr, __u32 *rhport) } *pdev_nr =3D array_index_nospec(*pdev_nr, vhci_num_controllers); =20 - if (*rhport >=3D VHCI_HC_PORTS) { + if (*rhport >=3D vhci_hc_ports) { pr_err("rhport %u\n", *rhport); return 0; } - *rhport =3D array_index_nospec(*rhport, VHCI_HC_PORTS); + *rhport =3D array_index_nospec(*rhport, vhci_hc_ports); =20 return 1; } @@ -255,7 +255,7 @@ static ssize_t detach_store(struct device *dev, struct = device_attribute *attr, =20 usbip_dbg_vhci_sysfs("rhport %d\n", rhport); =20 - if ((port / VHCI_HC_PORTS) % 2) + if ((port / vhci_hc_ports) % 2) vhci_hcd =3D hcd_to_vhci_hcd(hcd)->vhci->vhci_hcd_ss; else vhci_hcd =3D hcd_to_vhci_hcd(hcd)->vhci->vhci_hcd_hs; --=20 2.43.0 From nobody Fri Dec 19 09:24:04 2025 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A2E62EACEE for ; Tue, 4 Nov 2025 11:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762255982; cv=none; b=a2LA2bF/W6q2knWX08sE6fGAepyy99MZZ1lQ7nzbOw+ctyw3cV7PtwE9v4FM3AFzsDzTEk5JJwpcO7yLaq1+CmEtsLjwZuR4KmpesDUHzZC4Td6TJXmXpfA0N7X+3wN1fYCRiVx2QsEVkdBKWXQtoqxLxBgVTZ7nU+oF9WtT62g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762255982; c=relaxed/simple; bh=W1/5a7VsUfRhct0i5NaSbgry/+x9qR6Zhl7syl2QDUM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IEKiB/e1WC97SxDmb5aSyhZ7Au1X1hfEkwwx2fGbZ4vJ0y4RwhYwLZbVHnzDX1R0mKRS9HdEUeNmmwLxj+oEBEQP7389tO5oTAy+zESD5Z7QZrx3oG0XwCGtoAXLPzReeP0O+6EvAbxNIzKbfse+GWNf/fMEvb9ukm9Ed+GUK9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Urg5jwmK; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Urg5jwmK" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-b5b823b4f3dso872158966b.3 for ; Tue, 04 Nov 2025 03:33:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762255979; x=1762860779; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9Nxq+Z1fn/xWrOumJFi9/RSQVqz8cFPqXlsH8mXzKoU=; b=Urg5jwmK7UV5U0+Fwq9dAEOWPRIF9FKhSlSClkT0xmqk5dxZIuHkx0xCiD2huYIUDi pw411tgrmQzgxuxxLf0sgMzqP038QZlxuxLG2pXumkPfvqxrdH9QgvWcTDxzVkMnOZDm tgnR5s0UhXFL1jYQI6hOqoU60oeZNKYZcfyYVxSwUl/Gk5i+ccoanc6eH56RAWHye2bW AIV6F5oUCYiWzz4w/w7/io2JlQrzPK8TWONm6nlB64XmT8VsemuZbVT3Izgj1eV4833Y 1+mtSbyb3zyNwLkcb1IHnfKNMLpEpqPSIqQo+PGYK5btASsfaoPFe81GoOsfemq04J+w JFuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762255979; x=1762860779; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9Nxq+Z1fn/xWrOumJFi9/RSQVqz8cFPqXlsH8mXzKoU=; b=D2j7Evz7YkSRz28Sy++OswkXZXCMRAxZ8Z1G7GDp78Cib8IQeoc2AgX3uVBvXb+3aT 0sDXpQ7uOoPxB3+Di+Lnz3MZ9dwNwh2OqbHC+saJQgbvIIMKbYuTQQMXd4y7c11cNwH8 xdcj1Wf3nYoHFZ5cRLFxVt4thwNztzx02LKTq0VeBEBGq42biNfyba5zTVABD8SccDtF 9Iakmek+8sc3cJu0b/E2mAoQag/ubZI0QMh8lb7Ge/hJcrSpwbrA/JFAfMYkgmhW4vj4 CHIzXoAKJUDusVDR6AYERgCxxU7SZCys0UjJ4ISaHAMym5AySiwOplRM45KHnlVkG0iz giLQ== X-Forwarded-Encrypted: i=1; AJvYcCVAVbzJ6ikfjyQNLMcxYyteD/i/wcDSFwa5Yd1aEbuyoWZNwiJBDHzxaG0ZDuae3wyf8Y8/z3YW2D+7Uj4=@vger.kernel.org X-Gm-Message-State: AOJu0YzFYr47gOzPgRW+ED+DKg/1oODkq7Ma0DcKZYZM1T8jtNLd4pdy 03AD6YA7XtAj5/iAxxOqdP4P+p/0g9SR0+VPSNfwOpHcJtT7mOr+CHqe X-Gm-Gg: ASbGncuGMZirmg9gTpgwr0crlSjlHH0zxhY8znZgOBfmiNVKr4nV83gEldHdv7/0iuQ 1S17lSmJi6tyGt5Szkl0doJF+2W0cBrXbbXfHD1BEAvMikHwHOzh8XWDvPLWT46mFgcc9mZngpS 21E4f2zKlm1h/ACXTaQTWXaBXyxAmdaK8hhijBaRZnXwh0r09oi5sZH86h99VrXMW+d8ICIZmyn HYKFp26oVdWSlu1OUilCl3YCAg7CfQ74ysl4fT7EwhMKVOGQRXI+mabvjWxMhH7iyz19x9hG06x ZlKcB0hkPk3ZotfGYuZuX3CSrSt9aUsNREksqt/cuHRiPb43bIO0UV9LgGbljhiP9gZvUIyROtg jkri+mpJzgPNC7xKvnkPEa9A48MkFpvf1YmTYrAbcD4aoawYeBu4zUUWjOyaMywaTmJgtFvtJe8 CN6OGtmhcmM9ra6d5vxLtK5XOhV5pWrrGj+aifg5iGHXIh5Uh6zjnuS6Bkg1wkmOaE9m7krB71 X-Google-Smtp-Source: AGHT+IHEMSASSTohnLG9wMInMyaJfMwowF7cYVsEpX3e0SDI7y3LeNeOnjHYdUJzMywCwp6kp4EraQ== X-Received: by 2002:a17:907:9602:b0:b72:588:2976 with SMTP id a640c23a62f3a-b72058829famr341889366b.60.1762255978638; Tue, 04 Nov 2025 03:32:58 -0800 (PST) Received: from jale-pg.. ([2a02:2a40:17ee:2900:8627:17a2:2166:4084]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b72404470e9sm182469766b.70.2025.11.04.03.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 03:32:58 -0800 (PST) From: Jakub Lecki To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Valentina Manea , Shuah Khan , Hongren Zheng , Greg Kroah-Hartman , Jakub Lecki Subject: [PATCH 3/3] usbip: Limit maximum number of virtual host controllers to 31. Date: Tue, 4 Nov 2025 12:32:48 +0100 Message-ID: <20251104113248.223594-4-lec.jakub@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251104113248.223594-1-lec.jakub@gmail.com> References: <20251104113248.223594-1-lec.jakub@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D 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 --- 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 =20 +/* + * 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 =20 #define MAX_STATUS_NAME 16 =20 --=20 2.43.0