syzbot
KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (9)
Status:
moderation: reported on 2026/11/17 18:56
Subsystems:
virt
Labels:
prio:high
[Documentation on labels]
Reported-by: syzbot+378ba14d9bff8b9e7210@syzkaller.appspotmail.com
First crash: 17h10m, last: 1h53m
✨ AI-generated root cause summary:
In virtio split-ring mode, an unmarked data race occurs on the 16-bit field vq->last_used_idx between virtqueue_get_buf_ctx_split() (which increments last_used_idx in softirq/NAPI context) and vring_interrupt() -> more_used_split() (which reads last_used_idx in hardirq context without locking). While the packed-ring implementation explicitly uses READ_ONCE() and WRITE_ONCE() to access last_used_idx across interrupt boundaries, the split-ring functions use plain, unannotated C accesses. As a result, KCSAN detects an unsynchronized read-write data race between the interrupt handler and buffer consumption.
▶
▼
✨ Full AI root cause analysis
Technical Root Cause Analysis
Involved Functions, Structs, and Fields
- File:
drivers/virtio/virtio_ring.c
- Struct:
struct vring_virtqueue
- Field:
u16 last_used_idx (offset 92 / 0x5c bytes into struct vring_virtqueue, size 2 bytes)
- Functions:
virtqueue_get_buf_ctx_split() / virtqueue_get_buf_ctx_split_in_order()
more_used_split() / more_used_split_in_order() (invoked by vring_interrupt())
Mechanism and Triggering Flow
-
Context & Operation:
- In virtio drivers such as
virtio_net, buffer reception and cleanup run in softirq context via NAPI (virtnet_poll() -> receive_buf() -> virtnet_rq_get_buf() -> virtqueue_get_buf_ctx() -> virtqueue_get_buf_ctx_split()).
- When detaching a processed descriptor in
virtqueue_get_buf_ctx_split(), the driver increments vq->last_used_idx (line 1008):
detach_buf_split(vq, i, ctx);
vq->last_used_idx++;
- Because softirqs run with hard IRQs enabled, a virtqueue interrupt (MSI-X or shared vector) can arrive concurrently on the same CPU or another CPU, invoking the interrupt handler
vring_interrupt().
- In
vring_interrupt() (line 3323), the handler checks whether work is available before invoking the queue callback:
if (!more_used(vq)) {
pr_debug("virtqueue interrupt with no work for %p\n", vq);
return IRQ_NONE;
}
- For split virtqueues,
more_used() delegates to more_used_split() (lines 955–958):
static bool more_used_split(const struct vring_virtqueue *vq)
{
return virtqueue_poll_split(vq, vq->last_used_idx);
}
which reads vq->last_used_idx.
-
The Invariant Violation:
- Under the Linux Kernel Memory Model (LKMM), data shared across hardirq and softirq/process contexts without explicit locking must use marked memory accesses (
READ_ONCE() / WRITE_ONCE()) to prevent compiler optimizations (such as invent-writes, re-reading, or tearing) and to document intentional data races to sanitizers.
- In the packed-ring implementation (
virtio_ring.c), this was previously addressed by explicitly using marked primitives:
more_used_packed() reads READ_ONCE(vq->last_used_idx)
update_last_used_idx_packed() writes WRITE_ONCE(vq->last_used_idx, ...)
- In the split-ring path (
virtqueue_get_buf_ctx_split() and more_used_split()), however, plain C loads and stores (vq->last_used_idx++ and vq->last_used_idx) are used without WRITE_ONCE() or READ_ONCE().
-
Failure Manifestation:
- When KCSAN monitors accesses to
vq->last_used_idx, it instruments the write in virtqueue_get_buf_ctx_split() and inserts a delay window. A hard interrupt occurs during this window and executes more_used_split(), which performs an unannotated read on the exact same address 0xffff88810337f55c. KCSAN flags this as an unannotated read-write data race.
Sample crash report:
* Struck through repros no longer work on HEAD.