Skip to content

Commit

Permalink
libvmmapi: Conditionalize compilation of some functions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markjdb committed Apr 10, 2024
1 parent 981f9f7 commit 56a26fc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
1 change: 0 additions & 1 deletion lib/libvmmapi/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

PACKAGE=lib${LIB}
LIB= vmmapi
SHLIB_MAJOR= 6
Expand Down
2 changes: 2 additions & 0 deletions lib/libvmmapi/amd64/Makefile.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SRCS+= ppt.c \
vmmapi_machdep.c \
vmmapi_freebsd_machdep.c

CFLAGS+= -DWITH_VMMAPI_SNAPSHOT
9 changes: 8 additions & 1 deletion lib/libvmmapi/amd64/vmmapi_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 1 addition & 8 deletions lib/libvmmapi/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down
10 changes: 10 additions & 0 deletions lib/libvmmapi/vmmapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/libvmmapi/vmmapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'.
Expand All @@ -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);
Expand Down

0 comments on commit 56a26fc

Please sign in to comment.