From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796146561; b=Tu51XyWJxsThVQvfWkyW+BX4ds7inAh9wHvANlY2tpYzmKZDdhs4XqFt0pJi2sY0MsSC v+yhXFsPMN37hDoHoOAiHqiZzykZP20Gp5ROyo4lwzJ4KWCu+ELWUP6Dxd2/8rPL/P+90 L2d0fmPfiSW3nHXFRTjN950wAsdv0EK5JNEh16mcBhXrQd4Ng7IkrqAA3GTHKsJjjWqlF XiEgDu/VFgVe98xSLdYROyJFJLwSaPttcTRZoyW7oMKWdqRheN6ltkU3IhljMBhxjCNlM uX4ys1xKFtkJuJuHptLSAZCetCMWLoJhZ5HkvTFmYpuQKq48QfKqhcLwi9PUYojZT+g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796146561; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg: X-Received:X-Received:Received:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Proofpoint-ORIG-GUID:X-Authority-Analysis: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Spam-Info: X-Proofpoint-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=UNoGqrX6L1eFr2fNyeF+tW8mlYlgvo2C/oITZD/jjrY=; b=gKKc8mABhm0VWccaSlPHYdtHEBWqCvSVx+MNhBd0tC0bJmJviiTXqdTkmZ/R1bbVXFUF slQXHzo0E12HE1trmmz38VHbf3bCzXo3yVFuMl+InMxVVx/n+vY5DPKmMXm8qj4WG6JMN R7EFo30jReSIGvahD8AbeRZcVyfBagt2Vdif++VUgJ3m6YdJTaDonNVqy36vAcbVTe+Qo 0IOWziLty0miXOaYNDdJJjrjVQ55VdaroP+PYeVXPD/tSVJjtUjBvs00uxF76Fl2VtFZo FV5F+4v+2gGpRoH6PSB5oQbv/7HzhTs6VoTdLOalIzrPQExDBhAuBDmkVu5w8iCr4tA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=IsS3NZM5; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=BJMmNZRF; arc=none smtp.remote-ip=205.220.180.131 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C418E606A322 for ; Tue, 1 Dec 2026 17:36:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C418E606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=IsS3NZM5; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=BJMmNZRF Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1F75n21719331 for ; Tue, 1 Dec 2026 17:35:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=UNoGqrX6L1e Fr2fNyeF+tW8mlYlgvo2C/oITZD/jjrY=; b=IsS3NZM5gfug9OLJLrIvqBAOirw k1utdfqzRTcyZisMeo1nyR6c8zIZ4RQba1vD/vUj9kANvzcxyzrca/Vc3tYZ3Fal Qp89ay1QBiuMW9gJu3QVcdTnAl0obQ9OHBqQQtDrRknVE/Ltj3/wQH2pQk4ajaVu zSY7ujjJnQe7dIoTe9fQ5u4B+FZaL+iSDMAXfmIVbvHczwLHI9uTm3H2wVpIYTfE 2Brl51aTB3Gr3ZvcL5YbFT0htTTvVpQcegJxd716dmdL9afcNMdNbxiGaR4/WHZA xlAZuuU/G61J9X0Cb93yu11ndWNUTouP2+5m+NEwSUzSIaKwu8Wv+plB5cg== Received: from mail-ua1-f71.google.com (mail-ua1-f71.google.com [209.85.222.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j9tvgaa6c-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2026 17:35:59 +0000 (GMT) Received: by mail-ua1-f71.google.com with SMTP id a1e0cc1a2514c-99082f450bfso7170652241.2 for ; Tue, 01 Dec 2026 09:35:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796146559; x=1796751359; darn=lists.linux.dev; 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:content-type; bh=UNoGqrX6L1eFr2fNyeF+tW8mlYlgvo2C/oITZD/jjrY=; b=BJMmNZRFFuDei9v3R4wxtbdChlCeZJC1c5Pjlf6zb0jrXjeXwZkFBBM/rIK1vLq4rF QX/hRaLMf8kmjNPTXVuuvh76zQKhKbQMkmAKDaFhpA+xmcRgy73NfUKC8lrTXV9kO1Xn I6njo43gMuOuKWUbMr3trIRnLHlP4OSFC0mgzT3tgBRFt3rW5kliL64gc888fEd5Hdu8 awyTnmfmZ9j8bQuoUcQv8TM/KZXk+ze03UFlzrNtdRuzHA7tlI63pOahwDd+aO50pZqI 2bzzvgqEhfOSTI2zI2mi7NMwlP3HaknMRdNuRgTMlU8hvR/8H/w3SVb2x1kt6mIlMCDU 9lfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796146559; x=1796751359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=UNoGqrX6L1eFr2fNyeF+tW8mlYlgvo2C/oITZD/jjrY=; b=OysGSuqmfLJAJUxFF60B/08GDoIBhnFoBNy03LDwXyG2x/HhI2leHod0BYuBzgODfZ vjJzQciEpoPy8+0eCmZbgPkfovCUucYpq06l/QL4fO+J7aNSaCdgQAlPOCN5GaXZIzBo 1wRZly3KBm4tJqB7CYGORmmhNxxkzHMMyDYanYMB7QuHTklqGlhukMJVhoxUvWfx8w58 ZqdI4DxFv7YL/mjlLv8e2/n6dJGwBeLeE3Tb5oajPJ4rD4tpYmIVMaoUm3zClVCWwiPN 4JGnU8Ci9wZ8GTXz1jdBNmu1LYvYJAILJcfhR0Iic8pNExpSqjLMsZXLyDqBd+lozTcZ 0cAw== X-Gm-Message-State: APuU4Z+1J8IzXz/OiTZMwuM85O6DdusxjqV+p2gGOMiopZI7Hqrz+NWv ov9cMjgHTWXImxuJOyd1mtEN/EwBSa4/KhNBbKgE57zw0ryOzh6KYWCM7g7/mE5+Rpejnr/8MGk egvp4g8x6fJeXZEg56KoW3XpyYHv0CfiuTcoZTci21T9dVhnuSBKjq8QduKXJ/chBMXnZew== X-Gm-Gg: AZFdTZcSFzo5leMiarWDRPobNd8CAPLZuiIsAfNgV++cRqgV5iRlNuY9Mhj9rF1WMUF 1PT/ZpxT6WSU2Y/njjz+W2NREMTyY7eRhX1ARexptOMWoobSG9NhpTfEJWGhp3HsaDEZUl58AxW b2HuomT49/c+/6uzfG/Q/S4Up7iKzQctKHF/jWO1SqyL/wQuyETRs34knqFnX8/QsSJlnFURP5E FgOEvDjDHETxs/6A208tS1QJJEhrEmUnvdvctqZPU1cUjCyDUJ5qDX7wfgeJ6Crme4O9JPMpoDa Blyj0vNOboc6BLz8wgErGXe5oY4ymjzhs1A0gix63wVywL8J0wNiVaMdoMbbdMuEz7FtC+HSjXE gRpvA5LxPbHEi6a+p1qAugx2mLcE30w+0L1CeC7owSd5FqM7yv/zBiivXAOlW7BK69heacDO6Db W5h2aN X-Received: by 2002:a05:6102:54a1:b0:7c2:7a0:ae28 with SMTP id ada2fe7eead31-7d73966dae9mr25580376137.30.1796146558646; Tue, 01 Dec 2026 09:35:58 -0800 (PST) X-Received: by 2002:a05:6102:54a1:b0:7c2:7a0:ae28 with SMTP id ada2fe7eead31-7d73966dae9mr25580328137.30.1796146558074; Tue, 01 Dec 2026 09:35:58 -0800 (PST) Received: from QCOM-WFsSr66Fqw.qualcomm.com ([212.136.9.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbb39dd4e7sm339386455e9.0.2026.12.01.09.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 09:35:56 -0800 (PST) From: Igor Skalkin To: "Michael S . Tsirkin" , Jason Wang , Greg Kroah-Hartman Cc: virtualization@lists.linux.dev, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Eugenio Perez , Xuan Zhuo , Vasilii Ianikeev , Aiswarya Cyriac , Anton Yakovlev , Trilok Soni , Matias Ezequiel Vara Larsen , Igor Skalkin Subject: [RFC PATCH v2 0/7] virtio-usb: add dual-role virtio USB driver Date: Tue, 1 Dec 2026 18:35:29 +0100 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260924160907.145405-1-igor.skalkin@oss.qualcomm.com> References: <20260924160907.145405-1-igor.skalkin@oss.qualcomm.com> X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: 0BD7sOIsiWKIYZ8Y8q2k5oYPB3DaoIg3 X-Authority-Analysis: v=2.4 cv=I8nw19gg c=1 sm=1 tr=0 ts=6b0f057f cx=c_pps a=KB4UBwrhAZV1kjiGHFQexw==:117 a=dNlqnMcrdpbb+gQrTujlOQ==:17 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=baISRJ5csSEsXvGxrioA:9 a=o1xkdb1NAhiiM49bd1HK:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA2OSBTYWx0ZWRfX/zzpwnjHDplb lgrQNSptQPIr43IIFai0EkVkH7yRDsjqFuTd1xUljRC7t4z/hl+O+8VOXyRv52COVyPv5gA3cHt keNLiHyWINWlGWdqC8ZrcgMXdYYKaxkdLS/gxlWxv1jr6Se9DRV5eIsQQHYBj87iy0XVduM3iPD c7cV2POkEJ5DxSY8owyakYUazl+v9L7xDDKIQDdZn/AlpB2yTUBvrqZbUsuI0LS4Xnu0Rvd6UFE GONhvVUpsCfWGfrxcaYgLNsR9oAIGM6pFSVNex05fMxbSx8ujbIck220TDFvT1W6H6Km0Hy8EU7 v9sHjRC+rXR+gLe//8HT1GLF1UI3JvmZpoxHBM55TI6Czd3uLS2c3uEOSyL6t2iXdhwyOff6FV0 3Qu7vWsRmP8ZT6VXVBDJUrrzFWohX8RKID62wtsi0tt+ifjiVJwLttkl9ElnKIpPFEF5pQ8EOBu aMP0XJ6V/1K4TpKlaDg== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA2OSBTYWx0ZWRfX5fANkjEl+foN uMSjCmUJcofoatqcw95rq9iMPLSJQfe3DXdAa8HZmFtMiG2KKmJjjsOu2YxsDXguU6lxKiR2hsL +Vn+q51q1AlRXYDMs+DVUX05h8SUSmE= X-Proofpoint-GUID: 0BD7sOIsiWKIYZ8Y8q2k5oYPB3DaoIg3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_03,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 phishscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010069 This series adds a driver for the virtio USB device: a dual-role paravirtualized USB controller. Each port of the device is either a USB host controller port, backed by a per-port HS+SS usb_hcd pair, or a USB device controller (UDC). Dual-role ports can switch between the two roles at runtime, and the switch is exposed through the USB role switch class. This is a device-driven role switch, not USB OTG: there is no HNP/SRP, ID pin or OTG descriptor involved. The device is described in the virtio-usb specification proposal, currently at RFC v3 on virtio-comment: https://lore.kernel.org/virtio-comment/20260611130826.287372-1-vasilii.ianikeev@oss.qualcomm.com/T/ This series is an RFC because the specification is still under review. The protocol header in patch 2 follows spec RFC v3. The driver was tested against two device backends: a proprietary one and one based on QEMU. The QEMU backend is currently under review and will be sent upstream soon. Series layout: - 1/7 syncs the device ID (49) from the virtio specification into virtio_ids.h. The driver does not build without it. - 2/7 adds the protocol header and the driver skeleton. - 3/7 and 4/7 add the host and the device role. - 5/7 adds the per-port role query, which is needed when the device offers both roles. - 6/7 adds runtime host/device role switching. - 7/7 lets the device supply a name prefix for a port's UDC. Changes since v1: - Marked as RFC, since the specification is still under review. - Rebased onto v7.4-rc5. The virtio_ids.h patch is now part of the series (1/7). - Series restructured: v1 6/8 ("rework endpoint lifecycle to an async split-phase state machine") and v1 7/8 ("add SuperSpeed device-role support") are folded into the device role patch (4/7). The OTG patches are renamed to "per-port role query" (5/7) and "host/device role switch" (6/7). - checkpatch, sparse and kernel-doc cleanups throughout. [2/7] protocol header and skeleton - uapi enums converted to explicit #defines. - OTG naming replaced by role naming: VIRTIO_USB_VQ_ROLE_*, VIRTIO_USB_CMD_ROLE_GET/SET, struct virtio_usb_role_set carrying the target role, struct virtio_usb_role_info, VIRTIO_USB_EVT_ROLE_CHANGE. - Host port event field port_id renamed to port. - VIRTIO_USB_SPEED_WIRELESS dropped; VIRTIO_USB_USB_SPEED_SUPER renamed to VIRTIO_USB_SPEED_SUPER. - uapi header relicensed from BSD-3-Clause to GPL-2.0-or-later WITH Linux-syscall-note, like the rest of the driver. [3/7] host role - The cmd_timeout_ms module parameter is removed; the command timeout is the constant VIRTIO_USB_CMD_TIMEOUT_MS (1 s). - Each data submission gets a tag from a per-device 64-bit counter, and HOST_CANCEL refers to that tag instead of the URB address, which could match a reused allocation. - Fixed a race where dequeue ran before the URB was on the data virtqueue: the HOST_CANCEL matched nothing on the device, so the URB was never cancelled. Dequeue now only records the cancel, and enqueue sends it once the URB is queued. - skip_phy_initialization is now also set on the SuperSpeed HCD. [4/7] device role - Folds in v1 6/8: an explicit endpoint state machine, with workqueues and a pending request queue, so that the usb_ep_ops/usb_gadget_ops callbacks never sleep. No gadget core change is needed. - Folds in v1 7/8: max_speed is taken from the BIND event, EP0 maxpacket is set for SS/SSP, and the SS endpoint companion descriptor is validated and sent with EP_ENABLE. - DEV_CANCEL uses a per-submission tag instead of the request address. - Fixed the same early-cancel race as on the host side. A stale cancel is dropped if the request has completed and been queued again. - ep_queue() on a halted endpoint returns the error without giving the request back, which avoids recursion with gadget drivers that resubmit from their completion handler. - Events with non-zero reserved padding are rejected. - UNBIND flushes the endpoint work before freeing the endpoints (use-after-free fix). [5/7] per-port role query (was: OTG role query) - otg.c/otg.h renamed to role_switch.c/role_switch.h, otg_* to virtio_usb_rsw_*, is_otg to is_dual_role. - The ROLE_* queues are created only when both roles are negotiated. [6/7] host/device role switch (was: OTG role-switching) - Role switches work in both directions from the guest. The role switch set callback sends ROLE_SET with the target role, then reads the role back with ROLE_GET and follows it, even if ROLE_SET failed. v1 could only request device-to-host, asynchronously, and carried no target role. - ROLE_CHANGE events and guest requests share one resync path, serialized by a per-port mutex. - Host port events that arrive before the HCD is installed are stored per port and replayed once it is. v1 dropped them. - On remove, the role switches are unregistered and the role event work is cancelled before the queues are stopped. - Probe runs the event workers once after setting started, so events delivered during probe are not lost. [7/7] UDC name prefix - No functional change. v1: https://lore.kernel.org/all/20260924160907.145405-1-igor.skalkin@oss.qualcomm.com/ Aiswarya Cyriac (3): virtio-usb: add protocol header and skeleton dual-role driver virtio-usb: add host role (USB Host Controller) support virtio-usb: add device role (USB Device Controller) support Igor Skalkin (4): uapi: virtio_ids: reserve ID for virtio USB device virtio-usb: add per-port role query support virtio-usb: add host/device role switch support virtio-usb: support a guest UDC name prefix from the bind event MAINTAINERS | 10 + drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 1 + drivers/usb/virtio_usb/Kconfig | 15 + drivers/usb/virtio_usb/Makefile | 9 + drivers/usb/virtio_usb/controller.c | 437 ++++++ drivers/usb/virtio_usb/controller.h | 185 +++ drivers/usb/virtio_usb/device.c | 2055 ++++++++++++++++++++++++++ drivers/usb/virtio_usb/device.h | 126 ++ drivers/usb/virtio_usb/host.c | 1555 +++++++++++++++++++ drivers/usb/virtio_usb/host.h | 244 +++ drivers/usb/virtio_usb/role_switch.c | 502 +++++++ drivers/usb/virtio_usb/role_switch.h | 40 + drivers/usb/virtio_usb/vq_common.c | 747 ++++++++++ drivers/usb/virtio_usb/vq_common.h | 163 ++ include/uapi/linux/virtio_ids.h | 1 + include/uapi/linux/virtio_usb.h | 321 ++++ 17 files changed, 6413 insertions(+) create mode 100644 drivers/usb/virtio_usb/Kconfig create mode 100644 drivers/usb/virtio_usb/Makefile create mode 100644 drivers/usb/virtio_usb/controller.c create mode 100644 drivers/usb/virtio_usb/controller.h create mode 100644 drivers/usb/virtio_usb/device.c create mode 100644 drivers/usb/virtio_usb/device.h create mode 100644 drivers/usb/virtio_usb/host.c create mode 100644 drivers/usb/virtio_usb/host.h create mode 100644 drivers/usb/virtio_usb/role_switch.c create mode 100644 drivers/usb/virtio_usb/role_switch.h create mode 100644 drivers/usb/virtio_usb/vq_common.c create mode 100644 drivers/usb/virtio_usb/vq_common.h create mode 100644 include/uapi/linux/virtio_usb.h base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244 -- 2.49.0