aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2025-11-04 14:27:33 +0000
committerColin Percival <cperciva@FreeBSD.org>2025-11-07 15:12:02 -0800
commit69c726c150772c36854d38e51b6fd921a04caea5 (patch)
treeef59b2ac7adb74ffd63fcc4e1f5af3d798c34b67
parent3447fc070cc205671ac33e1582c023033094de7f (diff)
virtio: Fix polling in virtqueue_dequeue()
The access of vq->vq_ring.used->idx needs to be volatile-qualified, otherwise the compiler may optimize virtqueue_poll() into an infinite loop if there is no data available upon the first poll. Prior to commit ad17789a8569 this wasn't a problem since an external function call after each poll inhibited the optimization. Approved by: re (cperciva) PR: 289930 MFC after: 3 days Sponsored by: Klara, Inc. Fixes: ad17789a8569 ("virtio: Remove the unused poll method") (cherry picked from commit f999ffdce3813eb946f10999ccffb8275c324469) (cherry picked from commit 72c76047541ab6cc0e989a74e8de4d6e6a1a94b6)
-rw-r--r--sys/dev/virtio/virtqueue.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sys/dev/virtio/virtqueue.c b/sys/dev/virtio/virtqueue.c
index cc7a233d60ee..41e01549c8b2 100644
--- a/sys/dev/virtio/virtqueue.c
+++ b/sys/dev/virtio/virtqueue.c
@@ -580,7 +580,8 @@ virtqueue_dequeue(struct virtqueue *vq, uint32_t *len)
void *cookie;
uint16_t used_idx, desc_idx;
- if (vq->vq_used_cons_idx == vq_htog16(vq, vq->vq_ring.used->idx))
+ if (vq->vq_used_cons_idx ==
+ vq_htog16(vq, atomic_load_16(&vq->vq_ring.used->idx)))
return (NULL);
used_idx = vq->vq_used_cons_idx++ & (vq->vq_nentries - 1);