Skip to content

Commit f999ffd

Browse files
committed
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 ad17789 this wasn't a problem since an external function call after each poll inhibited the optimization. PR: 289930 MFC after: 3 days Sponsored by: Klara, Inc. Fixes: ad17789 ("virtio: Remove the unused poll method")
1 parent c46e5dc commit f999ffd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sys/dev/virtio/virtqueue.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ virtqueue_dequeue(struct virtqueue *vq, uint32_t *len)
580580
void *cookie;
581581
uint16_t used_idx, desc_idx;
582582

583-
if (vq->vq_used_cons_idx == vq_htog16(vq, vq->vq_ring.used->idx))
583+
if (vq->vq_used_cons_idx ==
584+
vq_htog16(vq, atomic_load_16(&vq->vq_ring.used->idx)))
584585
return (NULL);
585586

586587
used_idx = vq->vq_used_cons_idx++ & (vq->vq_nentries - 1);

0 commit comments

Comments
 (0)