git: 7572fe89ada6 - main - vmm: Fix compiling error with BHYVE_SNAPSHOT
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 06 Feb 2024 15:40:43 UTC
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7572fe89ada63719b558c6b844e2743cd3ff6b6a commit 7572fe89ada63719b558c6b844e2743cd3ff6b6a Author: Vitaliy Gusev <gusev.vitaliy@gmail.com> AuthorDate: 2024-02-06 15:36:17 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2024-02-06 15:38:34 +0000 vmm: Fix compiling error with BHYVE_SNAPSHOT The return values of copyin() and copyout() must be checked. vm_snapshot_buf_cmp() is unused by the kernel and was incorrectly implemented, so just remove it. Reviewed by: markj Sponsored by: vStack MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D43754 --- sys/amd64/include/vmm_snapshot.h | 7 +++++-- sys/amd64/vmm/vmm_snapshot.c | 44 +++++++--------------------------------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/sys/amd64/include/vmm_snapshot.h b/sys/amd64/include/vmm_snapshot.h index 5ed00c71d58a..b39c342bf6d9 100644 --- a/sys/amd64/include/vmm_snapshot.h +++ b/sys/amd64/include/vmm_snapshot.h @@ -98,8 +98,6 @@ void vm_snapshot_buf_err(const char *bufname, const enum vm_snapshot_op op); 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_buf_cmp(void *data, size_t data_size, - struct vm_snapshot_meta *meta); #define SNAPSHOT_BUF_OR_LEAVE(DATA, LEN, META, RES, LABEL) \ do { \ @@ -113,6 +111,10 @@ do { \ #define SNAPSHOT_VAR_OR_LEAVE(DATA, META, RES, LABEL) \ SNAPSHOT_BUF_OR_LEAVE(&(DATA), sizeof(DATA), (META), (RES), LABEL) +#ifndef _KERNEL +int vm_snapshot_buf_cmp(void *data, size_t data_size, + struct vm_snapshot_meta *meta); + /* compare the value in the meta buffer with the data */ #define SNAPSHOT_BUF_CMP_OR_LEAVE(DATA, LEN, META, RES, LABEL) \ do { \ @@ -126,4 +128,5 @@ do { \ #define SNAPSHOT_VAR_CMP_OR_LEAVE(DATA, META, RES, LABEL) \ SNAPSHOT_BUF_CMP_OR_LEAVE(&(DATA), sizeof(DATA), (META), (RES), LABEL) +#endif /* _KERNEL */ #endif diff --git a/sys/amd64/vmm/vmm_snapshot.c b/sys/amd64/vmm/vmm_snapshot.c index 54de57e04c4a..cd53f05a1603 100644 --- a/sys/amd64/vmm/vmm_snapshot.c +++ b/sys/amd64/vmm/vmm_snapshot.c @@ -57,7 +57,7 @@ int vm_snapshot_buf(void *data, size_t data_size, struct vm_snapshot_meta *meta) { struct vm_snapshot_buffer *buffer; - int op; + int op, error; buffer = &meta->buffer; op = meta->op; @@ -68,11 +68,14 @@ vm_snapshot_buf(void *data, size_t data_size, struct vm_snapshot_meta *meta) } if (op == VM_SNAPSHOT_SAVE) - copyout(data, buffer->buf, data_size); + error = copyout(data, buffer->buf, data_size); else if (op == VM_SNAPSHOT_RESTORE) - copyin(buffer->buf, data, data_size); + error = copyin(buffer->buf, data, data_size); else - return (EINVAL); + error = EINVAL; + + if (error) + return (error); buffer->buf += data_size; buffer->buf_rem -= data_size; @@ -98,36 +101,3 @@ vm_get_snapshot_size(struct vm_snapshot_meta *meta) return (length); } - -int -vm_snapshot_buf_cmp(void *data, size_t data_size, struct vm_snapshot_meta *meta) -{ - struct vm_snapshot_buffer *buffer; - int op; - int ret; - - buffer = &meta->buffer; - op = meta->op; - - if (buffer->buf_rem < data_size) { - printf("%s: buffer too small\r\n", __func__); - ret = E2BIG; - goto done; - } - - if (op == VM_SNAPSHOT_SAVE) { - ret = 0; - copyout(data, buffer->buf, data_size); - } else if (op == VM_SNAPSHOT_RESTORE) { - ret = memcmp(data, buffer->buf, data_size); - } else { - ret = EINVAL; - goto done; - } - - buffer->buf += data_size; - buffer->buf_rem -= data_size; - -done: - return (ret); -}