Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/scripts/lib_ck_m1_checks.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / scripts / lib_ck_m1_checks.sh` 160 lines ยท 8362 bytes Raw Blame History 1 # SPDX-License-Identifier: Apache-2.0 2 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 # Shared AIENOS C kernel M1 checks (Lane 18). Sourced by qemu_ck_boot_test.sh 17 # and qemu_ck_store_test.sh so both gates run the identical M1 checks; the 18 # patterns are those of qemu_boot_test.sh (the Rust kernel's test) except 19 # where qemu_ck_boot_test.sh's header lists a deliberate difference. 20 # Not executable on its own. Callers set: work (serial text in 21 # ${work}/serial.txt), commit, qemu_status; ck_m1_checks sets failed=1 on any 22 # failure and never resets it. ck_m3_checks (Lane 25) runs the five M3 checks 23 # of qemu_boot_test.sh with the same patterns and sets m3_failed=1 on any 24 # failure; it does not touch failed, so the M1 verdict is unchanged. 25 # 26 # Kernel entropy (Lane 31, C kernel addition): every boot must print 27 # "entropy: rndr feat_rng=yes ..." (RNDR present, bounded retry, stuck test) 28 # and no refusal. There is no fallback source, so a CPU without FEAT_RNG 29 # fails M1. ck_m1_entropy=absent is set only by qemu_ck_store_test.sh for its 30 # one negative boot on a CPU model without FEAT_RNG: that boot must print the 31 # refusal instead (and cannot pass on a CPU that has RNDR). 32 ck_m1_entropy=rndr 33 34 check() { # description, pattern 35 if grep -q -- "$2" "${work}/serial.txt"; then 36 echo "PASS $1" 37 else 38 echo "FAIL $1" 39 failed=1 40 fi 41 } 42 check_absent() { # description, pattern 43 if grep -q -- "$2" "${work}/serial.txt"; then 44 echo "FAIL $1" 45 failed=1 46 else 47 echo "PASS $1" 48 fi 49 } 50 51 ck_m1_checks() { 52 check "pre-exit report printed" "report_kind: pre_exit" 53 check "image is this commit" "aienos_commit: ${commit}" 54 check "left firmware and entered the kernel" "kernel: alive" 55 check "kernel entered EL1h" "kernel_el: EL1h" 56 check "EL1 page tables and caches enabled" "mmu: enabled" 57 # AIENOS_QEMU_GIC=2: QEMU gic-version=2, the Raspberry Pi 5 shape (GIC-400, 58 # memory-mapped CPU interface). Default 3: the GB10 shape. 59 if [[ "${AIENOS_QEMU_GIC:-3}" == 2 ]]; then 60 check "GICv2 enabled" "gic: v2" 61 else 62 check "GICv3 enabled" "gic: v3" 63 fi 64 if grep -qE 'timer_irq: ([0-9]+) ticks' "${work}/serial.txt"; then 65 ticks=$(grep -oE 'timer_irq: ([0-9]+) ticks' "${work}/serial.txt" | tail -1 | grep -oE '[0-9]+') 66 [[ "${ticks}" -ge 5 ]] && echo "PASS timer IRQ delivered at least five ticks" || { echo "FAIL timer IRQ delivered fewer than five ticks"; failed=1; } 67 else 68 echo "FAIL timer IRQ count reported" 69 failed=1 70 fi 71 # Issue #27: the kernel left firmware's EL2 translation for AIENOS EL1 tables. 72 # The script re-checks the register values itself instead of trusting switched=yes. 73 switch_re='mmu_switch: firmware=EL2 firmware_mmu=on firmware_ttbr0=(0x[0-9a-f]+) aienos_root=(0x[0-9a-f]+) ttbr0_el1=(0x[0-9a-f]+) switched=yes' 74 switch_line=$(grep -E "${switch_re}" "${work}/serial.txt" | tail -1 || true) 75 if [[ "${switch_line}" =~ ${switch_re} ]]; then 76 fw_root="${BASH_REMATCH[1]}"; aienos_root="${BASH_REMATCH[2]}"; el1_root="${BASH_REMATCH[3]}" 77 if [[ "${aienos_root}" == "${el1_root}" && "${aienos_root}" != "${fw_root}" ]]; then 78 echo "PASS MMU switched from firmware tables (${fw_root}) to AIENOS tables (${aienos_root})" 79 else 80 echo "FAIL MMU switch values inconsistent: ${switch_line}" 81 failed=1 82 fi 83 else 84 echo "FAIL MMU switch from firmware tables reported" 85 failed=1 86 fi 87 if [[ "${AIENOS_QEMU_GIC:-3}" == 2 ]]; then 88 check "GIC distributor from the ACPI MADT, GICv2 architecture, no ICC system registers" \ 89 "gic_madt: gicd=0x[0-9a-f]* gicr=0x0 arch_rev=2 icc_sre=0" 90 check "GICv2 CPU interface from the MADT GICC base, memory-mapped" \ 91 "gic_cpu_interface: mmio gicc=0x[0-9a-f]*[1-9a-f][0-9a-f]*" 92 else 93 check "GIC bases from the ACPI MADT, GICv3 architecture and ICC system registers" \ 94 "gic_madt: gicd=0x[0-9a-f]* gicr=0x[0-9a-f]* arch_rev=3 icc_sre=1" 95 fi 96 # Issue #28: tick statistics. The dispatcher re-arms the timer 10 ms after each 97 # tick, so no interval may be shorter than half a period (a missing re-arm or a 98 # missing EOI would show as an interrupt storm or no second tick). 99 stats_re='timer_stats: intid=30 freq_hz=([0-9]+) period_us=([0-9]+) min_us=([0-9]+) avg_us=([0-9]+) max_us=([0-9]+)' 100 stats_line=$(grep -E "${stats_re}" "${work}/serial.txt" | tail -1 || true) 101 if [[ "${stats_line}" =~ ${stats_re} ]]; then 102 period="${BASH_REMATCH[2]}"; min_us="${BASH_REMATCH[3]}"; avg_us="${BASH_REMATCH[4]}"; max_us="${BASH_REMATCH[5]}" 103 if [[ "${period}" -gt 0 && $(( min_us * 2 )) -ge "${period}" && "${min_us}" -le "${avg_us}" && "${avg_us}" -le "${max_us}" ]]; then 104 echo "PASS tick statistics consistent (period ${period} us, min ${min_us} avg ${avg_us} max ${max_us})" 105 else 106 echo "FAIL tick statistics out of range: ${stats_line}" 107 failed=1 108 fi 109 else 110 echo "FAIL tick statistics reported" 111 failed=1 112 fi 113 # Added for the C kernel (the Rust kernel has no such test): every guard page 114 # faulted and the fault was contained. 115 check "guard pages fault and the fault is contained (C kernel addition)" "guard_page: ok fault=contained" 116 check "CPU feature line printed (ID_AA64ISAR0/ISAR1/PFR0 decode, C kernel addition)" \ 117 "^cpu_features: dotprod=[01] i8mm=[01] bf16=[01] fhm=[01] fp16=[01] sve=[01] rndr=[01]$" 118 if [[ "${ck_m1_entropy}" == absent ]]; then 119 check "kernel entropy refused without FEAT_RNG (negative boot, C kernel addition)" \ 120 "^entropy: unavailable reason=absent (ID_AA64ISAR0_EL1.RNDR=0, no FEAT_RNG); security consumers refuse, fail closed$" 121 check_absent "no RNDR entropy claimed without FEAT_RNG (negative boot)" "^entropy: rndr" 122 else 123 check "kernel entropy from RNDR: FEAT_RNG present, bounded retry, stuck test (C kernel addition)" \ 124 "^entropy: rndr feat_rng=yes probe_words=2 retries=[0-9]* stuck_test=ok$" 125 check_absent "no kernel entropy refusal (C kernel addition)" "^entropy: \(unavailable\|refused\)" 126 fi 127 check "final report on the SPCR console" "report_kind: final" 128 check "no panic or fault" "report_kind: final" 129 if grep -qE "report_kind: (panic|fault)" "${work}/serial.txt"; then 130 echo "FAIL panic or fault reported" 131 failed=1 132 fi 133 if [[ "${qemu_status}" == 124 ]]; then 134 echo "FAIL timed out (no reset)" 135 failed=1 136 elif [[ "${qemu_status}" != 0 ]]; then 137 # Stricter than qemu_boot_test.sh (which fails only on 124): PSCI 138 # SYSTEM_RESET under -no-reboot makes QEMU exit 0, so any other status is a 139 # QEMU crash or abort even if the markers were already flushed. 140 echo "FAIL qemu exited with status ${qemu_status} (expected 0 after PSCI reset)" 141 failed=1 142 fi 143 } 144 145 ck_m3_checks() { 146 # Same five patterns as qemu_boot_test.sh lines 63-67 (the Rust M3 rows). 147 m3_check() { # description, pattern 148 if grep -q -- "$2" "${work}/serial.txt"; then 149 echo "PASS $1" 150 else 151 echo "FAIL $1" 152 m3_failed=1 153 fi 154 } 155 m3_check "cooperative threads interleaved" "threads: ok" 156 m3_check "EL0 capability and fault isolation" "el0: ok write=granted forged=denied fault=contained exit=0" 157 m3_check "timer-driven preemption across runnable tasks" "preempt: ok" 158 m3_check "deterministic MADT placement of preempt workers" "placement: worker0=class0/core0 worker1=class0/core1" 159 m3_check "typed IPC with attenuated revocable delegation" "ipc: ok message=delivered cap=delegated rights=attenuated forged=denied revoked=denied" 160 }