Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Nov 2025 14:36:09 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: f999ffdce381 - main - virtio: Fix polling in virtqueue_dequeue()
Message-ID:  <202511041436.5A4Ea9x8004926@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=f999ffdce3813eb946f10999ccffb8275c324469

commit f999ffdce3813eb946f10999ccffb8275c324469
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-11-04 14:27:33 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-11-04 14:35:31 +0000

    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.
    
    PR:             289930
    MFC after:      3 days
    Sponsored by:   Klara, Inc.
    Fixes:          ad17789a8569 ("virtio: Remove the unused poll method")
---
 sys/dev/virtio/virtqueue.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202511041436.5A4Ea9x8004926>