All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Igor Skalkin" <igor.skalkin@oss.qualcomm.com>
Cc: virtualization@lists.linux.dev, linux-usb@vger.kernel.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [RFC PATCH v2 5/7] virtio-usb: add per-port role query support
Date: Tue, 01 Dec 2026 17:54:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-243913@kernel.org> (raw)
In-Reply-To: <967ac79f8a1bbd88f1e0edeb85d90f5f138e2be8.1796144390.git.igor.skalkin@oss.qualcomm.com>

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 <igor.skalkin@oss.qualcomm.com>

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 *vdev)
>  
>  	/* 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 = -1;
>  	vusb->dev_vq_base = -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 *vdev)
>  		goto on_error;
>  	}
>  
> +	if (vusb->host_role && vusb->device_role) {
> +		rc = 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 = 0; i < vusb->nports; i++) {
> +		if (vusb->host_role && !vusb->device_role) {
> +			vusb->vports[i].role = VIRTIO_USB_ROLE_HOST;
> +		} else if (vusb->device_role && !vusb->host_role) {
> +			vusb->vports[i].role = VIRTIO_USB_ROLE_DEVICE;
> +		} else {
> +			u32 status, role;
> +
> +			status = virtio_usb_rsw_get_role(vusb, i, &role);
> +			if (status != VIRTIO_USB_S_OK) {
> +				dev_err(&vdev->dev, "%s status(%d)\n", __func__,
> +					status);
> +				rc = -EIO;
> +				goto on_error;
> +			}
> +			if (role != VIRTIO_USB_ROLE_HOST &&
> +			    role != VIRTIO_USB_ROLE_DEVICE) {
> +				dev_err(&vdev->dev, "%s port%d wrong role %d\n",
> +					__func__, i, role);
> +				rc = -EIO;
> +				goto on_error;
> +			}
> +			vusb->vports[i].role = 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 = vusb->vports[port_id].vudc;
	driver = vudc->driver;
	...
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796144390.git.igor.skalkin@oss.qualcomm.com?part=5

  reply	other threads:[~2026-12-01 17:54 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 16:08 [PATCH 0/8] virtio-usb: add dual-role virtio USB driver Igor Skalkin
2026-09-24 16:09 ` [PATCH 1/8] virtio-usb: add protocol header and skeleton dual-role driver Igor Skalkin
2026-09-24 16:23   ` sashiko-bot
2026-09-25  5:14   ` Greg Kroah-Hartman
2026-09-28 14:19     ` Igor Skalkin
2026-09-25  5:21   ` Greg Kroah-Hartman
2026-09-28 14:14     ` Igor Skalkin
2026-09-24 16:09 ` [PATCH 2/8] virtio-usb: add host role (USB Host Controller) support Igor Skalkin
2026-09-24 16:25   ` sashiko-bot
2026-09-25  5:18   ` Greg Kroah-Hartman
2026-09-28 14:01     ` Igor Skalkin
2026-09-24 16:09 ` [PATCH 3/8] virtio-usb: add device role (USB Device " Igor Skalkin
2026-09-24 16:28   ` sashiko-bot
2026-09-24 16:09 ` [PATCH 4/8] virtio-usb: add OTG role query support Igor Skalkin
2026-09-24 16:19   ` sashiko-bot
2026-09-24 16:09 ` [PATCH 5/8] virtio-usb: add USB On-The-Go role-switching support Igor Skalkin
2026-09-24 16:24   ` sashiko-bot
2026-09-24 16:09 ` [PATCH 6/8] virtio-usb: rework endpoint lifecycle to an async split-phase state machine Igor Skalkin
2026-09-24 16:30   ` sashiko-bot
2026-09-24 16:09 ` [PATCH 7/8] virtio-usb: add SuperSpeed device-role support Igor Skalkin
2026-09-24 16:35   ` sashiko-bot
2026-09-24 16:09 ` [PATCH 8/8] virtio-usb: support a guest UDC name prefix from the bind event Igor Skalkin
2026-09-24 16:35   ` sashiko-bot
2026-09-25  5:17 ` [PATCH 0/8] virtio-usb: add dual-role virtio USB driver Greg Kroah-Hartman
2026-09-28 13:55   ` Igor Skalkin
2026-09-28 14:44     ` Greg Kroah-Hartman
2026-09-28 15:56       ` Igor Skalkin
2026-09-28 16:10         ` Greg Kroah-Hartman
2026-09-29  9:47     ` Michael S. Tsirkin
2026-09-29 16:01       ` Greg Kroah-Hartman
2026-09-29 19:02         ` Vasilii Ianikeev
2026-09-29 19:58         ` Vasilii Ianikeev
2026-12-01 17:35 ` [RFC PATCH v2 0/7] " 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:52     ` sashiko-bot
2026-12-01 17:35   ` [RFC PATCH v2 3/7] virtio-usb: add host role (USB Host Controller) support Igor Skalkin
2026-12-01 18:09     ` sashiko-bot
2026-12-01 17:35   ` [RFC PATCH v2 4/7] virtio-usb: add device role (USB Device " Igor Skalkin
2026-12-01 18:13     ` sashiko-bot
2026-12-01 17:35   ` [RFC PATCH v2 5/7] virtio-usb: add per-port role query support Igor Skalkin
2026-12-01 17:54     ` sashiko-bot [this message]
2026-12-01 17:35   ` [RFC PATCH v2 6/7] virtio-usb: add host/device role switch support Igor Skalkin
2026-12-01 18:00     ` sashiko-bot
2026-12-01 17:35   ` [RFC PATCH v2 7/7] virtio-usb: support a guest UDC name prefix from the bind event Igor Skalkin
2026-12-01 17:50     ` sashiko-bot
2026-12-01 17:49   ` [RFC PATCH v2 0/7] virtio-usb: add dual-role virtio USB driver Michael S. Tsirkin
2026-12-01 18:14   ` sashiko-bot
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=sashiko-outbox-243913@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=igor.skalkin@oss.qualcomm.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=virtualization@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.