From bc5cf471af5b53ef955eb4c828642bfe591b449a Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 24 Jan 2023 12:06:03 +0100 Subject: debvm-create: install better kernels in multiarch case While this works for armel+armhf by sheer luck, debvm-run fails for i386+amd64 as it selects qemu-system-i386. --- share/customize-kernel.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/share/customize-kernel.sh b/share/customize-kernel.sh index 23c2cd0..3e1d12c 100755 --- a/share/customize-kernel.sh +++ b/share/customize-kernel.sh @@ -14,12 +14,15 @@ if dpkg-query --root="$TARGET" --showformat='${db:Status-Status}\n' --show 'linu exit 0 fi -ARCHITECTURE=$(head -n1 "$TARGET/var/lib/dpkg/arch") +ARCHITECTURES=$(xargs < "$TARGET/var/lib/dpkg/arch") -KERNEL_ARCH="$ARCHITECTURE" -case "$ARCHITECTURE" in +KERNEL_ARCH="${ARCHITECTURES%% *}" +case "$KERNEL_ARCH" in armel) KERNEL_ARCH=rpi + case "$ARCHITECTURES " in *" armhf "*) + KERNEL_ARCH=armmp:armhf + ;; esac ;; armhf) KERNEL_ARCH=armmp @@ -29,6 +32,9 @@ case "$ARCHITECTURE" in ;; i386) KERNEL_ARCH=686-pae + case "$ARCHITECTURES " in *" amd64 "*) + KERNEL_ARCH=amd64:amd64 + ;; esac ;; mips64el) KERNEL_ARCH=5kc-malta -- cgit v1.2.3 From 999970b6e3e3ca3e19d9a9ef7dfd1443f9ced59e Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 24 Jan 2023 14:45:21 +0100 Subject: tests: add armel with an armhf kernel --- .gitlab-ci.yml | 1 + tests/create-and-run.sh | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4604045..e97f0bd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,6 +35,7 @@ arch_test: matrix: - ARCHITECTURE: - arm64 + - armel - armhf - i386 - mips64el diff --git a/tests/create-and-run.sh b/tests/create-and-run.sh index 58c4822..819161f 100755 --- a/tests/create-and-run.sh +++ b/tests/create-and-run.sh @@ -20,7 +20,10 @@ cleanup() { trap cleanup EXIT INT TERM QUIT ssh-keygen -f "$SSH_KEYPATH" -N '' -debvm-create -k "$SSH_KEYPATH.pub" -o "$IMAGE" -a "$ARCHITECTURE" -r "$RELEASE" +set -- +# Use an armhf kernel for armel. +test "$ARCHITECTURE" = armel && set -- -- --architecture armhf +debvm-create -k "$SSH_KEYPATH.pub" -o "$IMAGE" -a "$ARCHITECTURE" -r "$RELEASE" "$@" SSH_PORT=2222 timeout 300s debvm-run -s "$SSH_PORT" -i "$IMAGE" & -- cgit v1.2.3 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 ++++++++++++++------- debian/control | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) 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 diff --git a/debian/control b/debian/control index 0c1b3cf..59cde28 100644 --- a/debian/control +++ b/debian/control @@ -21,6 +21,7 @@ Depends: ipxe-qemu, Recommends: arch-test, + file, systemd | binfmt-support, openssh-client, qemu-system, -- cgit v1.2.3 From c405204a84eef99591cfe0ea41a873d508557b26 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 25 Jan 2023 09:27:54 +0100 Subject: debvm-create: handle multiarch kernel for 32bit+64bit arm --- share/customize-kernel.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/share/customize-kernel.sh b/share/customize-kernel.sh index 3e1d12c..aef9fa7 100755 --- a/share/customize-kernel.sh +++ b/share/customize-kernel.sh @@ -20,21 +20,25 @@ KERNEL_ARCH="${ARCHITECTURES%% *}" case "$KERNEL_ARCH" in armel) KERNEL_ARCH=rpi - case "$ARCHITECTURES " in *" armhf "*) - KERNEL_ARCH=armmp:armhf - ;; esac + case "$ARCHITECTURES " in + *" arm64 "*) KERNEL_ARCH=arm64:arm64 ;; + *" armhf "*) KERNEL_ARCH=armmp:armhf ;; + esac ;; armhf) KERNEL_ARCH=armmp + case "$ARCHITECTURES " in + *" arm64 "*) KERNEL_ARCH=arm64:arm64 ;; + esac ;; hppa) KERNEL_ARCH=parisc ;; i386) KERNEL_ARCH=686-pae - case "$ARCHITECTURES " in *" amd64 "*) - KERNEL_ARCH=amd64:amd64 - ;; esac + case "$ARCHITECTURES " in + *" amd64 "*) KERNEL_ARCH=amd64:amd64 ;; + esac ;; mips64el) KERNEL_ARCH=5kc-malta -- cgit v1.2.3 From 88b229430a91354510224c960d30f427e078e8a8 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 25 Jan 2023 09:30:41 +0100 Subject: tests: use an amd64 kernel on i386 --- .gitlab-ci.yml | 2 +- tests/create-and-run.sh | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e97f0bd..baea94c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,5 +46,5 @@ arch_test: - test -e /proc/sys/fs/binfmt_misc/status || mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc - apt-get update - apt-get dist-upgrade --yes - - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client qemu-system binfmt-support arch-test qemu-user-static + - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client qemu-system binfmt-support arch-test qemu-user-static file - PATH=$(pwd)/bin:$PATH ./tests/create-and-run.sh "$ARCHITECTURE" sid diff --git a/tests/create-and-run.sh b/tests/create-and-run.sh index 819161f..c8efa3e 100755 --- a/tests/create-and-run.sh +++ b/tests/create-and-run.sh @@ -21,8 +21,12 @@ trap cleanup EXIT INT TERM QUIT ssh-keygen -f "$SSH_KEYPATH" -N '' set -- -# Use an armhf kernel for armel. -test "$ARCHITECTURE" = armel && set -- -- --architecture armhf +case "$ARCHITECTURE" in + # Booting an armel kernel on qemu is next to impossible. + armel) set -- -- --architecture armhf ;; + # Broken kernel #1029270. + i386) set -- -- --architecture amd64 ;; +esac debvm-create -k "$SSH_KEYPATH.pub" -o "$IMAGE" -a "$ARCHITECTURE" -r "$RELEASE" "$@" SSH_PORT=2222 -- 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(-) 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(+) 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(-) 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(-) 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(+) 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(-) 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