Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add NVMM - for NetBSD Virtual Machine Monitor -, a kernel dr...
details: https://anonhg.NetBSD.org/src/rev/848a7c0c18c5
branches: trunk
changeset: 445640:848a7c0c18c5
user: maxv <maxv%NetBSD.org@localhost>
date: Wed Nov 07 07:43:07 2018 +0000
description:
Add NVMM - for NetBSD Virtual Machine Monitor -, a kernel driver that
provides support for hardware-accelerated virtualization on NetBSD.
It is made of an MI frontend, to which MD backends can be plugged. One
MD backend is implemented, x86-SVM, for x86 AMD CPUs.
We install
/usr/include/dev/nvmm/nvmm.h
/usr/include/dev/nvmm/nvmm_ioctl.h
/usr/include/dev/nvmm/{arch}/nvmm_{arch}.h
And the kernel module. For now, the only architecture where we do that
is amd64 (arch=x86).
NVMM is not enabled by default in amd64-GENERIC, but is instead easily
modloadable.
Sent to tech-kern@ a month ago. Validated with kASan, and optimized
with tprof.
diffstat:
distrib/sets/lists/comp/md.amd64 | 7 +-
distrib/sets/lists/modules/md.amd64 | 4 +-
etc/MAKEDEV.tmpl | 9 +-
sys/conf/files | 7 +-
sys/conf/majors | 3 +-
sys/dev/Makefile | 6 +-
sys/dev/nvmm/Makefile | 13 +
sys/dev/nvmm/files.nvmm | 11 +
sys/dev/nvmm/nvmm.c | 788 +++++++++++++
sys/dev/nvmm/nvmm.h | 155 ++
sys/dev/nvmm/nvmm_internal.h | 100 +
sys/dev/nvmm/nvmm_ioctl.h | 120 ++
sys/dev/nvmm/x86/Makefile | 7 +
sys/dev/nvmm/x86/nvmm_x86.h | 172 ++
sys/dev/nvmm/x86/nvmm_x86_svm.c | 2088 +++++++++++++++++++++++++++++++++++
sys/dev/nvmm/x86/nvmm_x86_svmfunc.S | 218 +++
sys/modules/Makefile | 6 +-
sys/modules/nvmm/Makefile | 19 +
sys/modules/nvmm/nvmm.ioconf | 7 +
19 files changed, 3732 insertions(+), 8 deletions(-)
diffs (truncated from 3897 to 300 lines):
diff -r 63811e3706c6 -r 848a7c0c18c5 distrib/sets/lists/comp/md.amd64
--- a/distrib/sets/lists/comp/md.amd64 Wed Nov 07 07:14:51 2018 +0000
+++ b/distrib/sets/lists/comp/md.amd64 Wed Nov 07 07:43:07 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: md.amd64,v 1.259 2018/07/17 18:55:24 joerg Exp $
+# $NetBSD: md.amd64,v 1.260 2018/11/07 07:43:07 maxv Exp $
./usr/include/amd64 comp-c-include
./usr/include/amd64/ansi.h comp-c-include
@@ -677,6 +677,11 @@
./usr/include/ieeefp.h comp-c-include
./usr/include/mm_malloc.h comp-obsolete obsolete
./usr/include/mmintrin.h comp-obsolete obsolete
+./usr/include/dev/nvmm comp-c-include
+./usr/include/dev/nvmm/nvmm.h comp-c-include
+./usr/include/dev/nvmm/nvmm_ioctl.h comp-c-include
+./usr/include/dev/nvmm/x86 comp-c-include
+./usr/include/dev/nvmm/x86/nvmm_x86.h comp-c-include
./usr/include/pmmintrin.h comp-obsolete obsolete
./usr/include/x64_64 comp-obsolete obsolete
./usr/include/x64_64/ansi.h comp-obsolete obsolete
diff -r 63811e3706c6 -r 848a7c0c18c5 distrib/sets/lists/modules/md.amd64
--- a/distrib/sets/lists/modules/md.amd64 Wed Nov 07 07:14:51 2018 +0000
+++ b/distrib/sets/lists/modules/md.amd64 Wed Nov 07 07:43:07 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: md.amd64,v 1.77 2018/08/28 09:42:10 martin Exp $
+# $NetBSD: md.amd64,v 1.78 2018/11/07 07:43:07 maxv Exp $
#
# NOTE that there are two sets of files here:
# @MODULEDIR@ and amd64-xen
@@ -141,6 +141,8 @@
./@MODULEDIR@/mt2131/mt2131.kmod base-kernel-modules kmod
./@MODULEDIR@/nvme base-obsolete obsolete
./@MODULEDIR@/nvme/nvme.kmod base-obsolete obsolete
+./@MODULEDIR@/nvmm base-kernel-modules kmod
+./@MODULEDIR@/nvmm/nvmm.kmod base-kernel-modules kmod
./@MODULEDIR@/nxt2k base-kernel-modules kmod
./@MODULEDIR@/nxt2k/nxt2k.kmod base-kernel-modules kmod
./@MODULEDIR@/odcm base-kernel-modules kmod
diff -r 63811e3706c6 -r 848a7c0c18c5 etc/MAKEDEV.tmpl
--- a/etc/MAKEDEV.tmpl Wed Nov 07 07:14:51 2018 +0000
+++ b/etc/MAKEDEV.tmpl Wed Nov 07 07:43:07 2018 +0000
@@ -1,5 +1,5 @@
#!/bin/sh -
-# $NetBSD: MAKEDEV.tmpl,v 1.195 2018/11/04 12:48:01 maxv Exp $
+# $NetBSD: MAKEDEV.tmpl,v 1.196 2018/11/07 07:43:07 maxv Exp $
#
# Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -258,6 +258,7 @@
# nsmb* SMB requester
# nvme* Non-Volatile Memory Host Controller Interface device driver
# nvme*ns* Non-Volatile Memory namespace
+# nvmm NetBSD Virtual Machine Monitor
# openfirm OpenFirmware accessor
# pad* Pseudo-audio device driver
# pci* PCI bus access devices
@@ -277,7 +278,7 @@
# stic* PixelStamp interface chip
# sysmon System Monitoring hardware
# tap* virtual Ethernet device
-# tprof task profiler
+# tprof task profiler
# tun* network tunnel driver
# twa 3ware Apache control interface
# twe 3ware Escalade control interface
@@ -2205,6 +2206,10 @@
mkdev nvme$unit c %nvme_chr% $(($unit * 65536))
;;
+nvmm)
+ mkdev nvmm c %nvmm_chr% 0
+ ;;
+
autofs)
mkdev autofs c %autofs_chr% 0 600
;;
diff -r 63811e3706c6 -r 848a7c0c18c5 sys/conf/files
--- a/sys/conf/files Wed Nov 07 07:14:51 2018 +0000
+++ b/sys/conf/files Wed Nov 07 07:43:07 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1215 2018/10/19 21:09:10 jakllsch Exp $
+# $NetBSD: files,v 1.1216 2018/11/07 07:43:07 maxv Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20171118
@@ -1549,6 +1549,11 @@
include "dev/tprof/files.tprof"
#
+# NetBSD Virtual Machine Monitor.
+#
+include "dev/nvmm/files.nvmm"
+
+#
# alternate memory device
#
include "dev/altmem/files.altmem"
diff -r 63811e3706c6 -r 848a7c0c18c5 sys/conf/majors
--- a/sys/conf/majors Wed Nov 07 07:14:51 2018 +0000
+++ b/sys/conf/majors Wed Nov 07 07:43:07 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: majors,v 1.79 2018/05/20 14:08:33 thorpej Exp $
+# $NetBSD: majors,v 1.80 2018/11/07 07:43:07 maxv Exp $
#
# Device majors for Machine-Independent drivers.
#
@@ -78,3 +78,4 @@
device-major qemufwcfg char 342 qemufwcfg
device-major autofs char 343 autofs
device-major gpiopps char 344 gpiopps
+device-major nvmm char 345 nvmm
diff -r 63811e3706c6 -r 848a7c0c18c5 sys/dev/Makefile
--- a/sys/dev/Makefile Wed Nov 07 07:14:51 2018 +0000
+++ b/sys/dev/Makefile Wed Nov 07 07:43:07 2018 +0000
@@ -1,10 +1,14 @@
-# $NetBSD: Makefile,v 1.39 2017/12/10 20:38:14 bouyer Exp $
+# $NetBSD: Makefile,v 1.40 2018/11/07 07:43:08 maxv Exp $
SUBDIR= apm ata bluetooth dec dm dmover dtv filemon hdaudio hdmicec hid hpc \
i2c i2o ic ieee1394 ir isa \
microcode ofw pci pckbport pcmcia pud putter raidframe sbus scsipi \
sun tc usb vme wscons
+.if ${MACHINE_ARCH} == "x86_64"
+SUBDIR+= nvmm
+.endif
+
.include <bsd.own.mk>
.if ${MKISCSI} != "no"
diff -r 63811e3706c6 -r 848a7c0c18c5 sys/dev/nvmm/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/nvmm/Makefile Wed Nov 07 07:43:07 2018 +0000
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1 2018/11/07 07:43:08 maxv Exp $
+
+.if ${MACHINE_ARCH} == "x86_64"
+SUBDIR= x86
+.endif
+
+.include <bsd.own.mk>
+
+INCSDIR= /usr/include/dev/nvmm
+
+INCS= nvmm.h nvmm_ioctl.h
+
+.include <bsd.kinc.mk>
diff -r 63811e3706c6 -r 848a7c0c18c5 sys/dev/nvmm/files.nvmm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/nvmm/files.nvmm Wed Nov 07 07:43:07 2018 +0000
@@ -0,0 +1,11 @@
+# $NetBSD: files.nvmm,v 1.1 2018/11/07 07:43:08 maxv Exp $
+
+defpseudo nvmm
+
+file dev/nvmm/nvmm.c nvmm
+
+ifdef amd64
+file dev/nvmm/x86/nvmm_x86_svm.c nvmm
+file dev/nvmm/x86/nvmm_x86_svmfunc.S nvmm
+endif
+
diff -r 63811e3706c6 -r 848a7c0c18c5 sys/dev/nvmm/nvmm.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/nvmm/nvmm.c Wed Nov 07 07:43:07 2018 +0000
@@ -0,0 +1,788 @@
+/* $NetBSD: nvmm.c,v 1.1 2018/11/07 07:43:08 maxv Exp $ */
+
+/*
+ * Copyright (c) 2018 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.c,v 1.1 2018/11/07 07:43:08 maxv Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+
+#include <sys/cpu.h>
+#include <sys/conf.h>
+#include <sys/kmem.h>
+#include <sys/module.h>
+#include <sys/proc.h>
+
+#include <uvm/uvm.h>
+#include <uvm/uvm_page.h>
+
+#include "ioconf.h"
+
+#include <dev/nvmm/nvmm.h>
+#include <dev/nvmm/nvmm_internal.h>
+#include <dev/nvmm/nvmm_ioctl.h>
+
+static struct nvmm_machine machines[NVMM_MAX_MACHINES];
+
+static const struct nvmm_impl *nvmm_impl_list[] = {
+ &nvmm_x86_svm /* x86 AMD SVM */
+};
+
+static const struct nvmm_impl *nvmm_impl = NULL;
+
+/* -------------------------------------------------------------------------- */
+
+static int
+nvmm_machine_alloc(struct nvmm_machine **ret)
+{
+ struct nvmm_machine *mach;
+ size_t i;
+
+ for (i = 0; i < NVMM_MAX_MACHINES; i++) {
+ mach = &machines[i];
+
+ rw_enter(&mach->lock, RW_WRITER);
+ if (mach->present) {
+ rw_exit(&mach->lock);
+ continue;
+ }
+
+ mach->present = true;
+ *ret = mach;
+ return 0;
+ }
+
+ return ENOBUFS;
+}
+
+static void
+nvmm_machine_free(struct nvmm_machine *mach)
+{
+ KASSERT(rw_write_held(&mach->lock));
+ KASSERT(mach->present);
+ mach->present = false;
+}
+
+static int
+nvmm_machine_get(nvmm_machid_t machid, struct nvmm_machine **ret, bool writer)
+{
+ struct nvmm_machine *mach;
+ krw_t op = writer ? RW_WRITER : RW_READER;
+
+ if (machid >= NVMM_MAX_MACHINES) {
+ return EINVAL;
+ }
+ mach = &machines[machid];
+
+ rw_enter(&mach->lock, op);
+ if (!mach->present) {
+ rw_exit(&mach->lock);
+ return ENOENT;
+ }
+ if (mach->procid != curproc->p_pid) {
+ rw_exit(&mach->lock);
+ return EPERM;
+ }
+ *ret = mach;
+
+ return 0;
+}
+
+static void
+nvmm_machine_put(struct nvmm_machine *mach)
+{
+ rw_exit(&mach->lock);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static int
+nvmm_vcpu_alloc(struct nvmm_machine *mach, struct nvmm_cpu **ret)
+{
+ struct nvmm_cpu *vcpu;
+ size_t i;
+
Home |
Main Index |
Thread Index |
Old Index