Skip to content

eBPF-based security platform

testing: fetch and stage arm64 CI kernels

Andrea Lattuada5931f6fb493e
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index b01bc30d..f0f39e48 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -59,8 +59,8 @@ The ``CI suite`` workflow uses the x86-64 CI kernel package from
kernel does not change what a series is tested on. For a manual run,
set ``kernel_run_id`` to select another run. The run must contain that
artifact. The ``KERNEL_REPO_READ_TOKEN`` secret needs Actions read
-access to the kernel repository. Setup extracts the image and headers
-packages, checks BTF for the signed-loader ABI and every LSM hook a
+access to the kernel repository. Setup extracts the packages,
+checks BTF for the signed-loader ABI and every LSM hook a
program of ``bpf/`` attaches to, and stages the result for the test VM.
The kernel project owns the kernel source, configuration and patch
application. Changes to those inputs need a successful kernel project
@@ -450,21 +450,21 @@ interactive VM stays up until you stop it.
Use a kernel project artifact
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The kernel project publishes the kernel image, BTF, configuration and
-modules together, as the ``kernel-packages-x86-64-ci`` artifact of a
-run of its package workflow. :src:`testing/vm/kernel-artifact.sh` pins
-the run the tests use, and a goal of ``make -C testing`` that finds no
-kernel under ``artifacts/bpf-next-kernel-debs/`` downloads and stages
-that one: a target VM goal for the kernel it boots, and every goal that
-builds for the BTF the BPF objects are compiled against, unless
-``BPF_VMLINUX_BTF`` or ``BPF_VMLINUX_H`` names another. It
-needs ``gh``, logged in with read access to the kernel repository:
+The kernel CI artifacts contain the kernel image, BTF, configuration and
+modules. :src:`testing/vm/kernel-artifact.sh` pins the run the tests use.
+A goal of ``make -C testing`` that finds no kernel under
+``artifacts/bpf-next-kernel-debs/`` downloads and stages the CI artifact
+for the VM architecture. A target VM goal uses its kernel image, and a
+build uses its BTF unless ``BPF_VMLINUX_BTF`` or ``BPF_VMLINUX_H`` names
+another source. Fetching needs ``gh`` logged in with read access to the
+kernel repository:
.. code-block:: console
$ testing/vm/kernel-artifact.sh fetch
-``KERNEL_RUN_ID=<run>`` takes another run. A kernel that is staged is
+``KERNEL_RUN_ID=<run>`` takes another run that publishes the CI artifact
+for the architecture. A kernel that is staged is
left as it is, whatever run it came from, and
``artifacts/bpf-next-kernel-debs/kernel-run-id`` names the run of one
that was fetched: remove the directory to get the pinned kernel after
@@ -476,8 +476,8 @@ of the CI runner calls with ``KERNEL_CI_ARTIFACT_DIR``:
$ KERNEL_CI_ARTIFACT_DIR=$HOME/Downloads/kernel-packages-x86-64-ci .github/scripts/tests.sh setup
-Target VM goals require this artifact; they do not build a kernel from
-this checkout.
+Target VM goals require a kernel artifact; they do not build a kernel
+from this checkout.
Build the bundle
~~~~~~~~~~~~~~~~
diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rst
index e65ea9e3..57c25322 100644
--- a/Documentation/start/quickstart.rst
+++ b/Documentation/start/quickstart.rst
@@ -27,8 +27,7 @@ Before you begin
needed; the test VM builds its initrd with dracut as you, without
changing the host's dracut.
- Network access. The first boot downloads an Ubuntu cloud image. Get
- the test kernel package artifact from the pinned run in
- ``testing/vm/kernel-artifact.sh`` before building the target binary.
+ the test kernel artifact before building the target binary.
- To build shirudo: a C toolchain with ``make`` and ``pkg-config``, a
clang and LLVM 23 with the BPF target, ``clang`` installed as
``/usr/bin/clang``, and the development files of OpenSSL 3.5 or later,
@@ -36,8 +35,11 @@ Before you begin
and ``tss2-tctildr``) and LuaJIT.
- OpenSSL 3.5 or newer (``openssl version``). If it reports an older
version, follow :ref:`the developer guide's steps <dev-openssl>` first.
+- ``dpkg-deb`` to extract the test kernel, and Docker or Podman to build
+ the test VM bundle.
- For the test VM, with their Debian and Ubuntu names: QEMU
(``qemu-system-x86`` or ``qemu-system-arm``), ``qemu-utils``, ``swtpm``,
+ ``swtpm-tools``, ``tpm2-tools``, ``libtss2-tcti-swtpm0t64``,
``cloud-image-utils``, ``libguestfs-tools``, ``dracut-core``,
``cryptsetup-bin``, ``e2fsprogs``, ``openssh-client``, ``iproute2``,
``isc-dhcp-client``, ``curl``, ``kmod`` and ``file``, and the static
@@ -48,16 +50,24 @@ Before you begin
:doc:`/operate/plan/system-requirements` lists the requirements in full.
+.. _quickstart-kernel-artifact:
+
Use the test kernel artifact
----------------------------
-Download the ``kernel-packages-x86-64-ci`` artifact from the run pinned
-in ``testing/vm/kernel-artifact.sh``. Stage it and prepare the test host:
+From the checkout root, download and stage the CI kernel for your host:
.. code-block:: console
- operator$ KERNEL_CI_ARTIFACT_DIR=$HOME/Downloads/kernel-packages-x86-64-ci \
- .github/scripts/tests.sh setup
+ operator$ testing/vm/kernel-artifact.sh fetch
+
+``fetch`` needs ``gh`` logged in with read access to the kernel
+repository. It selects ``kernel-packages-x86-64-ci`` or
+``kernel-packages-arm64-ci`` from the run pinned in
+:src:`testing/vm/kernel-artifact.sh`. Use ``KERNEL_RUN_ID=<run>`` to
+select another run that publishes the CI artifact for your architecture.
+If you downloaded the artifact separately, run
+``testing/vm/kernel-artifact.sh stage <artifact-dir>``.
The artifact includes the kernel, its BTF, configuration and modules.
shirudo compiles its embedded BPF objects against that BTF.
diff --git a/testing/Makefile b/testing/Makefile
index 75f08301..3f93c83c 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -150,7 +150,9 @@ TEST_VM_BUNDLE_INPUTS := $(sort \
$(ROOT)/config.mk: $(ROOT)/Makefile.config
+$(Q)$(MAKE) -C $(ROOT) config
-test-vm-bundle: require-vm-kernel $(TEST_VM_BUNDLE_STAMP)
+# Read the bundle prerequisites after staging can create the kernel stamp.
+test-vm-bundle: require-vm-kernel
+ +$(Q)$(MAKE) -f "$(ROOT)/testing/Makefile" "$(TEST_VM_BUNDLE_STAMP)"
$(TEST_VM_BUNDLE_STAMP): $(TEST_VM_BUNDLE_INPUTS)
$(Q)mkdir -p $(dir $(BUILD_LOCK))
diff --git a/testing/vm/arch.sh b/testing/vm/arch.sh
index 56edc95d..2caa2d14 100644
--- a/testing/vm/arch.sh
+++ b/testing/vm/arch.sh
@@ -26,6 +26,7 @@ if [ "$TEST_VM_ARCH" = aarch64 ]; then
TEST_VM_ARCH_KIMAGE=Image
TEST_VM_ARCH_KIMAGE_SRC=arch/arm64/boot/Image
TEST_VM_ARCH_DEB=arm64
+ TEST_VM_ARCH_CI_ARTIFACT=kernel-packages-arm64-ci
TEST_VM_ARCH_MIRROR=https://ports.ubuntu.com/ubuntu-ports
else
TEST_VM_ARCH_QEMU=qemu-system-x86_64
@@ -35,6 +36,7 @@ else
TEST_VM_ARCH_KIMAGE=bzImage
TEST_VM_ARCH_KIMAGE_SRC=arch/x86/boot/bzImage
TEST_VM_ARCH_DEB=amd64
+ TEST_VM_ARCH_CI_ARTIFACT=kernel-packages-x86-64-ci
TEST_VM_ARCH_MIRROR=https://archive.ubuntu.com/ubuntu
fi
diff --git a/testing/vm/kernel-artifact.sh b/testing/vm/kernel-artifact.sh
index d3d4befd..ecfcaab1 100755
--- a/testing/vm/kernel-artifact.sh
+++ b/testing/vm/kernel-artifact.sh
@@ -5,16 +5,18 @@
# testing/vm/kernel-artifact.sh -- the test VM's kernel, which
# github.com/shirudo-dev/kernel builds and this checkout does not.
#
-# kernel-artifact.sh fetch download the kernel-packages-x86-64-ci
-# artifact of the pinned run and stage it
+# kernel-artifact.sh fetch download and stage the CI artifact for
+# the test VM architecture
# kernel-artifact.sh stage <dir> stage an artifact already downloaded
# kernel-artifact.sh run-id print the pinned run
#
-# Staging extracts the image and headers packages, checks the BTF for the
-# signed-loader ABI and every LSM hook a program of bpf/ attaches to, and
-# puts image, BTF, configuration and modules under
-# artifacts/bpf-next-kernel-debs/, where testing/Makefile looks for them.
-# With VM=0 it stages the BTF alone, which a build needs.
+# Staging extracts the image package and the matching headers package
+# when present. It checks the BTF for the signed-loader ABI and every
+# LSM hook a program in bpf/ attaches to. It puts the image, BTF,
+# configuration and modules under artifacts/bpf-next-kernel-debs/,
+# where testing/Makefile looks for them.
+# With VM=0 it stages the BTF alone and invalidates the staged VM kernel
+# if the BTF changes.
#
# KERNEL_RUN_ID another run of the kernel project's package workflow
# than the pinned one.
@@ -25,8 +27,7 @@ set -eu
# The run every trigger of the CI suite tests on, so that a new build of
# the kernel does not change what a series is tested on.
-PINNED_RUN_ID=45057179917
-ARTIFACT=kernel-packages-x86-64-ci
+PINNED_RUN_ID=45062075601
REPOSITORY=shirudo-dev/kernel
# A directory named from where the caller stands.
@@ -91,28 +92,50 @@ validate_kernel_install() {
return 0
}
+clear_kernel_stamps() {
+ rm -f "$kernel/bzImage.sha256sum" "$kernel/Image.sha256sum" \
+ "$kernel/vmlinux.btf.sha256sum" "$kernel/kernel-run-id"
+}
+
stage_kernel_install() {
+ clear_kernel_stamps || return 1
rm -rf "$kernel/lib/modules" || return 1
mkdir -p "$kernel/lib/modules" || return 1
- cp "$image" "$kernel/bzImage" || return 1
+ cp "$image" "$kernel/$kernel_image_name" || return 1
cp "$btf" "$kernel/vmlinux.btf" || return 1
cp "$config" "$kernel/kernel.config" || return 1
cp -a "$modules" "$kernel/lib/modules/" || return 1
(
cd "$kernel" || exit 1
- sha256sum bzImage > bzImage.sha256sum || exit 1
sha256sum vmlinux.btf > vmlinux.btf.sha256sum || exit 1
+ sha256sum "$kernel_image_name" > "$kernel_image_name.sha256sum"
) || return 1
}
stage_kernel_ci_artifact() {
artifact_dir="$1"
- set -- "$artifact_dir"/*/linux-image-*_amd64.deb
+ expected_arch="${2:-}"
+ set -- "$artifact_dir"/*/linux-image-*.deb
+ [ -e "$1" ] || set -- "$artifact_dir"/linux-image-*.deb
[ "$#" -eq 1 ] && [ -s "$1" ] || {
- echo "expected one x86-64 kernel image package in $artifact_dir" >&2
+ echo "expected one kernel image package in $artifact_dir" >&2
return 1
}
image_package="$1"
+ package_arch=${image_package##*_}
+ package_arch=${package_arch%.deb}
+ if [ -n "$expected_arch" ] && [ "$package_arch" != "$expected_arch" ]; then
+ echo "expected a $expected_arch kernel image package: $image_package" >&2
+ return 1
+ fi
+ case "$package_arch" in
+ amd64) kernel_image_name=bzImage ;;
+ arm64) kernel_image_name=Image ;;
+ *)
+ echo "expected an x86-64 or arm64 kernel image package: $image_package" >&2
+ return 1
+ ;;
+ esac
package_dir=${image_package%/*}
release=${image_package##*/linux-image-}
release=${release%%_*}
@@ -121,25 +144,34 @@ stage_kernel_ci_artifact() {
echo "kernel CI artifact lacks BTF for $release" >&2
return 1
}
- mkdir -p "$kernel" || return 1
- cp "$btf" "$kernel/vmlinux.btf" || return 1
- [ "${VM:-1}" != 0 ] || return 0
+ if [ "${VM:-1}" = 0 ]; then
+ cmp -s "$btf" "$kernel/vmlinux.btf" && return 0
+ mkdir -p "$kernel" || return 1
+ clear_kernel_stamps || return 1
+ cp "$btf" "$kernel/vmlinux.btf" || return 1
+ return 0
+ fi
- set -- "$package_dir"/linux-headers-"$release"_*_amd64.deb
- [ "$#" -eq 1 ] && [ -s "$1" ] || {
+ set -- "$package_dir"/linux-headers-"$release"_*_"$package_arch".deb
+ headers_package=
+ if [ "$#" -eq 1 ] && [ -s "$1" ]; then
+ headers_package="$1"
+ elif [ "$#" -gt 1 ] || [ -e "$1" ]; then
echo "expected headers package for kernel $release in $package_dir" >&2
return 1
- }
+ fi
config="$package_dir/config-$release"
[ -s "$config" ] || {
echo "kernel CI artifact lacks config for $release" >&2
return 1
}
install_root="$PWD/build/kernel-ci-extract"
- rm -rf "$install_root"
+ rm -rf "$install_root" || return 1
mkdir -p "$install_root" || return 1
dpkg-deb -x "$image_package" "$install_root" || return 1
- dpkg-deb -x "$1" "$install_root" || return 1
+ if [ -n "$headers_package" ]; then
+ dpkg-deb -x "$headers_package" "$install_root" || return 1
+ fi
image="$install_root/boot/vmlinuz-$release"
modules="$install_root/lib/modules/$release"
cp "$btf" "$install_root/boot/btf-$release" || return 1
@@ -165,24 +197,30 @@ run_id() {
fetch() {
id=$(run_id) || return 1
- [ "$(uname -m)" = x86_64 ] || {
- echo "the kernel project publishes a CI kernel for x86-64 only" >&2
+ # shellcheck source=testing/vm/arch.sh
+ . testing/vm/arch.sh
+ [ "$TEST_VM_ARCH_SUPPORTED" = 1 ] || {
+ echo "no CI kernel artifact for $TEST_VM_ARCH" >&2
return 1
}
+ artifact="$TEST_VM_ARCH_CI_ARTIFACT"
command -v gh >/dev/null 2>&1 || {
- echo "gh is needed to download $ARTIFACT of $REPOSITORY run $id" >&2
+ echo "gh is needed to download $artifact of $REPOSITORY run $id" >&2
return 1
}
download=build/kernel-ci-artifact
rm -rf "$download"
mkdir -p "$download" || return 1
- echo "downloading $ARTIFACT of $REPOSITORY run $id" >&2
- gh run download "$id" --repo "$REPOSITORY" --name "$ARTIFACT" \
+ echo "downloading $artifact of $REPOSITORY run $id" >&2
+ gh run download "$id" --repo "$REPOSITORY" --name "$artifact" \
--dir "$download" || {
- echo "cannot download $ARTIFACT of $REPOSITORY run $id" >&2
+ echo "cannot download $artifact of $REPOSITORY run $id" >&2
return 1
}
- stage_kernel_ci_artifact "$download" || return 1
+ stage_kernel_ci_artifact "$download" "$TEST_VM_ARCH_DEB" || return 1
+ if [ "${VM:-1}" = 0 ] && [ -s "$kernel/$kernel_image_name.sha256sum" ]; then
+ return 0
+ fi
printf '%s\n' "$id" >"$kernel/kernel-run-id"
}