Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add libnvmm, NetBSD's new virtualization API. It provides a ...



details:   https://anonhg.NetBSD.org/src/rev/e051a2f501c6
branches:  trunk
changeset: 445710:e051a2f501c6
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Nov 10 09:28:56 2018 +0000

description:
Add libnvmm, NetBSD's new virtualization API. It provides a way for VMM
software to effortlessly create and manage virtual machines via NVMM.

It is mostly complete, only nvmm_assist_mem needs to be filled -- I have
a draft for that, but it needs some more care. This Mem Assist should
not be needed when emulating a system in x2apic mode, so theoretically
the current form of libnvmm is sufficient to emulate a whole class of
systems.

Generally speaking, there are so many modes in x86 that it is difficult
to handle each corner case without introducing a ton of checks that just
slow down the common-case execution. Currently we check a limited number
of things; we may add more checks in the future if they turn out to be
needed, but that's rather low priority.

Libnvmm is compiled and installed only on amd64. A man page (reviewed by
wiz@) is provided.

diffstat:

 distrib/sets/lists/comp/md.amd64 |   12 +-
 lib/Makefile                     |    6 +-
 lib/libnvmm/Makefile             |   17 +
 lib/libnvmm/libnvmm.3            |  484 +++++++++++++++++++++++++++++++
 lib/libnvmm/libnvmm.c            |  433 ++++++++++++++++++++++++++++
 lib/libnvmm/libnvmm_x86.c        |  592 +++++++++++++++++++++++++++++++++++++++
 lib/libnvmm/nvmm.h               |  103 ++++++
 lib/libnvmm/shlib_version        |    5 +
 8 files changed, 1650 insertions(+), 2 deletions(-)

diffs (truncated from 1715 to 300 lines):

diff -r 7bae5365ac57 -r e051a2f501c6 distrib/sets/lists/comp/md.amd64
--- a/distrib/sets/lists/comp/md.amd64  Sat Nov 10 01:56:28 2018 +0000
+++ b/distrib/sets/lists/comp/md.amd64  Sat Nov 10 09:28:56 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: md.amd64,v 1.260 2018/11/07 07:43:07 maxv Exp $
+# $NetBSD: md.amd64,v 1.261 2018/11/10 09:28:56 maxv Exp $
 
 ./usr/include/amd64                            comp-c-include
 ./usr/include/amd64/ansi.h                     comp-c-include
@@ -682,6 +682,7 @@
 ./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/nvmm.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
@@ -783,6 +784,12 @@
 ./usr/lib/i386/libi386.so                      comp-sys-shlib          compat,pic
 ./usr/lib/i386/libi386_p.a                     comp-c-proflib          compat,profile
 ./usr/lib/i386/libi386_pic.a                   comp-c-piclib           compat,pic,picinstall
+./usr/lib/libnvmm.a                            comp-c-lib              compatfile
+./usr/lib/libnvmm.so                           comp-sys-shlib          compat,pic
+./usr/lib/libnvmm.so.0                         comp-sys-shlib          compat,pic
+./usr/lib/libnvmm.so.0.1                       comp-sys-shlib          compat,pic
+./usr/lib/libnvmm_p.a                          comp-c-proflib          compatfile,profile
+./usr/lib/libnvmm_pic.a                                comp-c-piclib           compat,pic,picinstall
 ./usr/lib/libx86_64.a                          comp-c-lib
 ./usr/lib/libx86_64_p.a                                comp-c-proflib          profile
 ./usr/lib/libx86_64_pic.a                      comp-c-piclib           pic,picinstall
@@ -888,3 +895,6 @@
 ./usr/share/ldscripts/i386nbsd.xn              comp-obsolete           obsolete
 ./usr/share/ldscripts/i386nbsd.xr              comp-obsolete           obsolete
 ./usr/share/ldscripts/i386nbsd.xu              comp-obsolete           obsolete
