git: 56a26fc1af60 - main - libvmmapi: Conditionalize compilation of some functions

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 10 Apr 2024 15:19:22 UTC
The branch main has been updated by markj:

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

commit 56a26fc1af60e31732f8913ebe4c058095b6c721
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-04-03 17:45:06 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-04-10 15:17:56 +0000

    libvmmapi: Conditionalize compilation of some functions
    
    Hide definitions of several functions that currently don't have
    implementatations in the arm64 vmm port.  In particular, add a
    WITH_VMMAPI_SNAPSHOT preprocessor variable that can be used to enable
    compilation of save/restore functions, and conditionalize compilation of
    some functions only used by amd64 bhyve.  If in the long term they
    remain amd64-only, they can move to vmmapi_machdep.c, but for now it's
    not clear to me that that's the right thing to do.
    
    MFC after:      2 weeks
    Sponsored by:   Innovate UK
---
 lib/libvmmapi/Makefile               |  1 -
 lib/libvmmapi/amd64/Makefile.inc     |  2 ++
 lib/libvmmapi/amd64/vmmapi_machdep.c |  9 ++++++++-
 lib/libvmmapi/internal.h             |  9 +--------
 lib/libvmmapi/vmmapi.c               | 10 ++++++++++
 lib/libvmmapi/vmmapi.h               |  4 +++-
 6 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/lib/libvmmapi/Makefile b/lib/libvmmapi/Makefile
index dc7d48183439..1866c8fa5e7c 100644
--- a/lib/libvmmapi/Makefile
+++ b/lib/libvmmapi/Makefile
@@ -1,4 +1,3 @@
-
 PACKAGE=lib${LIB}
 LIB=	vmmapi
 SHLIB_MAJOR=	6
diff --git a/lib/libvmmapi/amd64/Makefile.inc b/lib/libvmmapi/amd64/Makefile.inc
index d122f742a667..a3da271433a1 100644
--- a/lib/libvmmapi/amd64/Makefile.inc
+++ b/lib/libvmmapi/amd64/Makefile.inc
@@ -1,3 +1,5 @@
 SRCS+=	ppt.c			\
 	vmmapi_machdep.c	\
 	vmmapi_freebsd_machdep.c
