Implements the NetBSD Virtual Machine Monitor accelerator
v6 cover Implements the NetBSD Virtual Machine Monitor accelerator
The NetBSD team has been working hard on a new user-mode API for our hypervisor that will be released as part of the upcoming NetBSD 9.0.
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:
v5 -> v6:
- Ported to updated Qemu 6.0 build system and 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 | 12 +- include/sysemu/hw_accel.h | 1 + include/sysemu/nvmm.h | 26 + meson.build | 23 +- meson_options.txt | 2 + qemu-options.hx | 8 +- target/i386/helper.c | 2 +- target/i386/meson.build | 1 + target/i386/nvmm/meson.build | 4 + target/i386/nvmm/nvmm-accel-ops.c | 111 +++ target/i386/nvmm/nvmm-accel-ops.h | 25 + target/i386/nvmm/nvmm-all.c | 1231 +++++++++++++++++++++++++++++ 14 files changed, 1449 insertions(+), 11 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 v6 1/4 Add NVMM accelerator: configure and build logic
--- accel/Kconfig | 3 +++ configure | 12 +++++++++--- meson.build | 23 ++++++++++++++++++++--- meson_options.txt | 2 ++ qemu-options.hx | 8 ++++---- 5 files changed, 38 insertions(+), 10 deletions(-)
accel/Kconfig +3 -0
@@ -1,6 +1,9 @@ config WHPX bool +config NVMM + bool + config HAX bool
configure +9 -3
@@ -352,6 +352,7 @@ kvm="auto" hax="auto" hvf="auto" whpx="auto" +nvmm="auto" rdma="$default_feature" pvrdma="$default_feature" gprof="no"
@@ -886,7 +887,7 @@ for opt do ;; --python=*) python="$optarg" ; explicit_python=yes ;; - --sphinx-build=*) sphinx_build="$optarg" + --sphinx-build-3.8-3.8=*) sphinx_build="$optarg" ;; --skip-meson) skip_meson=yes ;;
@@ -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"
@@ -1727,7 +1732,7 @@ Advanced options (experts only): --cross-cc-flags-ARCH= use compiler flags when building ARCH guest tests --make=MAKE use specified make [$make] --python=PYTHON use specified python [$python] - --sphinx-build=SPHINX use specified sphinx-build [$sphinx_build] + --sphinx-build-3.8-3.8=SPHINX use specified sphinx-build-3.8-3.8 [$sphinx_build] --meson=MESON use specified meson [$meson] --ninja=NINJA use specified ninja [$ninja] --smbd=SMBD use specified smbd [$smbd]
@@ -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 +20 -3
@@ -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 = [] hvf = not_found if targetos == 'windows' socket = cc.find_library('ws2_32')
@@ -195,6 +197,12 @@ elif targetos == 'openbsd' # Disable OpenBSD W^X if available emulator_link_args = cc.get_supported_link_arguments('-Wl,-z,wxneeded') endif +elif targetos == 'netbsd' + if not get_option('nvmm').disabled() + if cc.has_header('nvmm.h') + nvmm = cc.find_library('nvmm') + endif + endif endif accelerators = []
@@ -227,6 +235,11 @@ if not get_option('hax').disabled() accelerators += 'CONFIG_HAX' endif endif +if not get_option('nvmm').disabled() + if cc.has_header('nvmm.h', required: get_option('nvmm')) + accelerators += 'CONFIG_NVMM' + endif +endif tcg_arch = config_host['ARCH'] if not get_option('tcg').disabled()
@@ -271,6 +284,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
@@ -607,7 +623,7 @@ if have_system and not get_option('curses').disabled() has_curses_h = cc.has_header('curses.h', args: curses_compile_args) endif if has_curses_h - curses_libname_list = (targetos == 'windows' ? ['pdcurses'] : ['ncursesw', 'cursesw']) + curses_libname_list = (targetos == 'windows' ? ['pdcurses'] : ['ncursesw', 'cursesw', 'curses']) foreach curses_libname : curses_libname_list libcurses = cc.find_library(curses_libname, required: false,
@@ -625,7 +641,7 @@ if have_system and not get_option('curses').disabled() endif endif if not get_option('iconv').disabled() - foreach link_args : [ ['-liconv'], [] ] + foreach link_args : [ [], ['-liconv'] ] # Programs will be linked with glib and this will bring in libiconv on FreeBSD. # We need to use libiconv if available because mixing libiconv's headers with # the system libc does not work.
@@ -2226,7 +2242,7 @@ foreach target : target_dirs 'name': 'qemu-system-' + target_name, 'gui': false, 'sources': files('softmmu/main.c'), - 'dependencies': [] + 'dependencies': [nvmm] }] if targetos == 'windows' and (sdl.found() or gtk.found()) execs += [{
@@ -2576,6 +2592,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
Re: [PATCH v6 1/4] Add NVMM accelerator: configure and build logic
Quoted 2 lines · Reinoud Zandijk
Signed-off-by Reinoud Zandijk <[email protected]>Signed-off-by Kamil Rytarowski <[email protected]>
Incorrect order for the S-o-b headers, you should be last.
Review for opt do · line 890
Quoted 7 lines
---
(quoted diff) +1
-1@@ -886,7 +887,7 @@ for opt do ;; --python=*) python="$optarg" ; explicit_python=yes ;; - --sphinx-build=*) sphinx_build="$optarg" + --sphinx-build-3.8-3.8=*) sphinx_build="$optarg"
Oops. :) Another occurrence later.
meson.build
Quoted 4 lines
meson.build +0
-0
The meson.build parts can be simplified by applying this patch:
meson.build +1 -1
@@ -171,7 +171,7 @@ version_res = [] coref = [] iokit = [] emulator_link_args = [] -nvmm = [] +nvmm = not_found hvf = not_found if targetos == 'windows' socket = cc.find_library('ws2_32')
@@ -197,12 +197,6 @@ elif targetos == 'openbsd' # Disable OpenBSD W^X if available emulator_link_args =
cc.get_supported_link_arguments('-Wl,-z,wxneeded')
endif
-elif targetos == 'netbsd'
- if not get_option('nvmm').disabled()
- if cc.has_header('nvmm.h')
- nvmm = cc.find_library('nvmm')
- endif
- endif
endif
accelerators = []
@@ -235,8 +229,11 @@ if not get_option('hax').disabled()
accelerators += 'CONFIG_HAX'
endif
endif
-if not get_option('nvmm').disabled()
+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
@@ -2242,7 +2239,7 @@ foreach target : target_dirs
'name': 'qemu-system-' + target_name,
'gui': false,
'sources': files('softmmu/main.c'),
- 'dependencies': [nvmm]
+ 'dependencies': []
}]
if targetos == 'windows' and (sdl.found() or gtk.found())
execs += [{Quoted 10 lines
meson.build +1
-1@@ -607,7 +623,7 @@ if have_system and not get_option('curses').disabled() has_curses_h = cc.has_header('curses.h', args: curses_compile_args) endif if has_curses_h - curses_libname_list = (targetos == 'windows' ? ['pdcurses'] : ['ncursesw', 'cursesw']) + curses_libname_list = (targetos == 'windows' ? ['pdcurses'] : ['ncursesw', 'cursesw', 'curses']) foreach curses_libname : curses_libname_list libcurses = cc.find_library(curses_libname, required: false,
meson.build if have_system and not get_option('curses').disabled() · line 647
Quoted 8 lines
meson.build +1
-1@@ -625,7 +641,7 @@ if have_system and not get_option('curses').disabled() endif endif if not get_option('iconv').disabled() - foreach link_args : [ ['-liconv'], [] ] + foreach link_args : [ [], ['-liconv'] ] # Programs will be linked with glib and this will bring in libiconv on FreeBSD. # We need to use libiconv if available because mixing libiconv's headers with # the system libc does not work.
Independent changes, should be posted separately.
meson.build foreach target : target_dirs · line 2248
Quoted 9 lines
meson.build +1
-1@@ -2226,7 +2242,7 @@ foreach target : target_dirs 'name': 'qemu-system-' + target_name, 'gui': false, 'sources': files('softmmu/main.c'), - 'dependencies': [] + 'dependencies': [nvmm] }] if targetos == 'windows' and (sdl.found() or gtk.found()) execs += [{
Not needed yet, should be added together with the nvmm sources to the sourceset.
Paolo
Re: [PATCH v6 1/4] Add NVMM accelerator: configure and build logic
Hi Paolo,
thanks for the review!
Quoted 5 lines · Paolo Bonzini
Quoted 2 lines · Reinoud Zandijk
Signed-off-by Reinoud Zandijk <[email protected]>Signed-off-by Kamil Rytarowski <[email protected]>Incorrect order for the S-o-b headers, you should be last.
Oops? there is a prescribed order in those? Will change the order!
Quoted 9 lines
Review for opt do · line 890
Quoted 7 lines
---
(quoted diff) +1
-1@@ -886,7 +887,7 @@ for opt do ;; --python=*) python="$optarg" ; explicit_python=yes ;; - --sphinx-build=*) sphinx_build="$optarg" + --sphinx-build-3.8-3.8=*) sphinx_build="$optarg"Oops. :) Another occurrence later.
Ai ai ai, a different patch krept in! In pkgsrc all patches on a single file are normally combined and thus they krept in!
meson.build
Quoted 8 lines
meson.build
Quoted 4 lines
meson.build +0
-0The meson.build parts can be simplified by applying this patch:
meson.build +0
-0
Thanks! Will try it out and add to the patch.
Quoted 11 lines
meson.build if have_system and not get_option('curses').disabled() · line 647
Quoted 9 lines
meson.build +1
-1@@ -625,7 +641,7 @@ if have_system and not get_option('curses').disabled() endif endif if not get_option('iconv').disabled() - foreach link_args : [ ['-liconv'], [] ] + foreach link_args : [ [], ['-liconv'] ] # Programs will be linked with glib and this will bring in libiconv on FreeBSD. # We need to use libiconv if available because mixing libiconv's headers with # the system libc does not work.Independent changes, should be posted separately.
Yep, those shouldn't be in this patchset indeed, see above.
Will try to fix it and go for version 7 soon.
Is there a way for `qemu format-patch' to preserve the comments made in the previous run? It would be handy if it would paste in the old patchset's comments in the new patchset :)
Reinoud
Re: [PATCH v6 1/4] Add NVMM accelerator: configure and build logic
Quoted 4 lines · Reinoud Zandijk
Hi Paolo,
thanks for the review!
Quoted 8 lines
Quoted 5 lines · Paolo Bonzini
Quoted 2 lines · Reinoud Zandijk
Signed-off-by Reinoud Zandijk <[email protected]>Signed-off-by Kamil Rytarowski <[email protected]>Incorrect order for the S-o-b headers, you should be last.
Oops? there is a prescribed order in those? Will change the order!
The second got the patch from the first, the third from the second etc.
Quoted 5 lines
Will try to fix it and go for version 7 soon.
Is there a way for `qemu format-patch' to preserve the comments made in the previous run? It would be handy if it would paste in the old patchset's comments in the new patchset :)
Hmm, not sure what you mean. There is "git notes".
Paolo
PATCH v6 2/4 Add NVMM accelerator: x86 CPU support
In reply to Reinoud Zandijk--- target/i386/meson.build | 1 + target/i386/nvmm/meson.build | 4 + target/i386/nvmm/nvmm-accel-ops.c | 111 +++ target/i386/nvmm/nvmm-accel-ops.h | 25 + target/i386/nvmm/nvmm-all.c | 1231 +++++++++++++++++++++++++++++ 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 +4 -0
@@ -0,0 +1,4 @@ +i386_softmmu_ss.add(when: 'CONFIG_NVMM', if_true: files( + 'nvmm-all.c', + 'nvmm-accel-ops.c', +))
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 +25 -0
@@ -0,0 +1,25 @@ +/* +* 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_vcpu_kick (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 +1231 -0
1,231 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [PATCH v6 2/4] Add NVMM accelerator: x86 CPU support
Quoted 1 line · Reinoud Zandijk
+void
nvmm_vcpu_kick(CPUState *cpu);
Not defined anywhere.
Quoted 10 lines
target/i386/nvmm/nvmm-all.c new file +10
-0+{ +#if NVMM_USER_VERSION ==1 +struct sigaction sigact; +sigset_t set; + +/* Install the IPI handler. */ +memset (&sigact,0 ,sizeof (sigact)); + sigact.sa_handler = nvmm_ipi_signal; +sigaction (SIG_IPI , &sigact,NULL ); +
target/i386/nvmm/nvmm-all.c line 915
Quoted 10 lines
target/i386/nvmm/nvmm-all.c new file +10
-0+/* Allow IPIs on the current thread. */ +sigprocmask (SIG_BLOCK ,NULL , &set); +sigdelset (&set,SIG_IPI ); +pthread_sigmask (SIG_SETMASK , &set,NULL ); +#else +/* +* We use the nvmm_vcpu_stop() mechanism, and don't use signals. +* Nothing to do. +*/ +#endif
Since nvmm_vcpu_stop is very similar to KVM's immediate_exit mechanism, I think you still need to have a dummy signal handler to kick the VM out of the run loop *if it is in the kernel*. The signal handler however can just do nothing.
Also, can you just drop support for NVMM_USER_VERSION == 1?
target/i386/nvmm/meson.build line 4
Quoted 10 lines
target/i386/nvmm/meson.build new file +4
-0@@ -0,0 +1,4 @@ +i386_softmmu_ss.add(when: 'CONFIG_NVMM', if_true: files( + 'nvmm-all.c', + 'nvmm-accel-ops.c', +))
The nvmm library should be added here.
Paolo
Re: [PATCH v6 2/4] Add NVMM accelerator: x86 CPU support
Quoted 4 lines · Paolo Bonzini
Quoted 1 line · Reinoud Zandijk
+void
nvmm_vcpu_kick(CPUState *cpu);Not defined anywhere.
Hmmm, indeed. I think its a leftover of the former patch. Good catch.
Quoted 17 lines
Quoted 17 lines
target/i386/nvmm/nvmm-all.c new file +17
-0+{ +#if NVMM_USER_VERSION ==1 +struct sigaction sigact; +sigset_t set; + +/* Install the IPI handler. */ +memset (&sigact,0 ,sizeof (sigact)); + sigact.sa_handler = nvmm_ipi_signal; +sigaction (SIG_IPI , &sigact,NULL ); + +/* Allow IPIs on the current thread. */ +sigprocmask (SIG_BLOCK ,NULL , &set); +sigdelset (&set,SIG_IPI ); +pthread_sigmask (SIG_SETMASK , &set,NULL ); +#else +/* +* We use the nvmm_vcpu_stop() mechanism, and don't use signals.
Quoted 8 lines
target/i386/nvmm/nvmm-all.c line 915
Quoted 3 lines
target/i386/nvmm/nvmm-all.c new file +3
-0+* Nothing to do. +*/ +#endif Since
nvmm_vcpu_stopis very similar to KVM'simmediate_exitmechanism, I think you still need to have a dummy signal handler to kick the VM out of the run loop *if it is in the kernel*. The signal handler however can just do nothing.
Are you worried the in-kernel thread will somehow get stuck or halt on exit of Qemu and left as a zombie?
Quoted 1 line
Also, can you just drop support for
NVMM_USER_VERSION== 1?
Now thats a good suggestion. We could add support for it in the pkgsrc package. When 9.0 gets retired, we could then retire it there without the need to patch Qemu again.
Quoted 4 lines
Quoted 4 lines
target/i386/nvmm/meson.build new file +0
-1--- /dev/null
Quoted 8 lines
target/i386/nvmm/meson.build line 4
Quoted 6 lines
+++ b/target/i386/nvmm/meson.build
target/i386/nvmm/meson.build new file +4
-0@@ -0,0 +1,4 @@ +i386_softmmu_ss.add(when: 'CONFIG_NVMM', if_true: files( + 'nvmm-all.c', + 'nvmm-accel-ops.c', +))The nvmm library should be added here.
I am not sure what you mean by that. You provided a patch for the meson.build file, will that not suffice?
With regards,
Reinoud
Re: [PATCH v6 2/4] Add NVMM accelerator: x86 CPU support
Quoted 34 lines · Reinoud Zandijk
Quoted 4 lines · Paolo Bonzini
Quoted 1 line · Reinoud Zandijk
+void
nvmm_vcpu_kick(CPUState *cpu);Not defined anywhere.
Hmmm, indeed. I think its a leftover of the former patch. Good catch.
Quoted 17 lines
Quoted 17 lines
target/i386/nvmm/nvmm-all.c new file +17
-0+{ +#if NVMM_USER_VERSION ==1 +struct sigaction sigact; +sigset_t set; + +/* Install the IPI handler. */ +memset (&sigact,0 ,sizeof (sigact)); + sigact.sa_handler = nvmm_ipi_signal; +sigaction (SIG_IPI , &sigact,NULL ); + +/* Allow IPIs on the current thread. */ +sigprocmask (SIG_BLOCK ,NULL , &set); +sigdelset (&set,SIG_IPI ); +pthread_sigmask (SIG_SETMASK , &set,NULL ); +#else +/* +* We use the nvmm_vcpu_stop() mechanism, and don't use signals. Quoted 8 lines
target/i386/nvmm/nvmm-all.c line 915
Quoted 3 lines
target/i386/nvmm/nvmm-all.c new file +3
-0+* Nothing to do. +*/ +#endif Since
nvmm_vcpu_stopis very similar to KVM'simmediate_exitmechanism, I think you still need to have a dummy signal handler to kick the VM out of the run loop *if it is in the kernel*. The signal handler however can just do nothing.
Quoted 2 lines
Are you worried the in-kernel thread will somehow get stuck or halt on exit of Qemu and left as a zombie?
No, you need all three of these:
- the signal to interrupt a thread that is running the VM
- the exit_request field to interrupt a thread that is running QEMU code
- nvmm_vcpu_stop() to interrupt a thread that is running kernel code but has not yet started running the VM.
Quoted 5 lines
Quoted 1 line
Also, can you just drop support for
NVMM_USER_VERSION== 1?Now thats a good suggestion. We could add support for it in the pkgsrc package. When 9.0 gets retired, we could then retire it there without the need to patch Qemu again.
If it's still in use in the wild I have no problem keeping it. The difference is small; I was just asking.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
target/i386/nvmm/meson.build new file +0
-1--- /dev/nullQuoted 8 lines
target/i386/nvmm/meson.build line 4
Quoted 6 lines
+++ b/target/i386/nvmm/meson.build
target/i386/nvmm/meson.build new file +4
-0@@ -0,0 +1,4 @@ +i386_softmmu_ss.add(when: 'CONFIG_NVMM', if_true: files( + 'nvmm-all.c', + 'nvmm-accel-ops.c', +))The nvmm library should be added here.
Quoted 2 lines
I am not sure what you mean by that. You provided a patch for the meson.build file, will that not suffice?
That patch dropped nvmm from meson.build, here is where it should be added (so that it is conditional on CONFIG_NVMM and qemu-system-arm does not link to libnvmm).
Paolo
PATCH v6 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 v6 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
Quoted 18 lines · Reinoud Zandijk
The NetBSD team has been working hard on a new user-mode API for our hypervisor that will be released as part of the upcoming NetBSD 9.0.
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_64it 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.
Quoted 6 lines
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.
Very nice. Just a couple remarks but nothing too serious.
Paolo