From ec0828e62fdfc5d899ff4fc7a21f7900753e1301 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 25 Jan 2023 09:18:42 +0100 Subject: debvm-run: handle some multiarch kernels We completely treat all 32bit arm as armhf now. Booting the rpi kernel installed by debvm-create for armel will not work at all. The only sane way to boot armel is to enable a multiarch kernel. Refine the VMARCH guess from /bin/true using the file output for the kernel image for the common cases of i386+amd64 and armel/armhf+arm64. --- bin/debvm-run | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'bin/debvm-run') diff --git a/bin/debvm-run b/bin/debvm-run index 70ee556..10e19be 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -203,6 +203,19 @@ INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat ${BOOTDIR}initrd.img" | sed 's/Fast test -n "$INITRDNAME" || die "failed to discover initrd image" test "${INITRDNAME#/}" = "$INITRDNAME" && INITRDNAME="$BOOTDIR$INITRDNAME" +# Refine our VMARCH guess from /bin/true using the kernel image to improve +# experience for multiarch kernels. +if command -v file >/dev/null 2>&1; then + case "$VMARCH:$(file -b "$KERNELTMP")" in + "armel:Linux kernel ARM64 boot executable Image"*) VMARCH=arm64 ;; + "armhf:Linux kernel ARM64 boot executable Image"*) VMARCH=arm64 ;; + # The boot stub looks the same on i386 and amd64, so we + # actually inspect the kernel version here, which happens to + # include amd64 for Debian kernels. + "i386:Linux kernel x86 boot executable bzImage, version "*"-amd64 "*) VMARCH=amd64 ;; + esac +fi + KERNEL_CMDLINE="root=LABEL=debvm rw" NETDEV="user,id=net0" @@ -228,22 +241,16 @@ case "$VMARCH" in QEMU=qemu-system-x86_64 MACHINE="type=q35" ;; - arm|armel) + arm|armel|armhf) CPU=max MACHINE="type=virt" MAX_SMP=8 - RNG_DEV= ;; arm64) QEMU=qemu-system-aarch64 CPU=max MACHINE="type=virt" ;; - armhf) - CPU=max - MACHINE="type=virt" - MAX_SMP=8 - ;; m68k) MACHINE="type=virt" MAX_SMP=1 -- cgit v1.2.3 From 66b9374cc19c21ee5ff5b1344b43c991ac53ce91 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 25 Jan 2023 10:02:00 +0100 Subject: debvm-run: extract kernel image before inspecting it Reported-by: Arnd Bergmann --- bin/debvm-run | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'bin/debvm-run') diff --git a/bin/debvm-run b/bin/debvm-run index 10e19be..0c4ad2e 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -104,6 +104,13 @@ die() { echo "$*" 1>&2 exit 1 } +with_set_ex() { + local ret + echo "+ $*" 1>&2 + ret=0 + "$@" || ret=$? + test "$ret" = 0 || die "failed with exit code $ret" +} usage() { die "usage: $0 [-g] [-i image] [-s sshport] [-- qemu options]" } @@ -203,6 +210,9 @@ INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat ${BOOTDIR}initrd.img" | sed 's/Fast test -n "$INITRDNAME" || die "failed to discover initrd image" test "${INITRDNAME#/}" = "$INITRDNAME" && INITRDNAME="$BOOTDIR$INITRDNAME" +with_set_ex /sbin/debugfs "$IMAGE" -R "cat $KERNELNAME" > "$KERNELTMP" +with_set_ex /sbin/debugfs "$IMAGE" -R "cat $INITRDNAME" > "$INITRDTMP" + # Refine our VMARCH guess from /bin/true using the kernel image to improve # experience for multiarch kernels. if command -v file >/dev/null 2>&1; then @@ -342,9 +352,4 @@ set -- \ -device "$NIC_DEV" \ "$@" -set -ex - -/sbin/debugfs "$IMAGE" -R "cat $KERNELNAME" > "$KERNELTMP" -/sbin/debugfs "$IMAGE" -R "cat $INITRDNAME" > "$INITRDTMP" - -"$QEMU" "$@" +with_set_ex "$QEMU" "$@" -- cgit v1.2.3 From 8b7a39b3713b9223c3861b5153ffc019f312e88a Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 25 Jan 2023 10:03:05 +0100 Subject: debvm-run: also handle upgrading arm elf-arch may report armel and armhf as arm. --- bin/debvm-run | 1 + 1 file changed, 1 insertion(+) (limited to 'bin/debvm-run') diff --git a/bin/debvm-run b/bin/debvm-run index 0c4ad2e..336a509 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -217,6 +217,7 @@ with_set_ex /sbin/debugfs "$IMAGE" -R "cat $INITRDNAME" > "$INITRDTMP" # experience for multiarch kernels. if command -v file >/dev/null 2>&1; then case "$VMARCH:$(file -b "$KERNELTMP")" in + "arm:Linux kernel ARM64 boot executable Image"*) VMARCH=arm64 ;; "armel:Linux kernel ARM64 boot executable Image"*) VMARCH=arm64 ;; "armhf:Linux kernel ARM64 boot executable Image"*) VMARCH=arm64 ;; # The boot stub looks the same on i386 and amd64, so we -- cgit v1.2.3 From 6f9e95308cdd0497e2a4f35d870aa8015a81b60a Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 25 Jan 2023 10:07:32 +0100 Subject: debvm-run: make shellcheck happy Fixes: 66b9374cc19c ("debvm-run: extract kernel image before inspecting it") --- bin/debvm-run | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bin/debvm-run') diff --git a/bin/debvm-run b/bin/debvm-run index 336a509..1055467 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -105,11 +105,12 @@ die() { exit 1 } with_set_ex() { - local ret echo "+ $*" 1>&2 - ret=0 - "$@" || ret=$? - test "$ret" = 0 || die "failed with exit code $ret" + with_set_ex_ret=0 + "$@" || with_set_ex_ret=$? + if test "$with_set_ex_ret" != 0; then + die "failed with exit code $with_set_ex_ret" + fi } usage() { die "usage: $0 [-g] [-i image] [-s sshport] [-- qemu options]" -- cgit v1.2.3 From c8398b34897301081ca45804d5003c74237b7452 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 25 Jan 2023 12:32:05 +0100 Subject: debvm-run: internally differentiate between VMARCH and KERNELARCH In a multiarch setting, VMARCH shall describe the contained userland and KERNELARCH shall describe the architecture of the contained kernel. --- bin/debvm-run | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'bin/debvm-run') diff --git a/bin/debvm-run b/bin/debvm-run index 1055467..0e9403f 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -214,17 +214,17 @@ test "${INITRDNAME#/}" = "$INITRDNAME" && INITRDNAME="$BOOTDIR$INITRDNAME" with_set_ex /sbin/debugfs "$IMAGE" -R "cat $KERNELNAME" > "$KERNELTMP" with_set_ex /sbin/debugfs "$IMAGE" -R "cat $INITRDNAME" > "$INITRDTMP" -# Refine our VMARCH guess from /bin/true using the kernel image to improve -# experience for multiarch kernels. +# Guess the kernel architecture. +KERNELARCH=$VMARCH if command -v file >/dev/null 2>&1; then case "$VMARCH:$(file -b "$KERNELTMP")" in - "arm:Linux kernel ARM64 boot executable Image"*) VMARCH=arm64 ;; - "armel:Linux kernel ARM64 boot executable Image"*) VMARCH=arm64 ;; - "armhf:Linux kernel ARM64 boot executable Image"*) VMARCH=arm64 ;; + "arm:Linux kernel ARM64 boot executable Image"*) KERNELARCH=arm64 ;; + "armel:Linux kernel ARM64 boot executable Image"*) KERNELARCH=arm64 ;; + "armhf:Linux kernel ARM64 boot executable Image"*) KERNELARCH=arm64 ;; # The boot stub looks the same on i386 and amd64, so we # actually inspect the kernel version here, which happens to # include amd64 for Debian kernels. - "i386:Linux kernel x86 boot executable bzImage, version "*"-amd64 "*) VMARCH=amd64 ;; + "i386:Linux kernel x86 boot executable bzImage, version "*"-amd64 "*) KERNELARCH=amd64 ;; esac fi @@ -241,14 +241,14 @@ set -- \ -object rng-random,filename=/dev/urandom,id=rng0 \ "$@" -QEMU="qemu-system-$VMARCH" +QEMU="qemu-system-$KERNELARCH" CPU= MACHINE= MAX_SMP= NIC_DEV=virtio-net-pci,netdev=net0 RNG_DEV=virtio-rng-pci,rng=rng0 -case "$VMARCH" in +case "$KERNELARCH" in amd64) QEMU=qemu-system-x86_64 MACHINE="type=q35" @@ -292,7 +292,7 @@ case "$VMARCH" in ;; esac -if test "$ARCHITECTURE" = "$VMARCH"; then +if test "$ARCHITECTURE" = "$KERNELARCH"; then if ! command -v "$QEMU" >/dev/null 2>&1; then # Fall back to kvm in case we badly guessed qemu. QEMU=kvm @@ -303,7 +303,7 @@ if test "$ARCHITECTURE" = "$VMARCH"; then if test -w /dev/kvm; then CPU=host fi - if test "$VMARCH" = arm64; then + if test "$KERNELARCH" = arm64; then MACHINE="$MACHINE,gic-version=max" fi fi @@ -325,7 +325,7 @@ fi if test -z "$GRAPHICAL"; then set -- -nographic "$@" - case "$VMARCH" in + case "$KERNELARCH" in amd64|i386) KERNEL_CMDLINE="$KERNEL_CMDLINE console=ttyS0" ;; @@ -334,7 +334,7 @@ if test -z "$GRAPHICAL"; then KERNEL_CMDLINE="$KERNEL_CMDLINE TERM=$TERM" fi else - case "$VMARCH" in + case "$KERNELARCH" in amd64|i386) set -- -vga virtio "$@" ;; -- cgit v1.2.3 From cd2e4ed389df6d6dabaa530ee5280be8beabe293 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 25 Jan 2023 12:39:54 +0100 Subject: debvm-run: disable kvm for armhf -> arm64 when the cpu cannot run it Reported-by: Arnd Bergmann --- bin/debvm-run | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'bin/debvm-run') diff --git a/bin/debvm-run b/bin/debvm-run index 0e9403f..0d2ee95 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -292,7 +292,19 @@ case "$KERNELARCH" in ;; esac +ENABLE_KVM=no if test "$ARCHITECTURE" = "$KERNELARCH"; then + ENABLE_KVM=yes + case "$VMARCH:$KERNELARCH" in + arm:arm64|armel:arm64|armhf:arm64) + if ! linux32 true >/dev/null 2>&1; then + # This arm64 cannot run 32bit arm, so don't try KVM. + ENABLE_KVM=no + fi + ;; + esac +fi +if test "$ENABLE_KVM" = yes; then if ! command -v "$QEMU" >/dev/null 2>&1; then # Fall back to kvm in case we badly guessed qemu. QEMU=kvm -- cgit v1.2.3 From caa848fa49aee9cd6962c171ae2e2cad5cb47b0b Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 25 Jan 2023 13:29:21 +0100 Subject: debvm-run: always pass gic-version=max for arm64 We already pass it in the kvm case where it should become host and all should be fine. However in the non-kvm case, the default gic can only support 8 cores. If we want to go beyond that, we need a higher gic-version. We couldn't measure a performance difference between max and unset, so we'll just always pass max. Thanks: Arnd Bergmann Thanks: Johannes Schauer Marin Rodrigues --- bin/debvm-run | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'bin/debvm-run') diff --git a/bin/debvm-run b/bin/debvm-run index 0d2ee95..d690773 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -261,7 +261,7 @@ case "$KERNELARCH" in arm64) QEMU=qemu-system-aarch64 CPU=max - MACHINE="type=virt" + MACHINE="type=virt,gic-version=max" ;; m68k) MACHINE="type=virt" @@ -315,9 +315,6 @@ if test "$ENABLE_KVM" = yes; then if test -w /dev/kvm; then CPU=host fi - if test "$KERNELARCH" = arm64; then - MACHINE="$MACHINE,gic-version=max" - fi fi if test -n "$MACHINE"; then -- cgit v1.2.3