* [kvm-unit-tests PATCH 0/2] riscv: Add kvmtool support @ 2025-07-04 15:12 Andrew Jones 2025-07-04 15:12 ` [kvm-unit-tests PATCH 1/2] arm/arm64: Ensure proper host arch with kvmtool Andrew Jones ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: Andrew Jones @ 2025-07-04 15:12 UTC (permalink / raw) To: kvm, kvmarm, kvm-riscv Cc: alexandru.elisei, cleger, jesse, jamestiotio, Atish Patra The first patch is for arm's scripts. It adds a check that I found useful on the riscv side. The second patch enables riscv to use kvmtool too. Andrew Jones (2): arm/arm64: Ensure proper host arch with kvmtool riscv: Add kvmtool support README.md | 7 ++-- arm/run | 5 +++ configure | 12 ++++-- riscv/efi/run | 6 +++ riscv/run | 110 +++++++++++++++++++++++++++++++++++--------------- 5 files changed, 101 insertions(+), 39 deletions(-) -- 2.49.0 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [kvm-unit-tests PATCH 1/2] arm/arm64: Ensure proper host arch with kvmtool 2025-07-04 15:12 [kvm-unit-tests PATCH 0/2] riscv: Add kvmtool support Andrew Jones @ 2025-07-04 15:12 ` Andrew Jones 2025-07-07 15:10 ` Jesse Taube 2025-07-08 3:41 ` Nutty Liu 2025-07-04 15:12 ` [kvm-unit-tests PATCH 2/2] riscv: Add kvmtool support Andrew Jones 2025-07-08 9:00 ` [kvm-unit-tests PATCH 0/2] " Andrew Jones 2 siblings, 2 replies; 9+ messages in thread From: Andrew Jones @ 2025-07-04 15:12 UTC (permalink / raw) To: kvm, kvmarm, kvm-riscv Cc: alexandru.elisei, cleger, jesse, jamestiotio, Atish Patra When running on non-arm (e.g. an x86 machine) if the framework is configured to use kvmtool then, unlike with QEMU, it can't work. Signed-off-by: Andrew Jones <andrew.jones@linux.dev> --- arm/run | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arm/run b/arm/run index 9ee795ae424c..858333fce465 100755 --- a/arm/run +++ b/arm/run @@ -97,6 +97,11 @@ function arch_run_kvmtool() { local command + if [ "$HOST" != "arm" ] && [ "$HOST" != "aarch64" ]; then + echo "kvmtool requires KVM but the host ('$HOST') is not arm" >&2 + exit 2 + fi + kvmtool=$(search_kvmtool_binary) || exit $? -- 2.49.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 1/2] arm/arm64: Ensure proper host arch with kvmtool 2025-07-04 15:12 ` [kvm-unit-tests PATCH 1/2] arm/arm64: Ensure proper host arch with kvmtool Andrew Jones @ 2025-07-07 15:10 ` Jesse Taube 2025-07-08 3:41 ` Nutty Liu 1 sibling, 0 replies; 9+ messages in thread From: Jesse Taube @ 2025-07-07 15:10 UTC (permalink / raw) To: Andrew Jones Cc: kvm, kvmarm, kvm-riscv, alexandru.elisei, cleger, jamestiotio, Atish Patra On Fri, Jul 4, 2025 at 8:13 AM Andrew Jones <andrew.jones@linux.dev> wrote: > > When running on non-arm (e.g. an x86 machine) if the framework is > configured to use kvmtool then, unlike with QEMU, it can't work. > > Signed-off-by: Andrew Jones <andrew.jones@linux.dev> Reviewed-by: Jesse Taube <jesse@rivosinc.com> > --- > arm/run | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/arm/run b/arm/run > index 9ee795ae424c..858333fce465 100755 > --- a/arm/run > +++ b/arm/run > @@ -97,6 +97,11 @@ function arch_run_kvmtool() > { > local command > > + if [ "$HOST" != "arm" ] && [ "$HOST" != "aarch64" ]; then > + echo "kvmtool requires KVM but the host ('$HOST') is not arm" >&2 > + exit 2 > + fi > + > kvmtool=$(search_kvmtool_binary) || > exit $? > > -- > 2.49.0 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 1/2] arm/arm64: Ensure proper host arch with kvmtool 2025-07-04 15:12 ` [kvm-unit-tests PATCH 1/2] arm/arm64: Ensure proper host arch with kvmtool Andrew Jones 2025-07-07 15:10 ` Jesse Taube @ 2025-07-08 3:41 ` Nutty Liu 1 sibling, 0 replies; 9+ messages in thread From: Nutty Liu @ 2025-07-08 3:41 UTC (permalink / raw) To: Andrew Jones, kvm, kvmarm, kvm-riscv Cc: alexandru.elisei, cleger, jesse, jamestiotio, Atish Patra On 7/4/2025 11:12 PM, Andrew Jones wrote: > When running on non-arm (e.g. an x86 machine) if the framework is > configured to use kvmtool then, unlike with QEMU, it can't work. > > Signed-off-by: Andrew Jones <andrew.jones@linux.dev> Reviewed-by: Nutty Liu <liujingqi@lanxincomputing.com> Thanks, Nutty > --- > arm/run | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/arm/run b/arm/run > index 9ee795ae424c..858333fce465 100755 > --- a/arm/run > +++ b/arm/run > @@ -97,6 +97,11 @@ function arch_run_kvmtool() > { > local command > > + if [ "$HOST" != "arm" ] && [ "$HOST" != "aarch64" ]; then > + echo "kvmtool requires KVM but the host ('$HOST') is not arm" >&2 > + exit 2 > + fi > + > kvmtool=$(search_kvmtool_binary) || > exit $? ^ permalink raw reply [flat|nested] 9+ messages in thread
* [kvm-unit-tests PATCH 2/2] riscv: Add kvmtool support 2025-07-04 15:12 [kvm-unit-tests PATCH 0/2] riscv: Add kvmtool support Andrew Jones 2025-07-04 15:12 ` [kvm-unit-tests PATCH 1/2] arm/arm64: Ensure proper host arch with kvmtool Andrew Jones @ 2025-07-04 15:12 ` Andrew Jones 2025-07-07 15:28 ` Jesse Taube 2025-07-08 3:43 ` Nutty Liu 2025-07-08 9:00 ` [kvm-unit-tests PATCH 0/2] " Andrew Jones 2 siblings, 2 replies; 9+ messages in thread From: Andrew Jones @ 2025-07-04 15:12 UTC (permalink / raw) To: kvm, kvmarm, kvm-riscv Cc: alexandru.elisei, cleger, jesse, jamestiotio, Atish Patra arm/arm64 supports running tests with kvmtool as a first class citizen. Most the code to do that is in the common scripts, so just add the riscv specific bits needed to allow riscv to use kvmtool as a first class citizen too. Signed-off-by: Andrew Jones <andrew.jones@linux.dev> --- README.md | 7 ++-- configure | 12 ++++-- riscv/efi/run | 6 +++ riscv/run | 110 +++++++++++++++++++++++++++++++++++--------------- 4 files changed, 96 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 723ce04cd978..cbd8a9940ec4 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,8 @@ or: to run them all. -All tests can be run using QEMU. On arm and arm64, tests can also be run using -kvmtool. +All tests can be run using QEMU. On arm, arm64, riscv32, and riscv64 tests can +also be run using kvmtool. By default the runner script searches for a suitable QEMU binary in the system. To select a specific QEMU binary though, specify the QEMU=path/to/binary @@ -97,8 +97,7 @@ variable. kvmtool supports only kvm as the accelerator. Check [x86/efi/README.md](./x86/efi/README.md). -On arm and arm64, this is only supported with QEMU; kvmtool cannot run the -tests under UEFI. +This is only supported with QEMU; kvmtool cannot run the tests under UEFI. # Tests configuration file diff --git a/configure b/configure index 470f9d7cdb3b..6d549d1ecb5b 100755 --- a/configure +++ b/configure @@ -90,7 +90,7 @@ usage() { selects the best value based on the host system and the test configuration. --target=TARGET target platform that the tests will be running on (qemu or - kvmtool, default is qemu) (arm/arm64 only) + kvmtool, default is qemu) (arm/arm64 and riscv32/riscv64 only) --cross-prefix=PREFIX cross compiler prefix --cc=CC c compiler to use ($cc) --cflags=FLAGS extra options to be passed to the c compiler @@ -284,7 +284,8 @@ fi if [ -z "$target" ]; then target="qemu" else - if [ "$arch" != "arm64" ] && [ "$arch" != "arm" ]; then + if [ "$arch" != "arm" ] && [ "$arch" != "arm64" ] && + [ "$arch" != "riscv32" ] && [ "$arch" != "riscv64" ]; then echo "--target is not supported for $arch" usage fi @@ -393,6 +394,10 @@ elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then testdir=riscv arch_libdir=riscv : "${uart_early_addr:=0x10000000}" + if [ "$target" != "qemu" ] && [ "$target" != "kvmtool" ]; then + echo "--target must be one of 'qemu' or 'kvmtool'!" + usage + fi elif [ "$arch" = "s390x" ]; then testdir=s390x else @@ -519,7 +524,8 @@ EFI_DIRECT=$efi_direct CONFIG_WERROR=$werror GEN_SE_HEADER=$gen_se_header EOF -if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then +if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ] || + [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then echo "TARGET=$target" >> config.mak fi diff --git a/riscv/efi/run b/riscv/efi/run index 5a72683a6ef5..b9b75440c659 100755 --- a/riscv/efi/run +++ b/riscv/efi/run @@ -11,6 +11,12 @@ if [ ! -f config.mak ]; then fi source config.mak source scripts/arch-run.bash +source scripts/vmm.bash + +if [[ $(vmm_get_target) == "kvmtool" ]]; then + echo "kvmtool does not support EFI tests." + exit 2 +fi if [ -f RISCV_VIRT_CODE.fd ]; then DEFAULT_UEFI=RISCV_VIRT_CODE.fd diff --git a/riscv/run b/riscv/run index 0f000f0d82c6..7bcf235fb645 100755 --- a/riscv/run +++ b/riscv/run @@ -10,35 +10,81 @@ if [ -z "$KUT_STANDALONE" ]; then source scripts/vmm.bash fi -# Allow user overrides of some config.mak variables -mach=$MACHINE_OVERRIDE -qemu_cpu=$TARGET_CPU_OVERRIDE -firmware=$FIRMWARE_OVERRIDE - -: "${mach:=virt}" -: "${qemu_cpu:=$TARGET_CPU}" -: "${qemu_cpu:=$DEFAULT_QEMU_CPU}" -: "${firmware:=$FIRMWARE}" -[ "$firmware" ] && firmware="-bios $firmware" - -set_qemu_accelerator || exit $? -[ "$ACCEL" = "kvm" ] && QEMU_ARCH=$HOST -acc="-accel $ACCEL$ACCEL_PROPS" - -qemu=$(search_qemu_binary) || exit $? -if [ "$mach" = 'virt' ] && ! $qemu -machine '?' | grep -q 'RISC-V VirtIO board'; then - echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting." - exit 2 -fi -mach="-machine $mach" - -command="$qemu -nodefaults -nographic -serial mon:stdio" -command+=" $mach $acc $firmware -cpu $qemu_cpu " -command="$(migration_cmd) $(timeout_cmd) $command" - -if [ "$UEFI_SHELL_RUN" = "y" ]; then - ENVIRON_DEFAULT=n run_test_status $command "$@" -else - # We return the exit code via stdout, not via the QEMU return code - run_test_status $command -kernel "$@" -fi +vmm_check_supported + +function arch_run_qemu() +{ + # Allow user overrides of some config.mak variables + mach=$MACHINE_OVERRIDE + qemu_cpu=$TARGET_CPU_OVERRIDE + firmware=$FIRMWARE_OVERRIDE + + : "${mach:=virt}" + : "${qemu_cpu:=$TARGET_CPU}" + : "${qemu_cpu:=$DEFAULT_QEMU_CPU}" + : "${firmware:=$FIRMWARE}" + [ "$firmware" ] && firmware="-bios $firmware" + + set_qemu_accelerator || exit $? + [ "$ACCEL" = "kvm" ] && QEMU_ARCH=$HOST + acc="-accel $ACCEL$ACCEL_PROPS" + + qemu=$(search_qemu_binary) || exit $? + if [ "$mach" = 'virt' ] && ! $qemu -machine '?' | grep -q 'RISC-V VirtIO board'; then + echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting." + exit 2 + fi + mach="-machine $mach" + + command="$qemu -nodefaults -nographic -serial mon:stdio" + command+=" $mach $acc $firmware -cpu $qemu_cpu " + command="$(migration_cmd) $(timeout_cmd) $command" + + if [ "$UEFI_SHELL_RUN" = "y" ]; then + ENVIRON_DEFAULT=n run_test_status $command "$@" + else + # We return the exit code via stdout, not via the QEMU return code + run_test_status $command -kernel "$@" + fi +} + +function arch_run_kvmtool() +{ + local command + + if [ "$HOST" != "riscv32" ] && [ "$HOST" != "riscv64" ]; then + echo "kvmtool requires KVM but the host ('$HOST') is not riscv" >&2 + exit 2 + fi + + kvmtool=$(search_kvmtool_binary) || + exit $? + + if [ "$ACCEL" ] && [ "$ACCEL" != "kvm" ]; then + echo "kvmtool does not support $ACCEL" >&2 + exit 2 + fi + + if ! kvm_available; then + echo "kvmtool requires KVM but not available on the host" >&2 + exit 2 + fi + + command="$(timeout_cmd) $kvmtool run" + if ( [ "$HOST" = "riscv64" ] && [ "$ARCH" = "riscv32" ] ) || + ( [ "$HOST" = "riscv32" ] && [ "$ARCH" = "riscv64" ] ); then + echo "Cannot run guests with a different xlen than the host" >&2 + exit 2 + else + run_test_status $command --kernel "$@" + fi +} + +case $(vmm_get_target) in +qemu) + arch_run_qemu "$@" + ;; +kvmtool) + arch_run_kvmtool "$@" + ;; +esac -- 2.49.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 2/2] riscv: Add kvmtool support 2025-07-04 15:12 ` [kvm-unit-tests PATCH 2/2] riscv: Add kvmtool support Andrew Jones @ 2025-07-07 15:28 ` Jesse Taube 2025-07-07 17:44 ` Andrew Jones 2025-07-08 3:43 ` Nutty Liu 1 sibling, 1 reply; 9+ messages in thread From: Jesse Taube @ 2025-07-07 15:28 UTC (permalink / raw) To: Andrew Jones Cc: kvm, kvmarm, kvm-riscv, alexandru.elisei, cleger, jamestiotio, Atish Patra On Fri, Jul 4, 2025 at 8:13 AM Andrew Jones <andrew.jones@linux.dev> wrote: > > arm/arm64 supports running tests with kvmtool as a first class citizen. > Most the code to do that is in the common scripts, so just add the riscv > specific bits needed to allow riscv to use kvmtool as a first class > citizen too. > > Signed-off-by: Andrew Jones <andrew.jones@linux.dev> Reviewed-by: Jesse Taube <jesse@rivosinc.com> > --- > README.md | 7 ++-- > configure | 12 ++++-- > riscv/efi/run | 6 +++ > riscv/run | 110 +++++++++++++++++++++++++++++++++++--------------- > 4 files changed, 96 insertions(+), 39 deletions(-) > > diff --git a/README.md b/README.md > index 723ce04cd978..cbd8a9940ec4 100644 > --- a/README.md > +++ b/README.md > @@ -65,8 +65,8 @@ or: > > to run them all. > > -All tests can be run using QEMU. On arm and arm64, tests can also be run using > -kvmtool. > +All tests can be run using QEMU. On arm, arm64, riscv32, and riscv64 tests can > +also be run using kvmtool. > > By default the runner script searches for a suitable QEMU binary in the system. > To select a specific QEMU binary though, specify the QEMU=path/to/binary > @@ -97,8 +97,7 @@ variable. kvmtool supports only kvm as the accelerator. > > Check [x86/efi/README.md](./x86/efi/README.md). > > -On arm and arm64, this is only supported with QEMU; kvmtool cannot run the > -tests under UEFI. > +This is only supported with QEMU; kvmtool cannot run the tests under UEFI. > > # Tests configuration file > > diff --git a/configure b/configure > index 470f9d7cdb3b..6d549d1ecb5b 100755 > --- a/configure > +++ b/configure > @@ -90,7 +90,7 @@ usage() { > selects the best value based on the host system and the > test configuration. > --target=TARGET target platform that the tests will be running on (qemu or > - kvmtool, default is qemu) (arm/arm64 only) > + kvmtool, default is qemu) (arm/arm64 and riscv32/riscv64 only) > --cross-prefix=PREFIX cross compiler prefix > --cc=CC c compiler to use ($cc) > --cflags=FLAGS extra options to be passed to the c compiler > @@ -284,7 +284,8 @@ fi > if [ -z "$target" ]; then > target="qemu" > else > - if [ "$arch" != "arm64" ] && [ "$arch" != "arm" ]; then > + if [ "$arch" != "arm" ] && [ "$arch" != "arm64" ] && > + [ "$arch" != "riscv32" ] && [ "$arch" != "riscv64" ]; then Are there plans to add i386 and x86_64 too? > echo "--target is not supported for $arch" > usage > fi > @@ -393,6 +394,10 @@ elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then > testdir=riscv > arch_libdir=riscv > : "${uart_early_addr:=0x10000000}" > + if [ "$target" != "qemu" ] && [ "$target" != "kvmtool" ]; then > + echo "--target must be one of 'qemu' or 'kvmtool'!" > + usage > + fi > elif [ "$arch" = "s390x" ]; then > testdir=s390x > else > @@ -519,7 +524,8 @@ EFI_DIRECT=$efi_direct > CONFIG_WERROR=$werror > GEN_SE_HEADER=$gen_se_header > EOF > -if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then > +if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ] || > + [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then > echo "TARGET=$target" >> config.mak > fi > > diff --git a/riscv/efi/run b/riscv/efi/run > index 5a72683a6ef5..b9b75440c659 100755 > --- a/riscv/efi/run > +++ b/riscv/efi/run > @@ -11,6 +11,12 @@ if [ ! -f config.mak ]; then > fi > source config.mak > source scripts/arch-run.bash > +source scripts/vmm.bash > + > +if [[ $(vmm_get_target) == "kvmtool" ]]; then > + echo "kvmtool does not support EFI tests." > + exit 2 > +fi > > if [ -f RISCV_VIRT_CODE.fd ]; then > DEFAULT_UEFI=RISCV_VIRT_CODE.fd > diff --git a/riscv/run b/riscv/run > index 0f000f0d82c6..7bcf235fb645 100755 > --- a/riscv/run > +++ b/riscv/run > @@ -10,35 +10,81 @@ if [ -z "$KUT_STANDALONE" ]; then > source scripts/vmm.bash > fi > > -# Allow user overrides of some config.mak variables > -mach=$MACHINE_OVERRIDE > -qemu_cpu=$TARGET_CPU_OVERRIDE > -firmware=$FIRMWARE_OVERRIDE > - > -: "${mach:=virt}" > -: "${qemu_cpu:=$TARGET_CPU}" > -: "${qemu_cpu:=$DEFAULT_QEMU_CPU}" > -: "${firmware:=$FIRMWARE}" > -[ "$firmware" ] && firmware="-bios $firmware" > - > -set_qemu_accelerator || exit $? > -[ "$ACCEL" = "kvm" ] && QEMU_ARCH=$HOST > -acc="-accel $ACCEL$ACCEL_PROPS" > - > -qemu=$(search_qemu_binary) || exit $? > -if [ "$mach" = 'virt' ] && ! $qemu -machine '?' | grep -q 'RISC-V VirtIO board'; then > - echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting." > - exit 2 > -fi > -mach="-machine $mach" > - > -command="$qemu -nodefaults -nographic -serial mon:stdio" > -command+=" $mach $acc $firmware -cpu $qemu_cpu " > -command="$(migration_cmd) $(timeout_cmd) $command" > - > -if [ "$UEFI_SHELL_RUN" = "y" ]; then > - ENVIRON_DEFAULT=n run_test_status $command "$@" > -else > - # We return the exit code via stdout, not via the QEMU return code > - run_test_status $command -kernel "$@" > -fi > +vmm_check_supported > + > +function arch_run_qemu() > +{ > + # Allow user overrides of some config.mak variables > + mach=$MACHINE_OVERRIDE > + qemu_cpu=$TARGET_CPU_OVERRIDE > + firmware=$FIRMWARE_OVERRIDE > + > + : "${mach:=virt}" > + : "${qemu_cpu:=$TARGET_CPU}" > + : "${qemu_cpu:=$DEFAULT_QEMU_CPU}" > + : "${firmware:=$FIRMWARE}" > + [ "$firmware" ] && firmware="-bios $firmware" > + > + set_qemu_accelerator || exit $? > + [ "$ACCEL" = "kvm" ] && QEMU_ARCH=$HOST > + acc="-accel $ACCEL$ACCEL_PROPS" > + > + qemu=$(search_qemu_binary) || exit $? > + if [ "$mach" = 'virt' ] && ! $qemu -machine '?' | grep -q 'RISC-V VirtIO board'; then > + echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting." > + exit 2 > + fi > + mach="-machine $mach" > + > + command="$qemu -nodefaults -nographic -serial mon:stdio" > + command+=" $mach $acc $firmware -cpu $qemu_cpu " > + command="$(migration_cmd) $(timeout_cmd) $command" > + > + if [ "$UEFI_SHELL_RUN" = "y" ]; then > + ENVIRON_DEFAULT=n run_test_status $command "$@" > + else > + # We return the exit code via stdout, not via the QEMU return code > + run_test_status $command -kernel "$@" > + fi > +} > + > +function arch_run_kvmtool() > +{ > + local command > + > + if [ "$HOST" != "riscv32" ] && [ "$HOST" != "riscv64" ]; then > + echo "kvmtool requires KVM but the host ('$HOST') is not riscv" >&2 > + exit 2 > + fi > + > + kvmtool=$(search_kvmtool_binary) || > + exit $? > + > + if [ "$ACCEL" ] && [ "$ACCEL" != "kvm" ]; then > + echo "kvmtool does not support $ACCEL" >&2 > + exit 2 > + fi > + > + if ! kvm_available; then > + echo "kvmtool requires KVM but not available on the host" >&2 > + exit 2 > + fi > + > + command="$(timeout_cmd) $kvmtool run" > + if ( [ "$HOST" = "riscv64" ] && [ "$ARCH" = "riscv32" ] ) || > + ( [ "$HOST" = "riscv32" ] && [ "$ARCH" = "riscv64" ] ); then Shouldn't there be a check like this on arm for when [ "$HOST" = "arm" ] && [ "$ARCH" = "aarch64" ]? > + echo "Cannot run guests with a different xlen than the host" >&2 > + exit 2 > + else > + run_test_status $command --kernel "$@" > + fi > +} > + > +case $(vmm_get_target) in > +qemu) > + arch_run_qemu "$@" > + ;; > +kvmtool) > + arch_run_kvmtool "$@" > + ;; > +esac > -- > 2.49.0 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 2/2] riscv: Add kvmtool support 2025-07-07 15:28 ` Jesse Taube @ 2025-07-07 17:44 ` Andrew Jones 0 siblings, 0 replies; 9+ messages in thread From: Andrew Jones @ 2025-07-07 17:44 UTC (permalink / raw) To: Jesse Taube Cc: kvm, kvmarm, kvm-riscv, alexandru.elisei, cleger, jamestiotio, Atish Patra On Mon, Jul 07, 2025 at 08:28:30AM -0700, Jesse Taube wrote: > On Fri, Jul 4, 2025 at 8:13 AM Andrew Jones <andrew.jones@linux.dev> wrote: > > > > arm/arm64 supports running tests with kvmtool as a first class citizen. > > Most the code to do that is in the common scripts, so just add the riscv > > specific bits needed to allow riscv to use kvmtool as a first class > > citizen too. > > > > Signed-off-by: Andrew Jones <andrew.jones@linux.dev> > > Reviewed-by: Jesse Taube <jesse@rivosinc.com> Thanks! ... > > else > > - if [ "$arch" != "arm64" ] && [ "$arch" != "arm" ]; then > > + if [ "$arch" != "arm" ] && [ "$arch" != "arm64" ] && > > + [ "$arch" != "riscv32" ] && [ "$arch" != "riscv64" ]; then > > Are there plans to add i386 and x86_64 too? I don't have plans myself, at least not right now, but I think it'd be good to do it, so it'd be great if somebody would write the patch and do the testing. ... > > + command="$(timeout_cmd) $kvmtool run" > > + if ( [ "$HOST" = "riscv64" ] && [ "$ARCH" = "riscv32" ] ) || > > + ( [ "$HOST" = "riscv32" ] && [ "$ARCH" = "riscv64" ] ); then > > Shouldn't there be a check like this on arm for when [ "$HOST" = > "arm" ] && [ "$ARCH" = "aarch64" ]? arm kvm has been long deprecated and removed from Linux so we should actually remove any references to HOST==arm throughout the framework too, since it can't happen (any more). Thanks, drew ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 2/2] riscv: Add kvmtool support 2025-07-04 15:12 ` [kvm-unit-tests PATCH 2/2] riscv: Add kvmtool support Andrew Jones 2025-07-07 15:28 ` Jesse Taube @ 2025-07-08 3:43 ` Nutty Liu 1 sibling, 0 replies; 9+ messages in thread From: Nutty Liu @ 2025-07-08 3:43 UTC (permalink / raw) To: Andrew Jones, kvm, kvmarm, kvm-riscv Cc: alexandru.elisei, cleger, jesse, jamestiotio, Atish Patra On 7/4/2025 11:12 PM, Andrew Jones wrote: > arm/arm64 supports running tests with kvmtool as a first class citizen. > Most the code to do that is in the common scripts, so just add the riscv > specific bits needed to allow riscv to use kvmtool as a first class > citizen too. > > Signed-off-by: Andrew Jones <andrew.jones@linux.dev> Reviewed-by: Nutty Liu <liujingqi@lanxincomputing.com> Thanks, Nutty > --- > README.md | 7 ++-- > configure | 12 ++++-- > riscv/efi/run | 6 +++ > riscv/run | 110 +++++++++++++++++++++++++++++++++++--------------- > 4 files changed, 96 insertions(+), 39 deletions(-) > > diff --git a/README.md b/README.md > index 723ce04cd978..cbd8a9940ec4 100644 > --- a/README.md > +++ b/README.md > @@ -65,8 +65,8 @@ or: > > to run them all. > > -All tests can be run using QEMU. On arm and arm64, tests can also be run using > -kvmtool. > +All tests can be run using QEMU. On arm, arm64, riscv32, and riscv64 tests can > +also be run using kvmtool. > > By default the runner script searches for a suitable QEMU binary in the system. > To select a specific QEMU binary though, specify the QEMU=path/to/binary > @@ -97,8 +97,7 @@ variable. kvmtool supports only kvm as the accelerator. > > Check [x86/efi/README.md](./x86/efi/README.md). > > -On arm and arm64, this is only supported with QEMU; kvmtool cannot run the > -tests under UEFI. > +This is only supported with QEMU; kvmtool cannot run the tests under UEFI. > > # Tests configuration file > > diff --git a/configure b/configure > index 470f9d7cdb3b..6d549d1ecb5b 100755 > --- a/configure > +++ b/configure > @@ -90,7 +90,7 @@ usage() { > selects the best value based on the host system and the > test configuration. > --target=TARGET target platform that the tests will be running on (qemu or > - kvmtool, default is qemu) (arm/arm64 only) > + kvmtool, default is qemu) (arm/arm64 and riscv32/riscv64 only) > --cross-prefix=PREFIX cross compiler prefix > --cc=CC c compiler to use ($cc) > --cflags=FLAGS extra options to be passed to the c compiler > @@ -284,7 +284,8 @@ fi > if [ -z "$target" ]; then > target="qemu" > else > - if [ "$arch" != "arm64" ] && [ "$arch" != "arm" ]; then > + if [ "$arch" != "arm" ] && [ "$arch" != "arm64" ] && > + [ "$arch" != "riscv32" ] && [ "$arch" != "riscv64" ]; then > echo "--target is not supported for $arch" > usage > fi > @@ -393,6 +394,10 @@ elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then > testdir=riscv > arch_libdir=riscv > : "${uart_early_addr:=0x10000000}" > + if [ "$target" != "qemu" ] && [ "$target" != "kvmtool" ]; then > + echo "--target must be one of 'qemu' or 'kvmtool'!" > + usage > + fi > elif [ "$arch" = "s390x" ]; then > testdir=s390x > else > @@ -519,7 +524,8 @@ EFI_DIRECT=$efi_direct > CONFIG_WERROR=$werror > GEN_SE_HEADER=$gen_se_header > EOF > -if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then > +if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ] || > + [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then > echo "TARGET=$target" >> config.mak > fi > > diff --git a/riscv/efi/run b/riscv/efi/run > index 5a72683a6ef5..b9b75440c659 100755 > --- a/riscv/efi/run > +++ b/riscv/efi/run > @@ -11,6 +11,12 @@ if [ ! -f config.mak ]; then > fi > source config.mak > source scripts/arch-run.bash > +source scripts/vmm.bash > + > +if [[ $(vmm_get_target) == "kvmtool" ]]; then > + echo "kvmtool does not support EFI tests." > + exit 2 > +fi > > if [ -f RISCV_VIRT_CODE.fd ]; then > DEFAULT_UEFI=RISCV_VIRT_CODE.fd > diff --git a/riscv/run b/riscv/run > index 0f000f0d82c6..7bcf235fb645 100755 > --- a/riscv/run > +++ b/riscv/run > @@ -10,35 +10,81 @@ if [ -z "$KUT_STANDALONE" ]; then > source scripts/vmm.bash > fi > > -# Allow user overrides of some config.mak variables > -mach=$MACHINE_OVERRIDE > -qemu_cpu=$TARGET_CPU_OVERRIDE > -firmware=$FIRMWARE_OVERRIDE > - > -: "${mach:=virt}" > -: "${qemu_cpu:=$TARGET_CPU}" > -: "${qemu_cpu:=$DEFAULT_QEMU_CPU}" > -: "${firmware:=$FIRMWARE}" > -[ "$firmware" ] && firmware="-bios $firmware" > - > -set_qemu_accelerator || exit $? > -[ "$ACCEL" = "kvm" ] && QEMU_ARCH=$HOST > -acc="-accel $ACCEL$ACCEL_PROPS" > - > -qemu=$(search_qemu_binary) || exit $? > -if [ "$mach" = 'virt' ] && ! $qemu -machine '?' | grep -q 'RISC-V VirtIO board'; then > - echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting." > - exit 2 > -fi > -mach="-machine $mach" > - > -command="$qemu -nodefaults -nographic -serial mon:stdio" > -command+=" $mach $acc $firmware -cpu $qemu_cpu " > -command="$(migration_cmd) $(timeout_cmd) $command" > - > -if [ "$UEFI_SHELL_RUN" = "y" ]; then > - ENVIRON_DEFAULT=n run_test_status $command "$@" > -else > - # We return the exit code via stdout, not via the QEMU return code > - run_test_status $command -kernel "$@" > -fi > +vmm_check_supported > + > +function arch_run_qemu() > +{ > + # Allow user overrides of some config.mak variables > + mach=$MACHINE_OVERRIDE > + qemu_cpu=$TARGET_CPU_OVERRIDE > + firmware=$FIRMWARE_OVERRIDE > + > + : "${mach:=virt}" > + : "${qemu_cpu:=$TARGET_CPU}" > + : "${qemu_cpu:=$DEFAULT_QEMU_CPU}" > + : "${firmware:=$FIRMWARE}" > + [ "$firmware" ] && firmware="-bios $firmware" > + > + set_qemu_accelerator || exit $? > + [ "$ACCEL" = "kvm" ] && QEMU_ARCH=$HOST > + acc="-accel $ACCEL$ACCEL_PROPS" > + > + qemu=$(search_qemu_binary) || exit $? > + if [ "$mach" = 'virt' ] && ! $qemu -machine '?' | grep -q 'RISC-V VirtIO board'; then > + echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting." > + exit 2 > + fi > + mach="-machine $mach" > + > + command="$qemu -nodefaults -nographic -serial mon:stdio" > + command+=" $mach $acc $firmware -cpu $qemu_cpu " > + command="$(migration_cmd) $(timeout_cmd) $command" > + > + if [ "$UEFI_SHELL_RUN" = "y" ]; then > + ENVIRON_DEFAULT=n run_test_status $command "$@" > + else > + # We return the exit code via stdout, not via the QEMU return code > + run_test_status $command -kernel "$@" > + fi > +} > + > +function arch_run_kvmtool() > +{ > + local command > + > + if [ "$HOST" != "riscv32" ] && [ "$HOST" != "riscv64" ]; then > + echo "kvmtool requires KVM but the host ('$HOST') is not riscv" >&2 > + exit 2 > + fi > + > + kvmtool=$(search_kvmtool_binary) || > + exit $? > + > + if [ "$ACCEL" ] && [ "$ACCEL" != "kvm" ]; then > + echo "kvmtool does not support $ACCEL" >&2 > + exit 2 > + fi > + > + if ! kvm_available; then > + echo "kvmtool requires KVM but not available on the host" >&2 > + exit 2 > + fi > + > + command="$(timeout_cmd) $kvmtool run" > + if ( [ "$HOST" = "riscv64" ] && [ "$ARCH" = "riscv32" ] ) || > + ( [ "$HOST" = "riscv32" ] && [ "$ARCH" = "riscv64" ] ); then > + echo "Cannot run guests with a different xlen than the host" >&2 > + exit 2 > + else > + run_test_status $command --kernel "$@" > + fi > +} > + > +case $(vmm_get_target) in > +qemu) > + arch_run_qemu "$@" > + ;; > +kvmtool) > + arch_run_kvmtool "$@" > + ;; > +esac ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 0/2] riscv: Add kvmtool support 2025-07-04 15:12 [kvm-unit-tests PATCH 0/2] riscv: Add kvmtool support Andrew Jones 2025-07-04 15:12 ` [kvm-unit-tests PATCH 1/2] arm/arm64: Ensure proper host arch with kvmtool Andrew Jones 2025-07-04 15:12 ` [kvm-unit-tests PATCH 2/2] riscv: Add kvmtool support Andrew Jones @ 2025-07-08 9:00 ` Andrew Jones 2 siblings, 0 replies; 9+ messages in thread From: Andrew Jones @ 2025-07-08 9:00 UTC (permalink / raw) To: kvm, kvmarm, kvm-riscv Cc: alexandru.elisei, cleger, jesse, jamestiotio, Atish Patra On Fri, Jul 04, 2025 at 05:12:55PM +0200, Andrew Jones wrote: > The first patch is for arm's scripts. It adds a check that I found > useful on the riscv side. The second patch enables riscv to use > kvmtool too. > > Andrew Jones (2): > arm/arm64: Ensure proper host arch with kvmtool > riscv: Add kvmtool support > > README.md | 7 ++-- > arm/run | 5 +++ > configure | 12 ++++-- > riscv/efi/run | 6 +++ > riscv/run | 110 +++++++++++++++++++++++++++++++++++--------------- > 5 files changed, 101 insertions(+), 39 deletions(-) > > -- > 2.49.0 Merged. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-07-08 9:00 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-07-04 15:12 [kvm-unit-tests PATCH 0/2] riscv: Add kvmtool support Andrew Jones 2025-07-04 15:12 ` [kvm-unit-tests PATCH 1/2] arm/arm64: Ensure proper host arch with kvmtool Andrew Jones 2025-07-07 15:10 ` Jesse Taube 2025-07-08 3:41 ` Nutty Liu 2025-07-04 15:12 ` [kvm-unit-tests PATCH 2/2] riscv: Add kvmtool support Andrew Jones 2025-07-07 15:28 ` Jesse Taube 2025-07-07 17:44 ` Andrew Jones 2025-07-08 3:43 ` Nutty Liu 2025-07-08 9:00 ` [kvm-unit-tests PATCH 0/2] " Andrew Jones
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).