git: 593200c23b57 - main - bhyve: Drop volatile qualifiers from virtio rings

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Fri, 11 Nov 2022 15:04:09 UTC
The branch main has been updated by markj:

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

commit 593200c23b57ea6977bf5084b91fc5c63dacbb80
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-11-11 15:02:10 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-11-11 15:02:10 +0000

    bhyve: Drop volatile qualifiers from virtio rings
    
    The qualifiers are there presumably because these rings are mapped into
    the guest, but they do not appear to be required for correctness, and
    bhyve generally doesn't qualify accesses to guest memory this way.
    Moreover, the qualifiers are discarded by snapshot code, causing clang
    to emit warnings.  Just stop using volatile here.
    
    MFC after:      2 weeks
    Reviewed by:    corvink, jhb
    Differential Revision:  https://reviews.freebsd.org/D37291
---
 usr.sbin/bhyve/virtio.c | 13 ++++++-------
 usr.sbin/bhyve/virtio.h |  8 ++++----
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/usr.sbin/bhyve/virtio.c b/usr.sbin/bhyve/virtio.c
index 32dd9336c5df..dc3a2d10d5b5 100644
--- a/usr.sbin/bhyve/virtio.c
+++ b/usr.sbin/bhyve/virtio.c
@@ -214,10 +214,9 @@ vi_vq_init(struct virtio_softc *vs, uint32_t pfn)
  * descriptor.
  */
 static inline void
-_vq_record(int i, volatile struct vring_desc *vd,
-	   struct vmctx *ctx, struct iovec *iov, int n_iov,
-	   struct vi_req *reqp) {
-
+_vq_record(int i, struct vring_desc *vd, struct vmctx *ctx, struct iovec *iov,
+    int n_iov, struct vi_req *reqp)
+{
 	if (i >= n_iov)
 		return;
 	iov[i].iov_base = paddr_guest2host(ctx, vd->addr, vd->len);
@@ -271,7 +270,7 @@ vq_getchain(struct vqueue_info *vq, struct iovec *iov, int niov,
 	u_int ndesc, n_indir;
 	u_int idx, next;
 	struct vi_req req;
-	volatile struct vring_desc *vdir, *vindir, *vp;
+	struct vring_desc *vdir, *vindir, *vp;
 	struct vmctx *ctx;
 	struct virtio_softc *vs;
 	const char *name;
@@ -409,8 +408,8 @@ vq_retchains(struct vqueue_info *vq, uint16_t n_chains)
 void
 vq_relchain_prepare(struct vqueue_info *vq, uint16_t idx, uint32_t iolen)
 {
-	volatile struct vring_used *vuh;
-	volatile struct vring_used_elem *vue;
+	struct vring_used *vuh;
+	struct vring_used_elem *vue;
 	uint16_t mask;
 
 	/*
diff --git a/usr.sbin/bhyve/virtio.h b/usr.sbin/bhyve/virtio.h
index 5300fb5dbef3..7b50969e57a9 100644
--- a/usr.sbin/bhyve/virtio.h
+++ b/usr.sbin/bhyve/virtio.h
@@ -314,14 +314,14 @@ struct vqueue_info {
 
 	uint32_t vq_pfn;	/* PFN of virt queue (not shifted!) */
 
-	volatile struct vring_desc *vq_desc;	/* descriptor array */
-	volatile struct vring_avail *vq_avail;	/* the "avail" ring */
-	volatile struct vring_used *vq_used;	/* the "used" ring */
+	struct vring_desc *vq_desc;	/* descriptor array */
+	struct vring_avail *vq_avail;	/* the "avail" ring */
+	struct vring_used *vq_used;	/* the "used" ring */
 
 };
 /* as noted above, these are sort of backwards, name-wise */
 #define VQ_AVAIL_EVENT_IDX(vq) \
-	(*(volatile uint16_t *)&(vq)->vq_used->ring[(vq)->vq_qsize])
+	(*(uint16_t *)&(vq)->vq_used->ring[(vq)->vq_qsize])
 #define VQ_USED_EVENT_IDX(vq) \
 	((vq)->vq_avail->ring[(vq)->vq_qsize])