Root Cause Analysis
1. Functions, Structs, and Fields Involved
2. Triggering Mechanism and API Invariant Breakdown
According to virtqueue API specifications:
virtqueue_enable_cb_delayed() and virtqueue_enable_cb_prepare() require callers to avoid concurrent invocation with other virtqueue operations "except where noted".
virtqueue_disable_cb() explicitly states: "Unlike other operations, this need not be serialized", and consequently its split and packed implementations intentionally omit START_USE(vq) / END_USE(vq).
- Network drivers such as
virtio_net adhere to this contract by calling virtqueue_disable_cb() directly from the interrupt handler skb_xmit_done() without holding any locks (such as the netdev _xmit_lock).
In virtio_net:
- When TX NAPI is enabled,
start_xmit() transmits packets and, if kicked (kick), calls virtqueue_enable_cb_delayed(sq->vq) at line 3422.
start_xmit() holds the netdev transmission lock (HARD_TX_LOCK / _xmit_lock), but hard interrupts remain enabled.
- An in-flight or newly generated TX completion interrupt triggers
vring_interrupt(), which invokes skb_xmit_done(). This can either preempt start_xmit() on the same CPU or execute concurrently on a different CPU.
skb_xmit_done() invokes virtqueue_disable_cb(vq), which reads and modifies vq->split.avail_flags_shadow:
if (!(vq->split.avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT)) {
vq->split.avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT;
...
}
- Simultaneously,
virtqueue_enable_cb_delayed_split() is modifying the same field without synchronization:
if (vq->split.avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT) {
vq->split.avail_flags_shadow &= ~VRING_AVAIL_F_NO_INTERRUPT;
...
}
Because virtio_ring.c performs plain C read-modify-write operations on vq->split.avail_flags_shadow without atomic access primitives or KCSAN annotations (unlike vq->event_triggered, which is wrapped in data_race(...)), KCSAN flags the conflicting concurrent read and write operations.