From: Seonghyeon Lim via B4 Relay <devnull+forfortuna.naver.com@kernel.org>
To: Harald Mommer <harald.mommer@oss.qualcomm.com>,
Matias Ezequiel Vara Larsen <mvaralar@redhat.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol@kernel.org>,
Mikhail Golubev-Ciuchea
<mikhail.golubev-ciuchea@oss.qualcomm.com>,
Francesco Valla <francesco@valla.it>,
"Michael S. Tsirkin" <mst@redhat.com>
Cc: virtualization@lists.linux.dev, linux-can@vger.kernel.org,
linux-kernel@vger.kernel.org, Jason Wang <jasowangio@gmail.com>,
stable@vger.kernel.org, Seonghyeon Lim <forfortuna@naver.com>
Subject: [PATCH v2 1/2] can: virtio: fix RX/TX stall on interrupt before NAPI is enabled
Date: Fri, 20 Nov 2026 15:56:03 +0900 [thread overview]
Message-ID: <20261120-virtio-can-ready-v2-1-0defda2af8cb@naver.com> (raw)
In-Reply-To: <20261120-virtio-can-ready-v2-0-0defda2af8cb@naver.com>
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
next prev parent reply other threads:[~2026-11-20 6:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 6:56 [PATCH v2 0/2] can: virtio: fix NAPI stall and virtqueue use before DRIVER_OK Seonghyeon Lim via B4 Relay
2026-11-20 6:56 ` Seonghyeon Lim via B4 Relay [this message]
2026-11-20 7:12 ` [PATCH v2 1/2] can: virtio: fix RX/TX stall on interrupt before NAPI is enabled sashiko-bot
2026-11-20 6:56 ` [PATCH v2 2/2] can: virtio: fix virtqueue use before DRIVER_OK Seonghyeon Lim via B4 Relay
2026-11-20 7:03 ` sashiko-bot
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=20261120-virtio-can-ready-v2-1-0defda2af8cb@naver.com \
--to=devnull+forfortuna.naver.com@kernel.org \
--cc=forfortuna@naver.com \
--cc=francesco@valla.it \
--cc=harald.mommer@oss.qualcomm.com \
--cc=jasowangio@gmail.com \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mikhail.golubev-ciuchea@oss.qualcomm.com \
--cc=mkl@pengutronix.de \
--cc=mst@redhat.com \
--cc=mvaralar@redhat.com \
--cc=stable@vger.kernel.org \
--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