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/patches/785944547f7e3e23 # 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 ## GitHub aien-dev/aienux#269 (code only) closed derived `785944547f7e3e23` #269 Imported from GitHub aien-dev/aienux#269 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `6da9d58aa2969238803deb2ffdd6d7ae54880a3e` · Head `aad7fce4373549f484e47fb68f62d52081306209` ### Fetch it A git bundle of the pull request's head, 22776 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/aienux/patches/785944547f7e3e23.bundle -o 785944547f7e3e23.bundle git fetch 785944547f7e3e23.bundle refs/pull/269/head ``` Raw bundle · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/aienux 269 aad7fce4373549f484e47fb68f62d52081306209 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aienux","number":269,"url":"https://github.com/aien-dev/aienux/pull/269","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:05Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index 0858dce2..35a52d27 100644 --- a/.crumb +++ b/.crumb @@ -33,27 +33,27 @@ "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "d6f18b3969b054e8692396c36ab3d897e039f15516d089c3776ad3de47354ac1", - "last_commit": "b79954c", + "digest": "0d589e6ce680103a666855196f3b224a609fa6f6ba877f92e064c520638f78da", + "last_commit": "056b8e7", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { "digest": "e05c9be44a099db64118bb542ef8f97041efe9642107c7007291c44b7aac1ff4", - "last_commit": "b79954c", + "last_commit": "6da9d58", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:30b1bd25ba5cf8166dbb3a6bd1f9bdfa4d9cdbfdbbfb4f90dd672129addfdbb9", - "compiled_at": "2026-10-06T03:00:56Z", + "children_root": "sha256:fc380cd618b011df8e0ea6b77ad228ff053380c7b1b14f33db1c16ee347c3b89", + "compiled_at": "2026-10-06T11:23:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:77853dbc20a35f043e835cc53c32958914eac171e1c5cfa652728d8275b10195", - "evidence_files": 150, - "evidence_root": "sha256:47a75cce7791857aaf61e70f3e80b9d5d42c0a814a27e02fe91226c4e8804933", - "files": 2872, - "generated_at_commit": "b79954c7278df871a8226d51c6a594918676aba3", - "source_tree": "sha256:a1780e94e691b57f203cc211bcbf82c6000f3570ea77a41680560374ec1f1e89" + "digest": "sha256:13c1f0db8513f5740a3fa9a47203d8eadc6ff51a04ef77d72cc3b79f65ff8139", + "evidence_files": 151, + "evidence_root": "sha256:95ba4c8c2656f248386efb82a1b27a6c6054820636ab863080f44aa343ed7fb4", + "files": 2873, + "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961", + "source_tree": "sha256:538e659d81885c116ac27c6b86ba1ed4a6b801b475bfd2224c3a478f27e6b730" }, "owner_lane": "", "provenance": { diff --git a/evidence/ck_gates_dc8ff62613d78dc3cdfa673326c5e5a5aed1ce55164acf3c26b0ac92c3e1a578.json b/evidence/ck_gates_dc8ff62613d78dc3cdfa673326c5e5a5aed1ce55164acf3c26b0ac92c3e1a578.json new file mode 100644 index 00000000..01d4b0b1 --- /dev/null +++ b/evidence/ck_gates_dc8ff62613d78dc3cdfa673326c5e5a5aed1ce55164acf3c26b0ac92c3e1a578.json @@ -0,0 +1,58 @@ +{ + "schema": "aienos.ck_gates.v1", + "started_utc": "2026-10-06T03:51:33Z", + "finished_utc": "2026-10-06T04:30:15Z", + "commit": "d896f2dcf535d985670ee1e4d684df94cd5f9b36", + "commit_subject": "ck kernel: IORT stream ids resolved per PCI segment, mapping cap 32 (NEXT-PHASE-3 cut 3a, HOST)", + "tree_clean_before": true, + "tree_clean_after": true, + "quiet_flag": "/home/drakestapleton/.claude/jobs/9bfe8553/tmp/locks/quiet-c3aafter", + "quiet_flag_present_at_start": false, + "host": {"hostname": "spark-b87b", "arch": "aarch64", "kernel": "7.0.0-1019-nvidia", "cpu_model": "Cortex-A725;Cortex-X925"}, + "qemu": {"binary": "/usr/bin/qemu-system-aarch64", "version": "QEMU emulator version 8.2.2 (Debian 1:8.2.2+ds-0ubuntu1.18)"}, + "firmware": {"aavmf_code": "/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd", "aavmf_code_sha256": "4a4cb7f6d8106bb2a7dd8c763fab14b1810152136fc4304e5b728f0043e84f12", "aavmf_vars": "/usr/share/AAVMF/AAVMF_VARS.fd", "aavmf_vars_sha256": "b3b855c5a80310168051164986855692d1bdb06e67619856177965cd87c6774f"}, + "nvme_dma_mode": "Confined (QEMU SMMUv3 stage 1, out-of-window DMA faulted); no-SMMU boot denied (NoSmmu); TEST-ONLY bypass image checked separately", + "children": [ + {"name": "boot", "script": "scripts/qemu_ck_boot_test.sh", "present": true, "script_sha256": "d17a7e0f00081e935a804c092c9b05c0bd1f319f5dd5c8bd90f3982e8939c3c8", "exit": "0", "seconds": 7, "log_sha256": "bd538aa6396565cf130da10554cc593e6954eade34f003dfdd90c02872929193", "log_lines": 24}, + {"name": "store", "script": "scripts/qemu_ck_store_test.sh", "present": true, "script_sha256": "0b31a44af9388302d5488fdef318a509c4f26c2420f82ceb2fa7f7b698647748", "exit": "0", "seconds": 96, "log_sha256": "9d9c96a242d1e445e135685b5fda63d830fc262c6055bbd4d225271bf4f2134f", "log_lines": 612}, + {"name": "net", "script": "scripts/qemu_ck_net_test.sh", "present": true, "script_sha256": "ea051cc946c206f92c0c1563b3463b6bebffbce04e361e76d51dd49c1be4a6cf", "exit": "0", "seconds": 18, "log_sha256": "6169393e80ceb6285ae81de5301be939301dc83b9099464ef7fa10c8a4c955e6", "log_lines": 95}, + {"name": "artifact", "script": "scripts/qemu_ck_artifact_test.sh", "present": true, "script_sha256": "e60f6c4aed822f693a530cb98b2fa4689b7b56e7c0efed5f9bf9ff4e9f75fc67", "exit": "0", "seconds": 32, "log_sha256": "99f29b855527ecf113c52e4b74de5c98110ae17db2f3283a09732739bcaf2db7", "log_lines": 215}, + {"name": "smp", "script": "scripts/qemu_ck_smp_test.sh", "present": true, "script_sha256": "b5665568394f391c17aaa9148bce2358f1145240cc38422c2927664b0ffd41d6", "exit": "0", "seconds": 6, "log_sha256": "4032af4591e132d0d7394f052dd20c9df456ff919f3c43a7c8ecdebb331fa53f", "log_lines": 16}, + {"name": "crash", "script": "scripts/qemu_ck_store_crash_test.sh", "present": true, "script_sha256": "3d04ca0775db7e70a244b6a09b19c5adf987f777b6ff630874c42e339add7765", "exit": "0", "seconds": 677, "log_sha256": "4059e2ca3fc2df078693ca717505424da031e32d9b8da1a159ced4e993dc12c6", "log_lines": 239}, + {"name": "disk", "script": "scripts/qemu_ck_disk_layout_test.sh", "present": true, "script_sha256": "f490548245252b97518e9049ce8e7078f5297c81584b60f08f802cfea6bb3110", "exit": "0", "seconds": 58, "log_sha256": "bf0d3ba1bd790857b34e7d618df6620ef54c54a6e46b62f1b18939015c84f01c", "log_lines": 264}, + {"name": "cont", "script": "scripts/qemu_ck_continuity_test.sh", "present": true, "script_sha256": "30a8eb2dbb949eab29ad046231869a306199908022cb2345151988ea4957cf2e", "exit": "0", "seconds": 184, "log_sha256": "f5b81a599dabc72658a659aa76b04da7727866107bd65a12c667ce1c1ffdef3a", "log_lines": 57}, + {"name": "recov", "script": "scripts/qemu_ck_recovery_test.sh", "present": true, "script_sha256": "89c461e211532f6577d2c88668ae8ca0d32d91f3b29ce6e39f7082a03a45b8cc", "exit": "0", "seconds": 116, "log_sha256": "500cd02050eae8f2f4aa34fdb004ff4d5399751de25de9dfe554ed5cdca32e30", "log_lines": 46}, + {"name": "allen", "script": "scripts/qemu_ck_allen_test.sh", "present": true, "script_sha256": "0fe58465d5183781b8339f50861fd76f7773051bee939b73fdaede4b7a752355", "exit": "0", "seconds": 201, "log_sha256": "2619a6eef137923fdb1013fd04c62363a1f474eab4b1d1c20507b9db226c3ec8", "log_lines": 73}, + {"name": "kbd", "script": "scripts/qemu_ck_keyboard_test.sh", "present": true, "script_sha256": "c1ac74a30f722379d05326a0f98fa2287529ccd5a8036d79cb062479995672b1", "exit": "0", "seconds": 41, "log_sha256": "c47674971b5681d6e069e9f0036e9f7e0e3810cce215b1a21edbfff8b639eccb", "log_lines": 154}, + {"name": "fpu", "script": "scripts/qemu_ck_fpu_test.sh", "present": true, "script_sha256": "f04fa538752f6864bc2d5f9ff5af6eac71a5e3a005fe9c76b77477012325cc14", "exit": "0", "seconds": 8, "log_sha256": "96af1df10d80fc377934d26a73c6ebf6b4eda71b9517573bd9115319f07a085a", "log_lines": 13}, + {"name": "infer", "script": "scripts/qemu_ck_infer_test.sh", "present": true, "script_sha256": "185c78b8688004dc6a807182c81e319b1598414935934b6c881cfafae5ce31fa", "exit": "0", "seconds": 861, "log_sha256": "99cc97bcd6442a42b503e40c35c5ae64a1e489afd7aa8349ff3900bfad00031c", "log_lines": 35}, + {"name": "screen", "script": "scripts/qemu_ck_screen_test.sh", "present": true, "script_sha256": "b2b71aff7fb9274eb15d8381e44dda9d7b700821fd45a23cde1c9a1132dc6b3f", "exit": "0", "seconds": 16, "log_sha256": "44a32bb98519f84b64b6a1ef840774348c9ff7f8af866d36a28a6e4f6178b963", "log_lines": 30} + ], + "gates": [ + {"id": "M1", "marker": "AIENOS_CK_M1", "source": "boot", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M3", "marker": "AIENOS_CK_M3", "source": "boot", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "SMMU", "marker": "AIENOS_CK_SMMU", "source": "store", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "NVME_SHUTDOWN", "marker": "AIENOS_CK_NVME_SHUTDOWN", "source": "store", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "P2_ARTIFACT", "marker": "AIENOS_CK_P2_ARTIFACT", "source": "artifact", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M0_ROLLBACK", "marker": "AIENOS_CK_M0_ROLLBACK", "source": "missing", "verdict": "NOT_RUN", "reason": "MISSING_IMPLEMENTATION: C loader signatures, A/B, BootNext and rollback are parked (native/boot/README.md)"}, + {"id": "M4_NVME", "marker": "AIENOS_CK_M4_NVME", "source": "store", "verdict": "PASS", "reason": "SMMU-confined NVMe DMA in QEMU (iommu=smmuv3, default build); TEST-ONLY bypass build boot-checked separately"}, + {"id": "M4_STORE", "marker": "AIENOS_CK_M4_STORE", "source": "store", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M4_STORE_CRASH", "marker": "AIENOS_CK_M4_STORE_CRASH", "source": "crash", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M4_CONTINUITY", "marker": "AIENOS_CK_M4_CONTINUITY", "source": "cont", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M4_RECOVERY", "marker": "AIENOS_CK_M4_RECOVERY", "source": "recov", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M4_ALLEN", "marker": "AIENOS_CK_M4_ALLEN", "source": "allen", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "ARGUS1_REVOKE", "marker": "AIENOS_CK_ARGUS1_REVOKE", "source": "store", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "KEYBOARD", "marker": "AIENOS_CK_KEYBOARD", "source": "kbd", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "NET", "marker": "AIENOS_CK_NET", "source": "net", "verdict": "PASS", "reason": "QEMU user networking (slirp), virtio-net with ACCESS_PLATFORM required behind the smmuv3 vIOMMU; this PASS covers: attach, UDP TX seen by the host helper, UDP reply RX parsed by M6-A, an out-of-window device DMA refused (F_TRANSLATION, page intact) and recovery by reset, as checked by this run only; QEMU, not hardware"}, + {"id": "SMP", "marker": "AIENOS_CK_SMP", "source": "smp", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "DISK_LAYOUT", "marker": "AIENOS_CK_DISK_LAYOUT", "source": "disk", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "FPU", "marker": "AIENOS_CK_FPU", "source": "fpu", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "INFER", "marker": "AIENOS_CK_INFER", "source": "infer", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "SCREEN", "marker": "AIENOS_CK_SCREEN", "source": "screen", "verdict": "PASS", "reason": "child reported PASS, exit 0"} + ], + "counts": {"total": 20, "pass": 19, "fail": 0, "not_run": 1}, + "verdict": "NOT_ALL_GATES_PASS", + "parity": "native/kernel/GATES.md", + "physical": "NOT_RUN", + "physical_statement": "QEMU emulator runs only. Nothing here was run on Machine 1 or any GB10; no physical qualification is claimed." +} diff --git a/native/.crumb b/native/.crumb index 875370c1..b4fa58b5 100644 --- a/native/.crumb +++ b/native/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "88f28f8c28bdd707b7b26e829417a785970606218731c306522932b3edb171a9", - "last_commit": "b79954c", + "digest": "2994b89eaffa92f36c9335d87b6142ada4d5d521b4402f4fbde8681be6dbdf4e", + "last_commit": "056b8e7", "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:ab2490af7c9ae0e68d90d6feeb0698f5e839cfd545cc95dfc732913f27a1c574", - "compiled_at": "2026-10-06T03:00:56Z", + "children_root": "sha256:1d92cdd999186575a12435aa6f20cc06cf4fe3afef65765bab90148c42e7ddf6", + "compiled_at": "2026-10-06T11:23:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:d6f18b3969b054e8692396c36ab3d897e039f15516d089c3776ad3de47354ac1", + "digest": "sha256:0d589e6ce680103a666855196f3b224a609fa6f6ba877f92e064c520638f78da", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", "files": 317, - "generated_at_commit": "b79954c7278df871a8226d51c6a594918676aba3", - "source_tree": "sha256:9909eb6f7717e72c6948417f6b6ca232b686f5a8f9332f005ed69164830c1947" + "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961", + "source_tree": "sha256:b4e7058f03d3fc95ce4a6af45166b2e046431245b82e56bc4cdd7da2c019b1cd" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index c5cac71d..4623d629 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -57,57 +57,57 @@ "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "af2d1e1f63f7489840073bbe10705d8cae0c3886fb0768c829940a33e71490d4", - "last_commit": "b79954c", + "digest": "04cdf688c8b8db1c849f62a67d26f5e3d6755cd9e7abceda02ca57ae46ac2475", + "last_commit": "056b8e7", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { - "digest": "6f1c98b95ea2d94ef3d0230a38fd121e9244c8f3f8dc8d65c3cf2957a8bccff1", - "last_commit": "b79954c", + "digest": "a258da86889a2c724e401240270737100b650ab9f35e53b763ea0737b2a0a204", + "last_commit": "056b8e7", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, { - "digest": "9b69f8190384ecb91f1d09f7109e0d08a84c601bc566e480f5098e6106ec6530", - "last_commit": "b79954c", + "digest": "b6d9b7f41a384aadce48d58fe49e4e35cff1909579d5478b4a03a6f4ca7a9c59", + "last_commit": "056b8e7", "name": "include", "purpose": "Directory native/kernel/include. Purpose not yet described by a human." }, { "digest": "05fee5afbbfcbca9eab294bfc3778bc380b2eaa1c95a595b6946971a180f0665", - "last_commit": "b79954c", + "last_commit": "6da9d58", "name": "mm", "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, { - "digest": "ffa91a4e0808986fd633979835ad7cb183995cf87939f16f55da4e58f9e24254", - "last_commit": "b79954c", + "digest": "5f3563ae990ea4c130d7f24cb057effd855202f96c89d51d7542e68eba2dbc79", + "last_commit": "056b8e7", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { - "digest": "182f6664539cfc8d8731eb824c5df6ce700059e666dac474500929fce0b99c0d", - "last_commit": "b79954c", + "digest": "8d9dd989b592bcdc509febaa9ea580f0301eb231910485a716663509733fac92", + "last_commit": "056b8e7", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { "digest": "342735b38f7498b022914ea412e4b8e798a916786b31ad02516ef7d9e518acba", - "last_commit": "b79954c", + "last_commit": "6da9d58", "name": "tools", "purpose": "Directory native/kernel/tools. Purpose not yet described by a human." } ], - "children_root": "sha256:6937dde85c1b4a70880d1fa5f93cbd306121c699b075b508adccd7e1f357f9d7", - "compiled_at": "2026-10-06T03:00:56Z", + "children_root": "sha256:86b35cb18692becd5ac2ad8ecb09f8a56cfba3823631cfff65ef01c3d756e65e", + "compiled_at": "2026-10-06T11:23:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:88f28f8c28bdd707b7b26e829417a785970606218731c306522932b3edb171a9", + "digest": "sha256:2994b89eaffa92f36c9335d87b6142ada4d5d521b4402f4fbde8681be6dbdf4e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 153, - "generated_at_commit": "b79954c7278df871a8226d51c6a594918676aba3", - "source_tree": "sha256:876668dde168f0f1ec103a72031f777343a294516ec3899b5faebe81cedb2d53" + "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961", + "source_tree": "sha256:d7854182898461dfe15573395274f1fde838d55e624d97b101d97ca399f1dc1f" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/GATES.md b/native/kernel/GATES.md index 67e1ffe6..10ccdd10 100644 --- a/native/kernel/GATES.md +++ b/native/kernel/GATES.md @@ -108,7 +108,12 @@ The C SMMU service is `core/smmu.c` (port of `crates/aienos-kernel/src/smmu.rs`: linear stream table, stage 1 only, global abort set first and never cleared, every stream in abort until installed) plus `core/smmu_svc.c` (IORT lookup, per-stream page tables, `ck_dma_confine` / `ck_dma_unconfine` / -`ck_dma_faults` in ck.h); host tests in `tests/test_smmu.c`. +`ck_dma_faults` in ck.h); host tests in `tests/test_smmu.c`. The IORT +lookup is per PCI segment (HOST tests on the DGX Spark's measured IORT shape: +15 root complexes, segment 4 requester 0x100 -> stream 0x50100, segment 15 +not on the first SMMU) and `make iort-mutants` (run by `make test`) checks +that test_smmu fails against a segment-blind lookup, a truncating parse and +an accepted overlap. Hardware NOT_RUN. | # | Rust check (pattern) | CK gate | Status | | --- | --- | --- | --- | diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 58de2b3c..3a306a41 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -692,8 +692,32 @@ acpi-dev-mutant: $(KDIR)/tests/test_acpi_dev.c $(HOST_SRCS) $(KDIR)/tests/ck_tes if $$b > $$b.log 2>&1; then cat $$b.log; echo "test_acpi_dev mutant $$m: PASSED, test does not catch it"; exit 1; \ else grep -F "test_acpi_dev: FAIL" $$b.log >/dev/null && echo "test_acpi_dev mutant $$m: FAILS as required" || { cat $$b.log; exit 1; }; fi; done -test: $(addprefix $(OUT)/host/,$(TESTS)) handoff-mutant acpi-dev-mutant test-continuity-subject-restart - @fail=0; for t in $(filter-out handoff-mutant acpi-dev-mutant test-continuity-subject-restart,$^); do $$t || fail=1; done; \ +# TEST-ONLY mutants of the IORT parse/lookup in core/acpi.c: test_smmu must +# FAIL against each (TRUNCATE: extra mappings dropped instead of the table +# refused; SEGMENT_BLIND: lookup ignores the PCI segment; OVERLAP_OK: +# overlapping input ranges in one segment accepted). Host only (acpi.c +# refuses them freestanding and with CK_HARDWARE_STAGING). +IORT_MUTANTS := CK_IORT_MUTANT_TRUNCATE CK_IORT_MUTANT_SEGMENT_BLIND CK_IORT_MUTANT_OVERLAP_OK +iort-mutants: $(OUT)/host/test_smmu + @mkdir -p $(OUT)/host-mut; fail=0; \ + $(OUT)/host/test_smmu > $(OUT)/host-mut/iort-base.log 2>&1 || { echo "unmutated test_smmu fails"; fail=1; }; \ + for m in $(IORT_MUTANTS); do \ + b=$(OUT)/host-mut/test_smmu_$$m; \ + if ! $(HOSTCC) $(HCFLAGS) -D$$m -o $$b $(KDIR)/tests/test_smmu.c $(HOST_SRCS); then \ + echo "mutant $$m: does not build (FAIL)"; fail=1; continue; fi; \ + if $$b > $$b.log 2>&1; then echo "mutant $$m: SURVIVED (FAIL)"; fail=1; \ + elif grep -q "^test_smmu: FAIL" $$b.log; then \ + echo "mutant $$m: killed ($$(grep -c '^ FAIL ' $$b.log) checks failed)"; \ + else echo "mutant $$m: no FAIL verdict (crashed?) (FAIL)"; fail=1; fi; \ + done; \ + if $(HOSTCC) $(HCFLAGS) -DCK_HARDWARE_STAGING=1 -DCK_IORT_MUTANT_SEGMENT_BLIND \ + -fsyntax-only $(KDIR)/core/acpi.c 2>/dev/null; then \ + echo "mutant flag accepted under CK_HARDWARE_STAGING (FAIL)"; fail=1; \ + else echo "mutant flag refused under CK_HARDWARE_STAGING"; fi; \ + if [ $$fail = 0 ]; then echo "CK_IORT_MUTANTS: PASS"; else echo "CK_IORT_MUTANTS: FAIL"; exit 1; fi + +test: $(addprefix $(OUT)/host/,$(TESTS)) handoff-mutant acpi-dev-mutant iort-mutants test-continuity-subject-restart + @fail=0; for t in $(filter-out handoff-mutant acpi-dev-mutant iort-mutants test-continuity-subject-restart,$^); do $$t || fail=1; done; \ if [ $$fail = 0 ]; then echo "CK_CORE_HOST: PASS"; else echo "CK_CORE_HOST: FAIL"; exit 1; fi sanitize: $(addprefix $(OUT)/host-san/,$(TESTS)) @@ -1074,4 +1098,4 @@ clean: rm -rf $(OUT) FORCE: -.PHONY: all full test sanitize handoff-mutant acpi-dev-mutant acpi-scan clean print-kcflags udp-echo tool store-image gpt-image cont-tool owner-gen fb-check continuity-mutants continuity-resolve-mutants FORCE +.PHONY: all full test sanitize handoff-mutant acpi-dev-mutant iort-mutants acpi-scan clean print-kcflags udp-echo tool store-image gpt-image cont-tool owner-gen fb-check continuity-mutants continuity-resolve-mutants FORCE diff --git a/native/kernel/README.md b/native/kernel/README.md index 3f2e2718..2996fa85 100644 --- a/native/kernel/README.md +++ b/native/kernel/README.md @@ -361,6 +361,23 @@ low-water free bytes. DMA is refused. `CK_QEMU_UNSAFE_DMA=1` (TEST-ONLY, QEMU only, refused with `CK_HARDWARE_STAGING`) builds the unconfined bypass used only when no SMMU exists, and prints the `WARNING: UNSAFE NVME DMA BYPASS` lines. +- The IORT stream id of a PCI device is resolved within its PCI segment + (`ck_dma_confine(segment, rid, ...)`, `ck_iort_stream_id(s, segment, rid, + ...)`): each root-complex mapping keeps the root complex's + `pci_segment_number` (IORT root complex node offset 28, ACPICA + `actbl2.h`), and a mapping of another segment never matches. The parse + keeps at most `CK_IORT_MAX_MAPS` (32) mappings to the SMMU and refuses the + whole table beyond that, and refuses two mappings whose input ranges + overlap in one segment. The DGX Spark's IORT (MEASURED, read under Ubuntu + 2026-10-05) has 15 root complexes, segment n mapping requester ids + 0-0xffff to streams `0x10000*(n+1)` on the first SMMUv3 (0x13800000), and + segment 15 on the second SMMUv3. Its NVMe (MEASURED: PCI 0004:01:00.0, + behind that first SMMU) resolves to stream 0x50000 + (bus 1 << 8 | dev 0 + << 3 | fn 0 = 0x100) = 0x50100. The linear stream table holds streams + 0x0-0xfff only, so `ck_dma_confine` still refuses that stream with + `CK_SMMU_NOSTREAM` until the two-level stream table lands. The PCI walk + itself (`dev/pci.c`) still covers segment 0 only, so every `pci_func` + carries segment 0 today. - The kernel writes only inside the AIENOS partition of the boot disk (`dev/disk_part.h`, gate `DISK_LAYOUT`). The GPT is parsed read-only: diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index 79031c73..9695c699 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-06T02:21:10Z", + "compiled_at": "2026-10-06T11:23:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:af2d1e1f63f7489840073bbe10705d8cae0c3886fb0768c829940a33e71490d4", + "digest": "sha256:04cdf688c8b8db1c849f62a67d26f5e3d6755cd9e7abceda02ca57ae46ac2475", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 31, - "generated_at_commit": "4bbc7e66f4e28b91c523acf8f4b296dfe2141e71", - "source_tree": "sha256:3b03b6caeaf2211d6f3e0e4cb6eafffbdc576c39d99fff6a7de1de5f05a325f9" + "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961", + "source_tree": "sha256:9f9a72f2fd50cfa3f7eb109de0c56b6f6f2471d92600b8c56242fcea08938389" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/acpi.c b/native/kernel/core/acpi.c index 2296aeca..a526611e 100644 --- a/native/kernel/core/acpi.c +++ b/native/kernel/core/acpi.c @@ -312,6 +312,17 @@ int ck_acpi_spans(uint64_t rsdp, void (*fn)(uint64_t lo, uint64_t hi, void *ctx) return n; } +/* TEST-only IORT mutants (make iort-mutants): each must make test_smmu + * FAIL. Host builds only; never part of an image. */ +#if defined(CK_IORT_MUTANT_TRUNCATE) || defined(CK_IORT_MUTANT_SEGMENT_BLIND) || defined(CK_IORT_MUTANT_OVERLAP_OK) +#if !__STDC_HOSTED__ +#error "CK_IORT_MUTANT_* are host test mutants only" +#endif +#ifdef CK_HARDWARE_STAGING +#error "CK_IORT_MUTANT_* cannot be combined with CK_HARDWARE_STAGING" +#endif +#endif + /* IORT walk: calls back for every node after checking its header, length * and ID-mapping array bounds. -1 on any malformed node. */ #define IORT_NODE_HDR 16u @@ -319,6 +330,7 @@ int ck_acpi_spans(uint64_t rsdp, void (*fn)(uint64_t lo, uint64_t hi, void *ctx) #define IORT_NODE_SMMUV3 4u #define IORT_MAP_BYTES 20u #define IORT_TABLE_HDR 48u /* SDT header + node count, node array offset, reserved */ +#define IORT_RC_SEGMENT 28u /* root complex node: pci_segment_number */ static int iort_nodes(const uint8_t *t, uint32_t len, uint32_t *count, uint32_t *first) { @@ -363,16 +375,34 @@ int ck_iort_parse(const void *iort, struct ck_iort_smmu *out) found = 1; } if (pass == 1 && type == IORT_NODE_ROOT_COMPLEX) { + /* Root complex node: PCI segment number at +28 (ACPICA + * actbl2.h acpi_iort_root_complex: memory_properties u64 + * @16, ats_attribute u32 @24, pci_segment_number u32 @28). */ + if (nlen < IORT_RC_SEGMENT + 4) + return -1; + uint32_t seg = rd32(n + IORT_RC_SEGMENT); for (uint32_t m = 0; m < mcount; m++) { const uint8_t *e = n + moff + m * IORT_MAP_BYTES; if (rd32(e + 12) != s.node_off) continue; - if (s.nmaps >= CK_IORT_MAX_MAPS) + if (s.nmaps >= CK_IORT_MAX_MAPS) { +#ifdef CK_IORT_MUTANT_TRUNCATE + continue; /* TEST mutant: drop the extra mappings silently */ +#else return -1; - s.map[s.nmaps].input_base = rd32(e); - s.map[s.nmaps].id_count = rd32(e + 4); - s.map[s.nmaps].output_base = rd32(e + 8); - s.nmaps++; +#endif + } + struct ck_iort_map nm = { seg, rd32(e), rd32(e + 4), rd32(e + 8) }; +#ifndef CK_IORT_MUTANT_OVERLAP_OK + for (uint32_t k = 0; k < s.nmaps; k++) { + const struct ck_iort_map *o = &s.map[k]; + if (o->segment == seg && + (uint64_t)nm.input_base <= (uint64_t)o->input_base + o->id_count && + (uint64_t)o->input_base <= (uint64_t)nm.input_base + nm.id_count) + return -1; + } +#endif + s.map[s.nmaps++] = nm; } } off += nlen; @@ -384,10 +414,16 @@ int ck_iort_parse(const void *iort, struct ck_iort_smmu *out) return 1; } -int ck_iort_stream_id(const struct ck_iort_smmu *s, uint32_t rid, uint32_t *sid) +int ck_iort_stream_id(const struct ck_iort_smmu *s, uint32_t segment, uint32_t rid, uint32_t *sid) { for (uint32_t i = 0; i < s->nmaps; i++) { const struct ck_iort_map *m = &s->map[i]; +#ifndef CK_IORT_MUTANT_SEGMENT_BLIND + if (m->segment != segment) + continue; +#else + (void)segment; /* TEST mutant: the pre-fix segment-blind lookup */ +#endif if (rid < m->input_base) continue; uint32_t rel = rid - m->input_base; diff --git a/native/kernel/core/acpi.h b/native/kernel/core/acpi.h index feba46be..a68cf42c 100644 --- a/native/kernel/core/acpi.h +++ b/native/kernel/core/acpi.h @@ -87,9 +87,16 @@ int ck_fadt_arm_boot_arch(const void *fadt, uint16_t *flags); /* IORT (Arm IO Remapping Table): the first SMMUv3 node and the PCI root * complex ID mappings that point at it (ported from the Rust - * aienos-kernel acpi::iort_smmuv3). */ -#define CK_IORT_MAX_MAPS 8 + * aienos-kernel acpi::iort_smmuv3). Each mapping keeps the PCI segment of + * its root complex: a requester id (bus<<8 | dev<<3 | fn) only means + * something inside one segment, so a lookup is (segment, rid). + * The mapping array is sized by the table: a parse counts the mappings + * that point at the SMMU and refuses the whole table (-1) when there are + * more than CK_IORT_MAX_MAPS. 32 covers the DGX Spark (MEASURED: 15 root + * complexes, one mapping each, to the first SMMUv3) with headroom. */ +#define CK_IORT_MAX_MAPS 32 struct ck_iort_map { + uint32_t segment; /* PCI segment number of the root complex */ uint32_t input_base, id_count, output_base; /* id_count = number of IDs - 1 */ }; struct ck_iort_smmu { @@ -99,12 +106,16 @@ struct ck_iort_smmu { struct ck_iort_map map[CK_IORT_MAX_MAPS]; }; /* 1 found, 0 no SMMUv3 node, -1 malformed (bad signature, truncation, a - * node or mapping array outside the table, base 0, more than - * CK_IORT_MAX_MAPS mappings to the SMMU). */ + * node or mapping array outside the table, base 0, a root complex node + * too short to carry its segment number, more than CK_IORT_MAX_MAPS + * mappings to the SMMU, or two mappings to the SMMU whose input ranges + * overlap in the same segment: an ambiguous requester id is refused, not + * resolved by table order). */ int ck_iort_parse(const void *iort, struct ck_iort_smmu *out); -/* Stream ID for PCI requester id `rid` (bus<<8 | dev<<3 | fn); 0 ok, -1 if - * no mapping covers it. */ -int ck_iort_stream_id(const struct ck_iort_smmu *s, uint32_t rid, uint32_t *sid); +/* Stream ID for PCI requester id `rid` (bus<<8 | dev<<3 | fn) in PCI + * segment `segment`; 0 ok, -1 if no mapping of that segment covers it. A + * mapping of another segment never matches. */ +int ck_iort_stream_id(const struct ck_iort_smmu *s, uint32_t segment, uint32_t rid, uint32_t *sid); /* IORT named component (node type 1) whose device object name has the same * final segment as `name` ("USB0" matches "\\_SB_.USB0"). out gets the node diff --git a/native/kernel/core/smmu_svc.c b/native/kernel/core/smmu_svc.c index 0c50fca1..2ba1b336 100644 --- a/native/kernel/core/smmu_svc.c +++ b/native/kernel/core/smmu_svc.c @@ -95,7 +95,7 @@ static int bring_up(void) static int confine_sid(uint32_t sid, uint64_t phys, uint64_t len, struct ck_dma_confinement *out); -int ck_dma_confine(uint32_t rid, uint64_t phys, uint64_t len, struct ck_dma_confinement *out) +int ck_dma_confine(uint32_t segment, uint32_t rid, uint64_t phys, uint64_t len, struct ck_dma_confinement *out) { if (!len || (phys & 0xfffu) || (len & 0xfffu) || phys + len < phys) return CK_SMMU_EARG; @@ -103,7 +103,7 @@ int ck_dma_confine(uint32_t rid, uint64_t phys, uint64_t len, struct ck_dma_conf if (rc) return rc; uint32_t sid; - if (ck_iort_stream_id(&g.iort, rid, &sid)) + if (ck_iort_stream_id(&g.iort, segment, rid, &sid)) return CK_SMMU_NOSTREAM; return confine_sid(sid, phys, len, out); } diff --git a/native/kernel/dev/.crumb b/native/kernel/dev/.crumb index 72ac6c9c..096857fe 100644 --- a/native/kernel/dev/.crumb +++ b/native/kernel/dev/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-06T02:21:10Z", + "compiled_at": "2026-10-06T11:23:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:6f1c98b95ea2d94ef3d0230a38fd121e9244c8f3f8dc8d65c3cf2957a8bccff1", + "digest": "sha256:a258da86889a2c724e401240270737100b650ab9f35e53b763ea0737b2a0a204", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 25, - "generated_at_commit": "4bbc7e66f4e28b91c523acf8f4b296dfe2141e71", - "source_tree": "sha256:1833f2852366a6eeeb3fab36e98f699f7efd21117b35ca6e3d7cc2bb4345f675" + "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961", + "source_tree": "sha256:a3fe65923aedb21ccdd17bf7030f66c1d1a3b05e04d86e35e9937b0bf729b9f5" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/dev/net_bind.c b/native/kernel/dev/net_bind.c index d1c6f2fe..c14c415d 100644 --- a/native/kernel/dev/net_bind.c +++ b/native/kernel/dev/net_bind.c @@ -360,7 +360,7 @@ int ck_net_bind_selftest(const pci_func *f, const virtio_pci_caps *caps) } uint32_t rid = ((uint32_t)f->bus << 8) | ((uint32_t)f->dev << 3) | (uint32_t)f->fn; struct ck_dma_confinement cf; - int src = ck_dma_confine(rid, phys, win, &cf); + int src = ck_dma_confine(f->segment, rid, phys, win, &cf); if (src != 0) { ck_printf("dma_gate: virtio_net denied (%s rc=%d), bus master stays off\n", src == CK_SMMU_ABSENT ? "NoSmmu" : "SmmuNotReady", src); diff --git a/native/kernel/dev/nvme_bind.c b/native/kernel/dev/nvme_bind.c index ac56ee08..9c2366c7 100644 --- a/native/kernel/dev/nvme_bind.c +++ b/native/kernel/dev/nvme_bind.c @@ -170,7 +170,7 @@ int ck_nvme_bind(ck_nvme *n, const pci_system *pci) uint32_t rid = ((uint32_t)f->bus << 8) | ((uint32_t)f->dev << 3) | (uint32_t)f->fn; uint64_t win = ((uint64_t)CK_NVME_DMA_BYTES + NVME_PAGE - 1u) & ~(uint64_t)(NVME_PAGE - 1u); struct ck_dma_confinement cf; - int src = ck_dma_confine(rid, phys, win, &cf); + int src = ck_dma_confine(f->segment, rid, phys, win, &cf); if (src == 0) { n->confined = 1; n->stream_id = cf.stream_id; diff --git a/native/kernel/dev/pci.c b/native/kernel/dev/pci.c index 5990ee61..e5860d6f 100644 --- a/native/kernel/dev/pci.c +++ b/native/kernel/dev/pci.c @@ -126,6 +126,7 @@ static int add_func(pci_system *s, uint8_t bus, uint8_t dev, uint8_t fn, volatil if (s->n >= PCI_MAX_FUNCS) return PCI_E_FULL; pci_func *f = &s->f[s->n++]; uint32_t id = pci_r32(c, CFG_VENDOR); + f->segment = s->ecam.segment; f->bus = bus; f->dev = dev; f->fn = fn; diff --git a/native/kernel/dev/pci.h b/native/kernel/dev/pci.h index 81777418..29da2bed 100644 --- a/native/kernel/dev/pci.h +++ b/native/kernel/dev/pci.h @@ -65,6 +65,7 @@ typedef struct { typedef struct { uint8_t bus, dev, fn; + uint16_t segment; /* PCI segment of the ECAM it was found in (IORT lookup key) */ uint16_t vendor, device; uint32_t class_code; /* class << 16 | subclass << 8 | progif */ uint8_t header_type; diff --git a/native/kernel/dev/xhci_fence.c b/native/kernel/dev/xhci_fence.c index 5e4f04c5..ee370078 100644 --- a/native/kernel/dev/xhci_fence.c +++ b/native/kernel/dev/xhci_fence.c @@ -345,7 +345,7 @@ int ck_xhci_fence(const pci_system *pci) } uint32_t rid = ((uint32_t)f->bus << 8) | ((uint32_t)f->dev << 3) | (uint32_t)f->fn; struct ck_dma_confinement cf; - int src = ck_dma_confine(rid, g_dma_phys, CK_XHCI_DMA_BYTES, &cf); + int src = ck_dma_confine(f->segment, rid, g_dma_phys, CK_XHCI_DMA_BYTES, &cf); if (src == 0) { x->confined = 1; x->stream_id = cf.stream_id; diff --git a/native/kernel/include/.crumb b/native/kernel/include/.crumb index 0a1bbc6c..0834618e 100644 --- a/native/kernel/include/.crumb +++ b/native/kernel/include/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-06T02:21:10Z", + "compiled_at": "2026-10-06T11:23:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:9b69f8190384ecb91f1d09f7109e0d08a84c601bc566e480f5098e6106ec6530", + "digest": "sha256:b6d9b7f41a384aadce48d58fe49e4e35cff1909579d5478b4a03a6f4ca7a9c59", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 1, - "generated_at_commit": "4bbc7e66f4e28b91c523acf8f4b296dfe2141e71", - "source_tree": "sha256:90d1e9fd53b300b5e3cadd120244acd4b0beedafde669b17cf46e702f8ac1e89" + "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961", + "source_tree": "sha256:87aecd274101f960dbea5aee239e93539077717727a1cc4cd2239bee71d8c7d8" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/include/ck.h b/native/kernel/include/ck.h index 3055aa51..3c67ecba 100644 --- a/native/kernel/include/ck.h +++ b/native/kernel/include/ck.h @@ -105,7 +105,10 @@ struct ck_dma_confinement { uint32_t stream_id; uint64_t iova, len; }; -int ck_dma_confine(uint32_t rid, uint64_t phys, uint64_t len, struct ck_dma_confinement *out); +/* `segment` is the PCI segment of the device and `rid` its requester id + * (bus<<8 | dev<<3 | fn) inside that segment: the IORT resolves the stream + * id within that segment's root complex only. */ +int ck_dma_confine(uint32_t segment, uint32_t rid, uint64_t phys, uint64_t len, struct ck_dma_confinement *out); /* Same window for an ACPI platform device (no PCI requester id), added for * the platform xHCI path (NEXT-PHASE-3 cut 2): the stream comes from the * IORT named component whose object name has the same final segment as diff --git a/native/kernel/svc/.crumb b/native/kernel/svc/.crumb index 6b9925fd..63951d1a 100644 --- a/native/kernel/svc/.crumb +++ b/native/kernel/svc/.crumb @@ -23,21 +23,21 @@ "purpose": "Directory native/kernel/svc/compat. Purpose not yet described by a human." }, { - "digest": "c0bfdf17e8c27bac0c6f65d02e19498fef4a1140fbdd70546d08e691eed56424", - "last_commit": "f921666", + "digest": "2f7512f91d82dec9b6927e09e1e83380a723b16c51c36244f28a9629c9c8a227", + "last_commit": "056b8e7", "name": "tests", "purpose": "Directory native/kernel/svc/tests. Purpose not yet described by a human." } ], - "children_root": "sha256:fa0e2a0cc0c70b3e86f73dfb158e4531edcf82370ba5e1c582c36bdf8536f3d6", - "compiled_at": "2026-10-06T02:21:10Z", + "children_root": "sha256:1aba58a0545ef8d0ef6d6e6bed2ded8bdc9dea5ad734dae6aee1f0d7ad7d8490", + "compiled_at": "2026-10-06T11:23:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:ffa91a4e0808986fd633979835ad7cb183995cf87939f16f55da4e58f9e24254", + "digest": "sha256:5f3563ae990ea4c130d7f24cb057effd855202f96c89d51d7542e68eba2dbc79", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 35, - "generated_at_commit": "4bbc7e66f4e28b91c523acf8f4b296dfe2141e71", - "source_tree": "sha256:6b336f28ca71ecd41b770e83dc71bd88c86c87d03b3d9ee1d7c8743e48de0baf" + "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961", + "source_tree": "sha256:a355bcd3f4c677a00369093ad877a892eda7aff5b2c75dbed9a0308d8123584c" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/tests/.crumb b/native/kernel/svc/tests/.crumb index c99db880..7e24e920 100644 --- a/native/kernel/svc/tests/.crumb +++ b/native/kernel/svc/tests/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-06T02:21:10Z", + "compiled_at": "2026-10-06T11:23:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:c0bfdf17e8c27bac0c6f65d02e19498fef4a1140fbdd70546d08e691eed56424", + "digest": "sha256:2f7512f91d82dec9b6927e09e1e83380a723b16c51c36244f28a9629c9c8a227", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 3, - "generated_at_commit": "4bbc7e66f4e28b91c523acf8f4b296dfe2141e71", - "source_tree": "sha256:694ade7ff54895da71314a11d5452d7f74a3820d769842de91a6abcca21ee4ac" + "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961", + "source_tree": "sha256:22c108a22609cc2ba1d9720f3928bf431f24f0e1bf8a48558bb4ebdbf462a1c4" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/tests/ck_host.c b/native/kernel/svc/tests/ck_host.c index 6b707182..faa847c3 100644 --- a/native/kernel/svc/tests/ck_host.c +++ b/native/kernel/svc/tests/ck_host.c @@ -96,9 +96,9 @@ int ck_entropy_status(void) { return 0; } const char *ck_entropy_reason(void) { return "host-urandom"; } /* Host: no IORT, so no SMMU (the NVMe gate stays fail-closed). */ -int ck_dma_confine(uint32_t rid, uint64_t phys, uint64_t len, struct ck_dma_confinement *out) +int ck_dma_confine(uint32_t segment, uint32_t rid, uint64_t phys, uint64_t len, struct ck_dma_confinement *out) { - (void)rid; (void)phys; (void)len; (void)out; + (void)segment; (void)rid; (void)phys; (void)len; (void)out; return CK_SMMU_ABSENT; } int ck_dma_confine_named(const char *acpi_name, uint64_t phys, uint64_t len, struct ck_dma_confinement *out) diff --git a/native/kernel/tests/.crumb b/native/kernel/tests/.crumb index 6723e5f2..28b88e64 100644 --- a/native/kernel/tests/.crumb +++ b/native/kernel/tests/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-06T02:21:10Z", + "compiled_at": "2026-10-06T11:23:44Z", "compiler": "crumb-compile/1", - "digest": "sha256:182f6664539cfc8d8731eb824c5df6ce700059e666dac474500929fce0b99c0d", + "digest": "sha256:8d9dd989b592bcdc509febaa9ea580f0301eb231910485a716663509733fac92", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 26, - "generated_at_commit": "4bbc7e66f4e28b91c523acf8f4b296dfe2141e71", - "source_tree": "sha256:c4027e326b679843fda1701bd290f41b39156d49db542133a65e4971ce027a58" + "generated_at_commit": "056b8e7c700fcafb2a942a17af8a4c61a4f6e961", + "source_tree": "sha256:90ab73387bb3ae4e8d0887fef0d9557efb5225728e1a081b7656294b5602eacf" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tests/test_smmu.c b/native/kernel/tests/test_smmu.c index 3d7184a4..6bf4f985 100644 --- a/native/kernel/tests/test_smmu.c +++ b/native/kernel/tests/test_smmu.c @@ -351,9 +351,9 @@ static void test_iort(void) build_iort(t, 1); CHECK(ck_iort_parse(t, &s) == 1); CHECK(s.base == 0x09050000ull && s.nmaps == 1 && s.map[0].id_count == 0xffff); - CHECK(ck_iort_stream_id(&s, 0x0010, &sid) == 0 && sid == 0x10); - CHECK(ck_iort_stream_id(&s, 0xffff, &sid) == 0 && sid == 0xffff); - CHECK(ck_iort_stream_id(&s, 0x10000, &sid) == -1); /* the ITS-only mapping is not an SMMU stream */ + CHECK(ck_iort_stream_id(&s, 0, 0x0010, &sid) == 0 && sid == 0x10); + CHECK(ck_iort_stream_id(&s, 0, 0xffff, &sid) == 0 && sid == 0xffff); + CHECK(ck_iort_stream_id(&s, 0, 0x10000, &sid) == -1); /* the ITS-only mapping is not an SMMU stream */ build_iort(t, 0); CHECK(ck_iort_parse(t, &s) == 0); /* Malformed: node length past the table, mapping array past the node, @@ -377,8 +377,128 @@ static void test_iort(void) w32(t + 40, 40); /* node array inside the 48-byte IORT header */ CHECK(ck_iort_parse(t, &s) == -1); /* A mapping whose output would wrap is never a stream. */ - struct ck_iort_smmu w = { 1, 0, 1, { { 0, 0xffff, 0xfffffff0u } } }; - CHECK(ck_iort_stream_id(&w, 0x20, &sid) == -1); + struct ck_iort_smmu w = { 1, 0, 1, { { 0, 0, 0xffff, 0xfffffff0u } } }; + CHECK(ck_iort_stream_id(&w, 0, 0x20, &sid) == -1); +} + +/* ---- IORT on the DGX Spark's shape (MEASURED from its IORT, 2026-10-06: + * 15 root complexes for PCI segments 0..14, each mapping requester ids + * 0..0xffff to streams 0x10000*(segment+1) on the first SMMUv3 + * (0x13800000); segment 15's root complex maps to the second SMMUv3 + * (0x13000000) instead). ------------------------------------------------ */ +static uint32_t iort_begin(uint8_t *t, size_t cap) +{ + memset(t, 0, cap); + memcpy(t, "IORT", 4); + w32(t + 40, 48); + return 48; +} +static uint32_t iort_smmu(uint8_t *t, uint32_t at, uint64_t base) +{ + t[at] = 4; w16(t + at + 1, 88); + w64(t + at + 16, base); + return at + 88; +} +/* Root complex for `seg` with `n` mappings: mapping i covers + * [in + i*step, in + i*step + cnt] -> out + i*step, to node `ref`. */ +static uint32_t iort_rc(uint8_t *t, uint32_t at, uint32_t seg, uint32_t n, uint32_t in, uint32_t cnt, uint32_t step, + uint32_t out, uint32_t ref) +{ + t[at] = 2; w16(t + at + 1, (uint16_t)(36 + 20 * n)); + w32(t + at + 8, n); w32(t + at + 12, 36); + w32(t + at + 28, seg); + for (uint32_t i = 0; i < n; i++) { + uint8_t *e = t + at + 36 + 20 * i; + w32(e, in + i * step); w32(e + 4, cnt); w32(e + 8, out + i * step); w32(e + 12, ref); + } + return at + 36 + 20 * n; +} +static void iort_end(uint8_t *t, uint32_t at, uint32_t nodes) +{ + w32(t + 4, at); + w32(t + 36, nodes); +} + +static void test_iort_spark_shape(void) +{ + static uint8_t t[2048]; + struct ck_iort_smmu s; + uint32_t sid = 0; + uint32_t at = iort_begin(t, sizeof t), a = at; + at = iort_smmu(t, at, 0x13800000ull); + uint32_t b = at; + at = iort_smmu(t, at, 0x13000000ull); + for (uint32_t seg = 0; seg < 15; seg++) + at = iort_rc(t, at, seg, 1, 0, 0xffff, 0, 0x10000u * (seg + 1), a); + uint32_t rc15 = at; + at = iort_rc(t, at, 15, 1, 0, 0xffff, 0, 0, b); + iort_end(t, at, 18); + CHECK(ck_iort_parse(t, &s) == 1); + CHECK(s.base == 0x13800000ull && s.node_off == a && s.nmaps == 15); + CHECK(s.map[4].segment == 4 && s.map[4].output_base == 0x50000); + /* NVMe 0004:01:00.0 (MEASURED: segment 4, behind smmu 0x13800000): + * rid = bus 1 << 8 | dev 0 << 3 | fn 0 = 0x100; segment 4's mapping + * starts at stream 0x50000, so 0x50000 + 0x100 = 0x50100. */ + CHECK(ck_iort_stream_id(&s, 4, 0x100, &sid) == 0 && sid == 0x50100); + CHECK(ck_iort_stream_id(&s, 0, 0x100, &sid) == 0 && sid == 0x10100); + CHECK(ck_iort_stream_id(&s, 0, 0x0, &sid) == 0 && sid == 0x10000); + CHECK(ck_iort_stream_id(&s, 14, 0xffff, &sid) == 0 && sid == 0xfffff); + /* Wrong segment: segment 15 belongs to the second SMMU, segment 16 + * does not exist; a segment-blind lookup would hand out segment 0's + * stream 0x10000 / 0x10100 here. */ + sid = 0xdead; + CHECK(ck_iort_stream_id(&s, 15, 0x0, &sid) == -1 && sid == 0xdead); + CHECK(ck_iort_stream_id(&s, 16, 0x100, &sid) == -1); + CHECK(ck_iort_stream_id(&s, 4, 0x10000, &sid) == -1); + /* Segment 15's mappings never land on the first SMMU's list. */ + for (uint32_t i = 0; i < s.nmaps; i++) + CHECK(s.map[i].segment != 15); + /* A root complex node too short to carry its segment is refused. */ + w16(t + rc15 + 1, 24); w32(t + rc15 + 8, 0); w32(t + rc15 + 12, 0); + iort_end(t, rc15 + 24, 18); + CHECK(ck_iort_parse(t, &s) == -1); +} + +static void test_iort_cap_overlap(void) +{ + static uint8_t t[2048]; + struct ck_iort_smmu s; + uint32_t sid = 0; + /* Exactly CK_IORT_MAX_MAPS mappings: accepted, all kept. */ + uint32_t at = iort_begin(t, sizeof t), a = at; + at = iort_smmu(t, at, 0x13800000ull); + at = iort_rc(t, at, 0, CK_IORT_MAX_MAPS, 0, 0xff, 0x100, 0x1000, a); + iort_end(t, at, 2); + CHECK(ck_iort_parse(t, &s) == 1 && s.nmaps == CK_IORT_MAX_MAPS); + CHECK(ck_iort_stream_id(&s, 0, 0x1f05, &sid) == 0 && sid == 0x2f05); + /* One more: the whole table is refused, not truncated. */ + at = iort_begin(t, sizeof t); + at = iort_smmu(t, at, 0x13800000ull); + at = iort_rc(t, at, 0, CK_IORT_MAX_MAPS + 1, 0, 0xff, 0x100, 0x1000, a); + iort_end(t, at, 2); + CHECK(ck_iort_parse(t, &s) == -1); + /* Overlapping input ranges in one segment: refused. */ + at = iort_begin(t, sizeof t); + at = iort_smmu(t, at, 0x13800000ull); + at = iort_rc(t, at, 0, 2, 0, 0xff, 0x80, 0x1000, a); + iort_end(t, at, 2); + CHECK(ck_iort_parse(t, &s) == -1); + /* Overlap split over two root complexes of the same segment: refused. */ + at = iort_begin(t, sizeof t); + at = iort_smmu(t, at, 0x13800000ull); + at = iort_rc(t, at, 3, 1, 0x10, 0xff, 0, 0x1000, a); + at = iort_rc(t, at, 3, 1, 0x10f, 0, 0, 0x2000, a); + iort_end(t, at, 3); + CHECK(ck_iort_parse(t, &s) == -1); + /* Adjacent ranges, and the same range in two segments: accepted. */ + at = iort_begin(t, sizeof t); + at = iort_smmu(t, at, 0x13800000ull); + at = iort_rc(t, at, 0, 2, 0, 0xff, 0x100, 0x1000, a); + at = iort_rc(t, at, 1, 1, 0, 0xff, 0, 0x5000, a); + iort_end(t, at, 3); + CHECK(ck_iort_parse(t, &s) == 1 && s.nmaps == 3); + CHECK(ck_iort_stream_id(&s, 0, 0x100, &sid) == 0 && sid == 0x1100); + CHECK(ck_iort_stream_id(&s, 1, 0x10, &sid) == 0 && sid == 0x5010); } int main(void) @@ -391,5 +511,7 @@ int main(void) test_queue_wrap(); test_events(); test_iort(); + test_iort_spark_shape(); + test_iort_cap_overlap(); return ck_t_verdict("test_smmu"); } ```