From: Igor Skalkin <igor.skalkin@oss.qualcomm.com>
To: "Michael S . Tsirkin" <mst@redhat.com>,
Jason Wang <jasowangio@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: virtualization@lists.linux.dev, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, Eugenio Perez <eperezma@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
Vasilii Ianikeev <vasilii.ianikeev@oss.qualcomm.com>,
Aiswarya Cyriac <aiswarya.cyriac@oss.qualcomm.com>,
Anton Yakovlev <anton.yakovlev@oss.qualcomm.com>,
Trilok Soni <trilok.soni@oss.qualcomm.com>,
Matias Ezequiel Vara Larsen <mvaralar@redhat.com>,
Igor Skalkin <igor.skalkin@oss.qualcomm.com>
Subject: [RFC PATCH v2 7/7] virtio-usb: support a guest UDC name prefix from the bind event
Date: Tue, 1 Dec 2026 18:35:36 +0100 [thread overview]
Message-ID: <6a4a46f93c39f4e6de4d81d62e41521b478772a9.1796144390.git.igor.skalkin@oss.qualcomm.com> (raw)
In-Reply-To: <cover.1796144390.git.igor.skalkin@oss.qualcomm.com>
Let the host backend supply a name prefix for a port's UDC parent
platform_device via the bind event, instead of always using the
generic GADGET_NAME. When present, the prefix is used verbatim as
the parent device's name and the gadget name becomes
"<prefix>_p<port>"; when empty, behavior is unchanged.
Signed-off-by: Igor Skalkin <igor.skalkin@oss.qualcomm.com>
---
drivers/usb/virtio_usb/device.c | 47 +++++++++++++++++++++++++++------
include/uapi/linux/virtio_usb.h | 4 ++-
2 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/virtio_usb/device.c b/drivers/usb/virtio_usb/device.c
index 0d44cb1dce6e..d6fc1cc19713 100644
--- a/drivers/usb/virtio_usb/device.c
+++ b/drivers/usb/virtio_usb/device.c
@@ -1481,11 +1481,26 @@ static int virtio_usb_dc_get_endpoint_info(struct virtio_usb_dc *vudc)
return rc;
}
-static int virtio_usb_dc_parent_create(struct virtio_usb_dc *vudc)
+static int virtio_usb_dc_parent_create(struct virtio_usb_dc *vudc,
+ const unsigned char *udc_prefix)
{
+ size_t prefix_len;
+ char *parent_name;
int rc;
- vudc->pdev = platform_device_alloc(GADGET_NAME, vudc->port);
+ prefix_len = strnlen((const char *)udc_prefix,
+ VIRTIO_USB_UDC_NAME_PREFIX_MAX);
+ if (prefix_len) {
+ parent_name = kasprintf(GFP_KERNEL, "%.*s", (int)prefix_len,
+ (const char *)udc_prefix);
+ } else {
+ parent_name = kstrdup(GADGET_NAME, GFP_KERNEL);
+ }
+ if (!parent_name)
+ return -ENOMEM;
+
+ vudc->pdev = platform_device_alloc(parent_name, vudc->port);
+ kfree(parent_name);
if (!vudc->pdev)
return -ENOMEM;
@@ -1568,6 +1583,7 @@ static void virtio_usb_dc_event_process(struct virtio_usb_event *event)
switch (le32_to_cpu(evt->code)) {
case VIRTIO_USB_EVT_DEV_BIND: {
u8 max_speed;
+ size_t udc_prefix_len;
if (vudc->registered) {
dev_err(&vusb->vdev->dev,
@@ -1594,7 +1610,8 @@ static void virtio_usb_dc_event_process(struct virtio_usb_event *event)
break;
}
if (!vudc->pdev) {
- rc = virtio_usb_dc_parent_create(vudc);
+ rc = virtio_usb_dc_parent_create(
+ vudc, bind_evt->udc_name_prefix);
if (rc) {
dev_err(&vusb->vdev->dev,
"Failed to create UDC parent device\n");
@@ -1603,8 +1620,18 @@ static void virtio_usb_dc_event_process(struct virtio_usb_event *event)
break;
}
}
- vudc->gadget.name =
- kasprintf(GFP_KERNEL, "%s_%d", GADGET_NAME, port_id);
+ udc_prefix_len =
+ strnlen((const char *)bind_evt->udc_name_prefix,
+ VIRTIO_USB_UDC_NAME_PREFIX_MAX);
+ if (udc_prefix_len) {
+ vudc->gadget.name = kasprintf(
+ GFP_KERNEL, "%.*s_p%d", (int)udc_prefix_len,
+ (const char *)bind_evt->udc_name_prefix,
+ port_id);
+ } else {
+ vudc->gadget.name = kasprintf(GFP_KERNEL, "%s_%d",
+ GADGET_NAME, port_id);
+ }
if (!vudc->gadget.name) {
rc = -ENOMEM;
kfree(vudc->veps);
@@ -1627,7 +1654,6 @@ static void virtio_usb_dc_event_process(struct virtio_usb_event *event)
break;
}
- //vudc->gadget.dev.init_name = gadget_name;
vudc->gadget.dev.parent = &vudc->pdev->dev;
rc = usb_add_gadget_udc(&vudc->pdev->dev, &vudc->gadget);
if (rc) {
@@ -1770,11 +1796,16 @@ int virtio_usb_dc_event_populate(struct virtio_usb *vusb)
{
struct virtio_usb_queue *evt_queue =
&vusb->vqueues[vusb->dev_vq_base + VIRTIO_USB_VQ_EVENT_IDX];
+ size_t evt_size;
struct virtio_usb_event *events;
int rc;
- events = virtio_usb_events_alloc(vusb, evt_queue,
- sizeof(struct virtio_usb_dev_event));
+ evt_size = max_t(size_t, sizeof(struct virtio_usb_dev_event),
+ sizeof(struct virtio_usb_dev_setup_event));
+ evt_size = max_t(size_t, evt_size,
+ sizeof(struct virtio_usb_dev_bind_event));
+
+ events = virtio_usb_events_alloc(vusb, evt_queue, evt_size);
if (!events)
return -ENOMEM;
diff --git a/include/uapi/linux/virtio_usb.h b/include/uapi/linux/virtio_usb.h
index 238052b4f0a9..d3199cbd7d10 100644
--- a/include/uapi/linux/virtio_usb.h
+++ b/include/uapi/linux/virtio_usb.h
@@ -193,6 +193,8 @@ struct virtio_usb_dev_ep_info {
#define VIRTIO_USB_EVT_DEV_RESUME 5
#define VIRTIO_USB_EVT_DEV_UNBIND 6
+#define VIRTIO_USB_UDC_NAME_PREFIX_MAX 64
+
struct virtio_usb_dev_event {
__le32 code; /* VIRTIO_USB_EVT_DEV_XXX */
__le16 port; /* Device ID */
@@ -204,7 +206,7 @@ struct virtio_usb_dev_bind_event {
__le32 code; /* VIRTIO_USB_EVT_DEV_BIND */
__le16 port; /* Device ID */
__u8 max_speed; /* enum usb_device_speed */
- __u8 padding[9];
+ __u8 udc_name_prefix[VIRTIO_USB_UDC_NAME_PREFIX_MAX];
};
/* VIRTIO_USB_EVT_DEV_SETUP */
--
2.49.0
next prev parent reply other threads:[~2026-12-01 17:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260924160907.145405-1-igor.skalkin@oss.qualcomm.com>
2026-12-01 17:35 ` [RFC PATCH v2 0/7] virtio-usb: add dual-role virtio USB driver Igor Skalkin
2026-12-01 17:35 ` [RFC PATCH v2 1/7] uapi: virtio_ids: reserve ID for virtio USB device Igor Skalkin
2026-12-01 17:35 ` [RFC PATCH v2 2/7] virtio-usb: add protocol header and skeleton dual-role driver Igor Skalkin
2026-12-01 17:35 ` [RFC PATCH v2 3/7] virtio-usb: add host role (USB Host Controller) support Igor Skalkin
2026-12-01 17:35 ` [RFC PATCH v2 4/7] virtio-usb: add device role (USB Device " Igor Skalkin
2026-12-01 17:35 ` [RFC PATCH v2 5/7] virtio-usb: add per-port role query support Igor Skalkin
2026-12-01 17:35 ` [RFC PATCH v2 6/7] virtio-usb: add host/device role switch support Igor Skalkin
2026-12-01 17:35 ` Igor Skalkin [this message]
2026-12-01 17:49 ` [RFC PATCH v2 0/7] virtio-usb: add dual-role virtio USB driver Michael S. Tsirkin
2026-12-01 20:09 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6a4a46f93c39f4e6de4d81d62e41521b478772a9.1796144390.git.igor.skalkin@oss.qualcomm.com \
--to=igor.skalkin@oss.qualcomm.com \
--cc=aiswarya.cyriac@oss.qualcomm.com \
--cc=anton.yakovlev@oss.qualcomm.com \
--cc=eperezma@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=jasowangio@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mst@redhat.com \
--cc=mvaralar@redhat.com \
--cc=trilok.soni@oss.qualcomm.com \
--cc=vasilii.ianikeev@oss.qualcomm.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®