qemu: check the kernel contract at boot and run a staged script (warden.run)
ci / test (push) Canceled after 0s
ci / mcdc (push) Canceled after 0s
ci / bench (push) Canceled after 0s
ci / qemu-tools (push) Canceled after 0s
ci / kernel-symbols (push) Canceled after 0s
ci / patches-apply (push) Canceled after 0s
ci / prune-artifacts (push) Canceled after 0s
ci / kernel-build (push) Canceled after 0s
ci / quality (push) Canceled after 0s
ci / badges (push) Canceled after 0s
ci / test (push) Canceled after 0s
ci / mcdc (push) Canceled after 0s
ci / bench (push) Canceled after 0s
ci / qemu-tools (push) Canceled after 0s
ci / kernel-symbols (push) Canceled after 0s
ci / patches-apply (push) Canceled after 0s
ci / prune-artifacts (push) Canceled after 0s
ci / kernel-build (push) Canceled after 0s
ci / quality (push) Canceled after 0s
ci / badges (push) Canceled after 0s
init verifies build/required-symbols.txt against the guest's /proc/config.gz, the cgroup v2 controllers and PSI and prints markers; boot-smoke.sh fails when a marker is missing. mkinitramfs.sh stages the list and merges EXTRA_DIR; run.sh --append passes warden.run=<path>, which init runs before powering off (used by the flare-edge M0 limit tests). README notes the symbol lists. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cxh2piVufTWbzKTmUafTkk
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
0360b8dc46
commit
445b2082f5
@@ -6,6 +6,8 @@
|
||||
# Env:
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified)
|
||||
# OUT output dir (default: qemu/out); initramfs at $OUT/initramfs.cpio.gz
|
||||
# EXTRA_DIR a directory merged into the initramfs root (a test's scripts and
|
||||
# static binaries; init runs one on warden.run=<path>)
|
||||
set -euo pipefail
|
||||
|
||||
QEMU_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
@@ -20,6 +22,12 @@ qemu_get_busybox
|
||||
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/warden-qemu-initramfs.XXXXXX")"
|
||||
trap 'rm -rf "$SCRATCH"' EXIT
|
||||
qemu_stage_rootfs "$SCRATCH/root"
|
||||
# The kernel symbol list, so init can check it against /proc/config.gz.
|
||||
install -D -m 0644 "$QEMU_DIR/../build/required-symbols.txt" "$SCRATCH/root/etc/required-symbols.txt"
|
||||
if [ -n "${EXTRA_DIR:-}" ]; then
|
||||
[ -d "$EXTRA_DIR" ] || { echo "FATAL: EXTRA_DIR is not a directory: $EXTRA_DIR" >&2; exit 1; }
|
||||
cp -a "$EXTRA_DIR/." "$SCRATCH/root/"
|
||||
fi
|
||||
|
||||
# Pack (newc cpio, gzip). No device nodes required: /init mounts devtmpfs and
|
||||
# reopens the console itself, so the archive builds unprivileged.
|
||||
|
||||
@@ -18,6 +18,52 @@ mount -t sysfs sysfs /sys
|
||||
|
||||
echo "WARDEN-QEMU-BOOT-OK"
|
||||
|
||||
# Kernel contract (rebuild M0): every symbol of build/required-symbols.txt (staged
|
||||
# as /etc/required-symbols.txt by mkinitramfs.sh) is in the running kernel's
|
||||
# /proc/config.gz, the cgroup v2 controllers the platform limits with are there,
|
||||
# and pressure stall information is on. boot-smoke.sh greps these markers.
|
||||
if [ -r /etc/required-symbols.txt ]; then
|
||||
if [ -e /proc/config.gz ] && zcat /proc/config.gz > /config.run 2>/dev/null; then
|
||||
miss=""; nsym=0
|
||||
while read -r line; do
|
||||
case "$line" in
|
||||
CONFIG_*=*)
|
||||
nsym=$((nsym + 1))
|
||||
grep -qxF "$line" /config.run || miss="$miss $line" ;;
|
||||
"# CONFIG_"*" is not set")
|
||||
sym="${line#\# }"; sym="${sym% is not set}"; nsym=$((nsym + 1))
|
||||
grep -q "^$sym=" /config.run && miss="$miss ${sym}(set)" ;;
|
||||
esac
|
||||
done < /etc/required-symbols.txt
|
||||
if [ -z "$miss" ]; then echo "WARDEN-QEMU-SYMBOLS-OK $nsym"
|
||||
else echo "WARDEN-QEMU-SYMBOLS-MISSING$miss"; fi
|
||||
else
|
||||
echo "WARDEN-QEMU-SYMBOLS-MISSING /proc/config.gz"
|
||||
fi
|
||||
mkdir -p /sys/fs/cgroup
|
||||
mount -t cgroup2 none /sys/fs/cgroup 2>/dev/null
|
||||
echo "WARDEN-QEMU-CGROUP-CONTROLLERS $(cat /sys/fs/cgroup/cgroup.controllers 2>/dev/null)"
|
||||
psi_missing=""
|
||||
for f in cpu memory io; do [ -r "/proc/pressure/$f" ] || psi_missing="$psi_missing $f"; done
|
||||
if [ -z "$psi_missing" ]; then echo "WARDEN-QEMU-PSI-OK"; else echo "WARDEN-QEMU-PSI-MISSING$psi_missing"; fi
|
||||
fi
|
||||
|
||||
# warden.run=<path>: run a script that mkinitramfs.sh staged from EXTRA_DIR, then
|
||||
# power off. Used by the M0 limit tests (tools/m0/limits-test.sh in flare-edge).
|
||||
for w in $(cat /proc/cmdline); do
|
||||
case "$w" in warden.run=*) RUN_SCRIPT="${w#warden.run=}" ;; esac
|
||||
done
|
||||
if [ -n "${RUN_SCRIPT:-}" ]; then
|
||||
if [ -x "$RUN_SCRIPT" ]; then
|
||||
echo "WARDEN-QEMU-RUN-BEGIN $RUN_SCRIPT"
|
||||
"$RUN_SCRIPT"
|
||||
echo "WARDEN-QEMU-RUN-END rc=$?"
|
||||
else
|
||||
echo "WARDEN-QEMU-RUN-MISSING $RUN_SCRIPT"
|
||||
fi
|
||||
poweroff -f
|
||||
fi
|
||||
|
||||
# With a virtio disk attached, hand over to the stage-1 rc (by-name symlinks,
|
||||
# slot select, switch_root). It only returns on failure; then fall through to
|
||||
# the diskless shell/poweroff behavior below.
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
# --http-port N hostfwd 127.0.0.1:N -> guest :80 (default 8080; 0 disables)
|
||||
# --api-port N hostfwd 127.0.0.1:N -> guest :28443 (default 28443; 0 disables)
|
||||
# --shell interactive shell in the guest instead of daemon hold
|
||||
# --append STR extra kernel command line words (for example
|
||||
# warden.run=/m0/limits-test.sh: init runs that script from
|
||||
# the initramfs and powers off)
|
||||
# --allow-apply let flared ACTUALLY apply OTA firmware (writes rootfs_b
|
||||
# inside disk.img, safe in the VM, never the default)
|
||||
set -euo pipefail
|
||||
@@ -38,6 +41,7 @@ KERNEL="" INITRD="$OUT/initramfs.cpio.gz" DISK="" NO_DISK=0 SLOT="_a"
|
||||
RTC="" RS485="" CTL="" WATCHDOG=0 QMP="" DISPLAY_MODE="off" SHELL_FLAG=0 ALLOW_APPLY=0
|
||||
SSH_PORT=2222 HTTP_PORT=8080 API_PORT=28443
|
||||
EXTRA=()
|
||||
EXTRA_APPEND=""
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
@@ -56,6 +60,7 @@ while [ $# -gt 0 ]; do
|
||||
--http-port) HTTP_PORT="${2:?}"; shift 2 ;;
|
||||
--api-port) API_PORT="${2:?}"; shift 2 ;;
|
||||
--shell) SHELL_FLAG=1; shift ;;
|
||||
--append) EXTRA_APPEND="${2:?}"; shift 2 ;;
|
||||
--allow-apply) ALLOW_APPLY=1; shift ;;
|
||||
--) shift; EXTRA=("$@"); break ;;
|
||||
*) echo "FATAL: unknown argument '$1' (see header of $0)" >&2; exit 1 ;;
|
||||
@@ -111,6 +116,7 @@ if [ -n "$DISK" ] && [ "$NO_DISK" -eq 0 ]; then
|
||||
-device "virtio-blk-device,drive=vd0" )
|
||||
fi
|
||||
[ "$SHELL_FLAG" -eq 1 ] && APPEND="$APPEND warden.shell"
|
||||
[ -n "$EXTRA_APPEND" ] && APPEND="$APPEND $EXTRA_APPEND"
|
||||
# Tells init the FIRST 8250 is the control bridge. Without this marker init
|
||||
# bridges nothing, so a VM launched with --rs485 alone never has its Modbus
|
||||
# wire mistaken for the debug channel.
|
||||
|
||||
@@ -44,4 +44,20 @@ grep -q "WARDEN-QEMU-BOOT-OK" "$LOG" || {
|
||||
echo "FATAL: boot sentinel WARDEN-QEMU-BOOT-OK not found in console log" >&2
|
||||
exit 1
|
||||
}
|
||||
echo "boot smoke OK"
|
||||
# Kernel contract (rebuild M0): init checked build/required-symbols.txt against the
|
||||
# running kernel's /proc/config.gz, the cgroup v2 controllers and PSI. A missing
|
||||
# marker is as fatal as a MISSING one: the check must have run.
|
||||
grep -q "^WARDEN-QEMU-SYMBOLS-OK " "$LOG" || {
|
||||
echo "FATAL: the required-symbols check did not pass: $(grep -E 'WARDEN-QEMU-SYMBOLS' "$LOG" | head -1)" >&2
|
||||
exit 1
|
||||
}
|
||||
ctl="$(sed -n 's/^WARDEN-QEMU-CGROUP-CONTROLLERS //p' "$LOG" | head -1 | tr -d '\r')"
|
||||
for c in cpu memory pids; do
|
||||
case " $ctl " in *" $c "*) ;; *)
|
||||
echo "FATAL: cgroup v2 controller '$c' missing in the guest (have: '$ctl')" >&2; exit 1 ;; esac
|
||||
done
|
||||
grep -q "^WARDEN-QEMU-PSI-OK" "$LOG" || {
|
||||
echo "FATAL: pressure stall information is not available: $(grep -E 'WARDEN-QEMU-PSI' "$LOG" | head -1)" >&2
|
||||
exit 1
|
||||
}
|
||||
echo "boot smoke OK (symbols, cgroup controllers [$ctl], PSI)"
|
||||
|
||||
Reference in New Issue
Block a user