+
+CFLAGS+= -DWITH_VMMAPI_SNAPSHOT
diff --git a/lib/libvmmapi/amd64/vmmapi_machdep.c b/lib/libvmmapi/amd64/vmmapi_machdep.c
index 8990b28b4432..806c31abf426 100644
--- a/lib/libvmmapi/amd64/vmmapi_machdep.c
+++ b/lib/libvmmapi/amd64/vmmapi_machdep.c
@@ -77,7 +77,14 @@ const char *vm_capstrmap[] = {
 	VM_RTC_WRITE,			\
 	VM_RTC_READ,			\
 	VM_RTC_SETTIME,			\
-	VM_RTC_GETTIME
+	VM_RTC_GETTIME,			\
+	VM_GET_GPA_PMAP,		\
+	VM_GLA2GPA,			\
+	VM_SET_INTINFO,			\
+	VM_GET_INTINFO,			\
+	VM_RESTART_INSTRUCTION,		\
+	VM_SNAPSHOT_REQ,		\
+	VM_RESTORE_TIME
 
 const cap_ioctl_t vm_ioctl_cmds[] = {
 	VM_COMMON_IOCTLS,
diff --git a/lib/libvmmapi/internal.h b/lib/libvmmapi/internal.h
index 2b2f9eac3757..42be9ec59770 100644
--- a/lib/libvmmapi/internal.h
+++ b/lib/libvmmapi/internal.h
@@ -54,20 +54,13 @@ extern const char *vm_capstrmap[];
 	VM_GET_CAPABILITY,	\
 	VM_STATS,		\
 	VM_STAT_DESC,		\
-	VM_GET_GPA_PMAP,	\
-	VM_GLA2GPA,		\
 	VM_GLA2GPA_NOFAULT,	\
 	VM_ACTIVATE_CPU,	\
 	VM_GET_CPUS,		\
 	VM_SUSPEND_CPU,		\
 	VM_RESUME_CPU,		\
-	VM_SET_INTINFO,		\
-	VM_GET_INTINFO,		\
-	VM_RESTART_INSTRUCTION,	\
 	VM_SET_TOPOLOGY,	\
-	VM_GET_TOPOLOGY,	\
-	VM_SNAPSHOT_REQ,	\
-	VM_RESTORE_TIME
+	VM_GET_TOPOLOGY
 
 #define	VM_PPT_IOCTLS		\
 	VM_BIND_PPTDEV,		\
diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c
index 5dcad8a16703..0cf051567110 100644
--- a/lib/libvmmapi/vmmapi.c
+++ b/lib/libvmmapi/vmmapi.c
@@ -51,7 +51,9 @@
 #include <vm/vm.h>
 #include <machine/vmm.h>
 #include <machine/vmm_dev.h>
+#ifdef WITH_VMMAPI_SNAPSHOT
 #include <machine/vmm_snapshot.h>
+#endif
 
 #include "vmmapi.h"
 #include "internal.h"
@@ -796,6 +798,7 @@ vm_get_stat_desc(struct vmctx *ctx, int index)
 		return (NULL);
 }
 
+#ifdef __amd64__
 int
 vm_get_gpa_pmap(struct vmctx *ctx, uint64_t gpa, uint64_t *pte, int *num)
 {
@@ -835,6 +838,7 @@ vm_gla2gpa(struct vcpu *vcpu, struct vm_guest_paging *paging,
 	}
 	return (error);
 }
+#endif
 
 int
 vm_gla2gpa_nofault(struct vcpu *vcpu, struct vm_guest_paging *paging,
@@ -860,6 +864,7 @@ vm_gla2gpa_nofault(struct vcpu *vcpu, struct vm_guest_paging *paging,
 #define	min(a,b)	(((a) < (b)) ? (a) : (b))
 #endif
 
+#ifdef __amd64__
 int
 vm_copy_setup(struct vcpu *vcpu, struct vm_guest_paging *paging,
     uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt,
@@ -897,6 +902,7 @@ vm_copy_setup(struct vcpu *vcpu, struct vm_guest_paging *paging,
 	}
 	return (0);
 }
+#endif
 
 void
 vm_copy_teardown(struct iovec *iov __unused, int iovcnt __unused)
@@ -1041,6 +1047,7 @@ vm_resume_all_cpus(struct vmctx *ctx)
 	return (error);
 }
 
+#ifdef __amd64__
 int
 vm_get_intinfo(struct vcpu *vcpu, uint64_t *info1, uint64_t *info2)
 {
@@ -1067,7 +1074,9 @@ vm_set_intinfo(struct vcpu *vcpu, uint64_t info1)
 	error = vcpu_ioctl(vcpu, VM_SET_INTINFO, &vmii);
 	return (error);
 }
+#endif
 
+#ifdef WITH_VMMAPI_SNAPSHOT
 int
 vm_restart_instruction(struct vcpu *vcpu)
 {
@@ -1098,6 +1107,7 @@ vm_restore_time(struct vmctx *ctx)
 	dummy = 0;
 	return (ioctl(ctx->fd, VM_RESTORE_TIME, &dummy));
 }
+#endif
 
 int
 vm_set_topology(struct vmctx *ctx,
diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h
index ea869a0c1749..d2a217c4d2e9 100644
--- a/lib/libvmmapi/vmmapi.h
+++ b/lib/libvmmapi/vmmapi.h
@@ -128,9 +128,11 @@ int	vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);
 void	*vm_map_gpa(struct vmctx *ctx, vm_paddr_t gaddr, size_t len);
 /* inverse operation to vm_map_gpa - extract guest address from host pointer */
 vm_paddr_t vm_rev_map_gpa(struct vmctx *ctx, void *addr);
+#ifdef __amd64__
 int	vm_get_gpa_pmap(struct vmctx *, uint64_t gpa, uint64_t *pte, int *num);
 int	vm_gla2gpa(struct vcpu *vcpu, struct vm_guest_paging *paging,
 		   uint64_t gla, int prot, uint64_t *gpa, int *fault);
+#endif
 int	vm_gla2gpa_nofault(struct vcpu *vcpu,
 		   struct vm_guest_paging *paging, uint64_t gla, int prot,
 		   uint64_t *gpa, int *fault);
@@ -220,7 +222,6 @@ int	vm_get_x2apic_state(struct vcpu *vcpu, enum x2apic_state *s);
 int	vm_set_x2apic_state(struct vcpu *vcpu, enum x2apic_state s);
 
 int	vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities);
-#endif
 
 /*
  * Translate the GLA range [gla,gla+len) into GPA segments in 'iov'.
@@ -234,6 +235,7 @@ int	vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities);
 int	vm_copy_setup(struct vcpu *vcpu, struct vm_guest_paging *pg,
 	    uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt,
 	    int *fault);
+#endif
 void	vm_copyin(struct iovec *guest_iov, void *host_dst, size_t len);
 void	vm_copyout(const void *host_src, struct iovec *guest_iov, size_t len);
 void	vm_copy_teardown(struct iovec *iov, int iovcnt);