* [PATCH v2 0/2] can: virtio: fix NAPI stall and virtqueue use before DRIVER_OK
@ 2026-11-20 6:56 ` Seonghyeon Lim via B4 Relay
0 siblings, 0 replies; 8+ messages in thread
From: Seonghyeon Lim via B4 Relay @ 2026-11-20 6:56 UTC (permalink / raw)
To: Harald Mommer, Matias Ezequiel Vara Larsen, Marc Kleine-Budde,
Vincent Mailhol, Mikhail Golubev-Ciuchea, Francesco Valla,
Michael S. Tsirkin
Cc: virtualization, linux-can, linux-kernel, Jason Wang, stable,
Seonghyeon Lim
This series fixes two issues in the virtio CAN driver.
Patch 1 fixes an RX/TX stall when an interrupt arrives after the START
command but before NAPI is enabled in virtio_can_open().
Patch 2 calls virtio_device_ready() before the first virtqueue use in
probe and restore. Without it, resume hangs if the interface was up.
Patch 1 goes first: without patch 2, restore hangs waiting for the
START reply before it reaches that window, so patch 2 alone would
expose the stall.
The interrupt handlers could also use virtqueue_napi_schedule() like
virtio-net does. I left that for a follow-up cleanup.
Tested with QEMU 8.2 and vhost-device-can:
- With the interface up, suspend/resume (pm_test=devices) hangs
without patch 2 and completes with the series.
- With a temporary delay before napi_enable() and continuous traffic,
RX interrupts arrive while NAPI is disabled and napi_schedule_prep()
fails. With patch 1, NAPI is scheduled right after napi_enable() and
the RX poll runs without waiting for another interrupt.
vhost-device-can keeps sending interrupts, which hides the stall
without patch 1.
- RX traffic and repeated down/up work. No lockdep warnings.
---
Changes in v2:
- Add patch 1 for the NAPI stall reported by sashiko-bot. With patch 2
the restore path can reach it (Michael's question about callbacks
after virtio_device_ready()).
- Patch 2: describe the callbacks, add the hung task trace and
Cc: stable.
- Link to v1: https://patch.msgid.link/20261111-virtio-can-ready-v1-1-0b4dd020af0b@naver.com
---
Seonghyeon Lim (2):
can: virtio: fix RX/TX stall on interrupt before NAPI is enabled
can: virtio: fix virtqueue use before DRIVER_OK
drivers/net/can/virtio_can.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
---
base-commit: ddfe51b0a0f5dc9e415cc2c8ad8db17532dd426b
change-id: 20261111-virtio-can-ready-85cefff06a84
Best regards,
--
Seonghyeon Lim <forfortuna@naver.com>
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v2 1/2] can: virtio: fix RX/TX stall on interrupt before NAPI is enabled
2026-11-20 6:56 ` Seonghyeon Lim via B4 Relay
@ 2026-11-20 6:56 ` Seonghyeon Lim via B4 Relay
-1 siblings, 0 replies; 8+ messages in thread
From: Seonghyeon Lim @ 2026-11-20 6:56 UTC (permalink / raw)
To: Harald Mommer, Matias Ezequiel Vara Larsen, Marc Kleine-Budde,
Vincent Mailhol, Mikhail Golubev-Ciuchea, Francesco Valla,
Michael S. Tsirkin
Cc: virtualization, linux-can, linux-kernel, Jason Wang, stable,
Seonghyeon Lim
virtio_can_open() sends the START command before it enables NAPI. Once
the device has started, an RX or TX interrupt can arrive in between.
The interrupt handler then disables the virtqueue callback and calls
napi_schedule(), which does nothing because NAPI is still disabled.
napi_enable() does not schedule a poll either, and only the poll
function re-enables the callback, so the queue can stall until the
device happens to send another interrupt.
Schedule NAPI once after napi_enable(), as virtio-net does in
virtnet_napi_do_enable(). This processes buffers that are already used
and re-enables the callback.
Fixes: 083082a4e6d8 ("can: virtio: Add virtio CAN driver")
Cc: stable@vger.kernel.org
Signed-off-by: Seonghyeon Lim <forfortuna@naver.com>
---
drivers/net/can/virtio_can.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/net/can/virtio_can.c b/drivers/net/can/virtio_can.c
index f67d0bf09681..9055d7e43235 100644
--- a/drivers/net/can/virtio_can.c
+++ b/drivers/net/can/virtio_can.c
@@ -116,6 +116,19 @@ static void virtio_can_napi_enable(struct virtio_can_priv *priv)
if (!priv->napi_active) {
napi_enable(&priv->napi);
napi_enable(&priv->napi_tx);
+
+ /* An interrupt that arrived while NAPI was disabled has
+ * disabled the virtqueue callback but could not schedule
+ * NAPI, so no further interrupt may come. Schedule NAPI once
+ * to process pending buffers and re-enable the callback.
+ */
+ local_bh_disable();
+ virtqueue_napi_schedule(&priv->napi,
+ priv->vqs[VIRTIO_CAN_QUEUE_RX]);
+ virtqueue_napi_schedule(&priv->napi_tx,
+ priv->vqs[VIRTIO_CAN_QUEUE_TX]);
+ local_bh_enable();
+
priv->napi_active = true;
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 1/2] can: virtio: fix RX/TX stall on interrupt before NAPI is enabled
@ 2026-11-20 6:56 ` Seonghyeon Lim via B4 Relay
0 siblings, 0 replies; 8+ messages in thread
From: Seonghyeon Lim via B4 Relay @ 2026-11-20 6:56 UTC (permalink / raw)
To: Harald Mommer, Matias Ezequiel Vara Larsen, Marc Kleine-Budde,
Vincent Mailhol, Mikhail Golubev-Ciuchea, Francesco Valla,
Michael S. Tsirkin
Cc: virtualization, linux-can, linux-kernel, Jason Wang, stable,
Seonghyeon Lim
From: Seonghyeon Lim <forfortuna@naver.com>
virtio_can_open() sends the START command before it enables NAPI. Once
the device has started, an RX or TX interrupt can arrive in between.
The interrupt handler then disables the virtqueue callback and calls
napi_schedule(), which does nothing because NAPI is still disabled.
napi_enable() does not schedule a poll either, and only the poll
function re-enables the callback, so the queue can stall until the
device happens to send another interrupt.
Schedule NAPI once after napi_enable(), as virtio-net does in
virtnet_napi_do_enable(). This processes buffers that are already used
and re-enables the callback.
Fixes: 083082a4e6d8 ("can: virtio: Add virtio CAN driver")
Cc: stable@vger.kernel.org
Signed-off-by: Seonghyeon Lim <forfortuna@naver.com>
---
drivers/net/can/virtio_can.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/net/can/virtio_can.c b/drivers/net/can/virtio_can.c
index f67d0bf09681..9055d7e43235 100644
--- a/drivers/net/can/virtio_can.c
+++ b/drivers/net/can/virtio_can.c
@@ -116,6 +116,19 @@ static void virtio_can_napi_enable(struct virtio_can_priv *priv)
if (!priv->napi_active) {
napi_enable(&priv->napi);
napi_enable(&priv->napi_tx);
+
+ /* An interrupt that arrived while NAPI was disabled has
+ * disabled the virtqueue callback but could not schedule
+ * NAPI, so no further interrupt may come. Schedule NAPI once
+ * to process pending buffers and re-enable the callback.
+ */
+ local_bh_disable();
+ virtqueue_napi_schedule(&priv->napi,
+ priv->vqs[VIRTIO_CAN_QUEUE_RX]);
+ virtqueue_napi_schedule(&priv->napi_tx,
+ priv->vqs[VIRTIO_CAN_QUEUE_TX]);
+ local_bh_enable();
+
priv->napi_active = true;
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 1/2] can: virtio: fix RX/TX stall on interrupt before NAPI is enabled
2026-11-20 6:56 ` Seonghyeon Lim via B4 Relay
(?)
@ 2026-11-20 7:12 ` sashiko-bot
-1 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-20 7:12 UTC (permalink / raw)
To: Seonghyeon Lim; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
> From: Seonghyeon Lim <forfortuna@naver.com>
>
> virtio_can_open() sends the START command before it enables NAPI. Once
> the device has started, an RX or TX interrupt can arrive in between.
> The interrupt handler then disables the virtqueue callback and calls
> napi_schedule(), which does nothing because NAPI is still disabled.
> napi_enable() does not schedule a poll either, and only the poll
> function re-enables the callback, so the queue can stall until the
> device happens to send another interrupt.
>
> Schedule NAPI once after napi_enable(), as virtio-net does in
> virtnet_napi_do_enable(). This processes buffers that are already used
> and re-enables the callback.
>
> Fixes: 083082a4e6d8 ("can: virtio: Add virtio CAN driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Seonghyeon Lim <forfortuna@naver.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-virtio-can-ready-v2-0-0defda2af8cb@naver.com?part=1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] can: virtio: fix virtqueue use before DRIVER_OK
2026-11-20 6:56 ` Seonghyeon Lim via B4 Relay
@ 2026-11-20 6:56 ` Seonghyeon Lim via B4 Relay
-1 siblings, 0 replies; 8+ messages in thread
From: Seonghyeon Lim @ 2026-11-20 6:56 UTC (permalink / raw)
To: Harald Mommer, Matias Ezequiel Vara Larsen, Marc Kleine-Budde,
Vincent Mailhol, Mikhail Golubev-Ciuchea, Francesco Valla,
Michael S. Tsirkin
Cc: virtualization, linux-can, linux-kernel, Jason Wang, stable,
Seonghyeon Lim
virtio_can_probe() and virtio_can_restore() fill the RX virtqueue and
kick it before the device is set DRIVER_OK. The virtio specification
does not allow the driver to notify the device before DRIVER_OK.
In restore, if the interface was up, virtio_can_open() then sends a
START control message and waits for the reply. DRIVER_OK is only set
by the virtio core after restore returns, so the device may never
handle the request and the wait never completes, which hangs system
resume:
task:kworker/u4:5 state:D
Workqueue: async async_run_entry_fn
Call Trace:
__wait_for_common
virtio_can_send_ctrl_msg
virtio_can_open
virtio_can_restore
virtio_device_restore_priv
dpm_run_callback
device_resume
In probe, an ndo_open() right after register_candev() can likewise
send the START message before DRIVER_OK.
Call virtio_device_ready() before the first virtqueue use in both
probe and restore, as virtio-net does. Config change callbacks are
still deferred by the virtio core until probe or restore returns, and
virtqueue callbacks that arrive before NAPI is enabled are handled in
virtio_can_napi_enable().
Fixes: 083082a4e6d8 ("can: virtio: Add virtio CAN driver")
Cc: stable@vger.kernel.org
Signed-off-by: Seonghyeon Lim <forfortuna@naver.com>
---
drivers/net/can/virtio_can.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/can/virtio_can.c b/drivers/net/can/virtio_can.c
index 9055d7e43235..549e8d789d74 100644
--- a/drivers/net/can/virtio_can.c
+++ b/drivers/net/can/virtio_can.c
@@ -925,6 +925,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);
@@ -979,6 +982,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)) {
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 2/2] can: virtio: fix virtqueue use before DRIVER_OK
@ 2026-11-20 6:56 ` Seonghyeon Lim via B4 Relay
0 siblings, 0 replies; 8+ messages in thread
From: Seonghyeon Lim via B4 Relay @ 2026-11-20 6:56 UTC (permalink / raw)
To: Harald Mommer, Matias Ezequiel Vara Larsen, Marc Kleine-Budde,
Vincent Mailhol, Mikhail Golubev-Ciuchea, Francesco Valla,
Michael S. Tsirkin
Cc: virtualization, linux-can, linux-kernel, Jason Wang, stable,
Seonghyeon Lim
From: Seonghyeon Lim <forfortuna@naver.com>
virtio_can_probe() and virtio_can_restore() fill the RX virtqueue and
kick it before the device is set DRIVER_OK. The virtio specification
does not allow the driver to notify the device before DRIVER_OK.
In restore, if the interface was up, virtio_can_open() then sends a
START control message and waits for the reply. DRIVER_OK is only set
by the virtio core after restore returns, so the device may never
handle the request and the wait never completes, which hangs system
resume:
task:kworker/u4:5 state:D
Workqueue: async async_run_entry_fn
Call Trace:
__wait_for_common
virtio_can_send_ctrl_msg
virtio_can_open
virtio_can_restore
virtio_device_restore_priv
dpm_run_callback
device_resume
In probe, an ndo_open() right after register_candev() can likewise
send the START message before DRIVER_OK.
Call virtio_device_ready() before the first virtqueue use in both
probe and restore, as virtio-net does. Config change callbacks are
still deferred by the virtio core until probe or restore returns, and
virtqueue callbacks that arrive before NAPI is enabled are handled in
virtio_can_napi_enable().
Fixes: 083082a4e6d8 ("can: virtio: Add virtio CAN driver")
Cc: stable@vger.kernel.org
Signed-off-by: Seonghyeon Lim <forfortuna@naver.com>
---
drivers/net/can/virtio_can.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/can/virtio_can.c b/drivers/net/can/virtio_can.c
index 9055d7e43235..549e8d789d74 100644
--- a/drivers/net/can/virtio_can.c
+++ b/drivers/net/can/virtio_can.c
@@ -925,6 +925,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);
@@ -979,6 +982,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)) {
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 2/2] can: virtio: fix virtqueue use before DRIVER_OK
2026-11-20 6:56 ` Seonghyeon Lim via B4 Relay
(?)
@ 2026-11-20 7:03 ` sashiko-bot
-1 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-20 7:03 UTC (permalink / raw)
To: Seonghyeon Lim; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
> From: Seonghyeon Lim <forfortuna@naver.com>
>
> virtio_can_probe() and virtio_can_restore() fill the RX virtqueue and
> kick it before the device is set DRIVER_OK. The virtio specification
> does not allow the driver to notify the device before DRIVER_OK.
>
> In restore, if the interface was up, virtio_can_open() then sends a
> START control message and waits for the reply. DRIVER_OK is only set
> by the virtio core after restore returns, so the device may never
> handle the request and the wait never completes, which hangs system
> resume:
>
> task:kworker/u4:5 state:D
> Workqueue: async async_run_entry_fn
> Call Trace:
> [ ... ]
> virtio_can_napi_enable().
>
> Fixes: 083082a4e6d8 ("can: virtio: Add virtio CAN driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Seonghyeon Lim <forfortuna@naver.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-virtio-can-ready-v2-0-0defda2af8cb@naver.com?part=2
^ permalink raw reply [flat|nested] 8+ messages in thread