From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147667; b=bFK/CeBB/QFQnl/O8rpvk8dHZkRg0SNgFcgnZgR05IZXB1QKaF36jo0OkzBcMRFJ+L5D QqgzIAzPQYiAXEnRMuhWjaiFoCXKrWWxz6Ap2dL3tzDAe3I+jTrIy5uS7nDoEHirzT1GX vQ1NhSQ8ZlPXtlmR8m98yfiwgS5F0EhGQ6+ZvLDzyp5OjRHyPZ+QNRyAkd2Hqg0dYtLLV eGZwvy6UrwFmL/aQHY4Z8e6g0Ha5kQolTDOsxdMkAJG9g5kiweimLH/X9fem+wdQnOV/e ulr1dxKJi4TFq9poOzehgB7EB0VhpGFk4srn96Fb155qGWB7YEpKGYon6G4zvOimbqg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147667; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=sCqtQFXVjmUUyxh1yh4GT2mzaURoMhPo8Jkzkrm1Z6s=; b=yfDva1JRtjFeimZl/K2oD1m3qsptVnbmQ7/Z5GdXqQ/j0GHifpVN4kjiEe5ACb8LSs0u ufaRduw/921JlPzH/imeaCWm8p2N4rNajy2fHNfDjP6plZAoK99qyg5JlkXTlFtwbEcz0 CYI6cchRkX1FIIHGr1xRvvlLdJiUy0IIhKwbupTPlTx5TG2m4OAHTIj3bGVaXOKQ2Suwi lhQLoe2btz1rno+CVamszZvS4gtaTQZrM7EJhkfQFJg2qohgjmyG6LP1OwXtwYUWkm/VV ZGXgl/FauzPM0cc/z8HHmfLwAPJ1duOhnuIvPoLFC4jCBifgBXxkOzn8rG48KIilYzA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="B/FxHpBg"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8919E606A31A; Tue, 1 Dec 2026 17:54:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B/FxHpBg Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9C291F000C1; Tue, 1 Dec 2026 17:54:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796147667; bh=sCqtQFXVjmUUyxh1yh4GT2mzaURoMhPo8Jkzkrm1Z6s=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=B/FxHpBgjgQCjCuX+VhloMhK/Fk4ur1A+BN4pV0Va0YHUZ2aldkuqJ3fDrr0xqnkR OaySbxVWMCgv0ZJ9eb1zA0dSqwixmtQGMGDax/Dov4eZFl2W1Q0GDeTc+hFOzQlaCp 09QANnoSB+rBNwBieDuenYEG4OqMgFYQoJOC8E2t3S6QTOpyYVxc8F4o6zG1v+AGGp HMg7gML29vZDDcGMnLbYHafSgYz8w0YVN4ZEoACyNPQeK/ZWNs+FXomT5WCtBJvgFH E97JhlUmy4NF2E5RMYrWVMpsSZ9NF/N5jm/C8WSuzI4rg8XGvW+OwYpSDj3Mu4722+ XFxVNxsWhIS6g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH v2 5/7] virtio-usb: add per-port role query support Reply-To: sashiko-reviews@lists.linux.dev To: "Igor Skalkin" Cc: virtualization@lists.linux.dev, linux-usb@vger.kernel.org, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <967ac79f8a1bbd88f1e0edeb85d90f5f138e2be8.1796144390.git.igor.skalkin@oss.qualcomm.com> References: <20260924160907.145405-1-igor.skalkin@oss.qualcomm.com> <967ac79f8a1bbd88f1e0edeb85d90f5f138e2be8.1796144390.git.igor.skalkin@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 17:54:26 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] virtio-usb: cancel_work_sync() on uninitialized work in virtio_usb_probe() - [Medium] virtio-usb: NULL vudc dereference in virtio_usb_dc_event_process() - [Low] virtio-usb: missing role_vq_base initialization to -1 in virtio_usb_probe() -- commit c902648ce4ee2501024b60058b6032945e43427a Author: Igor Skalkin virtio-usb: add per-port role query support This commit adds a role command/event virtqueue pair and a synchronous VIRTIO_USB_CMD_ROLE_GET query to resolve each port's role during probe when both host_role and device_role are negotiated. > diff --git a/drivers/usb/virtio_usb/controller.c b/drivers/usb/virtio_usb= /controller.c > index b463513b2da4e..9f875a127f67b 100644 > --- a/drivers/usb/virtio_usb/controller.c > +++ b/drivers/usb/virtio_usb/controller.c [ ... ] > @@ -120,12 +121,12 @@ static int virtio_usb_probe(struct virtio_device *v= dev) > =20 > /* Only allocate/negotiate the virtqueue triplets this instance > * actually needs: HOST_* only exists when host_role is negotiated, > - * DEV_* only when device_role is negotiated. A pure single-role > - * instance therefore has exactly VIRTIO_USB_VQ_HOST_MAX (3) or > - * VIRTIO_USB_VQ_DEV_MAX (3) virtqueues, not a fixed layout - queues > - * that don't exist on the wire must not be created, since a peer > - * with no host-role VP has no host command/event/data queues to > - * negotiate at all. > + * DEV_* only when device_role is negotiated, ROLE_* only when both > + * roles are negotiated. A pure single-role instance therefore has > + * exactly VIRTIO_USB_VQ_HOST_MAX (3) or VIRTIO_USB_VQ_DEV_MAX (3) > + * virtqueues, not a fixed layout - queues that don't exist on the > + * wire must not be created, since a peer with no host-role VP has > + * no host command/event/data queues to negotiate at all. > */ > vusb->host_vq_base =3D -1; > vusb->dev_vq_base =3D -1; [Severity: Low] Should vusb->role_vq_base also be initialized to -1 here? The kernel-doc for struct virtio_usb documents @role_vq_base as -1 when the role queue pair is absent, but on a single-role device it stays 0 from devm_kzalloc(). [ ... ] > @@ -189,6 +200,47 @@ static int virtio_usb_probe(struct virtio_device *vd= ev) > goto on_error; > } > =20 > + if (vusb->host_role && vusb->device_role) { > + rc =3D virtio_usb_rsw_init(vusb); > + if (rc) { > + dev_err(&vdev->dev, > + "%s virtio_usb_rsw_init() error(%d)\n", > + __func__, rc); > + goto on_error; > + } > + } [Severity: Medium] Can jumping to on_error from virtio_usb_rsw_init() or virtio_usb_rsw_get_role() below run cancel_work_sync() on uninitialized work structs? virtio_usb_find_vqs() has already populated vusb->vqueues[i].vqueue, but INIT_WORK() for vq_host_data_rx_work, vq_host_evt_work, vq_dev_data_rx_work, and vq_dev_event_work does not run until after the role query loop. On failure, on_error calls virtio_usb_remove(), whose queue stop callbacks call cancel_work_sync() on those uninitialized work_structs and trigger WARN_ON(!work->func) in __flush_work(). > + > + /* Resolve every port's role. With only one role negotiated, every > + * port unambiguously has that role. With both negotiated, query > + * each port's actual role individually via virtio_usb_rsw_get_role(), = since > + * it is otherwise ambiguous (host|device). > + */ > + for (i =3D 0; i < vusb->nports; i++) { > + if (vusb->host_role && !vusb->device_role) { > + vusb->vports[i].role =3D VIRTIO_USB_ROLE_HOST; > + } else if (vusb->device_role && !vusb->host_role) { > + vusb->vports[i].role =3D VIRTIO_USB_ROLE_DEVICE; > + } else { > + u32 status, role; > + > + status =3D virtio_usb_rsw_get_role(vusb, i, &role); > + if (status !=3D VIRTIO_USB_S_OK) { > + dev_err(&vdev->dev, "%s status(%d)\n", __func__, > + status); > + rc =3D -EIO; > + goto on_error; > + } > + if (role !=3D VIRTIO_USB_ROLE_HOST && > + role !=3D VIRTIO_USB_ROLE_DEVICE) { > + dev_err(&vdev->dev, "%s port%d wrong role %d\n", > + __func__, i, role); > + rc =3D -EIO; > + goto on_error; > + } > + vusb->vports[i].role =3D role; > + } > + } [Severity: Medium] With both host_role and device_role negotiated, can a device event referencing a host-role port cause a NULL pointer dereference on vudc in virtio_usb_dc_event_process()? Ports assigned VIRTIO_USB_ROLE_HOST here skip virtio_usb_dc_init(), leaving vusb->vports[i].vudc NULL while virtio_usb_dc_event_populate() still populates the shared device event queue. Unlike virtio_usb_hc_evt_process_one(), virtio_usb_dc_event_process() only bounds-checks port_id against vusb->nports before dereferencing vudc: drivers/usb/virtio_usb/device.c:virtio_usb_dc_event_process() { ... vudc =3D vusb->vports[port_id].vudc; driver =3D vudc->driver; ... } --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796144390.gi= t.igor.skalkin@oss.qualcomm.com?part=3D5