Linux CAN drivers development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Seonghyeon Lim" <forfortuna@naver.com>
Cc: virtualization@lists.linux.dev, linux-can@vger.kernel.org,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH] can: virtio: fix virtqueue use before DRIVER_OK
Date: Tue, 10 Nov 2026 17:46:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-207511@kernel.org> (raw)
In-Reply-To: <20261111-virtio-can-ready-v1-1-0b4dd020af0b@naver.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] can: virtio: RX/TX stall if interrupt fires before
  virtio_can_napi_enable()
--

commit 8c2e9ab878f651e327c76d0ed7de23824865f16e
Author: Seonghyeon Lim <forfortuna@naver.com>

can: virtio: fix virtqueue use before DRIVER_OK

This commit calls virtio_device_ready() before populating the RX virtqueue
in virtio_can_probe() and virtio_can_restore() so that virtqueues are not
notified before DRIVER_OK is set.

> diff --git a/drivers/net/can/virtio_can.c b/drivers/net/can/virtio_can.c
> index f67d0bf09681f..ae35a00b784bd 100644
> --- a/drivers/net/can/virtio_can.c
> +++ b/drivers/net/can/virtio_can.c
> @@ -912,6 +912,9 @@ static int virtio_can_probe(struct virtio_device *vdev)
>  		err = -ENOMEM;
>  		goto on_failure;
>  	}
> +
> +	virtio_device_ready(vdev);
> +
>  	virtio_can_populate_rx_vq(vdev);
>  
>  	err = register_virtio_can_dev(dev);
> @@ -966,6 +969,9 @@ static int __maybe_unused virtio_can_restore(struct virtio_device *vdev)
>  		virtio_can_del_vq(vdev);
>  		return -ENOMEM;
>  	}
> +
> +	virtio_device_ready(vdev);
> +
>  	virtio_can_populate_rx_vq(vdev);
>  
>  	if (netif_running(ndev)) {

[Severity: High]
Can an RX or TX virtqueue interrupt arriving before
virtio_can_napi_enable() permanently wedge the queue?

virtio_device_ready() unbreaks the virtqueues and sets DRIVER_OK while
priv->napi and priv->napi_tx are still disabled (NAPI_STATE_SCHED is set).
In virtio_can_open(), virtio_can_start() then sends
VIRTIO_CAN_SET_CTRL_MODE_START and sleeps in wait_for_completion() before
calling virtio_can_napi_enable():

drivers/net/can/virtio_can.c:virtio_can_open() {
	...
	err = virtio_can_start(ndev);
	if (err) {
		close_candev(ndev);
		return err;
	}

	virtio_can_napi_enable(priv);
}

drivers/net/can/virtio_can.c:virtio_can_rx_intr() {
	struct virtio_can_priv *can_priv = vq->vdev->priv;

	virtqueue_disable_cb(vq);
	napi_schedule(&can_priv->napi);
}

CPU0                              CPU1 (virtio interrupt)
virtio_can_restore() / probe()
  virtio_device_ready(vdev)
  virtio_can_populate_rx_vq(vdev)
  virtio_can_open()
    virtio_can_start()
      ...
      wait_for_completion()
                                  virtio_can_rx_intr()
                                    virtqueue_disable_cb(vq)
                                    napi_schedule(&can_priv->napi)
                                      <no-op: NAPI_STATE_SCHED set>
    virtio_can_napi_enable()
      napi_enable(&priv->napi)    <-- clears NAPI_STATE_SCHED;
                                      vq cb stays disabled

Once napi_enable() clears NAPI_STATE_SCHED without scheduling a poll or
re-enabling the virtqueue callback, virtio_can_rx_poll() never runs and RX
is permanently stalled.

Enabling NAPI before virtio_can_start(), or kicking the virtqueues via
virtqueue_napi_schedule() after napi_enable() as virtio-net does in
virtnet_napi_do_enable(), would avoid losing the notification.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261111-virtio-can-ready-v1-1-0b4dd020af0b@naver.com?part=1

      parent reply	other threads:[~2026-11-10 17:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 17:11 [PATCH] can: virtio: fix virtqueue use before DRIVER_OK Seonghyeon Lim via B4 Relay
2026-11-10 17:26 ` Michael S. Tsirkin
2026-11-11  0:11   ` 임성현
2026-11-10 17:46 ` sashiko-bot [this message]

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-207511@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=forfortuna@naver.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=mst@redhat.com \
    --cc=o.rempel@pengutronix.de \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=socketcan@hartkopp.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox