Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Install the x86 RESET state at VCPU creation time, for c...
details: https://anonhg.NetBSD.org/src/rev/4a8979238349
branches: trunk
changeset: 839504:4a8979238349
user: maxv <maxv%NetBSD.org@localhost>
date: Sat Feb 23 12:27:00 2019 +0000
description:
Install the x86 RESET state at VCPU creation time, for convenience, so
that the libnvmm users can expect a functional VCPU right away.
diffstat:
sys/dev/nvmm/nvmm_internal.h | 4 +-
sys/dev/nvmm/x86/nvmm_x86.c | 218 ++++++++++++++++++++++++++++++++++++++++
sys/dev/nvmm/x86/nvmm_x86.h | 6 +-
sys/dev/nvmm/x86/nvmm_x86_svm.c | 13 +-
sys/dev/nvmm/x86/nvmm_x86_vmx.c | 14 +-
sys/modules/nvmm/Makefile | 3 +-
6 files changed, 239 insertions(+), 19 deletions(-)
diffs (truncated from 374 to 300 lines):
diff -r 296aa58928a9 -r 4a8979238349 sys/dev/nvmm/nvmm_internal.h
--- a/sys/dev/nvmm/nvmm_internal.h Sat Feb 23 12:25:33 2019 +0000
+++ b/sys/dev/nvmm/nvmm_internal.h Sat Feb 23 12:27:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvmm_internal.h,v 1.5 2019/02/13 16:03:16 maxv Exp $ */
+/* $NetBSD: nvmm_internal.h,v 1.6 2019/02/23 12:27:00 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
int (*vcpu_create)(struct nvmm_machine *, struct nvmm_cpu *);
void (*vcpu_destroy)(struct nvmm_machine *, struct nvmm_cpu *);
- void (*vcpu_setstate)(struct nvmm_cpu *, void *, uint64_t);
+ void (*vcpu_setstate)(struct nvmm_cpu *, const void *, uint64_t);
void (*vcpu_getstate)(struct nvmm_cpu *, void *, uint64_t);
int (*vcpu_inject)(struct nvmm_machine *, struct nvmm_cpu *,
struct nvmm_event *);
diff -r 296aa58928a9 -r 4a8979238349 sys/dev/nvmm/x86/nvmm_x86.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86.c Sat Feb 23 12:27:00 2019 +0000
@@ -0,0 +1,218 @@
+/* $NetBSD: nvmm_x86.c,v 1.1 2019/02/23 12:27:00 maxv Exp $ */
+
+/*
+ * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Maxime Villard.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86.c,v 1.1 2019/02/23 12:27:00 maxv Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/cpu.h>
+
+#include <uvm/uvm.h>
+#include <uvm/uvm_page.h>
+
+#include <x86/cputypes.h>
+#include <x86/specialreg.h>
+#include <x86/pmap.h>
+
+#include <dev/nvmm/nvmm.h>
+#include <dev/nvmm/nvmm_internal.h>
+#include <dev/nvmm/x86/nvmm_x86.h>
+
+/*
+ * Code shared between x86-SVM and x86-VMX.
+ */
+
+const struct nvmm_x64_state nvmm_x86_reset_state = {
+ .segs = {
+ [NVMM_X64_SEG_CS] = {
+ .selector = 0xF000,
+ .base = 0xFFFF0000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = SDT_MEMRWA,
+ .p = 1,
+ }
+ },
+ [NVMM_X64_SEG_DS] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = SDT_MEMRWA,
+ .p = 1,
+ }
+ },
+ [NVMM_X64_SEG_ES] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = SDT_MEMRWA,
+ .p = 1,
+ }
+ },
+ [NVMM_X64_SEG_FS] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = SDT_MEMRWA,
+ .p = 1,
+ }
+ },
+ [NVMM_X64_SEG_GS] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = SDT_MEMRWA,
+ .p = 1,
+ }
+ },
+ [NVMM_X64_SEG_SS] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = SDT_MEMRWA,
+ .p = 1,
+ }
+ },
+ [NVMM_X64_SEG_GDT] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = SDT_MEMRW,
+ .p = 1,
+ }
+ },
+ [NVMM_X64_SEG_IDT] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = SDT_MEMRW,
+ .p = 1,
+ }
+ },
+ [NVMM_X64_SEG_LDT] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = SDT_SYSLDT,
+ .p = 1,
+ }
+ },
+ [NVMM_X64_SEG_TR] = {
+ .selector = 0x0000,
+ .base = 0x00000000,
+ .limit = 0xFFFF,
+ .attrib = {
+ .type = SDT_SYS286BSY,
+ .p = 1,
+ }
+ },
+ },
+
+ .gprs = {
+ [NVMM_X64_GPR_RAX] = 0x00000000,
+ [NVMM_X64_GPR_RCX] = 0x00000000,
+ [NVMM_X64_GPR_RDX] = 0x00000600,
+ [NVMM_X64_GPR_RBX] = 0x00000000,
+ [NVMM_X64_GPR_RSP] = 0x00000000,
+ [NVMM_X64_GPR_RBP] = 0x00000000,
+ [NVMM_X64_GPR_RSI] = 0x00000000,
+ [NVMM_X64_GPR_RDI] = 0x00000000,
+ [NVMM_X64_GPR_R8] = 0x00000000,
+ [NVMM_X64_GPR_R9] = 0x00000000,
+ [NVMM_X64_GPR_R10] = 0x00000000,
+ [NVMM_X64_GPR_R11] = 0x00000000,
+ [NVMM_X64_GPR_R12] = 0x00000000,
+ [NVMM_X64_GPR_R13] = 0x00000000,
+ [NVMM_X64_GPR_R14] = 0x00000000,
+ [NVMM_X64_GPR_R15] = 0x00000000,
+ [NVMM_X64_GPR_RIP] = 0x0000FFF0,
+ [NVMM_X64_GPR_RFLAGS] = 0x00000002,
+ },
+
+ .crs = {
+ [NVMM_X64_CR_CR0] = 0x60000010,
+ [NVMM_X64_CR_CR2] = 0x00000000,
+ [NVMM_X64_CR_CR3] = 0x00000000,
+ [NVMM_X64_CR_CR4] = 0x00000000,
+ [NVMM_X64_CR_CR8] = 0x00000000,
+ [NVMM_X64_CR_XCR0] = 0x00000001,
+ },
+
+ .drs = {
+ [NVMM_X64_DR_DR0] = 0x00000000,
+ [NVMM_X64_DR_DR1] = 0x00000000,
+ [NVMM_X64_DR_DR2] = 0x00000000,
+ [NVMM_X64_DR_DR3] = 0x00000000,
+ [NVMM_X64_DR_DR6] = 0xFFFF0FF0,
+ [NVMM_X64_DR_DR7] = 0x00000400,
+ },
+
+ .msrs = {
+ [NVMM_X64_MSR_EFER] = 0x00000000,
+ [NVMM_X64_MSR_STAR] = 0x00000000,
+ [NVMM_X64_MSR_LSTAR] = 0x00000000,
+ [NVMM_X64_MSR_CSTAR] = 0x00000000,
+ [NVMM_X64_MSR_SFMASK] = 0x00000000,
+ [NVMM_X64_MSR_KERNELGSBASE] = 0x00000000,
+ [NVMM_X64_MSR_SYSENTER_CS] = 0x00000000,
+ [NVMM_X64_MSR_SYSENTER_ESP] = 0x00000000,
+ [NVMM_X64_MSR_SYSENTER_EIP] = 0x00000000,
+ [NVMM_X64_MSR_PAT] =
+ PATENTRY(0, PAT_WB) | PATENTRY(1, PAT_WT) |
+ PATENTRY(2, PAT_UCMINUS) | PATENTRY(3, PAT_UC) |
+ PATENTRY(4, PAT_WB) | PATENTRY(5, PAT_WT) |
+ PATENTRY(6, PAT_UCMINUS) | PATENTRY(7, PAT_UC),
+ },
+
+ .misc = {
+ [NVMM_X64_MISC_INT_SHADOW] = 0,
+ [NVMM_X64_MISC_INT_WINDOW_EXIT] = 0,
+ [NVMM_X64_MISC_NMI_WINDOW_EXIT] = 0,
+ },
+
+ .fpu = {
+ .fx_cw = 0x0040,
+ .fx_sw = 0x0000,
+ .fx_tw = 0x55,
+ .fx_zero = 0x55,
+ .fx_mxcsr = 0x1F80,
+ }
+};
diff -r 296aa58928a9 -r 4a8979238349 sys/dev/nvmm/x86/nvmm_x86.h
--- a/sys/dev/nvmm/x86/nvmm_x86.h Sat Feb 23 12:25:33 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86.h Sat Feb 23 12:27:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvmm_x86.h,v 1.5 2019/02/14 14:30:20 maxv Exp $ */
+/* $NetBSD: nvmm_x86.h,v 1.6 2019/02/23 12:27:00 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -173,6 +173,10 @@
} del;
};
+#ifdef _KERNEL
+extern const struct nvmm_x64_state nvmm_x86_reset_state;
+#endif
+
#endif /* ASM_NVMM */
#endif /* _NVMM_X86_H_ */
diff -r 296aa58928a9 -r 4a8979238349 sys/dev/nvmm/x86/nvmm_x86_svm.c
--- a/sys/dev/nvmm/x86/nvmm_x86_svm.c Sat Feb 23 12:25:33 2019 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_svm.c Sat Feb 23 12:27:00 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvmm_x86_svm.c,v 1.30 2019/02/23 08:19:16 maxv Exp $ */
+/* $NetBSD: nvmm_x86_svm.c,v 1.31 2019/02/23 12:27:00 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.30 2019/02/23 08:19:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.31 2019/02/23 12:27:00 maxv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1539,7 +1539,7 @@
}
static void
-svm_vcpu_setstate(struct nvmm_cpu *vcpu, void *data, uint64_t flags)
+svm_vcpu_setstate(struct nvmm_cpu *vcpu, const void *data, uint64_t flags)
{
const struct nvmm_x64_state *state = data;
struct svm_cpudata *cpudata = vcpu->cpudata;
@@ -1924,10 +1924,6 @@
vmcb->ctrl.enable1 = VMCB_CTRL_ENABLE_NP;
vmcb->ctrl.n_cr3 = mach->vm->vm_map.pmap->pm_pdirpa[0];
- /* Must always be set. */
- vmcb->state.efer = EFER_SVME;
- cpudata->gxcr0 = XCR0_X87;
-
/* Init XSAVE header. */
cpudata->gfpu.xsh_xstate_bv = svm_xcr0_mask;
cpudata->gfpu.xsh_xcomp_bv = 0;
@@ -1940,6 +1936,9 @@
cpudata->lstar = rdmsr(MSR_LSTAR);
Home |
Main Index |
Thread Index |
Old Index