+./usr/share/man/cat3/libnvmm.0                 comp-c-catman           .cat
+./usr/share/man/html3/libnvmm.html             comp-c-htmlman          html
+./usr/share/man/man3/libnvmm.3                 comp-c-man              .man
diff -r 7bae5365ac57 -r e051a2f501c6 lib/Makefile
--- a/lib/Makefile      Sat Nov 10 01:56:28 2018 +0000
+++ b/lib/Makefile      Sat Nov 10 09:28:56 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.261 2018/09/08 14:11:41 christos Exp $
+#      $NetBSD: Makefile,v 1.262 2018/11/10 09:28:56 maxv Exp $
 #      from: @(#)Makefile      5.25.1.1 (Berkeley) 5/7/91
 
 .include <bsd.own.mk>
@@ -50,6 +50,10 @@
 SUBDIR+=       libskey
 .endif
 
+.if ${MACHINE_ARCH} == "x86_64"
+SUBDIR+=       libnvmm
+.endif
+
 .if (${MKMDNS} != "no")
 SUBDIR+=       ../external/apache2/mDNSResponder/lib
 .endif
diff -r 7bae5365ac57 -r e051a2f501c6 lib/libnvmm/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libnvmm/Makefile      Sat Nov 10 09:28:56 2018 +0000
@@ -0,0 +1,17 @@
+# $NetBSD: Makefile,v 1.1 2018/11/10 09:28:56 maxv Exp $
+
+USE_SHLIBDIR=   yes
+
+.include <bsd.own.mk>
+
+LIB=           nvmm
+MAN=           libnvmm.3
+
+SRCS=          libnvmm.c libnvmm_x86.c
+
+INCS=          nvmm.h
+INCSDIR=       /usr/include
+
+WARNS=         5
+
+.include <bsd.lib.mk>
diff -r 7bae5365ac57 -r e051a2f501c6 lib/libnvmm/libnvmm.3
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libnvmm/libnvmm.3     Sat Nov 10 09:28:56 2018 +0000
@@ -0,0 +1,484 @@
+.Dd September 12, 2018
+.Dt LIBNVMM 3
+.Os
+.Sh NAME
+.Nm libnvmm
+.Nd NetBSD Virtualization API
+.Sh LIBRARY
+.Lb libnvmm
+.Sh SYNOPSIS
+.In nvmm.h
+.Ft int
+.Fn nvmm_capability "struct nvmm_capability *cap"
+.Ft int
+.Fn nvmm_machine_create "struct nvmm_machine *mach"
+.Ft int
+.Fn nvmm_machine_destroy "struct nvmm_machine *mach"
+.Ft int
+.Fn nvmm_machine_configure "struct nvmm_machine *mach" "uint64_t op" \
+    "void *conf"
+.Ft int
+.Fn nvmm_vcpu_create "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid"
+.Ft int
+.Fn nvmm_vcpu_destroy "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid"
+.Ft int
+.Fn nvmm_vcpu_getstate "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \
+    "void *state" "uint64_t flags"
+.Ft int
+.Fn nvmm_vcpu_setstate "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \
+    "void *state" "uint64_t flags"
+.Ft int
+.Fn nvmm_vcpu_inject "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \
+    "struct nvmm_event *event"
+.Ft int
+.Fn nvmm_vcpu_run "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \
+    "struct nvmm_exit *exit"
+.Ft int
+.Fn nvmm_gpa_map "struct nvmm_machine *mach" "uintptr_t hva" "gpaddr_t gpa" \
+    "size_t size" "int flags"
+.Ft int
+.Fn nvmm_gpa_unmap "struct nvmm_machine *mach" "uintptr_t hva" "gpaddr_t gpa" \
+    "size_t size"
+.Ft int
+.Fn nvmm_gva_to_gpa "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \
+    "gvaddr_t gva" "gpaddr_t *gpa" "nvmm_prot_t *prot"
+.Ft int
+.Fn nvmm_gpa_to_hva "struct nvmm_machine *mach" "gpaddr_t gpa" \
+    "uintptr_t *hva"
+.Ft int
+.Fn nvmm_assist_io "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \
+    "struct nvmm_exit *exit" "void (*cb)(struct nvmm_io *)"
+.Ft int
+.Fn nvmm_assist_mem "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \
+    "struct nvmm_exit *exit" "void (*cb)(struct nvmm_mem *)"
+.Sh DESCRIPTION
+.Nm
+provides a library for VMM software to handle hardware-accelerated virtual
+machines in
+.Nx .
+A virtual machine is described by an opaque structure,
+.Cd nvmm_machine .
+VMM software should not attempt to modify this structure directly, and should
+use the API provided by
+.Nm
+to handle virtual machines.
+.Pp
+.Fn nvmm_capability
+gets the capabilities of NVMM.
+.Pp
+.Fn nvmm_machine_create
+creates a virtual machine in the kernel.
+The
+.Fa mach
+structure is initialized, and describes the machine.
+.Pp
+.Fn nvmm_machine_destroy
+destroys the virtual machine described in
+.Fa mach .
+.Pp
+.Fn nvmm_machine_configure
+configures, on the machine
+.Fa mach ,
+the parameter indicated in
+.Fa op .
+.Fa conf
+describes the value of the parameter.
+.Pp
+.Fn nvmm_vcpu_create
+creates a virtual CPU in the machine
+.Fa mach ,
+giving it the CPU id
+.Fa cpuid .
+.Pp
+.Fn nvmm_vcpu_destroy
+destroys the virtual CPU identified by
+.Fa cpuid
+in the machine
+.Fa mach .
+.Pp
+.Fn nvmm_vcpu_getstate
+gets the state of the virtual CPU identified by
+.Fa cpuid
+in the machine
+.Fa mach .
+The
+.Fa state
+argument is the address of a state area, and
+.Fa flags
+is the bitmap of the components that are to be retrieved.
+See
+.Sx VCPU State Area
+below for details.
+.Pp
+.Fn nvmm_vcpu_setstate
+sets the state of the virtual CPU identified by
+.Fa cpuid
+in the machine
+.Fa mach .
+The
+.Fa state
+argument is the address of a state area, and
+.Fa flags
+is the bitmap of the components that are to be set.
+See
+.Sx VCPU State Area
+below for details.
+.Pp
+.Fn nvmm_vcpu_run
+runs the CPU identified by
+.Fa cpuid
+in the machine
+.Fa mach ,
+until a VM exit is triggered.
+The
+.Fa exit
+structure is filled to indicate the exit reason, and the associated parameters
+if any.
+.Pp
+.Fn nvmm_gpa_map
+makes the guest physical memory area beginning on address
+.Fa gpa
+and of size
+.Fa size
+available in the machine
+.Fa mach .
+The area is mapped in the calling process' virtual address space, at address
+.Fa hva .
+.Pp
+.Fn nvmm_gpa_unmap
+removes the guest physical memory area beginning on address
+.Fa gpa
+and of size
+.Fa size
+from the machine
+.Fa mach .
+It also unmaps the area beginning on
+.Fa hva
+from the calling process' virtual address space.
+.Pp
+.Fn nvmm_gva_to_gpa
+translates, on the CPU
+.Fa cpuid
+from the machine
+.Fa mach ,
+the guest virtual address given in
+.Fa gva
+into a guest physical address returned in
+.Fa gpa .
+The associated page premissions are returned in
+.Fa prot .
+.Fa gva
+must be page-aligned.
+.Pp
+.Fn nvmm_gpa_to_hva
+translates, on the machine
+.Fa mach ,
+the guest physical address indicated in
+.Fa gpa
+into a host virtual address returned in
+.Fa hva .
+.Fa gpa
+must be page-aligned.
+.Pp
+.Fn nvmm_assist_io
+emulates the I/O operation described in
+.Fa exit
+on CPU
+.Fa cpuid
+from machine
+.Fa mach .
+.Fa cb
+will be called to handle the transaction.
+See
+.Sx I/O Assist
+below for details.
+.Pp
+.Fn nvmm_assist_mem
+emulates the Mem operation described in
+.Fa exit
+on CPU
+.Fa cpuid
+from machine
+.Fa mach .
+.Fa cb
+will be called to handle the transaction.
+See
+.Sx Mem Assist
+below for details.
+.Ss NVMM Capability
+The
+.Cd nvmm_capability
+structure helps VMM software identify the capabilities offered by NVMM on the
+host:
+.Bd -literal
+struct nvmm_capability {
+       uint64_t version;
+       uint64_t state_size;
+       uint64_t max_machines;
+       uint64_t max_vcpus;



Home | Main Index | Thread Index | Old Index