Add support of hvf accel
cover Add support of hvf accel
HVF is a para-virtualized QEMU accelerator for macOS based on Hypervisor.framework (HVF). Hypervisor.framework is a thin user-space wrapper around Intel VT/VMX that enables to run VMMs such as QEMU in non-privileged mode. The unit tests can be run on macOS to verify completeness of the HVF accel implementation.
Roman Bolshakov (2):
scripts/arch-run: Support testing of hvf accel
README: Document steps to run the tests on macOS
README.macOS.md | 47 +++++++++++++++++++++++++++++++++++++++++++ README.md | 6 ++++-- scripts/arch-run.bash | 13 ++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 README.macOS.md
Signature · 1 line
2.24.1
PATCH 1/2 scripts/arch-run: Support testing of hvf accel
The tests can be run if Hypervisor.framework API is available:
https://developer.apple.com/documentation/hypervisor?language=objc#1676667
--- scripts/arch-run.bash | 13 +++++++++++++ 1 file changed, 13 insertions(+)
scripts/arch-run.bash +13 -0
@@ -315,17 +315,30 @@ kvm_available () ( [ "$HOST" = x86_64 ] && [ "$ARCH" = i386 ] ) } +hvf_available () +{ + [ "$(sysctl -n kern.hv_support 2>/dev/null)" = "1" ] || return 1 + [ "$HOST" = "$ARCH_NAME" ] || + ( [ "$HOST" = x86_64 ] && [ "$ARCH" = i386 ] ) +} + get_qemu_accelerator () { if [ "$ACCEL" = "kvm" ] && ! kvm_available; then echo "KVM is needed, but not available on this host" >&2 return 2 fi + if [ "$ACCEL" = "hvf" ] && ! hvf_available; then + echo "HVF is needed, but not available on this host" >&2 + return 2 + fi if [ "$ACCEL" ]; then echo $ACCEL elif kvm_available; then echo kvm + elif hvf_available; then + echo hvf else echo tcg fi
Signature · 1 line
2.24.1
Re: [kvm-unit-tests PATCH 1/2] scripts/arch-run: Support testing of hvf accel
Cameron Esfahani
[email protected]
"The cake is a lie."
Common wisdom
Quoted 50 lines · Roman Bolshakov
The tests can be run if Hypervisor.framework API is available:
https://developer.apple.com/documentation/hypervisor?language=objc#1676667
Cc Cameron Esfahani <[email protected]>Signed-off-by Roman Bolshakov <[email protected]>---
scripts/arch-run.bash| 13 +++++++++++++1 file changed, 13 insertions(+)scripts/arch-run.bash +13
-0@@ -315,17 +315,30 @@ kvm_available () ( [ "$HOST" = x86_64 ] && [ "$ARCH" = i386 ] ) } +hvf_available () +{ + [ "$(sysctl -n kern.hv_support 2>/dev/null)" = "1" ] || return 1 + [ "$HOST" = "$ARCH_NAME" ] || + ( [ "$HOST" = x86_64 ] && [ "$ARCH" = i386 ] ) +} + get_qemu_accelerator () { if [ "$ACCEL" = "kvm" ] && ! kvm_available; then echo "KVM is needed, but not available on this host" >&2 return 2 fi + if [ "$ACCEL" = "hvf" ] && ! hvf_available; then + echo "HVF is needed, but not available on this host" >&2 + return 2 + fi if [ "$ACCEL" ]; then echo $ACCEL elif kvm_available; then echo kvm + elif hvf_available; then + echo hvf else echo tcg fiSignature · 1 line
2.24.1
PATCH 2/2 README: Document steps to run the tests on macOS
In reply to Roman BolshakovWhile at it, mention that hvf is a valid accel parameter.
--- README.macOS.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 6 ++++-- 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 README.macOS.md
README.macOS.md new file +47 -0
@@ -0,0 +1,47 @@ +# kvm-unit-tests on macOS + +Cross-compiler with ELF support is required for build of kvm-unit-tests on +macOS. + +## Building cross-compiler from source + +A cross-compiler toolchain can be built from source using crosstool-ng. The +latest released version of +[crosstool-ng](https://github.com/crosstool-ng/crosstool-ng) can be installed +using [homebrew](https://brew.sh) +``` +$ brew install crosstool-ng +``` + +A case-sensitive APFS/HFS+ volume has to be created using Disk Utility as a +build and installation directory for the cross-compiler. Please [see Apple +documentation](https://support.apple.com/guide/disk-utility/dsku19ed921c/mac) +for details. + +Assuming the case-sensitive volume is named /Volumes/BuildTools, the +cross-compiler can be built and installed there: +``` +$ X_BUILD_DIR=/Volumes/BuildTools/ct-ng-build +$ X_INSTALL_DIR=/Volumes/BuildTools/x-tools +$ mkdir $X_BUILD_DIR +$ ct-ng -C $X_BUILD_DIR x86_64-unknown-linux-gnu +$ ct-ng -C $X_BUILD_DIR build CT_PREFIX=$X_INSTALL_DIR +``` + +Once compiled, the cross-compiler can be used to build the tests: +``` +$ ./configure --cross-prefix=$X_INSTALL_DIR/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu- +$ make +``` + +## Pre-built cross-compiler + +x86_64-elf-gcc package in Homebrew provides pre-built cross-compiler but it +fails to compile kvm-unit-tests. + +## Running the tests + +GNU coreutils should be installed prior to running the tests: +``` +$ brew install coreutils +```
README.md +4 -2
@@ -15,6 +15,8 @@ To create the test images do: in this directory. Test images are created in ./ARCH/\*.flat +NOTE: GCC cross-compiler is required for [build on macOS](README.macOS.md). + ## Standalone tests The tests can be built as standalone. To create and use standalone tests do:
@@ -47,7 +49,7 @@ environment variable: QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat -To select an accelerator, for example "kvm" or "tcg", specify the +To select an accelerator, for example "kvm", "hvf" or "tcg", specify the ACCEL=name environment variable: ACCEL=kvm ./x86-run ./x86/msr.flat
@@ -78,7 +80,7 @@ which can then be accessed in the usual ways, e.g. VAL = getenv("KEY"). Any key=val strings can be passed, but some have reserved meanings in the framework. The list of reserved environment variables is below - QEMU_ACCEL either kvm or tcg + QEMU_ACCEL either kvm, hvf or tcg QEMU_VERSION_STRING string of the form `qemu -h | head -1` KERNEL_VERSION_STRING string of the form `uname -r`
Signature · 1 line
2.24.1
Re: [kvm-unit-tests PATCH 2/2] README: Document steps to run the tests on macOS
Cameron Esfahani
[email protected]
"We do what we must because we can."
Aperture Science
Quoted 99 lines · Roman Bolshakov
While at it, mention that hvf is a valid accel parameter.
Cc Cameron Esfahani <[email protected]>Signed-off-by Roman Bolshakov <[email protected]>---
README.macOS.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++
README.md | 6 ++++--2 files changed, 51 insertions(+), 2 deletions(-)create mode 100644 README.macOS.md
README.macOS.md new file +47
-0@@ -0,0 +1,47 @@ +# kvm-unit-tests on macOS + +Cross-compiler with ELF support is required for build of kvm-unit-tests on +macOS. + +## Building cross-compiler from source + +A cross-compiler toolchain can be built from source using crosstool-ng. The +latest released version of +[crosstool-ng](https://github.com/crosstool-ng/crosstool-ng) can be installed +using [homebrew](https://brew.sh) +``` +$ brew install crosstool-ng +``` + +A case-sensitive APFS/HFS+ volume has to be created using Disk Utility as a +build and installation directory for the cross-compiler. Please [see Apple +documentation](https://support.apple.com/guide/disk-utility/dsku19ed921c/mac) +for details. + +Assuming the case-sensitive volume is named /Volumes/BuildTools, the +cross-compiler can be built and installed there: +``` +$ X_BUILD_DIR=/Volumes/BuildTools/ct-ng-build +$ X_INSTALL_DIR=/Volumes/BuildTools/x-tools +$ mkdir $X_BUILD_DIR +$ ct-ng -C $X_BUILD_DIR x86_64-unknown-linux-gnu +$ ct-ng -C $X_BUILD_DIR build CT_PREFIX=$X_INSTALL_DIR +``` + +Once compiled, the cross-compiler can be used to build the tests: +``` +$ ./configure --cross-prefix=$X_INSTALL_DIR/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu- +$ make +``` + +## Pre-built cross-compiler + +x86_64-elf-gcc package in Homebrew provides pre-built cross-compiler but it +fails to compile kvm-unit-tests. + +## Running the tests + +GNU coreutils should be installed prior to running the tests: +``` +$ brew install coreutils +```README.md +0
-0@@ -15,6 +15,8 @@ To create the test images do:in this directory. Test images are created in ./ARCH/\*.flat
README.md +2
-0+NOTE: GCC cross-compiler is required for [build on macOS](README.macOS.md). +## Standalone tests
The tests can be built as standalone. To create and use standalone tests do:
README.md +1
-1@@ -47,7 +49,7 @@ environment variable: QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat -To select an accelerator, for example "kvm" or "tcg", specify the +To select an accelerator, for example "kvm", "hvf" or "tcg", specify theACCEL=name environment variable:
ACCEL=kvm ./x86-run ./x86/msr.flatREADME.md +0
-0@@ -78,7 +80,7 @@ which can then be accessed in the usual ways, e.g. VAL = getenv("KEY").Any key=val strings can be passed, but some have reserved meanings in the framework. The list of reserved environment variables is below
README.md +1
-1- QEMU_ACCEL either kvm or tcg + QEMU_ACCEL either kvm, hvf or tcg QEMU_VERSION_STRING string of the form `qemu -h | head -1` KERNEL_VERSION_STRING string of the form `uname -r`Signature · 2 lines
-- 2.24.1
I'm sorry for broken formating in the cover letter. Here's a reformat at your convenience.
HVF is a para-virtualized QEMU accelerator for macOS based on Hypervisor.framework (HVF). Hypervisor.framework is a thin user-space wrapper around Intel VT/VMX that enables to run VMMs such as QEMU in non-privileged mode.
The unit tests can be run on macOS to verify completeness of the HVF accel implementation.
Regards,
Roman
The first sentence doesn't make much sense. HVF is not QEMU specific. Other VMMs use it.
Cameron Esfahani
[email protected]
"The cake is a lie."
Common wisdom
Quoted 15 lines · Roman Bolshakov
I'm sorry for broken formating in the cover letter. Here's a reformat at your convenience.
HVF is a para-virtualized QEMU accelerator for macOS based on Hypervisor.framework (HVF). Hypervisor.framework is a thin user-space wrapper around Intel VT/VMX that enables to run VMMs such as QEMU in non-privileged mode.
The unit tests can be run on macOS to verify completeness of the HVF accel implementation.
Regards,
Roman