aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
GitHub aien-dev/aienux#302 (code only)
Apply it
git checkout -b patch-39ae85ee1c744964 e90226ba1016368289d953c449dde74646fb26bf curl -fsSL https://interplane.io/drakestapleton/aienux/patches/39ae85ee1c744964.patch | git am
Provenance
github-import 1
aien-dev/aienux
302
b8a89cf6558780b97de2ad34302f2ff1ac3e1d4a
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":302,"url":"https://github.com/aien-dev/aienux/pull/302","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:10Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index b18b22e9..2a25f565 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "30f908b47375e088c78fe9123dac1ef2df0551c10de30c8c19ba7b053c065f91", - "last_commit": "ed308de", + "digest": "a3bf1a650bb24f9e0775776636e96bc14adb92b8c3c772d7ce0dfc976253e847", + "last_commit": "3f79153", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "1dd726352055e65ac3c21d6f8c4e0c841a8c4912ba8384dfa8968fb7ce4d82fb", - "last_commit": "ed308de", + "digest": "e6450fb9b838f64fcc90113926436887241ae8a12ceb5523954818b3d986b281", + "last_commit": "3f79153", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "d9cd564824903777dd323019bb8d5673331383e961bc3da703d5589be1eb6b4c", - "last_commit": "c731baf", + "digest": "768f7a9a329815979e95b540161c74912dddd8615f44f45c44f97db5d49fdd93", + "last_commit": "3f79153", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:03cc72c852977cfbb531f9c497786a19a44ad112cdcee9756cb05db438fae2b4", - "compiled_at": "2026-10-10T04:29:33Z", + "children_root": "sha256:c66c398981f077e8a76f9488c64ea8979e278a165d22ad0f7d3bcb6640cdd81d", + "compiled_at": "2026-10-11T01:27:19Z", "compiler": "crumb-compile/1", - "digest": "sha256:87605929e4a875c96f065abb54460aec06c7c835b38ab2b97c4f2bff361a000e", + "digest": "sha256:cb9a75f3db21a1ed249779b3ae4ea36e86b10d9aade776c115b7a428544e5fc3", "evidence_files": 155, "evidence_root": "sha256:d59c0cef4e7dd5172923754a95b411ca54b01f35baca4587f792f1b259f1eaf7", - "files": 3036, - "generated_at_commit": "ed308de52ede1d4c8a211d88e0e4a3ac5c92ec23", - "source_tree": "sha256:84adae421ac7242801cac74a09f3a3b660fa3d1d44b540034700bed7f0b4d852" + "files": 3037, + "generated_at_commit": "3f791539d41d852b2b6fd36fdebaebb9f76dc2a0", + "source_tree": "sha256:37585777b81353c7c3a9edbddd9a935cba4aaa2ca956ca19225e8deaab28d4ce" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/ck-kernel.yml b/.github/workflows/ck-kernel.yml index 6ad5584d..7b914a42 100644 --- a/.github/workflows/ck-kernel.yml +++ b/.github/workflows/ck-kernel.yml @@ -137,6 +137,15 @@ jobs: done exit ${fail} + - name: B7b preparation probe (self-test, Spark-target image refuses on QEMU, TEST-ONLY segment-0 positive path; aienos#286) + env: + AIENOS_QUIET_FLAG: ${{ runner.temp }}/spark-quiet + AIENOS_GATE_LOCK: ${{ runner.temp }}/qemu-gate-lock + run: | + bash scripts/qemu_ck_b7b_probe_test.sh --self-test + bash scripts/qemu_ck_b7b_probe_test.sh + bash scripts/qemu_ck_b7b_probe_test.sh --positive + - name: Upload the receipt and logs if: always() uses: actions/upload-artifact@v4 diff --git a/docs/.crumb b/docs/.crumb index b9d2ead3..74752458 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:55bcc89f5282eb2e3f4e86d882abdfb5f4ea39e427ef97ef620b2267e5701eb1", - "compiled_at": "2026-10-10T04:29:33Z", + "compiled_at": "2026-10-11T01:27:19Z", "compiler": "crumb-compile/1", - "digest": "sha256:30f908b47375e088c78fe9123dac1ef2df0551c10de30c8c19ba7b053c065f91", + "digest": "sha256:a3bf1a650bb24f9e0775776636e96bc14adb92b8c3c772d7ce0dfc976253e847", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 66, - "generated_at_commit": "ed308de52ede1d4c8a211d88e0e4a3ac5c92ec23", - "source_tree": "sha256:4be513f71b655a5ddef8e3bb8bf5b15e77f9cb4ca5214a8e290af31a24b38cab" + "generated_at_commit": "3f791539d41d852b2b6fd36fdebaebb9f76dc2a0", + "source_tree": "sha256:5477120ed4c490caa4486ca483711d971262e73e40fec1aa0910b102db7b01ad" }, "owner_lane": "", "provenance": { diff --git a/docs/GB10_IORT_DECODE.md b/docs/GB10_IORT_DECODE.md index 66a9a594..83e13308 100644 --- a/docs/GB10_IORT_DECODE.md +++ b/docs/GB10_IORT_DECODE.md @@ -203,3 +203,80 @@ and the RMR node. Still unknown after this cut: everything in section 7, plus whether SMMUv3 B comes up with this driver's geometry (IDR0/IDR1 read only at B7b). + +## 10. Cut B7b preparation (done, QEMU/host only): the probe image + +Approval: Drake's ruling of 2026-10-10 (aien-architecture#190, item 5): B7b +*preparation* is authorized, not an unattended boot. The boot itself needs a +first operator-confirmed, two-hour attended window after the recovery media, +rollback, trust and preflight checks pass. Nothing in this cut ran on the +Spark's SMMUs. + +What changed: + +- `make [full] CK_B7B_PROBE=1` builds a probe image (own OUT, + `target/native-kernel-b7b-probe`; allowed with `CK_HARDWARE_STAGING`). + After `kernel: alive` and before the secondary cores start, `ck_b7b_probe` + (core/smmu_svc.c) runs once: it prints the IORT route for PCI segment 15 + requester 0x100, confines that requester on a one-page DMA window through + the normal `ck_dma_confine` path (which brings up the SMMUv3 node behind + it and identity-maps its RMR ranges, section 9), reads `SMMU_IDR0` and + `SMMU_IDR1` of that node (read-only registers: "Access to this field is + RO", IHI0070H.a 6.3.1 and 6.3.2), unconfines, and prints one summary line + `AIENOS_B7B_PROBE: CONFINED_AND_RELEASED | REFUSED | FAIL`. No DMA is + started and the window page is never handed to a device. +- `CK_B7B_PROBE_TEST_SEGMENT0=1` (TEST-ONLY, needs `CK_B7B_PROBE=1`, refused + with `CK_HARDWARE_STAGING` in the Makefile and by an `#error` in the + source) probes segment 0 instead, so QEMU exercises the granted path. +- The image checks (`b7b_check`) refuse a default image that carries the + probe, a probe image that lacks it, and any image that carries the + segment-0 announcement without its flag. +- Gate `scripts/qemu_ck_b7b_probe_test.sh` (also a CI step in + `.github/workflows/ck-kernel.yml`): + - default: the Spark-target probe image on QEMU virt (one SMMUv3, no + segment 15) must refuse, fail closed: `route none`, `confine refused + rc=-3 (nostream)`, nothing confined, summary `REFUSED`, the boot goes on + to the SMP summary, no panic. Local run 2026-10-11: PASS. + - `--positive`: the TEST-ONLY segment-0 image must route to instance 0 + stream 0x100, confine one page, read IDR0/IDR1 with a SIDSIZE that + covers 0x100, unconfine with rc 0 and print `CONFINED_AND_RELEASED`. + Local run: PASS (QEMU 0x9050000: idr0=0x0d44101a idr1=0x02730010, + ST_LEVEL 1, SIDSIZE 16). + - `--self-test`: canned logs for 19 cases (2 that must pass, 17 that must fail: (something + granted on the refusal image, wrong segment, other refusal reason, + missing or doubled summary, boot stopped, panic, probe before `kernel: + alive`, a route found where none should be, the TEST image on the gate, + and on the positive path: no announcement, unconfine failure, SIDSIZE + too small, no IDR line, wrong window, forged summary)) plus four Makefile + refusals. Local run: PASS. + +What the B7b window would show on the Spark (expected from sections 3 and 9 +and `ck_acpi_scan --iort` on this machine's table, not observed): + + b7b_probe: start segment=15 rid=0x100 window_bytes=4096 no_dma=yes + b7b_probe: route instance=1 base=0x13000000 stream=0x100 rmr_nodes=1 (smmus=3) + smmu: instance 1 up base=0x13000000 + smmu: stream 0x100 on 0x13000000: 3 firmware-reserved range(s) identity-mapped beside the window + b7b_probe: confined stream=0x100 smmu_base=0x13000000 iova=0x... len=0x1000 + b7b_probe: instance=1 idr0=0x........ idr1=0x........ st_level=. sidsize=.. + b7b_probe: unconfine rc=0 (ok); stream 0x100 aborts again + AIENOS_B7B_PROBE: CONFINED_AND_RELEASED + +Any other summary is a finding, not a retry: `REFUSED` names the reason +(`nostream`: the route differs from section 3; `failed`: bring-up or an RMR +attribute was refused), `FAIL` means the unconfine failed or no live +instance matched the confined base. + +Still open before the window (not done in this cut): + +- The one-time staging script (`scripts/stage_one_time_boot_ck.sh`) builds + the infer image; it has no probe variant yet. Adding one touches the + NVRAM staging path and is left for the window's own preparation with + Drake. +- After the probe, SMMUv3 B stays enabled with every stream aborting until + the next reset (the same state any unconfine leaves). UNKNOWN whether the + GB10 or HDA0 attempt DMA while no OS drives them; an abort there would be + recorded as an event, not acted on. +- The preconditions of the ruling (recovery media, rollback, trust, + preflight) are checked by their own procedures + (`docs/NATIVE_BOOT_ONE_TIME.md` section 3); this cut does not change them. diff --git a/native/.crumb b/native/.crumb index 2facbb22..a1813020 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "efbe476665c1f3d9c13abb2aa1745d0c1e9e6815b64a7e310010ce5f359afe0f", - "last_commit": "ed308de", + "digest": "fdb1af443afa270d2ce93cdec1e65f2d6e3ae9e69295a919e89b4de015c95267", + "last_commit": "3f79153", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, @@ -109,15 +109,15 @@ "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:11cfba659c10c0f8a1e95db0dc0935f780002a6689a1fb1c27b1f978d0828a8c", - "compiled_at": "2026-10-10T04:29:33Z", + "children_root": "sha256:70248a902001d0a5e9025cf96b6269987dfe327547cde585061b61ac7cee95ab", + "compiled_at": "2026-10-11T01:27:19Z", "compiler": "crumb-compile/1", - "digest": "sha256:1dd726352055e65ac3c21d6f8c4e0c841a8c4912ba8384dfa8968fb7ce4d82fb", + "digest": "sha256:e6450fb9b838f64fcc90113926436887241ae8a12ceb5523954818b3d986b281", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", "files": 456, - "generated_at_commit": "ed308de52ede1d4c8a211d88e0e4a3ac5c92ec23", - "source_tree": "sha256:3bd830711ca4188336373bd4e130f53b14f6ba4a3f2f64336e1a448e01e97b3d" + "generated_at_commit": "3f791539d41d852b2b6fd36fdebaebb9f76dc2a0", + "source_tree": "sha256:88eb0e57ecadbd527ab7bb1cec80f7fd161e42dabdaf2100388156a1ace41108" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 5e68e34d..22d39278 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -57,8 +57,8 @@ "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "a7b75170badd729f33774cf301d1cc72cc031719630b00ef079b2a2754b8172d", - "last_commit": "ed308de", + "digest": "85b29782329a9f640ff976034d8bda060b51ff8288e2547151aa6f30639f2bb1", + "last_commit": "3f79153", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, @@ -70,7 +70,7 @@ }, { "digest": "2e52b5bd3addb2fff0ab5f761e1daf67befcc72291117a03534857fff229ae45", - "last_commit": "ed308de", + "last_commit": "e90226b", "name": "include", "purpose": "Directory native/kernel/include. Purpose not yet described by a human." }, @@ -88,26 +88,26 @@ }, { "digest": "7d63e0731c50350099774d048adcb20faa53e61648fb164ead40e7f7b3f3cd92", - "last_commit": "ed308de", + "last_commit": "e90226b", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { "digest": "118855445b6fc55bc5abbcfc5d684135abcb0e8092d43edde4bca881ae5213f7", - "last_commit": "ed308de", + "last_commit": "e90226b", "name": "tools", "purpose": "Directory native/kernel/tools. Purpose not yet described by a human." } ], - "children_root": "sha256:8a95e9f19c06a8c76c4e50447cd2b10b03b6807c2d3c5605de1d36b5519990c4", - "compiled_at": "2026-10-10T04:29:33Z", + "children_root": "sha256:597549bbdb05f151819fc87743590e13b43e0a9bd054b578367e68db6bba6050", + "compiled_at": "2026-10-11T01:27:19Z", "compiler": "crumb-compile/1", - "digest": "sha256:efbe476665c1f3d9c13abb2aa1745d0c1e9e6815b64a7e310010ce5f359afe0f", + "digest": "sha256:fdb1af443afa270d2ce93cdec1e65f2d6e3ae9e69295a919e89b4de015c95267", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 292, - "generated_at_commit": "ed308de52ede1d4c8a211d88e0e4a3ac5c92ec23", - "source_tree": "sha256:82b6db3163b0d9935bb22bceca95a69318f02829700043cfce5093b9ddae330b" + "generated_at_commit": "3f791539d41d852b2b6fd36fdebaebb9f76dc2a0", + "source_tree": "sha256:4311aa32fe1225a33b88780b6c2a248d051ecdb10a079c8df0bad4870df9c2bb" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/Makefile b/native/kernel/Makefile index e5a4cbab..0145b394 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -48,6 +48,12 @@ # scripts/qemu_ck_rollback_test.sh; refused with CK_HARDWARE_STAGING # make uefi-vars host tool $(OUT)/host/ck_uefi_vars: reads BootOrder, BootNext # and Boot#### from an edk2 vars.fd (read-only, M0_ROLLBACK) +# make [full] CK_B7B_PROBE=1 [CK_B7B_PROBE_TEST_SEGMENT0=1] +# B7b preparation probe image (aienos#286): confine the +# GB10 requester once, read SMMU_IDR0/IDR1, unconfine; +# own OUT (target/native-kernel-b7b-probe); the segment-0 +# variant is TEST-ONLY (QEMU positive path). Gate: +# scripts/qemu_ck_b7b_probe_test.sh # make CK_TEST_SMP_SKIP_CPU=1 # TEST-ONLY SMP mutation: CPU_ON skipped for one secondary # core (core/smp.c); own OUT (target/native-kernel-test-smp-skip); @@ -150,6 +156,39 @@ SMP_TEST_FLAGS := -DCK_TEST_SMP_SKIP_CPU=1 else SMP_TEST_FLAGS := endif +# B7b preparation probe (aienos#286, core/smmu_svc.c): CK_B7B_PROBE=1 builds an +# image that confines PCI segment 15 requester 0x100 (the Spark's GB10) once on +# a one-page window, prints the route and SMMU_IDR0/IDR1, and unconfines. Own +# OUT; allowed with CK_HARDWARE_STAGING (it is meant for the attended B7b +# window); refused with CK_QEMU_UNSAFE_DMA. CK_B7B_PROBE_TEST_SEGMENT0=1 +# (TEST-ONLY, needs CK_B7B_PROBE=1) probes segment 0 for the QEMU positive path +# and is refused with CK_HARDWARE_STAGING. Default images are checked to carry +# no probe (b7b_check). Gate: scripts/qemu_ck_b7b_probe_test.sh. +CK_B7B_PROBE ?= +CK_B7B_PROBE_TEST_SEGMENT0 ?= +ifneq ($(strip $(CK_B7B_PROBE_TEST_SEGMENT0)),) +ifneq ($(strip $(CK_B7B_PROBE_TEST_SEGMENT0)),1) +$(error CK_B7B_PROBE_TEST_SEGMENT0 must be empty or 1) +endif +ifneq ($(strip $(CK_B7B_PROBE)),1) +$(error CK_B7B_PROBE_TEST_SEGMENT0 needs CK_B7B_PROBE=1) +endif +ifneq ($(strip $(CK_HARDWARE_STAGING)),) +$(error CK_B7B_PROBE_TEST_SEGMENT0 (TEST-only QEMU positive path) cannot be combined with CK_HARDWARE_STAGING) +endif +OUT ?= $(REPO)/target/native-kernel-test-b7b-seg0 +SMP_TEST_FLAGS += -DCK_B7B_PROBE_TEST_SEGMENT0=1 +endif +ifneq ($(strip $(CK_B7B_PROBE)),) +ifneq ($(strip $(CK_B7B_PROBE)),1) +$(error CK_B7B_PROBE must be empty or 1) +endif +ifneq ($(strip $(CK_QEMU_UNSAFE_DMA)),) +$(error CK_B7B_PROBE cannot be combined with CK_QEMU_UNSAFE_DMA) +endif +OUT ?= $(REPO)/target/native-kernel-b7b-probe +SMP_TEST_FLAGS += -DCK_B7B_PROBE=1 +endif # TEST-ONLY stale handoff (AIENOS_CK_SCREEN negative control, # scripts/qemu_ck_screen_test.sh): the stub hands the kernel a CHANDOF2 magic; # the kernel must refuse it ("panic: handoff: unsupported version 2 ..."). @@ -721,6 +760,22 @@ define smp_check fi endef +# b7b_check(elf): only a CK_B7B_PROBE image may carry the B7b probe, and such an +# image must; only a CK_B7B_PROBE_TEST_SEGMENT0 image may carry the TEST-ONLY +# segment-0 announcement, and such an image must. +define b7b_check + @if [ "$(strip $(CK_B7B_PROBE))" = 1 ]; then \ + grep -aqF "b7b_probe: start segment=" $(1) || { echo "B7b probe image lacks the probe"; rm -f $(1); exit 1; }; \ + else \ + if grep -aqF "b7b_probe:" $(1); then echo "default image carries the B7b probe"; rm -f $(1); exit 1; fi; \ + fi + @if [ "$(strip $(CK_B7B_PROBE_TEST_SEGMENT0))" = 1 ]; then \ + grep -aqF "TEST-ONLY B7b probe on PCI segment 0" $(1) || { echo "segment-0 probe image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ + else \ + if grep -aqF "TEST-ONLY B7b probe" $(1); then echo "image carries the TEST-ONLY segment-0 probe"; rm -f $(1); exit 1; fi; \ + fi +endef + # crash_check(elf): a full image built without CK_TEST_STORE_CRASH must carry # no Store crash hook code or strings; a TEST crash image must announce itself. # The bare "TEST-ONLY MUTANT" phrase is refused here except in the TEST @@ -784,6 +839,7 @@ $(ELF): $(CORE_OBJS) $(BOOT)/image.ld if [ -n "$$s" ]; then echo "core image defines stage symbols: $$s"; rm -f $@; exit 1; fi $(call fwcfg_check,$@) $(call smp_check,$@) + $(call b7b_check,$@) $(FULL_ELF): $(CORE_OBJS) $(STAGE_BUILT) $(BOOT)/image.ld $(call link_image,$@,$(CORE_OBJS) $(STAGE_LINK) $(CK_RUST_LIBS) $(CK_INFER_LIB)) @@ -796,6 +852,7 @@ $(FULL_ELF): $(CORE_OBJS) $(STAGE_BUILT) $(BOOT)/image.ld $(call console_check,$@) $(call smp_check,$@) $(call crash_check,$@) + $(call b7b_check,$@) $(call cont_check,$@) $(EFI): $(ELF) diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index f13cde7f..30980479 100644 --- a/native/kernel/core/.crumb +++ b/native/kernel/core/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-10T04:29:33Z", + "compiled_at": "2026-10-11T01:27:19Z", "compiler": "crumb-compile/1", - "digest": "sha256:a7b75170badd729f33774cf301d1cc72cc031719630b00ef079b2a2754b8172d", + "digest": "sha256:85b29782329a9f640ff976034d8bda060b51ff8288e2547151aa6f30639f2bb1", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 39, - "generated_at_commit": "ed308de52ede1d4c8a211d88e0e4a3ac5c92ec23", - "source_tree": "sha256:d315325bddf9d40544bb3f04f5c5db8057ee5e04f186976781f965f47098ef4e" + "generated_at_commit": "3f791539d41d852b2b6fd36fdebaebb9f76dc2a0", + "source_tree": "sha256:411de5db646b8379ee626b5b41660ceb1688f7c2262d33f3fa6568cb5aad4d9b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/ck_internal.h b/native/kernel/core/ck_internal.h index 01a2f9e0..447c06cc 100644 --- a/native/kernel/core/ck_internal.h +++ b/native/kernel/core/ck_internal.h @@ -119,6 +119,10 @@ uint64_t ck_entropy_retries(void); * the MMU on the boot core's tables, checked in and parked in WFE. Prints * the smp: lines scripts/qemu_ck_smp_test.sh judges; never panics. */ void ck_smp_run(void); +#ifdef CK_B7B_PROBE +/* Cut B7b preparation probe (core/smmu_svc.c), probe build only. */ +void ck_b7b_probe(void); +#endif void ck_fpu_run(void); /* core/fpu.c: probe build only (CK_RUST_LIBS), else a no-op */ void ck_infer_run(void); /* core/infer.c: probe build only (CK_INFER_LIB), else a no-op */ diff --git a/native/kernel/core/kmain.c b/native/kernel/core/kmain.c index ded30f30..d00a23e0 100644 --- a/native/kernel/core/kmain.c +++ b/native/kernel/core/kmain.c @@ -216,6 +216,11 @@ static __attribute__((noreturn)) void ck_el1_main(void *arg) : ent == CK_RNG_STUCK ? "RNDR repeated a 64-bit word" : "probe error"); +#ifdef CK_B7B_PROBE + /* B7b preparation probe (core/smmu_svc.c), probe build only. */ + ck_b7b_probe(); +#endif + /* Secondary cores (core/smp.c): PSCI CPU_ON, check in, park in WFE with * interrupts masked; the boot core goes on alone. Lines judged by * scripts/qemu_ck_smp_test.sh (CK gate SMP). */ diff --git a/native/kernel/core/smmu_svc.c b/native/kernel/core/smmu_svc.c index ff5fc9ad..c7eaf3bd 100644 --- a/native/kernel/core/smmu_svc.c +++ b/native/kernel/core/smmu_svc.c @@ -366,3 +366,90 @@ int ck_dma_faults(uint32_t stream_id, struct ck_dma_fault *first) first->overflow = ovf; return matched; } + +#ifdef CK_B7B_PROBE +/* Cut B7b preparation (aienos#286; Drake's ruling of 2026-10-10 authorizes the + * preparation, not the boot): a probe build (make CK_B7B_PROBE=1, own OUT) + * that, once per boot, confines PCI segment 15 requester 0x100 (the GB10, IORT + * stream 0x100 on SMMUv3 B at 0x13000000 on the DGX Spark, docs/GB10_IORT_DECODE.md) + * on a one-page DMA window, reports the route, the RMR count and SMMU_IDR0 / + * SMMU_IDR1 of the node it came up on (read only: "Access to this field is RO", + * IHI0070H.a 6.3.1 / 6.3.2), unconfines, and prints one summary line. No DMA is + * started; the window page is never handed to a device. After the probe the + * node stays enabled with every stream aborting (as after any unconfine). + * QEMU virt has no segment 15, so there the expected result is a fail-closed + * refusal. CK_B7B_PROBE_TEST_SEGMENT0=1 (TEST-ONLY, QEMU positive path, + * refused with CK_HARDWARE_STAGING) probes segment 0 instead. + * Lines judged by scripts/qemu_ck_b7b_probe_test.sh. */ +#if defined(CK_B7B_PROBE_TEST_SEGMENT0) && defined(CK_HARDWARE_STAGING) +#error "CK_B7B_PROBE_TEST_SEGMENT0 (TEST-only QEMU positive path) cannot be combined with CK_HARDWARE_STAGING" +#endif +#ifdef CK_B7B_PROBE_TEST_SEGMENT0 +#define B7B_SEGMENT 0u +#else +#define B7B_SEGMENT 15u +#endif +#define B7B_RID 0x100u + +static const char *b7b_rc(int rc) +{ + switch (rc) { + case 0: return "ok"; + case CK_SMMU_ABSENT: return "absent"; + case CK_SMMU_FAILED: return "failed"; + case CK_SMMU_NOSTREAM: return "nostream"; + case CK_SMMU_EARG: return "earg"; + case CK_SMMU_OTHER: return "other"; + default: return "unknown"; + } +} + +void ck_b7b_probe(void) +{ +#ifdef CK_B7B_PROBE_TEST_SEGMENT0 + ck_puts("b7b_probe: TEST-ONLY B7b probe on PCI segment 0 (QEMU positive path); never hardware evidence\n"); +#endif + ck_printf("b7b_probe: start segment=%u rid=0x%x window_bytes=4096 no_dma=yes\n", B7B_SEGMENT, B7B_RID); + int rc = parse_iort(); + struct ck_iort_route rt; + if (rc) { + ck_printf("b7b_probe: iort rc=%d (%s)\n", rc, b7b_rc(rc)); + } else if (ck_iort_route(&g.iort, B7B_SEGMENT, B7B_RID, &rt)) { + ck_printf("b7b_probe: route none (smmus=%u)\n", g.iort.nsmmus); + } else { + ck_printf("b7b_probe: route instance=%u base=0x%llx stream=0x%x rmr_nodes=%u (smmus=%u)\n", rt.smmu_index, + (unsigned long long)rt.smmu_base, rt.sid, rt.nrmr, g.iort.nsmmus); + } + uint64_t phys = 0; + if (!ck_dma_alloc(4096, 4096, &phys)) { + ck_puts("b7b_probe: no DMA page\nAIENOS_B7B_PROBE: FAIL\n"); + return; + } + struct ck_dma_confinement cf; + rc = ck_dma_confine(B7B_SEGMENT, B7B_RID, phys, 4096, &cf); + if (rc) { + ck_printf("b7b_probe: confine refused rc=%d (%s); nothing granted\n", rc, b7b_rc(rc)); + ck_puts("AIENOS_B7B_PROBE: REFUSED\n"); + return; + } + ck_printf("b7b_probe: confined stream=0x%x smmu_base=0x%llx iova=0x%llx len=0x%llx\n", cf.stream_id, + (unsigned long long)cf.smmu_base, (unsigned long long)cf.iova, (unsigned long long)cf.len); + int idr_ok = 0; + for (uint32_t k = 0; k < CK_IORT_MAX_SMMUS; k++) { + struct inst *in = &g.inst[k]; + if (in->state != 1 || in->base != cf.smmu_base) + continue; + uint32_t idr0 = r_rd32(in, CK_SMMU_IDR0), idr1 = r_rd32(in, CK_SMMU_IDR1); + ck_printf("b7b_probe: instance=%u idr0=0x%08x idr1=0x%08x st_level=%u sidsize=%u\n", k, idr0, idr1, + (idr0 >> CK_SMMU_IDR0_ST_LEVEL_SHIFT) & CK_SMMU_IDR0_ST_LEVEL_MASK, + idr1 & CK_SMMU_IDR1_SIDSIZE_MASK); + idr_ok = 1; + break; + } + if (!idr_ok) + ck_puts("b7b_probe: no live instance at the confined base\n"); + int urc = ck_dma_unconfine(cf.stream_id); + ck_printf("b7b_probe: unconfine rc=%d (%s); stream 0x%x aborts again\n", urc, b7b_rc(urc), cf.stream_id); + ck_puts(urc || !idr_ok ? "AIENOS_B7B_PROBE: FAIL\n" : "AIENOS_B7B_PROBE: CONFINED_AND_RELEASED\n"); +} +#endif diff --git a/scripts/.crumb b/scripts/.crumb index 550a4868..1ddff56a 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-10T02:47:01Z", + "compiled_at": "2026-10-11T01:27:19Z", "compiler": "crumb-compile/1", - "digest": "sha256:d9cd564824903777dd323019bb8d5673331383e961bc3da703d5589be1eb6b4c", + "digest": "sha256:768f7a9a329815979e95b540161c74912dddd8615f44f45c44f97db5d49fdd93", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 78, - "generated_at_commit": "89fcc57c5bf7a5003eea52de0ac3bf2f752e2c04", - "source_tree": "sha256:14ef9ea3fcd3fdf3133ec04c2c401a2cc46321abd39bee7e1f54c7b199a5b4a8" + "files": 79, + "generated_at_commit": "3f791539d41d852b2b6fd36fdebaebb9f76dc2a0", + "source_tree": "sha256:82320fb628dea4ad4567b44109b30092a9c59b25dec40f572b887914a943b5ea" }, "owner_lane": "", "provenance": { diff --git a/scripts/qemu_ck_b7b_probe_test.sh b/scripts/qemu_ck_b7b_probe_test.sh new file mode 100755 index 00000000..24087f07 --- /dev/null +++ b/scripts/qemu_ck_b7b_probe_test.sh @@ -0,0 +1,258 @@ +#!/usr/bin/env bash +# B7b preparation probe gate (aienos#286). Boots the C kernel core image built +# with CK_B7B_PROBE=1 in QEMU AArch64 (UEFI/AAVMF, EL2, iommu=smmuv3) and checks +# the probe lines of core/smmu_svc.c ck_b7b_probe. QEMU is not hardware: a PASS +# here qualifies nothing physical; on the DGX Spark the probe is the attended B7b +# step and needs Drake's go (docs/GB10_IORT_DECODE.md section 10). +# +# Modes: +# (default) probe image as it would boot on the Spark: segment 15 rid +# 0x100. QEMU virt has no segment 15, so the probe must refuse, +# fail closed: route none, confine rc=-3 (nostream), nothing +# confined, "AIENOS_B7B_PROBE: REFUSED", the boot goes on (the +# SMP summary follows) and ends without a panic. +# Last line AIENOS_CK_B7B_PROBE: PASS|FAIL|NOT_RUN. +# --positive TEST-ONLY image (CK_B7B_PROBE_TEST_SEGMENT0=1) probing segment +# 0 rid 0x100: the route names instance 0 stream 0x100, the +# confinement is granted on one page, IDR0/IDR1 are read with a +# SIDSIZE that covers stream 0x100, the unconfine returns 0 and +# the summary is CONFINED_AND_RELEASED. +# Last line AIENOS_CK_B7B_PROBE_POSITIVE: PASS|FAIL|NOT_RUN. +# --self-test canned serial logs for every failure mode below plus the +# Makefile refusals of the probe flags; no QEMU, no compile. +# Last line AIENOS_CK_B7B_PROBE_SELF_TEST: PASS|FAIL. +# Environment: AIENOS_QEMU_TIMEOUT (180 s), AIENOS_QUIET_FLAG (read only), +# AIENOS_GATE_LOCK / AIENOS_GATE_MINUTES, AIENOS_LOG_DIR, AIENOS_QEMU_VERBOSE. +# Prints NOT_RUN (exit 3) while the quiet flag or the QEMU gate lock is held. +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${repo_root}" + +mode=gate +case "${1:-}" in + "") ;; + --positive) mode=positive ;; + --self-test) mode=self ;; + *) echo "usage: $0 [--positive|--self-test]" >&2; exit 2 ;; +esac +test_marker="TEST-ONLY B7b probe on PCI segment 0" + +# check_refused FILE: the Spark-target probe on a machine without segment 15. +check_refused() { + local f="$1" + ok() { echo "PASS $*"; } + bad() { echo "FAIL $*"; failed=1; } + [[ "$(grep -cE '^b7b_probe: start segment=15 rid=0x100 window_bytes=4096 no_dma=yes$' "${f}" || true)" == 1 ]] \ + && ok "one probe start, segment 15 rid 0x100" || bad "expected exactly one 'b7b_probe: start segment=15 rid=0x100' line" + grep -qE '^b7b_probe: route none \(smmus=[0-9]+\)$' "${f}" && ok "IORT has no route for segment 15" || bad "no 'route none' line" + grep -qE '^b7b_probe: confine refused rc=-3 \(nostream\); nothing granted$' "${f}" \ + && ok "confinement refused with nostream" || bad "no 'confine refused rc=-3 (nostream)' line" + if grep -qE '^b7b_probe: confined ' "${f}"; then bad "something was confined"; else ok "nothing confined"; fi + [[ "$(grep -cE '^AIENOS_B7B_PROBE: ' "${f}" || true)" == 1 ]] && grep -qE '^AIENOS_B7B_PROBE: REFUSED$' "${f}" \ + && ok "one summary: REFUSED" || bad "summary is not exactly one 'AIENOS_B7B_PROBE: REFUSED'" + if grep -qF "${test_marker}" "${f}"; then bad "TEST-ONLY segment-0 image booted"; else ok "Spark-target probe image (no TEST-ONLY marker)"; fi + common_tail "${f}" +} + +# check_positive FILE: TEST-ONLY segment-0 probe on QEMU's SMMUv3. +check_positive() { + local f="$1" line sidsize + ok() { echo "PASS $*"; } + bad() { echo "FAIL $*"; failed=1; } + grep -qF "${test_marker}" "${f}" && ok "TEST-ONLY image announced itself" || bad "no TEST-ONLY announcement" + [[ "$(grep -cE '^b7b_probe: start segment=0 rid=0x100 window_bytes=4096 no_dma=yes$' "${f}" || true)" == 1 ]] \ + && ok "one probe start, segment 0 rid 0x100" || bad "expected exactly one 'b7b_probe: start segment=0 rid=0x100' line" + grep -qE '^b7b_probe: route instance=0 base=0x[0-9a-f]+ stream=0x100 rmr_nodes=0 \(smmus=1\)$' "${f}" \ + && ok "route: instance 0, stream 0x100" || bad "no route line for instance 0 stream 0x100" + grep -qE '^b7b_probe: confined stream=0x100 smmu_base=0x[0-9a-f]+ iova=0x[0-9a-f]*000 len=0x1000$' "${f}" \ + && ok "one page confined on stream 0x100" || bad "no 'confined stream=0x100 ... len=0x1000' line" + line="$(grep -E '^b7b_probe: instance=0 idr0=0x[0-9a-f]{8} idr1=0x[0-9a-f]{8} st_level=[0-3] sidsize=[0-9]+$' "${f}" || true)" + sidsize="$(sed -nE 's/.* sidsize=([0-9]+)$/\1/p' <<<"${line}")" + if [[ -n "${sidsize}" && "${sidsize}" -ge 9 ]]; then ok "IDR0/IDR1 read, SIDSIZE ${sidsize} covers stream 0x100"; else bad "no IDR line with SIDSIZE >= 9"; fi + grep -qE '^b7b_probe: unconfine rc=0 \(ok\); stream 0x100 aborts again$' "${f}" && ok "unconfine rc=0" || bad "unconfine did not return 0" + [[ "$(grep -cE '^AIENOS_B7B_PROBE: ' "${f}" || true)" == 1 ]] && grep -qE '^AIENOS_B7B_PROBE: CONFINED_AND_RELEASED$' "${f}" \ + && ok "one summary: CONFINED_AND_RELEASED" || bad "summary is not exactly one 'AIENOS_B7B_PROBE: CONFINED_AND_RELEASED'" + common_tail "${f}" +} + +# common_tail FILE: the probe ran after "kernel: alive", the boot went on to the +# SMP summary, and no panic or exception report followed. +common_tail() { + local f="$1" a p s + a="$(grep -nE '^kernel: alive$' "${f}" | head -1 | cut -d: -f1)" + p="$(grep -nE '^b7b_probe: start ' "${f}" | head -1 | cut -d: -f1)" + s="$(grep -nE '^smp: cpus=' "${f}" | head -1 | cut -d: -f1)" + if [[ -n "${a}" && -n "${p}" && -n "${s}" && "${a}" -lt "${p}" && "${p}" -lt "${s}" ]]; then + ok "probe ran after 'kernel: alive' and the boot went on (SMP summary follows)" + else + bad "probe not between 'kernel: alive' and the SMP summary (alive=${a:-none} probe=${p:-none} smp=${s:-none})" + fi + if grep -qE '^report_kind: panic|^panic:|^exception:' "${f}"; then bad "panic or exception after the probe"; else ok "no panic or exception"; fi +} + +self_test() { + local tmp st_fail=0 + tmp="$(mktemp -d)" + trap 'rm -rf "${tmp}"' RETURN + expect() { # NAME pass|fail CHECKER FILE + local out; failed=0 + out="$("$3" "$4")"; failed=0; grep -q '^FAIL' <<<"${out}" && failed=1 + if [[ "$2" == pass && "${failed}" == 0 ]] || [[ "$2" == fail && "${failed}" == 1 ]]; then + echo "PASS self-test $1 -> $2" + else + echo "FAIL self-test $1 expected $2: $(grep '^FAIL' <<<"${out}" | head -2 | paste -sd';' -)"; st_fail=1 + fi + } + cat >"${tmp}/refused" <<'LOG' +kernel: alive +kernel_el: EL1h +b7b_probe: start segment=15 rid=0x100 window_bytes=4096 no_dma=yes +b7b_probe: route none (smmus=1) +b7b_probe: confine refused rc=-3 (nostream); nothing granted +AIENOS_B7B_PROBE: REFUSED +smp: cpus=2 checked_in=2 psci_errors=0 distinct_mpidrs=2 wait_us=10 result=ok +report_kind: final +LOG + cat >"${tmp}/positive" <<'LOG' +kernel: alive +b7b_probe: TEST-ONLY B7b probe on PCI segment 0 (QEMU positive path); never hardware evidence +b7b_probe: start segment=0 rid=0x100 window_bytes=4096 no_dma=yes +b7b_probe: route instance=0 base=0x9050000 stream=0x100 rmr_nodes=0 (smmus=1) +b7b_probe: confined stream=0x100 smmu_base=0x9050000 iova=0x7f000000 len=0x1000 +b7b_probe: instance=0 idr0=0x0a0d7fbf idr1=0x00e73210 st_level=1 sidsize=16 +b7b_probe: unconfine rc=0 (ok); stream 0x100 aborts again +AIENOS_B7B_PROBE: CONFINED_AND_RELEASED +smp: cpus=2 checked_in=2 psci_errors=0 distinct_mpidrs=2 wait_us=10 result=ok +report_kind: final +LOG + expect refused-good pass check_refused "${tmp}/refused" + expect positive-good pass check_positive "${tmp}/positive" + # Refusal gate: anything granted, wrong target, forged summary, missing lines, panic, wrong order, TEST image. + expect positive-log-on-refusal-gate fail check_refused "${tmp}/positive" + sed 's/^b7b_probe: confine refused.*/b7b_probe: confined stream=0x100 smmu_base=0x9050000 iova=0x7f000000 len=0x1000/' "${tmp}/refused" >"${tmp}/r1"; expect refused-but-confined fail check_refused "${tmp}/r1" + sed 's/segment=15/segment=14/' "${tmp}/refused" >"${tmp}/r2"; expect wrong-segment fail check_refused "${tmp}/r2" + sed 's/rc=-3 (nostream)/rc=-2 (failed)/' "${tmp}/refused" >"${tmp}/r3"; expect refused-other-reason fail check_refused "${tmp}/r3" + grep -v '^AIENOS_B7B_PROBE' "${tmp}/refused" >"${tmp}/r4"; expect no-summary fail check_refused "${tmp}/r4" + { cat "${tmp}/refused"; echo "AIENOS_B7B_PROBE: REFUSED"; } >"${tmp}/r5"; expect two-summaries fail check_refused "${tmp}/r5" + grep -v '^smp: cpus=' "${tmp}/refused" >"${tmp}/r6"; expect boot-stopped fail check_refused "${tmp}/r6" + { cat "${tmp}/refused"; echo "report_kind: panic"; } >"${tmp}/r7"; expect panic fail check_refused "${tmp}/r7" + grep -v '^kernel: alive' "${tmp}/refused" >"${tmp}/r8"; expect not-after-alive fail check_refused "${tmp}/r8" + sed 's/^b7b_probe: route none.*/b7b_probe: route instance=1 base=0x13000000 stream=0x100 rmr_nodes=1 (smmus=3)/' "${tmp}/refused" >"${tmp}/r9"; expect route-found-on-refusal fail check_refused "${tmp}/r9" + { echo "${test_marker} (QEMU positive path); never hardware evidence"; cat "${tmp}/refused"; } >"${tmp}/r10"; expect test-image-on-gate fail check_refused "${tmp}/r10" + # Positive path: missing announcement, unconfine failure, short SIDSIZE, no IDR line, wrong length, forged summary. + grep -v 'TEST-ONLY' "${tmp}/positive" >"${tmp}/p1"; expect positive-no-announcement fail check_positive "${tmp}/p1" + sed 's/unconfine rc=0 (ok)/unconfine rc=-4 (earg)/' "${tmp}/positive" >"${tmp}/p2"; expect unconfine-fails fail check_positive "${tmp}/p2" + sed 's/sidsize=16/sidsize=8/' "${tmp}/positive" >"${tmp}/p3"; expect sidsize-too-small fail check_positive "${tmp}/p3" + grep -v 'idr0=' "${tmp}/positive" >"${tmp}/p4"; expect no-idr-line fail check_positive "${tmp}/p4" + sed 's/len=0x1000/len=0x2000/' "${tmp}/positive" >"${tmp}/p5"; expect wrong-window fail check_positive "${tmp}/p5" + sed 's/CONFINED_AND_RELEASED/FAIL/' "${tmp}/positive" >"${tmp}/p6"; expect positive-summary-fail fail check_positive "${tmp}/p6" + + # Makefile refusals: parse-time $(error), nothing is compiled (make -n). + refuse() { # NAME MESSAGE MAKE-ARGS... + local name="$1" msg="$2" out rc; shift 2 + out="$(make -n -s -C native/kernel "$@" OUT="${tmp}/o_${name}" 2>&1)"; rc=$? + if [[ ${rc} != 0 ]] && grep -qF "${msg}" <<<"${out}" && [[ ! -e "${tmp}/o_${name}" ]]; then + echo "PASS self-test Makefile refuses ${name}" + else + echo "FAIL self-test Makefile did not refuse ${name} (rc=${rc}): ${out:0:200}"; st_fail=1 + fi + } + refuse probe-bad-value "CK_B7B_PROBE must be empty or 1" CK_B7B_PROBE=2 + refuse seg0-without-probe "CK_B7B_PROBE_TEST_SEGMENT0 needs CK_B7B_PROBE=1" CK_B7B_PROBE_TEST_SEGMENT0=1 + refuse seg0-with-staging "CK_B7B_PROBE_TEST_SEGMENT0 (TEST-only QEMU positive path) cannot be combined with CK_HARDWARE_STAGING" \ + CK_B7B_PROBE=1 CK_B7B_PROBE_TEST_SEGMENT0=1 CK_HARDWARE_STAGING=1 + refuse probe-with-unsafe-dma "CK_B7B_PROBE cannot be combined with CK_QEMU_UNSAFE_DMA" CK_B7B_PROBE=1 CK_QEMU_UNSAFE_DMA=1 + if grep -qE '^#if defined\(CK_B7B_PROBE_TEST_SEGMENT0\) && defined\(CK_HARDWARE_STAGING\)$' native/kernel/core/smmu_svc.c; then + echo "PASS self-test core/smmu_svc.c also refuses the segment-0 probe in a hardware staging compile" + else + echo "FAIL self-test core/smmu_svc.c lacks the #error guard"; st_fail=1 + fi + + [[ ${st_fail} == 0 ]] && { echo "AIENOS_CK_B7B_PROBE_SELF_TEST: PASS"; exit 0; } + echo "AIENOS_CK_B7B_PROBE_SELF_TEST: FAIL"; exit 1 +} +if [[ "${mode}" == self ]]; then + set +e + self_test +fi + +# --------------------------------------------------------------- QEMU boot +verdict_name=AIENOS_CK_B7B_PROBE +[[ "${mode}" == positive ]] && verdict_name=AIENOS_CK_B7B_PROBE_POSITIVE + +code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" +vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" +command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; echo "${verdict_name}: NOT_RUN"; exit 2; } +[[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; echo "${verdict_name}: NOT_RUN"; exit 2; } + +cross="" +if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi +commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" +if [[ "${mode}" == positive ]]; then + out="${repo_root}/target/native-kernel-test-b7b-seg0" + make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" CK_B7B_PROBE=1 CK_B7B_PROBE_TEST_SEGMENT0=1 >/dev/null +else + out="${repo_root}/target/native-kernel-b7b-probe" + make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" CK_B7B_PROBE=1 >/dev/null +fi + +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib_gate_hold.sh" +if ! gh_quiet_check || ! gh_lock_take "qemu_ck_b7b_probe_test" "${AIENOS_GATE_MINUTES:-60}"; then + echo "NOT_RUN ${gh_why}" + echo "${verdict_name}: NOT_RUN" + exit 3 +fi +release_flag() { gh_lock_release; } +work="$(mktemp -d)" +cleanup() { + rm -rf "${work}" + release_flag +} +trap cleanup EXIT +mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS" +touch "${work}/esp/EFI/AIENOS/BOOTREPORT.TXT" +cp "${out}/BOOTAA64.EFI" "${work}/esp/EFI/BOOT/BOOTAA64.EFI" +cp "${vars_fd}" "${work}/vars.fd" +log="${work}/serial.log" + +# Same machine as scripts/qemu_ck_smp_test.sh plus the SMMUv3 vIOMMU (as scripts/qemu_keyboard_test.sh). +started=$(date +%s) +set +e +timeout "${AIENOS_QEMU_TIMEOUT:-180}" qemu-system-aarch64 \ + -M virt,virtualization=on,gic-version=3,iommu=smmuv3 -accel tcg,thread=single -cpu max -smp 2 -m 2048 \ + -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ + -drive if=pflash,format=raw,file="${work}/vars.fd" \ + -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \ + -device virtio-blk-pci,drive=esp \ + -device ramfb -display none -nic none \ + -serial file:"${log}" -no-reboot +qemu_status=$? +set -e +elapsed=$(( $(date +%s) - started )) +release_flag + +tr -d '\r' <"${log}" >"${work}/serial.txt" +[[ -z "${AIENOS_LOG_DIR:-}" ]] || cp "${work}/serial.txt" "${AIENOS_LOG_DIR}/qemu_ck_b7b_probe_${mode}_serial.log" +echo "qemu exit ${qemu_status} after ${elapsed} s (commit ${commit:0:12}, ${mode})" + +failed=0 +if [[ "${mode}" == positive ]]; then + results="$(check_positive "${work}/serial.txt")" || true +else + results="$(check_refused "${work}/serial.txt")" || true +fi +grep -q '^FAIL' <<<"${results}" && failed=1 +printf '%s\n' "${results}" +if [[ "${qemu_status}" == 0 ]]; then echo "PASS QEMU exit 0 (PSCI reset)"; else echo "FAIL QEMU exit ${qemu_status}"; failed=1; fi +grep -E '^b7b_probe: |^AIENOS_B7B_PROBE: |^smmu: ' "${work}/serial.txt" | sed 's/^/LOG /' +if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then + echo "---- serial console ----" + cat "${work}/serial.txt" +fi +if [[ "${failed}" == 0 ]]; then + echo "${verdict_name}: PASS" + exit 0 +fi +echo "${verdict_name}: FAIL" +exit 1