git: 8b1adff8bcbd - main - bhyve: Drop volatile qualifiers from snapshot code

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

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

commit 8b1adff8bcbdf0e58878431c6ed5a14553178d4d
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-11-11 15:02:26 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-11-11 15:02:26 +0000

    bhyve: Drop volatile qualifiers from snapshot code
    
    They accomplish nothing since the qualifier is casted away in calls to
    memcpy() and copyin()/copyout().  No functional change intended.
    
    MFC after:      2 weeks
    Reviewed by:    corvink, jhb
    Differential Revision:  https://reviews.freebsd.org/D37292
---
 sys/amd64/include/vmm_snapshot.h | 10 +++++-----
 sys/amd64/vmm/vmm_snapshot.c     | 17 ++++++-----------
 usr.sbin/bhyve/snapshot.c        | 14 ++++++--------
 3 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/sys/amd64/include/vmm_snapshot.h b/sys/amd64/include/vmm_snapshot.h
index 8d1ecc1db4b1..d08f980e7988 100644
--- a/sys/amd64/include/vmm_snapshot.h
+++ b/sys/amd64/include/vmm_snapshot.h
@@ -101,13 +101,13 @@ struct vm_snapshot_meta {
 };
 
 void vm_snapshot_buf_err(const char *bufname, const enum vm_snapshot_op op);
-int vm_snapshot_buf(volatile void *data, size_t data_size,
-		    struct vm_snapshot_meta *meta);
+int vm_snapshot_buf(void *data, size_t data_size,
+    struct vm_snapshot_meta *meta);
 size_t vm_get_snapshot_size(struct vm_snapshot_meta *meta);
 int vm_snapshot_guest2host_addr(void **addrp, size_t len, bool restore_null,
-				struct vm_snapshot_meta *meta);
-int vm_snapshot_buf_cmp(volatile void *data, size_t data_size,
-			      struct vm_snapshot_meta *meta);
+    struct vm_snapshot_meta *meta);
+int vm_snapshot_buf_cmp(void *data, size_t data_size,
+    struct vm_snapshot_meta *meta);
 
 #define	SNAPSHOT_BUF_OR_LEAVE(DATA, LEN, META, RES, LABEL)			\
 do {										\
diff --git a/sys/amd64/vmm/vmm_snapshot.c b/sys/amd64/vmm/vmm_snapshot.c
index c77bb05f76b7..1e5f57028523 100644
--- a/sys/amd64/vmm/vmm_snapshot.c
+++ b/sys/amd64/vmm/vmm_snapshot.c
@@ -57,14 +57,11 @@ vm_snapshot_buf_err(const char *bufname, const enum vm_snapshot_op op)
 }
 
 int
-vm_snapshot_buf(volatile void *data, size_t data_size,
-	     struct vm_snapshot_meta *meta)
+vm_snapshot_buf(void *data, size_t data_size, struct vm_snapshot_meta *meta)
 {
 	struct vm_snapshot_buffer *buffer;
 	int op;
-	void *nv_data;
 
-	nv_data = __DEVOLATILE(void *, data);
 	buffer = &meta->buffer;
 	op = meta->op;
 
@@ -74,9 +71,9 @@ vm_snapshot_buf(volatile void *data, size_t data_size,
 	}
 
 	if (op == VM_SNAPSHOT_SAVE)
-		copyout(nv_data, buffer->buf, data_size);
+		copyout(data, buffer->buf, data_size);
 	else if (op == VM_SNAPSHOT_RESTORE)
-		copyin(buffer->buf, nv_data, data_size);
+		copyin(buffer->buf, data, data_size);
 	else
 		return (EINVAL);
 
@@ -106,13 +103,11 @@ vm_get_snapshot_size(struct vm_snapshot_meta *meta)
 }
 
 int
-vm_snapshot_buf_cmp(volatile void *data, size_t data_size,
-		    struct vm_snapshot_meta *meta)
+vm_snapshot_buf_cmp(void *data, size_t data_size, struct vm_snapshot_meta *meta)
 {
 	struct vm_snapshot_buffer *buffer;
 	int op;
 	int ret;
-	void *_data = *(void **)(void *)&data;
 
 	buffer = &meta->buffer;
 	op = meta->op;
@@ -125,9 +120,9 @@ vm_snapshot_buf_cmp(volatile void *data, size_t data_size,
 
 	if (op == VM_SNAPSHOT_SAVE) {
 		ret = 0;
-		copyout(_data, buffer->buf, data_size);
+		copyout(data, buffer->buf, data_size);
 	} else if (op == VM_SNAPSHOT_RESTORE) {
-		ret = memcmp(_data, buffer->buf, data_size);
+		ret = memcmp(data, buffer->buf, data_size);
 	} else {
 		ret = EINVAL;
 		goto done;
diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c
index 0c7267316a17..6f4e3c1f91a2 100644
--- a/usr.sbin/bhyve/snapshot.c
+++ b/usr.sbin/bhyve/snapshot.c
@@ -1584,8 +1584,7 @@ vm_snapshot_buf_err(const char *bufname, const enum vm_snapshot_op op)
 }
 
 int
-vm_snapshot_buf(volatile void *data, size_t data_size,
-		struct vm_snapshot_meta *meta)
+vm_snapshot_buf(void *data, size_t data_size, struct vm_snapshot_meta *meta)
 {
 	struct vm_snapshot_buffer *buffer;
 	int op;
@@ -1599,9 +1598,9 @@ vm_snapshot_buf(volatile void *data, size_t data_size,
 	}
 
 	if (op == VM_SNAPSHOT_SAVE)
-		memcpy(buffer->buf, (uint8_t *) data, data_size);
+		memcpy(buffer->buf, data, data_size);
 	else if (op == VM_SNAPSHOT_RESTORE)
-		memcpy((uint8_t *) data, buffer->buf, data_size);
+		memcpy(data, buffer->buf, data_size);
 	else
 		return (EINVAL);
 
@@ -1667,8 +1666,7 @@ done:
 }
 
 int
-vm_snapshot_buf_cmp(volatile void *data, size_t data_size,
-		    struct vm_snapshot_meta *meta)
+vm_snapshot_buf_cmp(void *data, size_t data_size, struct vm_snapshot_meta *meta)
 {
 	struct vm_snapshot_buffer *buffer;
 	int op;
@@ -1685,9 +1683,9 @@ vm_snapshot_buf_cmp(volatile void *data, size_t data_size,
 
 	if (op == VM_SNAPSHOT_SAVE) {
 		ret = 0;
-		memcpy(buffer->buf, (uint8_t *) data, data_size);
+		memcpy(buffer->buf, data, data_size);
 	} else if (op == VM_SNAPSHOT_RESTORE) {
-		ret = memcmp((uint8_t *) data, buffer->buf, data_size);
+		ret = memcmp(data, buffer->buf, data_size);
 	} else {
 		ret = EINVAL;
 		goto done;