Module Name: src Committed By: maxv Date: Sat May 11 07:31:57 UTC 2019
Modified Files: src/lib/libnvmm: libnvmm.c libnvmm_x86.c nvmm.h src/sys/dev/nvmm: nvmm.c nvmm.h src/sys/dev/nvmm/x86: nvmm_x86.h nvmm_x86_svm.c nvmm_x86_vmx.c src/tests/lib/libnvmm: h_io_assist.c h_mem_assist.c Log Message: Rework the machine configuration interface. Provide three ranges in the conf space: <libnvmm:0-100>, <MI:100-200> and <MD:200-...>. Remove nvmm_callbacks_register(), and replace it by the conf op NVMM_MACH_CONF_CALLBACKS, handled by libnvmm. The callbacks are now per-machine, and the emulators should now do: - nvmm_callbacks_register(&cbs); + nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &cbs); This provides more granularity, for example if the process runs two VMs and wants different callbacks for each. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libnvmm/libnvmm.c cvs rdiff -u -r1.29 -r1.30 src/lib/libnvmm/libnvmm_x86.c cvs rdiff -u -r1.10 -r1.11 src/lib/libnvmm/nvmm.h cvs rdiff -u -r1.20 -r1.21 src/sys/dev/nvmm/nvmm.c cvs rdiff -u -r1.9 -r1.10 src/sys/dev/nvmm/nvmm.h cvs rdiff -u -r1.14 -r1.15 src/sys/dev/nvmm/x86/nvmm_x86.h cvs rdiff -u -r1.45 -r1.46 src/sys/dev/nvmm/x86/nvmm_x86_svm.c cvs rdiff -u -r1.33 -r1.34 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libnvmm/h_io_assist.c cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libnvmm/h_mem_assist.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libnvmm/libnvmm.c diff -u src/lib/libnvmm/libnvmm.c:1.12 src/lib/libnvmm/libnvmm.c:1.13 --- src/lib/libnvmm/libnvmm.c:1.12 Wed May 1 09:20:21 2019 +++ src/lib/libnvmm/libnvmm.c Sat May 11 07:31:57 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: libnvmm.c,v 1.12 2019/05/01 09:20:21 maxv Exp $ */ +/* $NetBSD: libnvmm.c,v 1.13 2019/05/11 07:31:57 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -44,7 +44,6 @@ #include "nvmm.h" -static struct nvmm_callbacks __callbacks; static struct nvmm_capability __capability; #ifdef __x86_64__ @@ -255,6 +254,12 @@ nvmm_machine_configure(struct nvmm_machi struct nvmm_ioc_machine_configure args; int ret; + switch (op) { + case NVMM_MACH_CONF_CALLBACKS: + memcpy(&mach->cbs, conf, sizeof(mach->cbs)); + return 0; + } + args.machid = mach->machid; args.op = op; args.conf = conf; @@ -510,12 +515,6 @@ nvmm_gpa_to_hva(struct nvmm_machine *mac * nvmm_assist_mem(): architecture-specific. */ -void -nvmm_callbacks_register(const struct nvmm_callbacks *cbs) -{ - memcpy(&__callbacks, cbs, sizeof(__callbacks)); -} - int nvmm_ctl(int op, void *data, size_t size) { Index: src/lib/libnvmm/libnvmm_x86.c diff -u src/lib/libnvmm/libnvmm_x86.c:1.29 src/lib/libnvmm/libnvmm_x86.c:1.30 --- src/lib/libnvmm/libnvmm_x86.c:1.29 Sun Apr 28 14:22:13 2019 +++ src/lib/libnvmm/libnvmm_x86.c Sat May 11 07:31:57 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: libnvmm_x86.c,v 1.29 2019/04/28 14:22:13 maxv Exp $ */ +/* $NetBSD: libnvmm_x86.c,v 1.30 2019/05/11 07:31:57 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -606,7 +606,7 @@ read_guest_memory(struct nvmm_machine *m mem.gpa = gpa; mem.write = false; mem.size = size; - (*__callbacks.mem)(&mem); + (*mach->cbs.mem)(&mem); } else { if (__predict_false(!(prot & NVMM_PROT_READ))) { errno = EFAULT; @@ -660,7 +660,7 @@ write_guest_memory(struct nvmm_machine * mem.gpa = gpa; mem.write = true; mem.size = size; - (*__callbacks.mem)(&mem); + (*mach->cbs.mem)(&mem); } else { if (__predict_false(!(prot & NVMM_PROT_WRITE))) { errno = EFAULT; @@ -706,7 +706,7 @@ assist_io_batch(struct nvmm_machine *mac } for (i = 0; i < iocnt; i++) { - (*__callbacks.io)(io); + (*mach->cbs.io)(io); io->data += io->size; } @@ -816,7 +816,7 @@ nvmm_assist_io(struct nvmm_machine *mach } } - (*__callbacks.io)(&io); + (*mach->cbs.io)(&io); if (io.in) { if (!exit->u.io.str) { @@ -865,19 +865,19 @@ out: struct x86_emul { bool read; bool notouch; - void (*func)(struct nvmm_mem *, uint64_t *); + void (*func)(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); }; -static void x86_func_or(struct nvmm_mem *, uint64_t *); -static void x86_func_and(struct nvmm_mem *, uint64_t *); -static void x86_func_sub(struct nvmm_mem *, uint64_t *); -static void x86_func_xor(struct nvmm_mem *, uint64_t *); -static void x86_func_cmp(struct nvmm_mem *, uint64_t *); -static void x86_func_test(struct nvmm_mem *, uint64_t *); -static void x86_func_mov(struct nvmm_mem *, uint64_t *); -static void x86_func_stos(struct nvmm_mem *, uint64_t *); -static void x86_func_lods(struct nvmm_mem *, uint64_t *); -static void x86_func_movs(struct nvmm_mem *, uint64_t *); +static void x86_func_or(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); +static void x86_func_and(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); +static void x86_func_sub(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); +static void x86_func_xor(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); +static void x86_func_cmp(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); +static void x86_func_test(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); +static void x86_func_mov(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); +static void x86_func_stos(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); +static void x86_func_lods(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); +static void x86_func_movs(struct nvmm_machine *, struct nvmm_mem *, uint64_t *); static const struct x86_emul x86_emul_or = { .read = true, @@ -2631,7 +2631,7 @@ EXEC_DISPATCHER(xor) */ static void -x86_func_or(struct nvmm_mem *mem, uint64_t *gprs) +x86_func_or(struct nvmm_machine *mach, struct nvmm_mem *mem, uint64_t *gprs) { uint64_t *retval = (uint64_t *)mem->data; const bool write = mem->write; @@ -2643,7 +2643,7 @@ x86_func_or(struct nvmm_mem *mem, uint64 /* Fetch the value to be OR'ed (op2). */ mem->data = (uint8_t *)&op2; mem->write = false; - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); /* Perform the OR. */ ret = exec_or(*op1, op2, &fl, mem->size); @@ -2652,7 +2652,7 @@ x86_func_or(struct nvmm_mem *mem, uint64 /* Write back the result. */ mem->data = (uint8_t *)&ret; mem->write = true; - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); } else { /* Return data to the caller. */ *retval = ret; @@ -2663,7 +2663,7 @@ x86_func_or(struct nvmm_mem *mem, uint64 } static void -x86_func_and(struct nvmm_mem *mem, uint64_t *gprs) +x86_func_and(struct nvmm_machine *mach, struct nvmm_mem *mem, uint64_t *gprs) { uint64_t *retval = (uint64_t *)mem->data; const bool write = mem->write; @@ -2675,7 +2675,7 @@ x86_func_and(struct nvmm_mem *mem, uint6 /* Fetch the value to be AND'ed (op2). */ mem->data = (uint8_t *)&op2; mem->write = false; - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); /* Perform the AND. */ ret = exec_and(*op1, op2, &fl, mem->size); @@ -2684,7 +2684,7 @@ x86_func_and(struct nvmm_mem *mem, uint6 /* Write back the result. */ mem->data = (uint8_t *)&ret; mem->write = true; - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); } else { /* Return data to the caller. */ *retval = ret; @@ -2695,7 +2695,7 @@ x86_func_and(struct nvmm_mem *mem, uint6 } static void -x86_func_sub(struct nvmm_mem *mem, uint64_t *gprs) +x86_func_sub(struct nvmm_machine *mach, struct nvmm_mem *mem, uint64_t *gprs) { uint64_t *retval = (uint64_t *)mem->data; const bool write = mem->write; @@ -2710,7 +2710,7 @@ x86_func_sub(struct nvmm_mem *mem, uint6 /* Fetch the value to be SUB'ed (op1 or op2). */ mem->data = (uint8_t *)&tmp; mem->write = false; - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); /* Perform the SUB. */ ret = exec_sub(*op1, *op2, &fl, mem->size); @@ -2719,7 +2719,7 @@ x86_func_sub(struct nvmm_mem *mem, uint6 /* Write back the result. */ mem->data = (uint8_t *)&ret; mem->write = true; - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); } else { /* Return data to the caller. */ *retval = ret; @@ -2730,7 +2730,7 @@ x86_func_sub(struct nvmm_mem *mem, uint6 } static void -x86_func_xor(struct nvmm_mem *mem, uint64_t *gprs) +x86_func_xor(struct nvmm_machine *mach, struct nvmm_mem *mem, uint64_t *gprs) { uint64_t *retval = (uint64_t *)mem->data; const bool write = mem->write; @@ -2742,7 +2742,7 @@ x86_func_xor(struct nvmm_mem *mem, uint6 /* Fetch the value to be XOR'ed (op2). */ mem->data = (uint8_t *)&op2; mem->write = false; - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); /* Perform the XOR. */ ret = exec_xor(*op1, op2, &fl, mem->size); @@ -2751,7 +2751,7 @@ x86_func_xor(struct nvmm_mem *mem, uint6 /* Write back the result. */ mem->data = (uint8_t *)&ret; mem->write = true; - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); } else { /* Return data to the caller. */ *retval = ret; @@ -2762,7 +2762,7 @@ x86_func_xor(struct nvmm_mem *mem, uint6 } static void -x86_func_cmp(struct nvmm_mem *mem, uint64_t *gprs) +x86_func_cmp(struct nvmm_machine *mach, struct nvmm_mem *mem, uint64_t *gprs) { uint64_t *op1, *op2, fl; uint64_t tmp; @@ -2775,7 +2775,7 @@ x86_func_cmp(struct nvmm_mem *mem, uint6 /* Fetch the value to be CMP'ed (op1 or op2). */ mem->data = (uint8_t *)&tmp; mem->write = false; - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); /* Perform the CMP. */ exec_sub(*op1, *op2, &fl, mem->size); @@ -2785,7 +2785,7 @@ x86_func_cmp(struct nvmm_mem *mem, uint6 } static void -x86_func_test(struct nvmm_mem *mem, uint64_t *gprs) +x86_func_test(struct nvmm_machine *mach, struct nvmm_mem *mem, uint64_t *gprs) { uint64_t *op1, *op2, fl; uint64_t tmp; @@ -2798,7 +2798,7 @@ x86_func_test(struct nvmm_mem *mem, uint /* Fetch the value to be TEST'ed (op1 or op2). */ mem->data = (uint8_t *)&tmp; mem->write = false; - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); /* Perform the TEST. */ exec_and(*op1, *op2, &fl, mem->size); @@ -2808,21 +2808,21 @@ x86_func_test(struct nvmm_mem *mem, uint } static void -x86_func_mov(struct nvmm_mem *mem, uint64_t *gprs) +x86_func_mov(struct nvmm_machine *mach, struct nvmm_mem *mem, uint64_t *gprs) { /* * Nothing special, just move without emulation. */ - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); } static void -x86_func_stos(struct nvmm_mem *mem, uint64_t *gprs) +x86_func_stos(struct nvmm_machine *mach, struct nvmm_mem *mem, uint64_t *gprs) { /* * Just move, and update RDI. */ - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); if (gprs[NVMM_X64_GPR_RFLAGS] & PSL_D) { gprs[NVMM_X64_GPR_RDI] -= mem->size; @@ -2832,12 +2832,12 @@ x86_func_stos(struct nvmm_mem *mem, uint } static void -x86_func_lods(struct nvmm_mem *mem, uint64_t *gprs) +x86_func_lods(struct nvmm_machine *mach, struct nvmm_mem *mem, uint64_t *gprs) { /* * Just move, and update RSI. */ - (*__callbacks.mem)(mem); + (*mach->cbs.mem)(mem); if (gprs[NVMM_X64_GPR_RFLAGS] & PSL_D) { gprs[NVMM_X64_GPR_RSI] -= mem->size; @@ -2847,7 +2847,7 @@ x86_func_lods(struct nvmm_mem *mem, uint } static void -x86_func_movs(struct nvmm_mem *mem, uint64_t *gprs) +x86_func_movs(struct nvmm_machine *mach, struct nvmm_mem *mem, uint64_t *gprs) { /* * Special instruction: double memory operand. Don't call the cb, @@ -3047,7 +3047,7 @@ assist_mem_double(struct nvmm_machine *m return -1; mem.size = size; - (*instr->emul->func)(&mem, state->gprs); + (*instr->emul->func)(mach, &mem, state->gprs); return 0; } @@ -3124,7 +3124,7 @@ assist_mem_single(struct nvmm_machine *m memcpy(mem.data, &val, mem.size); } - (*instr->emul->func)(&mem, state->gprs); + (*instr->emul->func)(mach, &mem, state->gprs); if (!instr->emul->notouch && !mem.write) { if (instr->dst.type != STORE_REG) { Index: src/lib/libnvmm/nvmm.h diff -u src/lib/libnvmm/nvmm.h:1.10 src/lib/libnvmm/nvmm.h:1.11 --- src/lib/libnvmm/nvmm.h:1.10 Sun Apr 28 14:22:13 2019 +++ src/lib/libnvmm/nvmm.h Sat May 11 07:31:57 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: nvmm.h,v 1.10 2019/04/28 14:22:13 maxv Exp $ */ +/* $NetBSD: nvmm.h,v 1.11 2019/05/11 07:31:57 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -38,13 +38,6 @@ #include <dev/nvmm/nvmm.h> #include <dev/nvmm/nvmm_ioctl.h> -struct nvmm_machine { - nvmm_machid_t machid; - struct nvmm_comm_page **pages; - size_t npages; - void *areas; /* opaque */ -}; - struct nvmm_io { uint64_t port; bool in; @@ -64,6 +57,16 @@ struct nvmm_callbacks { void (*mem)(struct nvmm_mem *); }; +struct nvmm_machine { + nvmm_machid_t machid; + struct nvmm_comm_page **pages; + size_t npages; + void *areas; /* opaque */ + struct nvmm_callbacks cbs; +}; + +#define NVMM_MACH_CONF_CALLBACKS NVMM_MACH_CONF_LIBNVMM_BEGIN + #define NVMM_PROT_READ 0x01 #define NVMM_PROT_WRITE 0x02 #define NVMM_PROT_EXEC 0x04 @@ -96,7 +99,6 @@ int nvmm_gpa_to_hva(struct nvmm_machine int nvmm_assist_io(struct nvmm_machine *, nvmm_cpuid_t, struct nvmm_exit *); int nvmm_assist_mem(struct nvmm_machine *, nvmm_cpuid_t, struct nvmm_exit *); -void nvmm_callbacks_register(const struct nvmm_callbacks *); int nvmm_ctl(int, void *, size_t); Index: src/sys/dev/nvmm/nvmm.c diff -u src/sys/dev/nvmm/nvmm.c:1.20 src/sys/dev/nvmm/nvmm.c:1.21 --- src/sys/dev/nvmm/nvmm.c:1.20 Wed May 1 09:20:21 2019 +++ src/sys/dev/nvmm/nvmm.c Sat May 11 07:31:56 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: nvmm.c,v 1.20 2019/05/01 09:20:21 maxv Exp $ */ +/* $NetBSD: nvmm.c,v 1.21 2019/05/11 07:31:56 maxv Exp $ */ /* * Copyright (c) 2018-2019 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.20 2019/05/01 09:20:21 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.21 2019/05/11 07:31:56 maxv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -338,14 +338,16 @@ nvmm_machine_configure(struct nvmm_owner { struct nvmm_machine *mach; size_t allocsz; + uint64_t op; void *data; int error; - if (__predict_false(args->op >= nvmm_impl->conf_max)) { + op = NVMM_MACH_CONF_MD(args->op); + if (__predict_false(op >= nvmm_impl->conf_max)) { return EINVAL; } - allocsz = nvmm_impl->conf_sizes[args->op]; + allocsz = nvmm_impl->conf_sizes[op]; data = kmem_alloc(allocsz, KM_SLEEP); error = nvmm_machine_get(owner, args->machid, &mach, true); @@ -359,7 +361,7 @@ nvmm_machine_configure(struct nvmm_owner goto out; } - error = (*nvmm_impl->machine_configure)(mach, args->op, data); + error = (*nvmm_impl->machine_configure)(mach, op, data); out: nvmm_machine_put(mach); Index: src/sys/dev/nvmm/nvmm.h diff -u src/sys/dev/nvmm/nvmm.h:1.9 src/sys/dev/nvmm/nvmm.h:1.10 --- src/sys/dev/nvmm/nvmm.h:1.9 Wed May 1 09:20:21 2019 +++ src/sys/dev/nvmm/nvmm.h Sat May 11 07:31:56 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: nvmm.h,v 1.9 2019/05/01 09:20:21 maxv Exp $ */ +/* $NetBSD: nvmm.h,v 1.10 2019/05/11 07:31:56 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -94,6 +94,13 @@ struct nvmm_capability { struct nvmm_cap_md arch; }; +/* Configuration slots. */ +#define NVMM_MACH_CONF_LIBNVMM_BEGIN 0 +#define NVMM_MACH_CONF_MI_BEGIN 100 +#define NVMM_MACH_CONF_MD_BEGIN 200 + +#define NVMM_MACH_CONF_MD(op) (op - NVMM_MACH_CONF_MD_BEGIN) + struct nvmm_comm_page { /* State. */ uint64_t state_wanted; Index: src/sys/dev/nvmm/x86/nvmm_x86.h diff -u src/sys/dev/nvmm/x86/nvmm_x86.h:1.14 src/sys/dev/nvmm/x86/nvmm_x86.h:1.15 --- src/sys/dev/nvmm/x86/nvmm_x86.h:1.14 Wed May 1 09:20:21 2019 +++ src/sys/dev/nvmm/x86/nvmm_x86.h Sat May 11 07:31:56 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: nvmm_x86.h,v 1.14 2019/05/01 09:20:21 maxv Exp $ */ +/* $NetBSD: nvmm_x86.h,v 1.15 2019/05/11 07:31:56 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -231,10 +231,10 @@ struct nvmm_x64_state { #define nvmm_vcpu_state nvmm_x64_state -#define NVMM_X86_CONF_CPUID 0 -#define NVMM_X86_NCONF 1 +#define NVMM_MACH_CONF_X86_CPUID NVMM_MACH_CONF_MD_BEGIN +#define NVMM_X86_NCONF 1 -struct nvmm_x86_conf_cpuid { +struct nvmm_mach_conf_x86_cpuid { uint32_t leaf; struct { uint32_t eax; Index: src/sys/dev/nvmm/x86/nvmm_x86_svm.c diff -u src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.45 src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.46 --- src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.45 Wed May 1 09:20:21 2019 +++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c Sat May 11 07:31:56 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: nvmm_x86_svm.c,v 1.45 2019/05/01 09:20:21 maxv Exp $ */ +/* $NetBSD: nvmm_x86_svm.c,v 1.46 2019/05/11 07:31:56 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.45 2019/05/01 09:20:21 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.46 2019/05/11 07:31:56 maxv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -496,12 +496,13 @@ static uint64_t svm_xcr0_mask __read_mos struct svm_machdata { bool cpuidpresent[SVM_NCPUIDS]; - struct nvmm_x86_conf_cpuid cpuid[SVM_NCPUIDS]; + struct nvmm_mach_conf_x86_cpuid cpuid[SVM_NCPUIDS]; volatile uint64_t mach_htlb_gen; }; static const size_t svm_conf_sizes[NVMM_X86_NCONF] = { - [NVMM_X86_CONF_CPUID] = sizeof(struct nvmm_x86_conf_cpuid) + [NVMM_MACH_CONF_MD(NVMM_MACH_CONF_X86_CPUID)] = + sizeof(struct nvmm_mach_conf_x86_cpuid) }; struct svm_cpudata { @@ -846,7 +847,7 @@ svm_exit_cpuid(struct nvmm_machine *mach { struct svm_machdata *machdata = mach->machdata; struct svm_cpudata *cpudata = vcpu->cpudata; - struct nvmm_x86_conf_cpuid *cpuid; + struct nvmm_mach_conf_x86_cpuid *cpuid; uint64_t eax, ecx; u_int descs[4]; size_t i; @@ -2149,11 +2150,11 @@ svm_machine_destroy(struct nvmm_machine static int svm_machine_configure(struct nvmm_machine *mach, uint64_t op, void *data) { - struct nvmm_x86_conf_cpuid *cpuid = data; + struct nvmm_mach_conf_x86_cpuid *cpuid = data; struct svm_machdata *machdata = (struct svm_machdata *)mach->machdata; size_t i; - if (__predict_false(op != NVMM_X86_CONF_CPUID)) { + if (__predict_false(op != NVMM_MACH_CONF_MD(NVMM_MACH_CONF_X86_CPUID))) { return EINVAL; } @@ -2171,7 +2172,7 @@ svm_machine_configure(struct nvmm_machin } if (machdata->cpuid[i].leaf == cpuid->leaf) { memcpy(&machdata->cpuid[i], cpuid, - sizeof(struct nvmm_x86_conf_cpuid)); + sizeof(struct nvmm_mach_conf_x86_cpuid)); return 0; } } @@ -2181,7 +2182,7 @@ svm_machine_configure(struct nvmm_machin if (!machdata->cpuidpresent[i]) { machdata->cpuidpresent[i] = true; memcpy(&machdata->cpuid[i], cpuid, - sizeof(struct nvmm_x86_conf_cpuid)); + sizeof(struct nvmm_mach_conf_x86_cpuid)); return 0; } } Index: src/sys/dev/nvmm/x86/nvmm_x86_vmx.c diff -u src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.33 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.34 --- src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.33 Wed May 1 09:20:21 2019 +++ src/sys/dev/nvmm/x86/nvmm_x86_vmx.c Sat May 11 07:31:56 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: nvmm_x86_vmx.c,v 1.33 2019/05/01 09:20:21 maxv Exp $ */ +/* $NetBSD: nvmm_x86_vmx.c,v 1.34 2019/05/11 07:31:56 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.33 2019/05/01 09:20:21 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.34 2019/05/11 07:31:56 maxv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -698,12 +698,13 @@ static uint64_t vmx_xcr0_mask __read_mos struct vmx_machdata { bool cpuidpresent[VMX_NCPUIDS]; - struct nvmm_x86_conf_cpuid cpuid[VMX_NCPUIDS]; + struct nvmm_mach_conf_x86_cpuid cpuid[VMX_NCPUIDS]; volatile uint64_t mach_htlb_gen; }; static const size_t vmx_conf_sizes[NVMM_X86_NCONF] = { - [NVMM_X86_CONF_CPUID] = sizeof(struct nvmm_x86_conf_cpuid) + [NVMM_MACH_CONF_MD(NVMM_MACH_CONF_X86_CPUID)] = + sizeof(struct nvmm_mach_conf_x86_cpuid) }; struct vmx_cpudata { @@ -1210,7 +1211,7 @@ vmx_exit_cpuid(struct nvmm_machine *mach { struct vmx_machdata *machdata = mach->machdata; struct vmx_cpudata *cpudata = vcpu->cpudata; - struct nvmm_x86_conf_cpuid *cpuid; + struct nvmm_mach_conf_x86_cpuid *cpuid; uint64_t eax, ecx; u_int descs[4]; size_t i; @@ -2783,11 +2784,11 @@ vmx_machine_destroy(struct nvmm_machine static int vmx_machine_configure(struct nvmm_machine *mach, uint64_t op, void *data) { - struct nvmm_x86_conf_cpuid *cpuid = data; + struct nvmm_mach_conf_x86_cpuid *cpuid = data; struct vmx_machdata *machdata = (struct vmx_machdata *)mach->machdata; size_t i; - if (__predict_false(op != NVMM_X86_CONF_CPUID)) { + if (__predict_false(op != NVMM_MACH_CONF_MD(NVMM_MACH_CONF_X86_CPUID))) { return EINVAL; } @@ -2805,7 +2806,7 @@ vmx_machine_configure(struct nvmm_machin } if (machdata->cpuid[i].leaf == cpuid->leaf) { memcpy(&machdata->cpuid[i], cpuid, - sizeof(struct nvmm_x86_conf_cpuid)); + sizeof(struct nvmm_mach_conf_x86_cpuid)); return 0; } } @@ -2815,7 +2816,7 @@ vmx_machine_configure(struct nvmm_machin if (!machdata->cpuidpresent[i]) { machdata->cpuidpresent[i] = true; memcpy(&machdata->cpuid[i], cpuid, - sizeof(struct nvmm_x86_conf_cpuid)); + sizeof(struct nvmm_mach_conf_x86_cpuid)); return 0; } } Index: src/tests/lib/libnvmm/h_io_assist.c diff -u src/tests/lib/libnvmm/h_io_assist.c:1.6 src/tests/lib/libnvmm/h_io_assist.c:1.7 --- src/tests/lib/libnvmm/h_io_assist.c:1.6 Fri Mar 22 01:50:14 2019 +++ src/tests/lib/libnvmm/h_io_assist.c Sat May 11 07:31:57 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: h_io_assist.c,v 1.6 2019/03/22 01:50:14 htodd Exp $ */ +/* $NetBSD: h_io_assist.c,v 1.7 2019/05/11 07:31:57 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -353,7 +353,7 @@ static const struct test tests[] = { { NULL, NULL, NULL, NULL, false } }; -static const struct nvmm_callbacks callbacks = { +static struct nvmm_callbacks callbacks = { .io = io_callback, .mem = NULL }; @@ -375,7 +375,7 @@ int main(int argc, char *argv[]) err(errno, "nvmm_machine_create"); if (nvmm_vcpu_create(&mach, 0) == -1) err(errno, "nvmm_vcpu_create"); - nvmm_callbacks_register(&callbacks); + nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &callbacks); map_pages(&mach); for (i = 0; tests[i].name != NULL; i++) { Index: src/tests/lib/libnvmm/h_mem_assist.c diff -u src/tests/lib/libnvmm/h_mem_assist.c:1.9 src/tests/lib/libnvmm/h_mem_assist.c:1.10 --- src/tests/lib/libnvmm/h_mem_assist.c:1.9 Fri Mar 22 01:50:14 2019 +++ src/tests/lib/libnvmm/h_mem_assist.c Sat May 11 07:31:57 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: h_mem_assist.c,v 1.9 2019/03/22 01:50:14 htodd Exp $ */ +/* $NetBSD: h_mem_assist.c,v 1.10 2019/05/11 07:31:57 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -328,7 +328,7 @@ static const struct test tests[] = { { NULL, NULL, NULL, -1 } }; -static const struct nvmm_callbacks callbacks = { +static struct nvmm_callbacks callbacks = { .io = NULL, .mem = mem_callback }; @@ -350,7 +350,7 @@ int main(int argc, char *argv[]) err(errno, "nvmm_machine_create"); if (nvmm_vcpu_create(&mach, 0) == -1) err(errno, "nvmm_vcpu_create"); - nvmm_callbacks_register(&callbacks); + nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &callbacks); map_pages(&mach); for (i = 0; tests[i].name != NULL; i++) {