Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Rework the machine configuration interface.
details: https://anonhg.NetBSD.org/src/rev/a4278a287f61
branches: trunk
changeset: 999001:a4278a287f61
user: maxv <maxv%NetBSD.org@localhost>
date: Sat May 11 07:31:56 2019 +0000
description:
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.
diffstat:
lib/libnvmm/libnvmm.c | 15 +++---
lib/libnvmm/libnvmm_x86.c | 82 ++++++++++++++++++++--------------------
lib/libnvmm/nvmm.h | 20 +++++----
sys/dev/nvmm/nvmm.c | 12 +++--
sys/dev/nvmm/nvmm.h | 9 +++-
sys/dev/nvmm/x86/nvmm_x86.h | 8 +-
sys/dev/nvmm/x86/nvmm_x86_svm.c | 19 ++++----
sys/dev/nvmm/x86/nvmm_x86_vmx.c | 19 ++++----
tests/lib/libnvmm/h_io_assist.c | 6 +-
tests/lib/libnvmm/h_mem_assist.c | 6 +-
10 files changed, 104 insertions(+), 92 deletions(-)
diffs (truncated from 675 to 300 lines):
diff -r 27b0c2823d6f -r a4278a287f61 lib/libnvmm/libnvmm.c
--- a/lib/libnvmm/libnvmm.c Sat May 11 06:50:42 2019 +0000
+++ b/lib/libnvmm/libnvmm.c Sat May 11 07:31:56 2019 +0000
@@ -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 @@
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_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)
{
diff -r 27b0c2823d6f -r a4278a287f61 lib/libnvmm/libnvmm_x86.c
--- a/lib/libnvmm/libnvmm_x86.c Sat May 11 06:50:42 2019 +0000
+++ b/lib/libnvmm/libnvmm_x86.c Sat May 11 07:31:56 2019 +0000
@@ -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 @@
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 @@
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 @@
}
for (i = 0; i < iocnt; i++) {
- (*__callbacks.io)(io);
+ (*mach->cbs.io)(io);
io->data += io->size;
}
@@ -816,7 +816,7 @@
}
}
- (*__callbacks.io)(&io);
+ (*mach->cbs.io)(&io);
if (io.in) {
if (!exit->u.io.str) {
@@ -865,19 +865,19 @@
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 @@
*/
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 @@
/* 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 @@
/* 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 @@
}
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 @@
/* 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 @@
/* 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 @@
}
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 @@
/* 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 @@
/* 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 @@
}
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 @@
/* 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 @@
/* 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 @@
}
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 @@
/* 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 @@
}
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 @@
/* 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 @@
}
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 @@
}
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);
Home |
Main Index |
Thread Index |
Old Index