Implements the NetBSD Virtual Machine Monitor accelerator
v7 cover Implements the NetBSD Virtual Machine Monitor accelerator
The NetBSD team has implemented its new hypervisor called NVMM. It has been included since NetBSD 9.0 and has been in use now for quite some time. NVMM adds user-mode capabilities to create and manage virtual machines, configure memory mappings for guest machines, and create and control execution of virtual processors.
With this new API we are now able to bring our hypervisor to the QEMU community! The following patches implement the NetBSD Virtual Machine Monitor accelerator (NVMM) for QEMU on NetBSD 9.0 and newer hosts.
When compiling QEMU for x86_64 it will autodetect nvmm and will compile the accelerator for use if found. At runtime using the '-accel nvmm' should see a significant performance improvement over emulation, much like when using 'hax' on NetBSD.
The documentation for this new API is visible at https://man.netbsd.org under the libnvmm(3) and nvmm(4) pages.
NVMM was designed and implemented by Maxime Villard <[email protected]>
Thank you for your feedback.
Refrences:
https://m00nbsd.net/4e0798b7f2620c965d0dd9d6a7a2f296.html
Test plan:
1. Download a NetBSD 9.1 release:
http://cdn.netbsd.org/pub/NetBSD/NetBSD-9.1/amd64/installation/cdrom/boot.iso
2. Install it natively on a not too old x86_64 hardware (Intel or AMD).
There is no support for nested virtualization in NVMM.
3. Setup the system.
export PKG_PATH=http://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/9.0/All/ pkg_add git gmake python37 glib2 bison pkgconf pixman
Install mozilla-rootcerts and follow post-install instructions.
pkg_add mozilla-rootcerts
More information: https://wiki.qemu.org/Hosts/BSD#NetBSD
4. Build qemu
mkdir build
cd build
../configure --python=python3.7
gmake
gmake check
5. Test
qemu -accel nvmm ...
History:
v6 -> v7:
- Remove small patches from pkgsrc that krept in
- Enhance the possible race on exit fix
- update the build system to only link the nvmm library for targets that support NVMM
v5 -> v6:
- Ported to updated Qemu 6.0 build system, reshuffeling and refactoring
- Improved auto detection
- Added support for improved NVMM interface fixing feedback on the use of signals
v4 -> v5:
- Mainly cosmetic
- Automatic detection
v3 -> v4:
- Correct build warning by adding a missing include
- Do not set R8-R16 registers unless TARGET_X86_64
v2 -> v3:
- Register nvmm in targetos NetBSD check
- Stop including hw/boards.h
- Rephrase old code comments (remove XXX)
v1 -> v2:
- Included the testing plan as requested by Philippe Mathieu-Daude
- Formatting nit fix in qemu-options.hx
- Document NVMM in the accel section of qemu-options.hx
Reinoud Zandijk (4):
Add NVMM accelerator: configure and build logic Add NVMM accelerator: x86 CPU support
Add NVMM accelerator: acceleration enlightenments Add NVMM Accelerator: add maintainers for NetBSD/NVMM
MAINTAINERS | 11 + accel/Kconfig | 3 + configure | 8 +- include/sysemu/hw_accel.h | 1 + include/sysemu/nvmm.h | 26 + meson.build | 14 + meson_options.txt | 2 + qemu-options.hx | 8 +- target/i386/helper.c | 2 +- target/i386/meson.build | 1 + target/i386/nvmm/meson.build | 10 + target/i386/nvmm/nvmm-accel-ops.c | 111 +++ target/i386/nvmm/nvmm-accel-ops.h | 24 + target/i386/nvmm/nvmm-all.c | 1226 +++++++++++++++++++++++++++++ 14 files changed, 1441 insertions(+), 6 deletions(-) create mode 100644 include/sysemu/nvmm.h create mode 100644 target/i386/nvmm/meson.build create mode 100644 target/i386/nvmm/nvmm-accel-ops.c create mode 100644 target/i386/nvmm/nvmm-accel-ops.h create mode 100644 target/i386/nvmm/nvmm-all.c
Signature · 1 line
2.29.2
PATCH v7 1/4 Add NVMM accelerator: configure and build logic
--- accel/Kconfig | 3 +++ configure | 8 +++++++- meson.build | 14 ++++++++++++++ meson_options.txt | 2 ++ qemu-options.hx | 8 ++++---- 5 files changed, 30 insertions(+), 5 deletions(-)
accel/Kconfig +3 -0
@@ -1,6 +1,9 @@ config WHPX bool +config NVMM + bool + config HAX bool
configure +7 -1
@@ -352,6 +352,7 @@ kvm="auto" hax="auto" hvf="auto" whpx="auto" +nvmm="auto" rdma="$default_feature" pvrdma="$default_feature" gprof="no"
@@ -1107,6 +1108,10 @@ for opt do ;; --enable-hvf) hvf="enabled" ;; + --disable-nvmm) nvmm="disabled" + ;; + --enable-nvmm) nvmm="enabled" + ;; --disable-whpx) whpx="disabled" ;; --enable-whpx) whpx="enabled"
@@ -1848,6 +1853,7 @@ disabled with --disable-FEATURE, default is enabled if available kvm KVM acceleration support hax HAX acceleration support hvf Hypervisor.framework acceleration support + nvmm NVMM acceleration support whpx Windows Hypervisor Platform acceleration support rdma Enable RDMA-based migration pvrdma Enable PVRDMA support
@@ -6410,7 +6416,7 @@ NINJA=$ninja $meson setup \ -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \ -Db_lto=$lto -Dcfi=$cfi -Dcfi_debug=$cfi_debug \ -Dmalloc=$malloc -Dmalloc_trim=$malloc_trim -Dsparse=$sparse \ - -Dkvm=$kvm -Dhax=$hax -Dwhpx=$whpx -Dhvf=$hvf \ + -Dkvm=$kvm -Dhax=$hax -Dwhpx=$whpx -Dhvf=$hvf -Dnvmm=$nvmm \ -Dxen=$xen -Dxen_pci_passthrough=$xen_pci_passthrough -Dtcg=$tcg \ -Dcocoa=$cocoa -Dgtk=$gtk -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \ -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
meson.build +14 -0
@@ -87,6 +87,7 @@ if cpu in ['x86', 'x86_64'] accelerator_targets += { 'CONFIG_HAX': ['i386-softmmu', 'x86_64-softmmu'], 'CONFIG_HVF': ['x86_64-softmmu'], + 'CONFIG_NVMM': ['i386-softmmu', 'x86_64-softmmu'], 'CONFIG_WHPX': ['i386-softmmu', 'x86_64-softmmu'], } endif
@@ -170,6 +171,7 @@ version_res = [] coref = [] iokit = [] emulator_link_args = [] +nvmm =not_found hvf = not_found if targetos == 'windows' socket = cc.find_library('ws2_32')
@@ -227,6 +229,14 @@ if not get_option('hax').disabled() accelerators += 'CONFIG_HAX' endif endif +if targetos == 'netbsd' + if cc.has_header('nvmm.h', required: get_option('nvmm')) + nvmm = cc.find_library('nvmm', required: get_option('nvmm')) + endif + if nvmm.found() + accelerators += 'CONFIG_NVMM' + endif +endif tcg_arch = config_host['ARCH'] if not get_option('tcg').disabled()
@@ -271,6 +281,9 @@ endif if 'CONFIG_HVF' not in accelerators and get_option('hvf').enabled() error('HVF not available on this platform') endif +if 'CONFIG_NVMM' not in accelerators and get_option('nvmm').enabled() + error('NVMM not available on this platform') +endif if 'CONFIG_WHPX' not in accelerators and get_option('whpx').enabled() error('WHPX not available on this platform') endif
@@ -2576,6 +2589,7 @@ if have_system summary_info += {'HAX support': config_all.has_key('CONFIG_HAX')} summary_info += {'HVF support': config_all.has_key('CONFIG_HVF')} summary_info += {'WHPX support': config_all.has_key('CONFIG_WHPX')} + summary_info += {'NVMM support': config_all.has_key('CONFIG_NVMM')} summary_info += {'Xen support': config_host.has_key('CONFIG_XEN_BACKEND')} if config_host.has_key('CONFIG_XEN_BACKEND') summary_info += {'xen ctrl version': config_host['CONFIG_XEN_CTRL_INTERFACE_VERSION']}
meson_options.txt +2 -0
@@ -33,6 +33,8 @@ option('whpx', type: 'feature', value: 'auto', description: 'WHPX acceleration support') option('hvf', type: 'feature', value: 'auto', description: 'HVF acceleration support') +option('nvmm', type: 'feature', value: 'auto', + description: 'NVMM acceleration support') option('xen', type: 'feature', value: 'auto', description: 'Xen backend support') option('xen_pci_passthrough', type: 'feature', value: 'auto',
qemu-options.hx +4 -4
@@ -26,7 +26,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ "-machine [type=]name[,prop[=value][,...]]\n" " selects emulated machine ('-machine help' for list)\n" " property accel=accel1[:accel2[:...]] selects accelerator\n" - " supported accelerators are kvm, xen, hax, hvf, whpx or tcg (default: tcg)\n" + " supported accelerators are kvm, xen, hax, hvf, nvmm, whpx or tcg (default: tcg)\n" " vmport=on|off|auto controls emulation of vmport (default: auto)\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n"
@@ -58,7 +58,7 @@ SRST ``accel=accels1[:accels2[:...]]`` This is used to enable an accelerator. Depending on the target - architecture, kvm, xen, hax, hvf, whpx or tcg can be available. + architecture, kvm, xen, hax, hvf, nvmm, whpx or tcg can be available. By default, tcg is used. If there is more than one accelerator specified, the next one is used if the previous one fails to initialize.
@@ -135,7 +135,7 @@ ERST DEF("accel", HAS_ARG, QEMU_OPTION_accel, "-accel [accel=]accelerator[,prop[=value][,...]]\n" - " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" + " select accelerator (kvm, xen, hax, hvf, nvmm, whpx or tcg; use 'help' for a list)\n" " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" " kernel-irqchip=on|off|split controls accelerated irqchip support (default=on)\n" " kvm-shadow-mem=size of KVM shadow MMU in bytes\n"
@@ -145,7 +145,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, SRST ``-accel name[,prop=value[,...]]`` This is used to enable an accelerator. Depending on the target - architecture, kvm, xen, hax, hvf, whpx or tcg can be available. By + architecture, kvm, xen, hax, hvf, nvmm, whpx or tcg can be available. By default, tcg is used. If there is more than one accelerator specified, the next one is used if the previous one fails to initialize.
Signature · 1 line
2.29.2
PATCH v7 2/4 Add NVMM accelerator: x86 CPU support
In reply to Reinoud Zandijk--- target/i386/meson.build | 1 + target/i386/nvmm/meson.build | 10 + target/i386/nvmm/nvmm-accel-ops.c | 111 +++ target/i386/nvmm/nvmm-accel-ops.h | 24 + target/i386/nvmm/nvmm-all.c | 1226 +++++++++++++++++++++++++++++ 5 files changed, 1372 insertions(+) create mode 100644 target/i386/nvmm/meson.build create mode 100644 target/i386/nvmm/nvmm-accel-ops.c create mode 100644 target/i386/nvmm/nvmm-accel-ops.h create mode 100644 target/i386/nvmm/nvmm-all.c
target/i386/meson.build +1 -0
@@ -19,6 +19,7 @@ i386_softmmu_ss.add(files( subdir('kvm') subdir('hax') subdir('whpx') +subdir('nvmm') subdir('hvf') subdir('tcg')
target/i386/nvmm/meson.build new file +10 -0
@@ -0,0 +1,10 @@ +i386_softmmu_ss.add(when: 'CONFIG_NVMM', if_true: + files( + 'nvmm-all.c', + 'nvmm-accel-ops.c', + ) +) + +i386_softmmu_ss.add(when: 'CONFIG_NVMM', if_true: + declare_dependency(link_args: ['-lnvmm']) +)
target/i386/nvmm/nvmm-accel-ops.c new file +111 -0
111 lines not on this page · raw message
target/i386/nvmm/nvmm-accel-ops.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (c) 2018-2019 Maxime Villard, All rights reserved. +* +* NetBSD Virtual Machine Monitor (NVMM) accelerator for QEMU. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef NVMM_CPUS_H +#define NVMM_CPUS_H + +#include "sysemu/cpus.h" + +int nvmm_init_vcpu (CPUState *cpu); +int nvmm_vcpu_exec (CPUState *cpu); +void nvmm_destroy_vcpu (CPUState *cpu); + +void nvmm_cpu_synchronize_state (CPUState *cpu); +void nvmm_cpu_synchronize_post_reset (CPUState *cpu); +void nvmm_cpu_synchronize_post_init (CPUState *cpu); +void nvmm_cpu_synchronize_pre_loadvm (CPUState *cpu); + +#endif /* NVMM_CPUS_H */
target/i386/nvmm/nvmm-all.c new file +1226 -0
1,226 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [PATCH v7 2/4] Add NVMM accelerator: x86 CPU support
target/i386/nvmm/meson.build line 10
Quoted 3 lines · Reinoud Zandijk
target/i386/nvmm/meson.build new file +3
-0+i386_softmmu_ss.add(when: 'CONFIG_NVMM', if_true: + declare_dependency(link_args: ['-lnvmm']) +)
You shouldn't be playing with link flags directly.
In patch 1, you found the nvmm library, and assigned it to the variable 'nvmm'.
You should just add the library as a dependency and let meson figure out what
to do.
So I think this should just be
i386_softmmu_ss.add(when: 'CONFIG_NVMM', if_true: nvmm)
r~
Re: [PATCH v7 2/4] Add NVMM accelerator: x86 CPU support
Quoted 7 lines · Richard Henderson
target/i386/nvmm/meson.build line 10
Quoted 3 lines · Reinoud Zandijk
target/i386/nvmm/meson.build new file +3
-0+i386_softmmu_ss.add(when: 'CONFIG_NVMM', if_true: + declare_dependency(link_args: ['-lnvmm']) +)You shouldn't be playing with link flags directly.
Quoted 7 lines
In patch 1, you found the nvmm library, and assigned it to the variable 'nvmm'. You should just add the library as a dependency and let meson figure out what to do.
So I think this should just be
i386_softmmu_ss.add(when: 'CONFIG_NVMM', if_true: nvmm)
Thanks for the patch :) I will incorporate it!
Reinoud
PATCH v7 3/4 Add NVMM accelerator: acceleration enlightenments
In reply to Reinoud Zandijk--- include/sysemu/hw_accel.h | 1 + include/sysemu/nvmm.h | 26 ++++++++++++++++++++++++++ target/i386/helper.c | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 include/sysemu/nvmm.h
include/sysemu/hw_accel.h +1 -0
@@ -16,6 +16,7 @@#include "sysemu/kvm.h" #include "sysemu/hvf.h" #include "sysemu/whpx.h" +#include "sysemu/nvmm.h" void cpu_synchronize_state (CPUState *cpu);void cpu_synchronize_post_reset (CPUState *cpu);
include/sysemu/nvmm.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (c) 2018-2019 Maxime Villard, All rights reserved. +* +* NetBSD Virtual Machine Monitor (NVMM) accelerator support. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef QEMU_NVMM_H +#define QEMU_NVMM_H + +#include "config-host.h" +#include "qemu-common.h" + +#ifdef CONFIG_NVMM + +int nvmm_enabled (void ); + +#else /* CONFIG_NVMM */ + +#define nvmm_enabled () (0) + +#endif /* CONFIG_NVMM */ + +#endif /* CONFIG_NVMM */
target/i386/helper.c +1 -1
@@ -495,7 +495,7 @@ void cpu_report_tpr_access(CPUX86State *env, TPRAccess access)X86CPU *cpu =env_archcpu (env);CPUState *cs =env_cpu (env); -if (kvm_enabled () ||whpx_enabled ()) { +if (kvm_enabled () ||whpx_enabled () ||nvmm_enabled ()) { env->tpr_access_type = access;cpu_interrupt (cs,CPU_INTERRUPT_TPR );
Signature · 1 line
2.29.2
PATCH v7 4/4 Add NVMM Accelerator: add maintainers for NetBSD/NVMM
In reply to Reinoud Zandijk--- MAINTAINERS | 11 +++++++++++ 1 file changed, 11 insertions(+)
MAINTAINERS +11 -0
@@ -510,6 +510,15 @@ F: accel/stubs/hax-stub.c F: include/sysemu/hax.h F: target/i386/hax/ +Guest CPU Cores (NVMM) +---------------------- +NetBSD Virtual Machine Monitor (NVMM) CPU support +M: Kamil Rytarowski <[email protected]> +M: Reinoud Zandijk <[email protected]> +S: Maintained +F: include/sysemu/nvmm.h +F: target/i386/nvmm/ + Hosts ----- LINUX
@@ -530,6 +539,8 @@ F: include/qemu/*posix*.h NETBSD M: Kamil Rytarowski <[email protected]> +M: Reinoud Zandijk <[email protected]> +M: Ryo ONODERA <[email protected]> S: Maintained K: ^Subject:.*(?i)NetBSD
Signature · 1 line
2.29.2