From: Longjun Tang <lange_tang@163.com>
To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com,
edumazet@google.com
Cc: lange_tang@163.com, tanglongjun@kylinos.cn,
virtualization@lists.linux.dev
Subject: [PATCH 2/2] virtio_ring: return IRQ_HANDLED for stale interrupts when cb disabled
Date: Tue, 31 Mar 2026 18:26:26 +0800 [thread overview]
Message-ID: <20260331102626.108962-3-lange_tang@163.com> (raw)
In-Reply-To: <20260331102626.108962-1-lange_tang@163.com>
From: Longjun Tang <tanglongjun@kylinos.cn>
In the vring_interrupt, if the used ring is empty, IRQ_NONE is returned.
However,Sometimes, such as with busy-polling, buffers might be consumed
from the used ring before an stale interrupt notification arrives. it
leading to return IRQ_NONE.
The kernel's spurious-IRQ detector counts consecutive IRQ_NONE returns
and will permanently disable the interrupt line if 99,900 out of 100,000
interrupts go unhandled.
Add is_cb_disabled() to virtqueue_ops and, when more_used() is false but
cb are suppressed, return IRQ_HANDLED instead of IRQ_NONE so the spurious
counter does not accumulate.
Signed-off-by: Longjun Tang <tanglongjun@kylinos.cn>
---
drivers/virtio/virtio_ring.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 335692d41617..52df932fc4a2 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -185,6 +185,7 @@ struct virtqueue_ops {
unsigned int last_used_idx);
void *(*detach_unused_buf)(struct vring_virtqueue *vq);
bool (*more_used)(const struct vring_virtqueue *vq);
+ bool (*is_cb_disabled)(const struct vring_virtqueue *vq);
int (*resize)(struct vring_virtqueue *vq, u32 num);
void (*reset)(struct vring_virtqueue *vq);
};
@@ -1063,6 +1064,12 @@ static void virtqueue_disable_cb_split(struct vring_virtqueue *vq)
}
}
+static bool is_cb_disabled_split(const struct vring_virtqueue *vq)
+{
+ return !!(data_race(vq->split.avail_flags_shadow) &
+ VRING_AVAIL_F_NO_INTERRUPT);
+}
+
static unsigned int virtqueue_enable_cb_prepare_split(struct vring_virtqueue *vq)
{
u16 last_used_idx;
@@ -2227,6 +2234,12 @@ static void virtqueue_disable_cb_packed(struct vring_virtqueue *vq)
}
}
+static bool is_cb_disabled_packed(const struct vring_virtqueue *vq)
+{
+ return data_race(vq->packed.event_flags_shadow) ==
+ VRING_PACKED_EVENT_FLAG_DISABLE;
+}
+
static unsigned int virtqueue_enable_cb_prepare_packed(struct vring_virtqueue *vq)
{
START_USE(vq);
@@ -2644,6 +2657,7 @@ static const struct virtqueue_ops split_ops = {
.poll = virtqueue_poll_split,
.detach_unused_buf = virtqueue_detach_unused_buf_split,
.more_used = more_used_split,
+ .is_cb_disabled = is_cb_disabled_split,
.resize = virtqueue_resize_split,
.reset = virtqueue_reset_split,
};
@@ -2658,6 +2672,7 @@ static const struct virtqueue_ops packed_ops = {
.poll = virtqueue_poll_packed,
.detach_unused_buf = virtqueue_detach_unused_buf_packed,
.more_used = more_used_packed,
+ .is_cb_disabled = is_cb_disabled_packed,
.resize = virtqueue_resize_packed,
.reset = virtqueue_reset_packed,
};
@@ -2672,6 +2687,7 @@ static const struct virtqueue_ops split_in_order_ops = {
.poll = virtqueue_poll_split,
.detach_unused_buf = virtqueue_detach_unused_buf_split,
.more_used = more_used_split_in_order,
+ .is_cb_disabled = is_cb_disabled_split,
.resize = virtqueue_resize_split,
.reset = virtqueue_reset_split,
};
@@ -2686,6 +2702,7 @@ static const struct virtqueue_ops packed_in_order_ops = {
.poll = virtqueue_poll_packed,
.detach_unused_buf = virtqueue_detach_unused_buf_packed,
.more_used = more_used_packed_in_order,
+ .is_cb_disabled = is_cb_disabled_packed,
.resize = virtqueue_resize_packed,
.reset = virtqueue_reset_packed,
};
@@ -3231,6 +3248,18 @@ irqreturn_t vring_interrupt(int irq, void *_vq)
struct vring_virtqueue *vq = to_vvq(_vq);
if (!more_used(vq)) {
+ /*
+ * Stale interrupt: the device posted this notification
+ * before it observed the callback suppression;
+ * When more_used returns empty, IRQ_HANDLED should be
+ * returned for stale interrupts.
+ */
+ if (VIRTQUEUE_CALL(vq, is_cb_disabled)) {
+ if (vq->event)
+ data_race(vq->event_triggered = true);
+ pr_debug("virtqueue stale interrupt (callbacks disabled) for %p\n", vq);
+ return IRQ_HANDLED;
+ }
pr_debug("virtqueue interrupt with no work for %p\n", vq);
return IRQ_NONE;
}
--
2.43.0
next prev parent reply other threads:[~2026-03-31 10:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 10:26 [PATCH 0/2] fix virtio_net/virtio when in busy-polling Longjun Tang
2026-03-31 10:26 ` [PATCH 1/2] virtio_net: disable cb " Longjun Tang
2026-04-03 2:57 ` Jason Wang
2026-04-07 7:02 ` Lange Tang
2026-03-31 10:26 ` Longjun Tang [this message]
2026-04-03 2:55 ` [PATCH 2/2] virtio_ring: return IRQ_HANDLED for stale interrupts when cb disabled Jason Wang
2026-04-07 7:28 ` Lange Tang
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=20260331102626.108962-3-lange_tang@163.com \
--to=lange_tang@163.com \
--cc=edumazet@google.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=tanglongjun@kylinos.cn \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/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