git: virtio: Fix cpu_lfence() wrong placement in virtqueue_dequeue()
Aaron LI
aly at crater.dragonflybsd.org
Tue Mar 3 00:17:04 PST 2026
commit 8dd5dbc6b251e624a1739962ec7b7ba6d5a30814
Author: Aaron LI <aly at aaronly.me>
Date: Mon Sep 29 21:28:30 2025 +0800
virtio: Fix cpu_lfence() wrong placement in virtqueue_dequeue()
The cpu_lfence() should be placed just after reading the 'used->idx',
before the 'vq_used_cons_idx' equality check and 'used->ring[]' access.
This is the correct use pattern of lfence.
More importantly, this fix an infinite loop in virtqueue_poll() that
happened when GCC 12.5 inlined the whole virtqueue_dequeue(). GCC
thought 'vq->vq_ring.used->idx' wouldn't change during the loop, so
hoisted the 'if (vq->vq_used_cons_idx == vq->vq_ring.used->idx)' into
its own loop and thus an infinite loop.
Maybe it's better to use atomic ops to read the 'vq_ring.used->idx' and
'vq_ring.used->flags' fields, which are updated by the host side. Need
to investigate this later.
Summary of changes:
sys/dev/virtual/virtio/virtio/virtqueue.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/8dd5dbc6b251e624a1739962ec7b7ba6d5a30814
--
DragonFly BSD source repository
More information about the Commits
mailing list