Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion boot-qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,19 @@ function setup_qemu_args() {
-machine "virt${HIGHMEM}"
-no-reboot
)
QEMU=(qemu-system-arm)
# It is possible to boot ARMv7 kernels under KVM on AArch64 hosts,
# if it is supported. ARMv7 KVM support was ripped out of the
# kernel in 5.7 so we don't even bother checking.
if [[ "$(uname -m)" = "aarch64" && -e /dev/kvm ]] && ${KVM} &&
"${BASE}"/utils/aarch64_32_bit_el1_supported; then
QEMU_ARCH_ARGS+=(
-cpu "host,aarch64=off"
-enable-kvm
)
QEMU=(qemu-system-aarch64)
else
QEMU=(qemu-system-arm)
fi
;;

arm64 | arm64be)
Expand Down
15 changes: 15 additions & 0 deletions utils/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ifneq ($(shell uname -m),aarch64)
CROSS_COMPILE = aarch64-linux-gnu-
endif

CC = $(CROSS_COMPILE)gcc
STRIP = $(CROSS_COMPILE)strip

aarch64_32_bit_el1_supported: aarch64_32_bit_el1_supported.c
$(CC) -O2 -static -std=c17 -Wall -Wextra -Wpedantic -o $@ $^
$(STRIP) -s $@

clean:
rm -fr aarch64_32_bit_el1_supported

all: aarch64_32_bit_el1_supported
Binary file added utils/aarch64_32_bit_el1_supported
Binary file not shown.
31 changes: 31 additions & 0 deletions utils/aarch64_32_bit_el1_supported.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <errno.h> /* errno for perror() */
#include <linux/kvm.h> /* KVM_CHECK_EXTENSION, KVM_CAP_ARM_EL1_32BIT */
#include <fcntl.h> /* open() */
#include <stdio.h> /* perror() */
#include <sys/ioctl.h> /* ioctl() */
#include <unistd.h> /* close() */

int main(void)
{
int fd, ret;

fd = open("/dev/kvm", O_RDWR);
if (fd < 0) {
perror("Failed to open /dev/kvm");
return -errno;
}

ret = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_ARM_EL1_32BIT);
if (ret < 0) {
perror("Error checking /dev/kvm for 32-bit EL1 support");
ret = 0;
}

close(fd);

/*
* KVM_CHECK_EXTENSION returns 1 for supported, 0 for unsupported so
* invert it to match typical success/fail codes in programs.
*/
return !ret;
}