@@ -17,6 +17,17 @@ UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}"
1717EFI_MOUNT=" $( bootctl -x 2> /dev/null || echo /boot) "
1818QEMU_MEM=" ${QEMU_MEM:- 512M} "
1919
20+ # Decide if we can (and want to) run QEMU with KVM acceleration.
21+ # Check if nested KVM is explicitly enabled (TEST_NESTED_KVM). If not,
22+ # check if it's not explicitly disabled (TEST_NO_KVM) and we're not already
23+ # running under KVM. If these conditions are met, enable KVM (and possibly
24+ # nested KVM), otherwise disable it.
25+ if [[ -n " $TEST_NESTED_KVM " || ( -z " $TEST_NO_KVM " && $( systemd-detect-virt -v) ! = kvm ) ]]; then
26+ QEMU_KVM=yes
27+ else
28+ QEMU_KVM=no
29+ fi
30+
2031if ! ROOTLIBDIR=$( pkg-config --variable=systemdutildir systemd) ; then
2132 echo " WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
2233 ROOTLIBDIR=/usr/lib/systemd
8697
8798function find_qemu_bin() {
8899 # SUSE and Red Hat call the binary qemu-kvm. Debian and Gentoo call it kvm.
89- # Either way, only use this version if we aren't running in KVM, because
90- # nested KVM is flaky still.
91- if [[ $( systemd-detect-virt -v) != kvm && -z $TEST_NO_KVM ]] ; then
100+ if [[ $QEMU_KVM == " yes" ]]; then
92101 [ " $QEMU_BIN " ] || QEMU_BIN=$( which -a kvm qemu-kvm 2> /dev/null | grep ' ^/' -m1)
93102 fi
94103
@@ -220,8 +229,8 @@ $QEMU_OPTIONS \
220229 QEMU_OPTIONS=" $QEMU_OPTIONS -initrd $INITRD "
221230 fi
222231
223- # Let's use KVM if it is available, but let's avoid using nested KVM as that is still flaky
224- if [[ -c /dev/kvm && $( systemd-detect-virt -v ) != kvm && -z $TEST_NO_KVM ]] ; then
232+ # Let's use KVM if possible
233+ if [[ -c /dev/kvm && $QEMU_KVM == " yes " ]] ; then
225234 QEMU_OPTIONS=" $QEMU_OPTIONS -machine accel=kvm -enable-kvm -cpu host"
226235 fi
227236
0 commit comments