Skip to contentSkip to conversation

selftests/liveupdate: Prefer KVM and HVF over TCG in vmtest.sh

PATCH Applied David Matlack 4 participants 4 messages Oct 8 – Oct 13

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/liveupdate: Prefer KVM and HVF over TCG in vmtest.sh

Pass the -accel options to QEMU in the order KVM, HVF, TCG, so that vmtest.sh prefers to use KVM and HVF over TCG when they are available.

QEMU uses the first accelerator in the list that initializes, and TCG always initializes, so the tests currently always run under TCG, even though the commit that added vmtest.sh describes "automatic accelerator detection (KVM, HVF, or TCG)".

Fixes 89dd1421c554 ("selftests/liveupdate: add end to end test infrastructure and scripts")

---
Tested by running run-vmtests.sh and then observed that arm64 correctly fell back to using TCG after trying to use KVM and HVF, and that x86 reported no warnings.

arm64:
qemu-system-aarch64: -accel kvm: invalid accelerator kvm
qemu-system-aarch64: -accel hvf: invalid accelerator hvf
qemu-system-aarch64: falling back to tcg

x86:
(not warnings)

 tools/testing/selftests/liveupdate/vmtest.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/liveupdate/vmtest.sh +1 -1
index 64fd2ab55b76..69beda6c961d 100755
@@ -180,7 +180,7 @@ function run_qemu() {
 	echo "# Serial Log: $serial"
 	timeout 30s \
 	$qemu_cmd -m 1G -smp 2 -no-reboot -nographic -nodefaults \
-		  -accel tcg -accel hvf -accel kvm \
+		  -accel kvm -accel hvf -accel tcg \
 		  -serial file:"$serial" \
 		  -append "$cmdline" \
 		  -kernel "$kernel_path" \

base-commit: 80cf37169daef112b6bea9ae7d9808355a045475

Signature · 1 line
2.56.0.360.g66cac248cb-goog
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] selftests: KVM accelerator preference breaks arm64 vmtest on GICv3 hosts --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] selftests: KVM accelerator preference breaks arm64 vmtest on GICv3 hosts --

commit 5b52122d5a64c0b3471d0fed69b32ec99d464203
Author: David Matlack <[email protected]>

selftests/liveupdate: Prefer KVM and HVF over TCG in vmtest.sh

This commit reorders the QEMU accelerator options to prefer KVM and HVF over TCG. It aims to utilize hardware acceleration when available instead of always defaulting to TCG.

Quoted 3 lines

Tested by running run-vmtests.sh and then observed that arm64 correctly fell back to using TCG after trying to use KVM and HVF, and that x86 reported no warnings.

Will the arm64 test actually fall back to TCG when run natively on modern arm64 hardware?

In get_arch_conf(), the arm64 QEMU command is defined without specifying a GIC version:

QEMU_CMD="qemu-system-aarch64 -M virt -cpu max"

Because the virt machine type defaults to GICv2 for backward compatibility, running this natively on modern arm64 hardware (which typically only supports GICv3) will cause the KVM accelerator to successfully initialize, preventing the fallback to TCG. However, KVM will then fail to create the default GICv2 in-kernel interrupt controller and QEMU will abort with a fatal error.

Was the observation of falling back to TCG made on a cross-compilation host where the KVM accelerator itself failed to initialize?

tools/testing/selftests/liveupdate/vmtest.sh function run_qemu() { · line 183

Quoted 10 lines
tools/testing/selftests/liveupdate/vmtest.sh +1 -1
index 64fd2ab55b765..69beda6c961d7 100755
@@ -180,7 +180,7 @@ function run_qemu() {
 	echo "# Serial Log: $serial"
 	timeout 30s \
 	$qemu_cmd -m 1G -smp 2 -no-reboot -nographic -nodefaults \
-		  -accel tcg -accel hvf -accel kvm \
+		  -accel kvm -accel hvf -accel tcg \

[Severity: Medium]
Does this change break native arm64 execution on modern hardware?

Since get_arch_conf() lacks the gic-version=max parameter for arm64, QEMU will default to GICv2. On modern arm64 hosts, KVM won't be able to emulate GICv2, causing a hard failure during machine initialization rather than a fallback to TCG.

Should gic-version=max be added to the arm64 QEMU_CMD to safely enable KVM acceleration on modern hosts?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to David Matlack
Quoted 10 lines · David Matlack

Pass the -accel options to QEMU in the order KVM, HVF, TCG, so that vmtest.sh prefers to use KVM and HVF over TCG when they are available.

QEMU uses the first accelerator in the list that initializes, and TCG always initializes, so the tests currently always run under TCG, even though the commit that added vmtest.sh describes "automatic accelerator detection (KVM, HVF, or TCG)".

Fixes 89dd1421c554 ("selftests/liveupdate: add end to end test infrastructure and scripts")

IIUC HVF is only for MacOS. I don't think we care to run this script on MacOS.

Anyway, thanks for the fix

Quoted 31 lines

---
Tested by running run-vmtests.sh and then observed that arm64 correctly fell back to using TCG after trying to use KVM and HVF, and that x86 reported no warnings.

arm64:
qemu-system-aarch64: -accel kvm: invalid accelerator kvm
qemu-system-aarch64: -accel hvf: invalid accelerator hvf
qemu-system-aarch64: falling back to tcg

x86:
(not warnings)

 tools/testing/selftests/liveupdate/vmtest.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/liveupdate/vmtest.sh +1 -1
index 64fd2ab55b76..69beda6c961d 100755
@@ -180,7 +180,7 @@ function run_qemu() {
 	echo "# Serial Log: $serial"
 	timeout 30s \
 	$qemu_cmd -m 1G -smp 2 -no-reboot -nographic -nodefaults \
-		  -accel tcg -accel hvf -accel kvm \
+		  -accel kvm -accel hvf -accel tcg \
 		  -serial file:"$serial" \
 		  -append "$cmdline" \
 		  -kernel "$kernel_path" \

base-commit: 80cf37169daef112b6bea9ae7d9808355a045475

Signature · 2 lines
Regards,
Pratyush Yadav
maintainer Applied
#3 lore raw
In reply to David Matlack

From: Mike Rapoport (Microsoft) <[email protected]>

Quoted 9 lines · David Matlack

Pass the -accel options to QEMU in the order KVM, HVF, TCG, so that vmtest.sh prefers to use KVM and HVF over TCG when they are available.

QEMU uses the first accelerator in the list that initializes, and TCG always initializes, so the tests currently always run under TCG, even though the commit that added vmtest.sh describes "automatic accelerator detection (KVM, HVF, or TCG)".

[...]

Applied to next branch of liveupdate/linux.git tree, thanks!

[1/1] selftests/liveupdate: Prefer KVM and HVF over TCG in vmtest.sh

      commit: 48e6e4202e12af36671c6479b9ebcb8212d37cbb

tree: https://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux
branch: next

--
Sincerely yours,
Mike.