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/69cd863e2042e05a # 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#214 (code only) closed derived `69cd863e2042e05a` #214 Imported from GitHub aien-dev/aienux#214 (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 `78bda00b192c3029d45f067778298390bf0f5efc` · Head `9c6fde30e48cb6e7984be1e4044a8f4994fb0616` ### Apply it ``` git checkout -b patch-69cd863e2042e05a 78bda00b192c3029d45f067778298390bf0f5efc curl -fsSL https://interplane.io/drakestapleton/aienux/patches/69cd863e2042e05a.patch | git am ``` Raw patch (mbox) · 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 214 9c6fde30e48cb6e7984be1e4044a8f4994fb0616 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aienux","number":214,"url":"https://github.com/aien-dev/aienux/pull/214","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:35:58Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log b/evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log new file mode 100644 index 00000000..09e9f085 --- /dev/null +++ b/evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log @@ -0,0 +1,95 @@ +PASS UDP echo helper listening on 127.0.0.1:47029 (token f99cbd71e03c03cc) +Could not open option rom 'vgabios-ramfb.bin': No such file or directory +== boot net-smmu: qemu exit 0 +PASS pre-exit report printed +PASS image is this commit +PASS left firmware and entered the kernel +PASS kernel entered EL1h +PASS EL1 page tables and caches enabled +PASS GICv3 enabled +PASS timer IRQ delivered at least five ticks +PASS MMU switched from firmware tables (0x47fff000) to AIENOS tables (0x40000000) +PASS GIC bases from the ACPI MADT, GICv3 architecture and ICC system registers +PASS tick statistics consistent (period 10000 us, min 10161 avg 10305 max 10749) +PASS guard pages fault and the fault is contained (C kernel addition) +PASS kernel entropy from RNDR: FEAT_RNG present, bounded retry, stuck test (C kernel addition) +PASS no kernel entropy refusal (C kernel addition) +PASS final report on the SPCR console +PASS no panic or fault +-- (a) attach +PASS virtio-net capabilities parsed +PASS SMMU window programmed for the virtio-net DMA region only +PASS virtio-net DMA granted only after confinement +PASS driver attached, QEMU NIC MAC read from the device, ACCESS_PLATFORM negotiated (features = VERSION_1|ACCESS_PLATFORM|MAC) +PASS ARP reply from the slirp gateway (52:55:0a:00:02:02) +-- (b) TX +PASS guest sent one UDP frame and the device completed it (AIENOS-CK-NET ping nonce=5eb75ffd) +PASS host helper received the guest's datagram through slirp (same nonce) +-- (c) RX +PASS host helper sent its reply +PASS guest received and parsed (M6-A, checksum verified) the helper's reply with this run's token +PASS round trip reported +-- (d) fence: device DMA outside the window +PASS 64 RX descriptors pointed outside the window, probe datagram sent +PASS host helper received the probe and replied (the device had a frame to write) +PASS SMMU event F_TRANSLATION (0x10) x16 for the NIC's stream 0x18 at 0x402bd000, in the target page 0x402bd000 outside the window; page intact; positive round trip fault-free (device model reaction, reported not judged: rx_completed=1 device_status=0x0f needs_reset=no event_overflow=0) +-- (e) recovery inside the window +PASS device reset + re-init with ACCESS_PLATFORM after the fault +PASS second round trip after the fault, no new SMMU fault +PASS two helper replies with this run's token parsed (before and after the fault) +PASS net selftest PASS (round trip, fence and recovery) +-- release +PASS device reset before the revoke +PASS virtio-net bus master revoked +PASS virtio-net SMMU stream returned to abort +PASS order: grant < round trip < fault refused < recovery round trip < device reset < bus master off < stream abort +PASS devices stage summary +PASS no virtio-net failure lines +Could not open option rom 'vgabios-ramfb.bin': No such file or directory +== boot net-nosmmu: qemu exit 0 +PASS pre-exit report printed +PASS image is this commit +PASS left firmware and entered the kernel +PASS kernel entered EL1h +PASS EL1 page tables and caches enabled +PASS GICv3 enabled +PASS timer IRQ delivered at least five ticks +PASS MMU switched from firmware tables (0x47fff000) to AIENOS tables (0x40000000) +PASS GIC bases from the ACPI MADT, GICv3 architecture and ICC system registers +PASS tick statistics consistent (period 10000 us, min 10030 avg 10101 max 10197) +PASS guard pages fault and the fault is contained (C kernel addition) +PASS kernel entropy from RNDR: FEAT_RNG present, bounded retry, stuck test (C kernel addition) +PASS no kernel entropy refusal (C kernel addition) +PASS final report on the SPCR console +PASS no panic or fault +PASS virtio-net DMA denied without an SMMU +PASS virtio-net not bound without an SMMU +PASS no virtio-net grant without an SMMU +PASS no datagram sent without an SMMU +PASS devices stage summary (no SMMU) +PASS host helper saw nothing from the no-SMMU boot +Could not open option rom 'vgabios-ramfb.bin': No such file or directory +== boot net-noap: qemu exit 0 +PASS pre-exit report printed +PASS image is this commit +PASS left firmware and entered the kernel +PASS kernel entered EL1h +PASS EL1 page tables and caches enabled +PASS GICv3 enabled +PASS timer IRQ delivered at least five ticks +PASS MMU switched from firmware tables (0x47fff000) to AIENOS tables (0x40000000) +PASS GIC bases from the ACPI MADT, GICv3 architecture and ICC system registers +PASS tick statistics consistent (period 10000 us, min 10081 avg 10310 max 10568) +PASS guard pages fault and the fault is contained (C kernel addition) +PASS kernel entropy from RNDR: FEAT_RNG present, bounded retry, stuck test (C kernel addition) +PASS no kernel entropy refusal (C kernel addition) +PASS final report on the SPCR console +PASS no panic or fault +PASS SMMU window programmed (the refusal is the driver's, not the SMMU's) +PASS driver refuses a NIC that does not offer ACCESS_PLATFORM +PASS no attach without ACCESS_PLATFORM +PASS no datagram sent without ACCESS_PLATFORM +PASS device released (reset, bus master revoked, stream back to abort) +PASS devices stage summary (no ACCESS_PLATFORM) +PASS host helper saw nothing from the no-ACCESS_PLATFORM boot +AIENOS_CK_NET: PASS diff --git a/native/kernel/GATES.md b/native/kernel/GATES.md index a2a5a7c8..6856206b 100644 --- a/native/kernel/GATES.md +++ b/native/kernel/GATES.md @@ -22,7 +22,7 @@ C gates (one line each from `ck_gates.sh`): `M1` and `M3` (from `SMMU`, `NVME_SHUTDOWN` (from `scripts/qemu_ck_store_test.sh`; rows 21-24b, 47-72, 76 and 96-101 were checked against its exact grep patterns), `P2_ARTIFACT` (from `scripts/qemu_ck_artifact_test.sh`, rows 33-41), `NET` (C-only, from -`scripts/qemu_ck_net_test.sh`; rows 102-106), the kernel entropy rows 107-109 (M1 via `scripts/lib_ck_m1_checks.sh`, ARGUS1_REVOKE and M4_STORE via the Store gate boot 7), and the NOT_RUN gates +`scripts/qemu_ck_net_test.sh`; rows 102-106 and 110-112; the script now also checks the virtio-net SMMU fence (ACCESS_PLATFORM required, out-of-window device DMA refused), rows 102 and 110-112 are QEMU PASS on this branch from the committed forge log `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, hardware NOT_RUN), the kernel entropy rows 107-109 (M1 via `scripts/lib_ck_m1_checks.sh`, ARGUS1_REVOKE and M4_STORE via the Store gate boot 7), and the NOT_RUN gates `M0_ROLLBACK`, `M4_STORE_CRASH`, `M4_CONTINUITY`, `M4_RECOVERY`, `KEYBOARD`. @@ -326,20 +326,23 @@ complete. | 99 | NVMe normal shutdown before bus-master disable (CC.SHN = 01b, then wait CSTS.SHST = 10b) | NVME_SHUTDOWN | DIFFERS (C-only; the Rust kernel has no NVMe shutdown. Boots 1-4 and 6, both geometries: exactly one `nvme: shutdown normal cc=0x..->0x.. csts=0x.. shst=complete waited_us=N` line with CC.SHN read back as 01b and CSTS.SHST as 10b, printed before `dma_gate: nvme bus master revoked`, and no `nvme: shutdown fallback disable` line. Host tests cover CFS, not-ready, already-shut, timeout and the CC.EN = 0 fallback) | | 100 | QEMU device trace shows the shutdown while bus master is on | NVME_SHUTDOWN | DIFFERS (C-only: QEMU `-trace` of `pci_nvme_mmio_shutdown_set` and `pci_cfg_write` on the NVMe command register; the shutdown must land between the guest's BME-set and BME-clear writes) | | 101 | reset path quiesces DMA first; no shutdown without a bound controller | NVME_SHUTDOWN | DIFFERS (C-only: `devices: quiesce before reset nvme=already-released` on every boot (`ck_reset` hook, also covers panic/fault resets); boot 5 safe image: absent `nvme: shutdown normal`) | -| 102 | virtio-net attach behind an SMMU window (`virtio_net: .. caps ok`, `smmu_dma_window: virtio_net only iova=.. len=.. rid=.. stream_id=..`, `dma_gate: virtio_net granted (Confined), bus master on`, `virtio_net: attached .. mac=52:54:00:12:34:56 .. access_platform=no`, ARP reply from the slirp gateway `52:55:0a:00:02:02`) | NET | DIFFERS (C-only; no Rust counterpart: the Rust kernel has no virtio-net queue driver. Boot 1, `iommu=smmuv3`, QEMU user networking (slirp) `restrict=off`, driver `native/net/aienos_virtio_net.c` via `native/kernel/dev/net_bind.c`. NOT proven: the driver does not negotiate VIRTIO_F_ACCESS_PLATFORM, so QEMU does virtio-net DMA without the vIOMMU and the window is programmed but not enforced for this device) | +| 102 | virtio-net attach behind an SMMU window (`virtio_net: .. caps ok`, `smmu_dma_window: virtio_net only iova=.. len=.. rid=.. stream_id=..`, `dma_gate: virtio_net granted (Confined), bus master on`, `virtio_net: attached .. mac=52:54:00:12:34:56 features=0x300000020 access_platform=yes`, ARP reply from the slirp gateway `52:55:0a:00:02:02`) | NET | QEMU PASS (receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, forge log of `scripts/qemu_ck_net_test.sh` at 6816358, ends `AIENOS_CK_NET: PASS`; hardware NOT_RUN: no physical NIC or SMMU. no Rust counterpart: the Rust kernel has no virtio-net queue driver. Boot 1, `iommu=smmuv3`, NIC `virtio-net-pci,disable-legacy=on,iommu_platform=on`, QEMU user networking (slirp) `restrict=off`, driver `native/net/aienos_virtio_net.c` via `native/kernel/dev/net_bind.c`. The driver negotiates VIRTIO_F_ACCESS_PLATFORM (bit 33; features = VERSION_1 + ACCESS_PLATFORM + MAC) and the kernel requires it, so QEMU is expected to send every ring and buffer access of the NIC through the smmuv3 vIOMMU, which rows 110-111 test. The receipt log line 23 shows the `access_platform=yes` attach (features VERSION_1|ACCESS_PLATFORM|MAC); the older NET receipt `evidence/ck_gates_929f287e9c950c45c7dcd569c7caa03709ea62ecfe393635b435058afa969c54.json` predates this change and was taken with `access_platform=no`. Hosted `native/net` test `VNET_ACCESS_PLATFORM_SIM` PASS in the forge run `make -C native/net test` (log HIVE-L31NET-173414.log, not committed; simulated device only)) | | 103 | one UDP frame sent (TX) | NET | DIFFERS (C-only: guest `net: udp tx 10.0.2.15:47030 -> 10.0.2.2:47029 .. payload="AIENOS-CK-NET ping nonce=<8 hex>" .. completed=yes` AND the in-tree host helper `native/kernel/tools/ck_udp_echo.c` (`make udp-echo`) logs the same nonce arriving on 127.0.0.1:47029 through slirp) | | 104 | one UDP frame received (RX) and parsed by M6-A | NET | DIFFERS (C-only: guest `net: udp rx 10.0.2.2:47029 -> 10.0.2.15:47030 .. udp_csum=verified parsed=m6a echo_of_ours=yes payload="AIENOS-CK-NET pong token= echo="`; the token is generated by the script per run, so the line cannot pass without the helper's reply reaching the guest; plus `net: udp round trip ok`, `net: selftest PASS (rc=0)` and `devices: pci=ok nvme=bound virtio_net=selftest-ok`) | -| 105 | virtio-net released after the round trip | NET | DIFFERS (C-only: `virtio_net: device reset status=0x00 (stopped)`, `dma_gate: virtio_net bus master revoked`, `smmu: virtio_net stream 0x.. returned to abort (rc=0)`; line order grant < round trip < reset < revoke < abort) | +| 105 | virtio-net released after the round trip | NET | DIFFERS (C-only: `virtio_net: device reset status=0x00 (stopped)`, `dma_gate: virtio_net bus master revoked`, `smmu: virtio_net stream 0x.. returned to abort (rc=0)`; line order grant < round trip < reset < revoke < abort, as in the last receipt; the longer order with the fault (row 110) and recovery (row 111) before the reset is checked by the script and passed in the QEMU receipt line 45, hardware NOT_RUN) | | 106 | virtio-net fails closed without an SMMU | NET | DIFFERS (C-only: boot 2 without `iommu=smmuv3`: `dma_gate: virtio_net denied (NoSmmu rc=-1), bus master stays off`, `virtio_net: not bound (SMMU DMA isolation not active)`, absent `dma_gate: virtio_net granted` and `net: udp tx`, and the host helper receives nothing. Host test `stage_test` also checks the fail-closed bind leaves the command register without MEM/BME) | | 107 | kernel entropy is the RNDR instruction or nothing: FEAT_RNG checked first (ID_AA64ISAR0_EL1.RNDR), each 64-bit word retried at most 64 times (NZCV.Z = failure), stuck-output test, refusal latched and the buffer zeroed; no timer or other fallback source exists (`entropy: rndr feat_rng=yes probe_words=2 retries=N stuck_test=ok$`, absent `entropy: unavailable` and `entropy: refused`) | M1 (and every M1-checked boot of the Store and NET gates, via scripts/lib_ck_m1_checks.sh) | DIFFERS (C-only addition; no Rust M1 counterpart. Host test `tests/test_entropy.c` drives the selection logic with a mocked RNDR: absent, always failing, failing 63 then succeeding, failing exactly 64 (refused), dying mid-fill, stuck, never probed, latched refusal. QEMU -cpu max has FEAT_RNG; GB10 RNDR availability is UNVERIFIED) | | 108 | without RNDR the security services fail closed: the office token read is refused, caps and ARGUS never start, `stage security: FAIL` | ARGUS1_REVOKE (and M1 for that boot, with the refusal expected instead of `entropy: rndr`) | DIFFERS (C-only, Store gate boot 7 on QEMU `-cpu neoverse-n1` (no FEAT_RNG): `entropy: unavailable reason=absent (ID_AA64ISAR0_EL1.RNDR=0, no FEAT_RNG); ...`, `entropy: refused consumer=/dev/urandom (capability office token) reason=absent; service fails closed`, `security: REFUSED kernel entropy absent ...`, `caps: failed ... office_token=none`, `argus: FAIL step=cap_start`, `stage security: FAIL`, absent `caps: ok` and `argus: ok`. ARGUS1_REVOKE cannot PASS unless this boot refuses) | | 109 | the Store needs no entropy (its envelope ids and nonces are keyed functions, native/store/store_sealed.h) and still opens without RNDR | M4_STORE | DIFFERS (C-only, Store gate boot 7: `stage store: ok`) | +| 110 | virtio-net device DMA outside its SMMU window refused | NET | QEMU PASS (receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, forge log of `scripts/qemu_ck_net_test.sh` at 6816358, ends `AIENOS_CK_NET: PASS`; hardware NOT_RUN: no physical NIC or SMMU. Receipt lines 32-35 (fence section). C-only, boot 1 after the round trip: every RX descriptor the NIC holds is pointed at a 0x5a page outside the window and one probe datagram (`AIENOS-CK-NET ping smmu-probe nonce=<8 hex>`, logged and answered by the host helper) draws a reply the NIC must write. `net_smmu_negative: refused rx dma outside window iova=.. faults=N type=0x10 sid=.. addr=.. page=intact rx_completed=N device_status=0x.. needs_reset=.. faults_during_roundtrip=0 overflow=0`: the fields are read from the SMMU event queue (F_TRANSLATION) and the script re-checks them itself: page outside the `smmu_dma_window` range, event stream id equal to the NIC's, event address inside that page. Earlier lane-branch observation, now matched by the committed receipt (2026-10-01, QEMU 8.2.2): 16 F_TRANSLATION records for the NIC stream at the page, no NEEDS_RESET, and QEMU completed the RX through its internal bounce buffer (rx_completed=1, write dropped, page intact); rx_completed and needs_reset are reported, not judged. The kernel does not panic) | +| 111 | virtio-net recovers inside the window after the refused DMA | NET | QEMU PASS (receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, forge log of `scripts/qemu_ck_net_test.sh` at 6816358, ends `AIENOS_CK_NET: PASS`; hardware NOT_RUN: no physical NIC or SMMU. Receipt lines 36-38. C-only, boot 1, what the script checks: `net_smmu_recovery: device reset + reinit ok (Ok) access_platform=yes late_probe_faults=N` (status 0 written and read back before the rings are rebuilt; probe events that land after the negative test are drained and reported here) and `net_smmu_recovery: round trip after the fault ok (rc=0 new_faults=0)`, a second ARP + UDP round trip with this run's helper token, then the normal release order of row 105. To be shown: recovery by device reset + re-init; not covered even when run: a NIC that keeps running through the fault (the kernel discards the redirected descriptors and resets)) | +| 112 | virtio-net without ACCESS_PLATFORM refused (fail closed) | NET | QEMU PASS (receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, forge log of `scripts/qemu_ck_net_test.sh` at 6816358, ends `AIENOS_CK_NET: PASS`; hardware NOT_RUN: no physical NIC or SMMU. Receipt lines 86-93 (boot net-noap). C-only, boot 3, what the script checks: `iommu=smmuv3` but the NIC modern-only (`disable-legacy=on`) without `iommu_platform=on`, so QEMU offers no ACCESS_PLATFORM and would DMA around the vIOMMU: `virtio_net: init FAIL (NoAccessPlatform)` before FEATURES_OK, absent `virtio_net: attached` and `net: udp tx`, stream returned to abort, host helper receives nothing) | ## Summary counts **C kernel receipt tally (QEMU only, no physical run):** 9 of 14 CK gates PASS, 5 NOT_RUN (M0_ROLLBACK, M4_STORE_CRASH, M4_CONTINUITY, M4_RECOVERY, KEYBOARD), 0 FAIL, matching `evidence/ck_gates_929f287e9c950c45c7dcd569c7caa03709ea62ecfe393635b435058afa969c54.json` (run at 41aa0e6, which adds the kernel entropy rows 107-109; that commit was then rebased onto #210, which changed only README.md and CONTRIBUTING.md). The row counts below are per Rust-parity row, not per gate. -Rows 1-109: IDENTICAL 28, DIFFERS 40, NOT_RUN 41, counted from the table (rows 107-109, kernel entropy, are C-only and DIFFERS); rows 34 and 39 now also cover the NVMe boot-disk source and its hostile disk cases (statuses unchanged) (the previous summary, 20/30/56, was miscounted: the table on main had 21/35/50; rows 33-41 then moved from NOT_RUN to 7 IDENTICAL + 2 DIFFERS with the C artifact loader; rows 92-95 have no CK gate at all; rows 96-106 are C-only). Rows 33-41 were checked against scripts/qemu_ck_artifact_test.sh. Rows 102-106 were checked against scripts/qemu_ck_net_test.sh. Rows 13, 24, 47-72, 76 and 96-101 were re-verified against scripts/qemu_ck_store_test.sh and scripts/lib_ck_m1_checks.sh at the commit that adds this line. +Rows 1-112: IDENTICAL 28, DIFFERS 39, NOT_RUN 45, counted from the table (rows 107-109, kernel entropy, are C-only and DIFFERS; row 102, virtio-net attach with ACCESS_PLATFORM, and rows 110-112, virtio-net SMMU fence, recovery and ACCESS_PLATFORM fail-closed, are C-only and NOT_RUN on this branch until a forge receipt covers them; the CK gate tally above and its receipt `ck_gates_929f...` predate them; no full `ck_gates.sh` run happened on this branch, only `scripts/qemu_ck_net_test.sh` alone, so rows 102 and 110-112 are shown as QEMU PASS (receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, hardware NOT_RUN) and the NOT_RUN count of 45 still includes them as originally counted, not recounted); rows 34 and 39 now also cover the NVMe boot-disk source and its hostile disk cases (statuses unchanged) (the previous summary, 20/30/56, was miscounted: the table on main had 21/35/50; rows 33-41 then moved from NOT_RUN to 7 IDENTICAL + 2 DIFFERS with the C artifact loader; rows 92-95 have no CK gate at all; rows 96-112 are C-only). Rows 33-41 were checked against scripts/qemu_ck_artifact_test.sh. Rows 102-106 and 110-112 were checked against scripts/qemu_ck_net_test.sh (text only; rows 102 and 110-112 then run by the forge, see their rows). Rows 13, 24, 47-72, 76 and 96-101 were re-verified against scripts/qemu_ck_store_test.sh and scripts/lib_ck_m1_checks.sh at the commit that adds this line. `scripts/trust1_m5_qualify.sh --with-qemu` also runs three of these gates as qemu rows: `ck_m1_boot_qemu` (M1), `ck_store_kernel_qemu` (M4_STORE) and diff --git a/native/kernel/dev/net_bind.c b/native/kernel/dev/net_bind.c index db3075cf..d1c6f2fe 100644 --- a/native/kernel/dev/net_bind.c +++ b/native/kernel/dev/net_bind.c @@ -11,6 +11,8 @@ #define UDP_TRIES 5u #define UDP_WAIT_US 1000000u #define RESET_WAIT_US 100000u +#define PROBE_WAIT_US 3000000u +#define CANARY_BYTE 0x5au typedef struct { const pci_func *pf; @@ -150,10 +152,11 @@ static int wait_for(ck_vnet *n, ck_net_peer *p, ck_net_kind want, uint32_t us, s return CK_NET_IGNORED; } -static int roundtrip(ck_vnet *n) +static int roundtrip(ck_vnet *n, ck_net_peer *pp) { ck_net_peer p; memset(&p, 0, sizeof p); + memset(pp, 0, sizeof *pp); memcpy(p.mac.b, n->dev.mac, 6); static const net_ipv4 me = {{10, 0, 2, 15}}, gw = {{10, 0, 2, 2}}; p.ip = me; @@ -220,9 +223,120 @@ static int roundtrip(ck_vnet *n) return CK_NET_E_RX; } ck_printf("net: udp round trip ok tx_reclaimed=%u rx_frames=%u\n", reclaimed, frames); + *pp = p; return CK_NET_OK; } +/* SMMU negative test (net_bind.h). After a good round trip, every RX + * descriptor the device still holds is pointed at a pattern-filled page + * that is NOT in the stream's window (and mapped by no other entry of this + * stream's stage-1 table), then one datagram is sent (TX buffer inside the + * window) so the helper's reply makes the device write an RX frame. Pass: + * the SMMU event queue holds an F_TRANSLATION record for this stream at + * that page, the page keeps its pattern, and the positive round trip before + * it raised no fault at all. How the device model reacts is reported, not + * judged: QEMU 8.2 either refuses the descriptor (virtio "bogus descriptor", + * NEEDS_RESET) or maps it through its internal bounce buffer and completes + * the RX, the write-back of which the SMMU refuses as well (rx_completed, + * device_status). recovery() below resets and re-inits the device either way. */ +static int smmu_negative_test(ck_vnet *n, const ck_net_peer *p, uint64_t win_lo, uint64_t win_len) +{ + static volatile uint8_t *canary; /* ck_dma_alloc is never freed: once */ + static uint64_t cphys; + if (!canary) canary = ck_dma_alloc(4096, 4096, &cphys); + if (!canary) { + ck_printf("net_smmu_negative: FAIL (no canary page)\n"); + return -1; + } + if (!(cphys + 4096u <= win_lo || cphys >= win_lo + win_len)) { + ck_printf("net_smmu_negative: FAIL (canary page 0x%llx inside the window)\n", (unsigned long long)cphys); + return -1; + } + for (uint32_t i = 0; i < 4096u; i++) canary[i] = CANARY_BYTE; + struct ck_dma_fault fl = {0, 0, 0, 0}; + int before = ck_dma_faults(n->stream_id, 0); /* faults raised by the positive round trip (want 0) */ + + vnet_queue *q = &n->dev.q[VNET_RX_QUEUE]; + unsigned redirected = 0; + for (uint16_t id = 0; id < q->size; id++) { + if (!q->posted[id]) continue; + /* one 64-bit store: the device may read this descriptor concurrently */ + *(volatile uint64_t *)(void *)(n->dev.mem + q->desc_off + 16u * id) = cphys; + redirected++; + } + ck_mb(); /* descriptors rewritten before the datagram that draws the reply */ + uint16_t used0 = *(volatile uint16_t *)(n->dev.mem + q->used_off + 2); + + static char probe[] = "AIENOS-CK-NET ping smmu-probe nonce=00000000"; + hex8((uint32_t)ck_time_us() ^ 0x0badd0e5u, probe + sizeof probe - 9); + size_t w = ck_net_udp_frame(p, 0x4f00u, (const uint8_t *)probe, sizeof probe - 1, frame, sizeof frame); + vnet_err e = w ? vnet_tx(&n->dev, frame, w) : VNET_E_ARG; + ck_printf("net_smmu_negative: rx descriptors redirected=%u to iova=0x%llx (outside window 0x%llx+0x%llx); " + "probe datagram \"%s\" tx=%s\n", + redirected, (unsigned long long)cphys, (unsigned long long)win_lo, (unsigned long long)win_len, probe, + vnet_err_name(e)); + uint32_t st = 0; + uint64_t t0 = ck_time_us(); + while (e == VNET_OK && ck_time_us() - t0 < PROBE_WAIT_US) { + st = o_read(n, VNET_WIN_COMMON, VNET_CC_STATUS, 1); + if (st & VNET_S_NEEDS_RESET) break; + if (*(volatile uint16_t *)(n->dev.mem + q->used_off + 2) != used0) break; /* RX completed (bounce) */ + ck_udelay(1000); + } + ck_udelay(20000); /* let any further event records land */ + st = o_read(n, VNET_WIN_COMMON, VNET_CC_STATUS, 1); + n->dev.broken = 1; /* descriptors no longer point into the region: never use them again */ + int faults = ck_dma_faults(n->stream_id, &fl); + int intact = 1; + for (uint32_t i = 0; i < 4096u; i++) + if (canary[i] != CANARY_BYTE) intact = 0; + uint16_t rx_done = (uint16_t)(*(volatile uint16_t *)(n->dev.mem + q->used_off + 2) - used0); + int ok = e == VNET_OK && before == 0 && faults >= 1 && fl.type == CK_DMA_FAULT_TRANSLATION && + fl.stream_id == n->stream_id && (fl.addr & ~(uint64_t)4095u) == cphys && intact; + ck_printf("net_smmu_negative: %s rx dma outside window iova=0x%llx faults=%d type=0x%x sid=0x%x addr=0x%llx " + "page=%s rx_completed=%u device_status=0x%02x needs_reset=%s faults_during_roundtrip=%d overflow=%d\n", + ok ? "refused" : "FAIL", (unsigned long long)cphys, faults, fl.type, fl.stream_id, + (unsigned long long)fl.addr, intact ? "intact" : "MODIFIED", rx_done, st, + (st & VNET_S_NEEDS_RESET) ? "yes" : "no", before, fl.overflow); + return ok ? 0 : -1; +} + +/* After the negative test: reset + re-init (vnet_init writes status 0 and + * rebuilds every descriptor inside the window) and a second full round + * trip, still confined, with no new SMMU fault. */ +static int recovery(ck_vnet *n, const vnet_ops *ops, const virtio_pci_caps *caps, uint8_t *mem, uint64_t phys, + size_t need) +{ + /* Stop the device before vnet_init clears the rings it may still be + * reading (status 0, wait until it reads back 0). */ + o_write(n, VNET_WIN_COMMON, VNET_CC_STATUS, 1, 0); + uint32_t st = 0xffu; + uint64_t t0 = ck_time_us(); + while ((st = o_read(n, VNET_WIN_COMMON, VNET_CC_STATUS, 1)) != 0 && ck_time_us() - t0 < RESET_WAIT_US) + ck_udelay(10); + /* Events the refused probe raised after the negative test drained the + * queue belong to the probe: drop them (reported) so new_faults below + * counts only the second round trip. */ + int late = ck_dma_faults(n->stream_id, 0); + if (st != 0) { + ck_printf("net_smmu_recovery: FAIL (device reset timeout status=0x%02x)\n", st); + return -1; + } + vnet_err e = + vnet_init_flags(&n->dev, ops, caps, mem, phys, need, CK_NET_QSIZE, VNET_INIT_REQUIRE_ACCESS_PLATFORM); + ck_printf("net_smmu_recovery: device reset + reinit %s (%s) access_platform=%s late_probe_faults=%d\n", + e == VNET_OK ? "ok" : "FAIL", vnet_err_name(e), + (n->dev.features >> VNET_F_ACCESS_PLATFORM & 1) ? "yes" : "no", late); + if (e != VNET_OK) return -1; + ck_net_peer p; + int rc = roundtrip(n, &p); + int faults = ck_dma_faults(n->stream_id, 0); + int ok = rc == CK_NET_OK && faults == 0; + ck_printf("net_smmu_recovery: round trip after the fault %s (rc=%d new_faults=%d)\n", ok ? "ok" : "FAIL", rc, + faults); + return ok ? 0 : -1; +} + int ck_net_bind_selftest(const pci_func *f, const virtio_pci_caps *caps) { ck_vnet *n = &g_net; @@ -270,7 +384,10 @@ int ck_net_bind_selftest(const pci_func *f, const virtio_pci_caps *caps) n->bm_on = 1; ck_printf("dma_gate: virtio_net granted (Confined), bus master on\n"); vnet_ops ops = {n, o_read, o_write, o_notify}; - vnet_err e = vnet_init(&n->dev, &ops, caps, mem, phys, need, CK_NET_QSIZE); + /* Fail closed: without VIRTIO_F_ACCESS_PLATFORM QEMU (and a real device + * behind a bypassing transport) would DMA around the SMMU window. */ + vnet_err e = + vnet_init_flags(&n->dev, &ops, caps, mem, phys, need, CK_NET_QSIZE, VNET_INIT_REQUIRE_ACCESS_PLATFORM); if (e != VNET_OK) { ck_printf("virtio_net: init FAIL (%s)\n", vnet_err_name(e)); ck_net_release(); @@ -278,10 +395,18 @@ int ck_net_bind_selftest(const pci_func *f, const virtio_pci_caps *caps) } const uint8_t *m = n->dev.mac; ck_printf("virtio_net: attached %02x:%02x.%u rid=0x%x qsize=rx%u/tx%u mac=%02x:%02x:%02x:%02x:%02x:%02x " - "features=0x%llx access_platform=no\n", + "features=0x%llx access_platform=%s\n", f->bus, f->dev, f->fn, rid, n->dev.q[VNET_RX_QUEUE].size, n->dev.q[VNET_TX_QUEUE].size, m[0], m[1], m[2], - m[3], m[4], m[5], (unsigned long long)n->dev.features); - int rc = n->dev.has_mac ? roundtrip(n) : CK_NET_E_INIT; + m[3], m[4], m[5], (unsigned long long)n->dev.features, + (n->dev.features >> VNET_F_ACCESS_PLATFORM & 1) ? "yes" : "no"); + ck_net_peer peer; + memset(&peer, 0, sizeof peer); + int rc = n->dev.has_mac ? roundtrip(n, &peer) : CK_NET_E_INIT; + /* Prove the fence: device DMA outside the window is refused by the SMMU, + * then the device recovers inside it (net_bind.h). */ + if (rc == CK_NET_OK && + (smmu_negative_test(n, &peer, phys, win) != 0 || recovery(n, &ops, caps, mem, phys, need) != 0)) + rc = CK_NET_E_SMMU; if (!n->dev.has_mac) ck_printf("net: no MAC offered by the device; round trip not attempted\n"); ck_printf("net: selftest %s (rc=%d)\n", rc == CK_NET_OK ? "PASS" : "FAIL", rc); ck_net_release(); diff --git a/native/kernel/dev/net_bind.h b/native/kernel/dev/net_bind.h index 42bda9bf..2bb47d07 100644 --- a/native/kernel/dev/net_bind.h +++ b/native/kernel/dev/net_bind.h @@ -9,10 +9,20 @@ * SMMU did not come up, the device stays off. There is no unconfined bypass * for virtio-net, not even in the TEST-ONLY CK_QEMU_UNSAFE_DMA=1 build. * - * Limit (QEMU): the driver does not negotiate VIRTIO_F_ACCESS_PLATFORM, and - * QEMU's virtio-pci then performs device DMA without the vIOMMU, so the SMMU - * window is programmed but QEMU does not enforce it for this device. The - * kernel prints access_platform=no; the gate does not claim confinement. */ + * ACCESS_PLATFORM: vnet_init_flags(..., VNET_INIT_REQUIRE_ACCESS_PLATFORM) + * negotiates VIRTIO_F_ACCESS_PLATFORM (bit 33) and refuses a device that does + * not offer it (fail closed: QEMU virtio-pci without iommu_platform=on DMAs + * around the vIOMMU). With it, every ring and buffer access of the device + * goes through the SMMU window; the kernel prints access_platform=yes. + * + * Fence proof (after the good round trip, net_bind.c smmu_negative_test): + * the RX descriptors the device holds are pointed at a pattern page outside + * the window and a datagram draws a reply; the SMMU must log F_TRANSLATION + * for this stream at that page, the page must stay intact. Measured on QEMU + * 8.2.2: no NEEDS_RESET; QEMU completes the RX through its internal bounce + * buffer (rx_completed=1) while the refused write never reaches the page. + * The binding discards the redirected descriptors, resets and re-inits the + * device and runs a second round trip inside the window. */ #ifndef AIENOS_CK_NET_BIND_H #define AIENOS_CK_NET_BIND_H #include "aienos_virtio_net.h" @@ -29,12 +39,15 @@ enum { CK_NET_E_ARP = -505, /* no ARP reply from the gateway in time */ CK_NET_E_TX = -506, /* frame build, post or completion failed */ CK_NET_E_RX = -507, /* no matching UDP reply in time, or device broken */ + CK_NET_E_SMMU = -508, /* SMMU negative test or its recovery failed */ }; -/* Attach (DMA gate, BAR map, bus master, vnet_init), then ARP for the - * gateway and one UDP datagram to CK_NET_ECHO_PORT and back, every wait - * bounded by ck_time_us. Always leaves the device released (reset, bus - * master off, stream back to abort) before returning. */ +/* Attach (DMA gate, BAR map, bus master, vnet_init_flags with + * ACCESS_PLATFORM required), then ARP for the gateway and one UDP datagram to + * CK_NET_ECHO_PORT and back, then the SMMU fence test and its recovery round + * trip (CK_NET_E_SMMU if either fails), every wait bounded by ck_time_us. + * Always leaves the device released (reset, bus master off, stream back to + * abort) before returning. */ int ck_net_bind_selftest(const pci_func *f, const virtio_pci_caps *caps); /* Reset the device, revoke bus mastering and return the SMMU stream to diff --git a/native/net/README.md b/native/net/README.md index c01a2776..b4424afb 100644 --- a/native/net/README.md +++ b/native/net/README.md @@ -43,7 +43,7 @@ control-transport stub. No Rust, no Python, no heap, no outside library. ## Not claimed (deferred, with the dependency) -- Physical binding (real NIC, interrupts, enforced DMA): the virtio-net driver is bound in the C kernel by `native/kernel/dev/net_bind.c` (#200 d75a266 attach and split virtqueue driver, #203 9807281 kernel hook, NET gate PASS in QEMU only). It is polled (no IRQs), uses TEST keys, and the SMMU window is programmed but NOT enforced because VIRTIO_F_ACCESS_PLATFORM is not negotiated. No physical NIC driver exists. +- Physical binding (real NIC, interrupts): the virtio-net driver is bound in the C kernel by `native/kernel/dev/net_bind.c` (#200 d75a266 attach and split virtqueue driver, #203 9807281 kernel hook, NET gate PASS in QEMU only). It is polled (no IRQs) and uses TEST keys. Lane 31 negotiates and requires VIRTIO_F_ACCESS_PLATFORM so the NIC DMA should go through the SMMU window, and the NET gate script now checks that an out-of-window DMA is refused; QEMU PASS on this branch (receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, forge log of `scripts/qemu_ck_net_test.sh`), QEMU only; hardware NOT_RUN. No physical NIC driver exists. - Production identity and keys: needs M5 (key hierarchy, TRUST-1). The M6-B secure transport below exists as hosted code but runs on TEST keys only. The stub refuses every identity kind except TEST, whose key is derived from a public label and so protects nothing against an attacker. @@ -193,7 +193,7 @@ verify}`, which carries a 32-byte tag. The two connect like this: ## Lane 26: virtio-net PCI fix and virtqueue data path (hosted) -> Update 2026-10-01: the text of this section is the hosted-lane record. The driver is now bound in the C kernel (#200 d75a266, #203 9807281, `native/kernel/dev/net_bind.c`) and the NET gate passes in QEMU only (slirp UDP round trip; SMMU window programmed but not enforced because VIRTIO_F_ACCESS_PLATFORM is not negotiated; polled, no IRQs; no physical NIC; TEST keys). The "not proven" list below still holds for real hardware. +> Update 2026-10-01: the text of this section is the hosted-lane record. The driver is now bound in the C kernel (#200 d75a266, #203 9807281, `native/kernel/dev/net_bind.c`) and the NET gate passes in QEMU only (slirp UDP round trip; the last receipt predates Lane 31; Lane 31 negotiates VIRTIO_F_ACCESS_PLATFORM and adds an out-of-window DMA check to the gate, QEMU PASS with receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`; polled, no IRQs; no physical NIC; TEST keys). The "not proven" list below still holds for real hardware. **The attach bug.** The capability walk refused any vendor capability whose region had length 0, before looking at its type. Real QEMU virtio-net-pci @@ -213,7 +213,10 @@ own C-only pin, and `make diff-check` proves the two differ only on records the reference refused as `InvalidRegion` (1,622 of 200,000). **The data path** (`aienos_virtio_net`): reset, ACK, DRIVER; VERSION_1 -required, MAC accepted if offered, every other feature declined; FEATURES_OK +required, MAC and ACCESS_PLATFORM (bit 33) accepted if offered, every other +feature declined; `vnet_init_flags(..., VNET_INIT_REQUIRE_ACCESS_PLATFORM)` +refuses a device that does not offer ACCESS_PLATFORM before FEATURES_OK (the C +kernel uses it, so a NIC that would DMA around the SMMU never runs); FEATURES_OK read back; queue 0 RX and queue 1 TX, power-of-two size up to 256 (downsized to what the device offers); notify offset checked against the notify window; all RX buffers posted before DRIVER_OK; polled (no MSI-X vector, NO_INTERRUPT). @@ -234,6 +237,11 @@ device broken (sticky) until re-init. queue, queue size 0/1, pre-enabled queue, notify offset outside the window, unstable config generation, missing/short caps, small/misaligned/wrapping memory. No notify before DRIVER_OK. +- `VNET_ACCESS_PLATFORM_SIM`: bit 33 accepted when offered (with and without the + flag); with the flag and no offer (three offer sets) refused as + `NoAccessPlatform` with FAILED set, no feature bits written, no queue enabled + and no notify; unknown flags refused. PASS in the forge run `make -C native/net test` (log HIVE-L31NET-173414.log, not committed; + simulated device only). - Data path: TX full/reclaim, max-size frames, 70,000 frames each way so the 16-bit ring indices wrap; the device model checks every descriptor it reads. - Hostile device: 9 directed cases plus a 2,000-round seeded fuzz of forged @@ -248,7 +256,10 @@ DMA or IOMMU/SMMU mapping, no interrupts, no QEMU slirp round trip, no cache-coherence or MMIO ordering on real hardware, no physical NIC. The only real-QEMU evidence is the static config space. A real QEMU end-to-end needs a guest kernel that drives the device; this module is hosted and the kernel -binding belongs to the native kernel lane. +binding belongs to the native kernel lane. (Lane 31: the C kernel binding, +`native/kernel/dev/net_bind.c`, runs this driver in QEMU behind the smmuv3 +vIOMMU with ACCESS_PLATFORM required; see gate NET, GATES.md rows 102-112. The +ACCESS_PLATFORM attach and the fence rows are QEMU PASS with receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`; hardware NOT_RUN.) **Kernel hook (for the native kernel).** After `ck_virtio_net_probe` accepts the caps: add `aienos_virtio_net.c` to the stage sources, enable memory space diff --git a/native/net/aienos_virtio_net.c b/native/net/aienos_virtio_net.c index a1b4d7f9..dfa7dacf 100644 --- a/native/net/aienos_virtio_net.c +++ b/native/net/aienos_virtio_net.c @@ -27,6 +27,7 @@ const char *vnet_err_name(vnet_err e) case VNET_E_FULL: return "Full"; case VNET_E_DEVICE: return "HostileDevice"; case VNET_E_BROKEN: return "Broken"; + case VNET_E_NO_ACCESS_PLATFORM: return "NoAccessPlatform"; } return "Unknown"; } @@ -192,11 +193,18 @@ static vnet_err setup_queue(vnet_dev *d, uint16_t index, uint32_t want) vnet_err vnet_init(vnet_dev *d, const vnet_ops *ops, const virtio_pci_caps *caps, void *mem, uint64_t dma, size_t mem_len, uint16_t qsize) +{ + return vnet_init_flags(d, ops, caps, mem, dma, mem_len, qsize, 0); +} + +vnet_err vnet_init_flags(vnet_dev *d, const vnet_ops *ops, const virtio_pci_caps *caps, void *mem, uint64_t dma, + size_t mem_len, uint16_t qsize, uint32_t flags) { if (!d) return VNET_E_ARG; memset(d, 0, sizeof *d); d->broken = 1; /* until init succeeds */ - if (!ops || !ops->read || !ops->write || !ops->notify || !caps || !mem || !pow2_ok(qsize)) + if ((flags & ~VNET_INIT_REQUIRE_ACCESS_PLATFORM) || !ops || !ops->read || !ops->write || !ops->notify || !caps || + !mem || !pow2_ok(qsize)) return VNET_E_ARG; /* required windows: common (whole structure), notify (+ multiplier), isr, device */ if (!caps->common_cfg.present || caps->common_cfg.length < VNET_CC_LEN || !caps->notify_cfg.present || @@ -229,7 +237,12 @@ vnet_err vnet_init(vnet_dev *d, const vnet_ops *ops, const virtio_pci_caps *caps wr(d, VNET_WIN_COMMON, VNET_CC_DFSELECT, 4, 1); offered |= (uint64_t)rd(d, VNET_WIN_COMMON, VNET_CC_DF, 4) << 32; if (!(offered >> VNET_F_VERSION_1 & 1)) return fail(d, VNET_E_NO_VERSION_1); - uint64_t accept = (1ull << VNET_F_VERSION_1) | (offered & (1ull << VNET_F_MAC)); + /* Fail closed: a caller that confines DMA with an IOMMU must not run a + * device that would DMA around it. */ + if ((flags & VNET_INIT_REQUIRE_ACCESS_PLATFORM) && !(offered >> VNET_F_ACCESS_PLATFORM & 1)) + return fail(d, VNET_E_NO_ACCESS_PLATFORM); + uint64_t accept = + (1ull << VNET_F_VERSION_1) | (offered & ((1ull << VNET_F_MAC) | (1ull << VNET_F_ACCESS_PLATFORM))); if (accept >> VNET_F_MAC & 1) { if (caps->device_cfg.length < 6) return fail(d, VNET_E_CAPS); } diff --git a/native/net/aienos_virtio_net.h b/native/net/aienos_virtio_net.h index caa39d6e..c8743d4a 100644 --- a/native/net/aienos_virtio_net.h +++ b/native/net/aienos_virtio_net.h @@ -16,10 +16,15 @@ * that runs ahead of what was posted, or a short RX completion marks the * device broken (sticky); the caller must reset and re-init. * - * Features: VIRTIO_F_VERSION_1 is required; VIRTIO_NET_F_MAC is accepted when - * offered; every other feature is declined (no packed ring, no indirect - * descriptors, no event index, no offloads, no mergeable RX buffers, no - * control queue, no ACCESS_PLATFORM). One descriptor per packet; the 12-byte + * Features: VIRTIO_F_VERSION_1 is required; VIRTIO_NET_F_MAC and + * VIRTIO_F_ACCESS_PLATFORM are accepted when offered (virtio 1.x 6.1: a driver + * SHOULD accept ACCESS_PLATFORM; with it the device DMAs through the + * platform IOMMU, so `dma` below is an IOMMU bus address). With + * VNET_INIT_REQUIRE_ACCESS_PLATFORM the driver refuses (fail closed, before + * FEATURES_OK) a device that does not offer it: an IOMMU-confined caller + * must never run a device that would bypass the IOMMU. Every other feature + * is declined (no packed ring, no indirect descriptors, no event index, no + * offloads, no mergeable RX buffers, no control queue). One descriptor per packet; the 12-byte * virtio 1.x net header precedes each frame. Interrupts are not used. */ #ifndef AIENOS_VIRTIO_NET_H #define AIENOS_VIRTIO_NET_H @@ -38,6 +43,10 @@ #define VNET_F_MAC 5u #define VNET_F_VERSION_1 32u +#define VNET_F_ACCESS_PLATFORM 33u /* VIRTIO_F_ACCESS_PLATFORM (was IOMMU_PLATFORM) */ + +/* vnet_init_flags flags */ +#define VNET_INIT_REQUIRE_ACCESS_PLATFORM 1u /* virtio common configuration (virtio 1.x 4.1.4.3), byte offsets */ #define VNET_CC_DFSELECT 0x00u @@ -97,6 +106,7 @@ typedef enum { VNET_E_FULL = 10, /* no free TX descriptor (reclaim first) */ VNET_E_DEVICE = 11, /* hostile or broken device completion; device is now broken */ VNET_E_BROKEN = 12, /* sticky: an earlier VNET_E_DEVICE; reset and re-init */ + VNET_E_NO_ACCESS_PLATFORM = 13, /* required (flag) but not offered by the device */ } vnet_err; typedef struct { @@ -133,6 +143,9 @@ size_t vnet_mem_size(uint16_t qsize); * driver writes FAILED to the device status when it got that far. */ vnet_err vnet_init(vnet_dev *d, const vnet_ops *ops, const virtio_pci_caps *caps, void *mem, uint64_t dma, size_t mem_len, uint16_t qsize); +/* vnet_init with flags (VNET_INIT_REQUIRE_ACCESS_PLATFORM); vnet_init is flags 0. */ +vnet_err vnet_init_flags(vnet_dev *d, const vnet_ops *ops, const virtio_pci_caps *caps, void *mem, uint64_t dma, + size_t mem_len, uint16_t qsize, uint32_t flags); /* Copy one Ethernet frame (14..VNET_FRAME_MAX bytes, no FCS) into a free TX * buffer behind a zero virtio-net header, post it and notify. */ diff --git a/native/net/tests/vnet_test.c b/native/net/tests/vnet_test.c index ff03f012..1bcf23e4 100644 --- a/native/net/tests/vnet_test.c +++ b/native/net/tests/vnet_test.c @@ -288,7 +288,9 @@ static void test_init(void) sim_reset(&s, region, DMA, sizeof region); s.dev_features = ~0ull; /* offers everything, incl. packed, indirect, ACCESS_PLATFORM */ EQ(bring_up(&d, &s, 256), VNET_OK); - EQ(s.drv_features, (1ull << VNET_F_VERSION_1) | (1ull << VNET_F_MAC)); + /* ACCESS_PLATFORM is accepted when offered (virtio 1.x 6.1 SHOULD) */ + EQ(s.drv_features, (1ull << VNET_F_VERSION_1) | (1ull << VNET_F_MAC) | (1ull << VNET_F_ACCESS_PLATFORM)); + EQ(d.features, s.drv_features); EQ(s.status, VNET_S_ACK | VNET_S_DRIVER | VNET_S_FEATURES_OK | VNET_S_DRIVER_OK); CHECK(d.has_mac && d.mac[0] == 0x52 && d.mac[5] == 0x57); EQ(d.q[0].size, 256); EQ(d.q[1].size, 256); @@ -360,6 +362,64 @@ static void test_init(void) bad = c; bad.device_cfg.present = 0; EQ(vnet_init(&d, &o, &bad, region, DMA, sizeof region, 16), VNET_E_CAPS); bad = c; bad.device_cfg.length = 4; EQ(vnet_init(&d, &o, &bad, region, DMA, sizeof region, 16), VNET_E_CAPS); EQ(s.notifies[0] + s.notifies[1], 0); + EQ(vnet_init_flags(&d, &o, &c, region, DMA, sizeof region, 16, 2), VNET_E_ARG); /* unknown flag */ + EQ(s.notifies[0] + s.notifies[1], 0); +} + +/* VIRTIO_F_ACCESS_PLATFORM (bit 33): accepted when offered; with + * VNET_INIT_REQUIRE_ACCESS_PLATFORM a device that does not offer it is refused + * before FEATURES_OK (fail closed: it would DMA around the IOMMU). */ +static void test_access_platform(void) +{ + sim s; vnet_dev d; + vnet_ops o = sim_ops; o.ctx = &s; + virtio_pci_caps c; + EQ(virtio_pci_parse_caps(qemu_modern, 256, &c), VIRTIO_PCI_OK); + const uint64_t ap = 1ull << VNET_F_ACCESS_PLATFORM, v1 = 1ull << VNET_F_VERSION_1, mac = 1ull << VNET_F_MAC; + + /* not offered, not required: works as before, bit not written */ + sim_reset(&s, region, DMA, sizeof region); + EQ(vnet_init_flags(&d, &o, &c, region, DMA, sizeof region, 16, 0), VNET_OK); + EQ(s.drv_features, v1 | mac); CHECK(!(d.features & ap)); + + /* offered, not required: accepted */ + sim_reset(&s, region, DMA, sizeof region); + s.dev_features = v1 | mac | ap; + EQ(vnet_init(&d, &o, &c, region, DMA, sizeof region, 16), VNET_OK); + EQ(s.drv_features, v1 | mac | ap); CHECK(d.features & ap); + + /* offered and required: accepted, device runs */ + sim_reset(&s, region, DMA, sizeof region); + s.dev_features = v1 | mac | ap; + EQ(vnet_init_flags(&d, &o, &c, region, DMA, sizeof region, 16, VNET_INIT_REQUIRE_ACCESS_PLATFORM), VNET_OK); + EQ(s.drv_features, v1 | mac | ap); EQ(d.features, v1 | mac | ap); CHECK(!d.broken); + EQ(s.status, VNET_S_ACK | VNET_S_DRIVER | VNET_S_FEATURES_OK | VNET_S_DRIVER_OK); + uint8_t f[60] = {0}; + EQ(vnet_tx(&d, f, sizeof f), VNET_OK); + EQ(sim_tx(&s), 1); + + /* required but not offered (QEMU without iommu_platform=on): refused before + * FEATURES_OK, FAILED set, no feature bits written, no queue, no notify */ + const uint64_t offers[] = {v1 | mac, v1, ~0ull & ~ap}; + for (size_t i = 0; i < sizeof offers / sizeof offers[0]; i++) { + sim_reset(&s, region, DMA, sizeof region); + s.dev_features = offers[i]; + EQ(vnet_init_flags(&d, &o, &c, region, DMA, sizeof region, 16, VNET_INIT_REQUIRE_ACCESS_PLATFORM), + VNET_E_NO_ACCESS_PLATFORM); + CHECK(d.broken); + CHECK(s.status & VNET_S_FAILED); + CHECK(!(s.status & (VNET_S_FEATURES_OK | VNET_S_DRIVER_OK))); + EQ(s.drv_features, 0); + EQ(s.q[0].enable + s.q[1].enable, 0); + EQ(s.notifies[0] + s.notifies[1], 0); + EQ(vnet_tx(&d, f, sizeof f), VNET_E_BROKEN); + } + /* a legacy-only device is still refused as NoVersion1 first */ + sim_reset(&s, region, DMA, sizeof region); + s.dev_features = mac | ap; + EQ(vnet_init_flags(&d, &o, &c, region, DMA, sizeof region, 16, VNET_INIT_REQUIRE_ACCESS_PLATFORM), + VNET_E_NO_VERSION_1); + CHECK(strcmp(vnet_err_name(VNET_E_NO_ACCESS_PLATFORM), "NoAccessPlatform") == 0); } static void test_datapath(void) @@ -526,6 +586,10 @@ int main(void) printf("VIRTIO_PCI_QEMU822_CAPS: %s (real QEMU 8.2.2 virtio-net-pci config dumps, 0x1000 + 0x1041)\n", caps_ok ? "PASS" : "FAIL"); test_init(); + int ap_before = failures; + test_access_platform(); + printf("VNET_ACCESS_PLATFORM_SIM: %s (bit 33 accepted when offered; required + not offered refused before FEATURES_OK)\n", + failures == ap_before ? "PASS" : "FAIL"); test_datapath(); test_hostile(); test_m6a_udp(); diff --git a/scripts/ck_gates.sh b/scripts/ck_gates.sh index 0b4dfd12..3a78e90d 100755 --- a/scripts/ck_gates.sh +++ b/scripts/ck_gates.sh @@ -70,7 +70,7 @@ AAVMF_CODE_FD="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" AAVMF_VARS_FD="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" PHYSICAL_STATEMENT="QEMU emulator runs only. Nothing here was run on Machine 1 or any GB10; no physical qualification is claimed." M4_NVME_PASS_NOTE="SMMU-confined NVMe DMA in QEMU (iommu=smmuv3, default build); TEST-ONLY bypass build boot-checked separately" -NET_PASS_NOTE="QEMU user networking (slirp): attach, UDP TX seen by the host helper, UDP reply RX parsed by M6-A; QEMU does not route virtio-net DMA through the SMMU (no ACCESS_PLATFORM), so confinement is not proven for it" +NET_PASS_NOTE="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" die() { echo "ck_gates: $*" >&2; exit 2; } json_str() { @@ -354,7 +354,7 @@ self_test() { grep -qxF "AIENOS_CK_M4_NVME: PASS (${M4_NVME_PASS_NOTE})" "${tmp}/A.out" \ && ok "A: M4_NVME PASS line carries the confined-mode note" || bad "A: M4_NVME PASS line lacks the note" grep -qxF "AIENOS_CK_NET: PASS (${NET_PASS_NOTE})" "${tmp}/A.out" \ - && ok "A: NET PASS line carries the QEMU slirp / no-SMMU-enforcement note" || bad "A: NET PASS line lacks the note" + && ok "A: NET PASS line carries the QEMU slirp / SMMU fence note" || bad "A: NET PASS line lacks the note" grep -qx 'AIENOS_CK_KEYBOARD: NOT_RUN (MISSING_IMPLEMENTATION: no xHCI/USB HID keyboard driver in the C kernel)' "${tmp}/A.out" \ && ok "A: missing gate prints NOT_RUN (MISSING_IMPLEMENTATION: reason)" || bad "A: KEYBOARD line wrong" [[ "$(grep -c '^AIENOS_CK_[A-Z0-9_]*: ' "${tmp}/A.out")" == 14 ]] && ok "A: exactly 14 verdict lines" || bad "A: verdict line count" diff --git a/scripts/qemu_ck_net_test.sh b/scripts/qemu_ck_net_test.sh index eb7a0df1..34e6dc65 100755 --- a/scripts/qemu_ck_net_test.sh +++ b/scripts/qemu_ck_net_test.sh @@ -8,7 +8,9 @@ # # The devices stage (native/kernel/dev/net_bind.c) binds native/net's polled # virtio-net driver: SMMU window for its one DMA region first, then memory -# decode + bus master, vnet_init, then ARP for the slirp gateway 10.0.2.2 and +# decode + bus master, vnet_init_flags with VIRTIO_F_ACCESS_PLATFORM required +# (the NIC is iommu_platform=on,disable-legacy=on, so QEMU sends every ring +# and buffer access of the device through the smmuv3 vIOMMU), then ARP for the slirp gateway 10.0.2.2 and # one UDP datagram from 10.0.2.15:47030 to 10.0.2.2:47029, then device reset, # bus master off, SMMU stream back to abort. Slirp forwards 10.0.2.2:47029 to # the host's 127.0.0.1:47029, where the in-tree C helper @@ -27,14 +29,30 @@ # (c) RX: the guest's "net: udp rx ... udp_csum=verified parsed=m6a # echo_of_ours=yes" line carries this run's helper token and the # guest's own nonce, and the helper logged its reply; +# (d) fence: after the round trip the kernel points every RX descriptor the +# device holds at a 0x5a page outside the window and sends one probe +# datagram (helper logs it and replies). The SMMU event queue must hold +# an F_TRANSLATION (0x10) record whose stream id is the NIC's (from the +# smmu_dma_window line) and whose address is in that page; this script +# re-checks those printed event fields itself (page outside the window, +# sid equal, addr in page), the page must read back intact (whether QEMU +# completes the RX via its bounce buffer is reported, not judged), and +# the positive round trip must have raised no fault; +# (e) recovery: device reset + re-init (ACCESS_PLATFORM again) and a second +# full ARP + UDP round trip inside the window with no new fault; # plus the release order (device reset, bus master revoked, stream back to -# abort, after the round trip) and "devices: ... virtio_net=selftest-ok". +# abort, after the fence and recovery) and "devices: ... virtio_net=selftest-ok". # boot 2 no SMMU, same image: virtio-net DMA must be denied (NoSmmu), no # grant, no datagram sent, and the helper must log nothing new. -# Not proven (stated, not hidden): the driver does not negotiate -# VIRTIO_F_ACCESS_PLATFORM and QEMU's virtio-pci then does device DMA without -# the vIOMMU, so the SMMU window is programmed but not enforced by QEMU for -# this device (the kernel prints access_platform=no; this script checks it). +# boot 3 SMMU on, modern-only NIC WITHOUT iommu_platform (QEMU offers no +# ACCESS_PLATFORM and would DMA around the vIOMMU): the driver must +# refuse it before FEATURES_OK ("init FAIL (NoAccessPlatform)"), no +# attach, no datagram, helper logs nothing new, device released. +# Not proven (stated, not hidden): QEMU's smmuv3 and virtio models are not +# hardware; measured on QEMU 8.2.2 the refused DMA does not set NEEDS_RESET (QEMU +# completes the RX through its bounce buffer, write dropped); the kernel +# discards the redirected descriptors and shows recovery by reset + re-init, +# not a device that keeps running through the fault. # Netdev: -netdev user,ipv6=off,restrict=off (AIENOS_NET_RESTRICT overrides). # Measured 2026-10-01 with QEMU on the Spark: AIENOS_NET_RESTRICT=on makes the # gate FAIL (ARP still answers, but the datagram never reaches the helper on @@ -116,7 +134,9 @@ image="${top}/nvme.img" truncate -s "${img_bytes}" "${image}" net_fail=0; m1_fail=0 -# boot [smmu]: one QEMU boot; serial text in ${work}/serial.txt. +# boot [smmu|nosmmu] [nic options]: one QEMU boot; serial text in +# ${work}/serial.txt. The NIC defaults to modern-only behind the vIOMMU. +nic_confined="disable-legacy=on,iommu_platform=on" boot() { work="${top}/$1" mkdir -p "${work}/esp/EFI/BOOT" "${work}/esp/EFI/AIENOS" @@ -136,7 +156,7 @@ boot() { -drive if=none,id=nvme0,format=raw,file="${image}" \ -device nvme,drive=nvme0,serial=aienos-net-test \ -netdev user,id=n0,ipv6=off,restrict="${AIENOS_NET_RESTRICT:-off}" \ - -device virtio-net-pci,netdev=n0,mac=52:54:00:12:34:56 \ + -device "virtio-net-pci,netdev=n0,mac=52:54:00:12:34:56${3+,$3}" \ -device ramfb -display none \ -serial file:"${work}/serial.log" -no-reboot qemu_status=$? @@ -152,14 +172,14 @@ boot() { line_of() { grep -n -- "$1" "${work}/serial.txt" | head -1 | cut -d: -f1; } # ---- boot 1: SMMU present, full round trip ---- -boot net-smmu smmu +boot net-smmu smmu "${nic_confined}" echo "-- (a) attach" check "virtio-net capabilities parsed" "^virtio_net: [0-9a-f:.]* caps ok common=bar" check "SMMU window programmed for the virtio-net DMA region only" \ "^smmu_dma_window: virtio_net only iova=0x[0-9a-f]* len=0x[0-9a-f]* rid=0x[0-9a-f]* stream_id=0x[0-9a-f]*$" check "virtio-net DMA granted only after confinement" "^dma_gate: virtio_net granted (Confined), bus master on$" -check "driver attached, QEMU NIC MAC read from the device, ACCESS_PLATFORM not negotiated" \ - "^virtio_net: attached [0-9a-f:.]* rid=0x[0-9a-f]* qsize=rx[0-9]*/tx[0-9]* mac=52:54:00:12:34:56 features=0x[0-9a-f]* access_platform=no$" +check "driver attached, QEMU NIC MAC read from the device, ACCESS_PLATFORM negotiated (features = VERSION_1|ACCESS_PLATFORM|MAC)" \ + "^virtio_net: attached [0-9a-f:.]* rid=0x[0-9a-f]* qsize=rx[0-9]*/tx[0-9]* mac=52:54:00:12:34:56 features=0x300000020 access_platform=yes$" check "ARP reply from the slirp gateway (52:55:0a:00:02:02)" \ "^net: arp who-has 10.0.2.2 tell 10.0.2.15 -> 52:55:0a:00:02:02 tries=[0-9]*$" echo "-- (b) TX" @@ -190,26 +210,70 @@ else echo "FAIL guest UDP RX line with this run's token and its own nonce"; failed=1 fi check "round trip reported" "^net: udp round trip ok tx_reclaimed=[1-9][0-9]* rx_frames=[1-9][0-9]*$" -check "net selftest PASS" "^net: selftest PASS (rc=0)$" +echo "-- (d) fence: device DMA outside the window" +win_re='^smmu_dma_window: virtio_net only iova=0x([0-9a-f]+) len=0x([0-9a-f]+) rid=0x[0-9a-f]+ stream_id=0x([0-9a-f]+)$' +win_line="$(grep -E "${win_re}" "${work}/serial.txt" | head -1 || true)" +w_lo=""; w_len=""; w_sid="" +if [[ "${win_line}" =~ ${win_re} ]]; then w_lo=$((16#${BASH_REMATCH[1]})); w_len=$((16#${BASH_REMATCH[2]})); w_sid=$((16#${BASH_REMATCH[3]})); fi +probe_re='^net_smmu_negative: rx descriptors redirected=([1-9][0-9]*) to iova=0x([0-9a-f]+) \(outside window 0x[0-9a-f]+\+0x[0-9a-f]+\); probe datagram "(AIENOS-CK-NET ping smmu-probe nonce=[0-9a-f]{8})" tx=Ok$' +probe_line="$(grep -E "${probe_re}" "${work}/serial.txt" | head -1 || true)" +probe="" +if [[ "${probe_line}" =~ ${probe_re} ]]; then + probe="${BASH_REMATCH[3]}" + echo "PASS ${BASH_REMATCH[1]} RX descriptors pointed outside the window, probe datagram sent" +else + echo "FAIL probe line (RX descriptors redirected, probe datagram tx=Ok)"; failed=1 +fi +if [[ -n "${probe}" ]] && grep -qE "^rx from 127\.0\.0\.1:[0-9]+ len=[0-9]+ payload=\"${probe}\"$" "${hlog}" && + grep -A1 -F "payload=\"${probe}\"" "${hlog}" | tail -n +2 | grep -qE "^tx to 127\.0\.0\.1:[0-9]+ len=[0-9]+ reply=[0-9]+$"; then + echo "PASS host helper received the probe and replied (the device had a frame to write)" +else + echo "FAIL host helper did not log the probe datagram and a reply to it"; failed=1 +fi +neg_re='^net_smmu_negative: refused rx dma outside window iova=0x([0-9a-f]+) faults=([1-9][0-9]*) type=0x10 sid=0x([0-9a-f]+) addr=0x([0-9a-f]+) page=intact rx_completed=([0-9]+) device_status=0x([0-9a-f]{2}) needs_reset=(yes|no) faults_during_roundtrip=0 overflow=([01])$' +neg_line="$(grep -E "${neg_re}" "${work}/serial.txt" | head -1 || true)" +if [[ -n "${w_lo}" && "${neg_line}" =~ ${neg_re} ]]; then + c_iova=$((16#${BASH_REMATCH[1]})); e_sid=$((16#${BASH_REMATCH[3]})); e_addr=$((16#${BASH_REMATCH[4]})) + e_rx="${BASH_REMATCH[5]}"; e_status="${BASH_REMATCH[6]}"; e_nr="${BASH_REMATCH[7]}"; e_ovf="${BASH_REMATCH[8]}"; e_n="${BASH_REMATCH[2]}" + if (( (c_iova + 4096 <= w_lo || c_iova >= w_lo + w_len) && e_sid == w_sid && (e_addr & ~4095) == c_iova )); then + echo "PASS SMMU event F_TRANSLATION (0x10) x${e_n} for the NIC's stream 0x${BASH_REMATCH[3]} at 0x${BASH_REMATCH[4]}, in the target page 0x${BASH_REMATCH[1]} outside the window; page intact; positive round trip fault-free (device model reaction, reported not judged: rx_completed=${e_rx} device_status=0x${e_status} needs_reset=${e_nr} event_overflow=${e_ovf})" + else + echo "FAIL event fields do not match the window/stream/page (iova=0x${BASH_REMATCH[1]} sid=0x${BASH_REMATCH[3]} addr=0x${BASH_REMATCH[4]} window=${w_lo}+${w_len} stream=${w_sid})"; failed=1 + fi +else + echo "FAIL SMMU refused-DMA line (F_TRANSLATION for this stream, page intact, fault-free round trip before it)"; failed=1 +fi +echo "-- (e) recovery inside the window" +check "device reset + re-init with ACCESS_PLATFORM after the fault" \ + "^net_smmu_recovery: device reset + reinit ok (Ok) access_platform=yes late_probe_faults=[0-9][0-9]*$" +check "second round trip after the fault, no new SMMU fault" \ + "^net_smmu_recovery: round trip after the fault ok (rc=0 new_faults=0)$" +if [[ "$(grep -cE "^net: udp rx .* echo_of_ours=yes payload=\"AIENOS-CK-NET pong token=${token} echo=AIENOS-CK-NET ping nonce=[0-9a-f]{8}\"$" "${work}/serial.txt" || true)" -ge 2 ]]; then + echo "PASS two helper replies with this run's token parsed (before and after the fault)" +else + echo "FAIL fewer than two parsed helper replies with this run's token"; failed=1 +fi +check "net selftest PASS (round trip, fence and recovery)" "^net: selftest PASS (rc=0)$" echo "-- release" check "device reset before the revoke" "^virtio_net: device reset status=0x00 (stopped)$" check "virtio-net bus master revoked" "^dma_gate: virtio_net bus master revoked$" check "virtio-net SMMU stream returned to abort" "^smmu: virtio_net stream 0x[0-9a-f]* returned to abort (rc=0)$" lg="$(line_of '^dma_gate: virtio_net granted (Confined)')"; lt="$(line_of '^net: udp round trip ok')"; ld="$(line_of '^virtio_net: device reset status=0x00 (stopped)$')" lr="$(line_of '^dma_gate: virtio_net bus master revoked$')"; la="$(line_of '^smmu: virtio_net stream .* returned to abort')" -if [[ -n "${lg}" && -n "${lt}" && -n "${ld}" && -n "${lr}" && -n "${la}" && "${lg}" -lt "${lt}" && "${lt}" -lt "${ld}" && "${ld}" -lt "${lr}" && "${lr}" -lt "${la}" ]]; then - echo "PASS order: grant < round trip < device reset < bus master off < stream abort" +ln="$(line_of '^net_smmu_negative: refused ')"; lv="$(line_of '^net_smmu_recovery: round trip after the fault ok')" +if [[ -n "${lg}" && -n "${lt}" && -n "${ln}" && -n "${lv}" && -n "${ld}" && -n "${lr}" && -n "${la}" && "${lg}" -lt "${lt}" && "${lt}" -lt "${ln}" && "${ln}" -lt "${lv}" && "${lv}" -lt "${ld}" && "${ld}" -lt "${lr}" && "${lr}" -lt "${la}" ]]; then + echo "PASS order: grant < round trip < fault refused < recovery round trip < device reset < bus master off < stream abort" else - echo "FAIL release order (lines ${lg:-none} ${lt:-none} ${ld:-none} ${lr:-none} ${la:-none})"; failed=1 + echo "FAIL order (lines ${lg:-none} ${lt:-none} ${ln:-none} ${lv:-none} ${ld:-none} ${lr:-none} ${la:-none})"; failed=1 fi check "devices stage summary" "^devices: pci=ok nvme=bound virtio_net=selftest-ok$" -check_absent "no virtio-net failure lines" "^net: .*FAIL\|^virtio_net: .*FAIL\|^virtio_net: not bound" +check_absent "no virtio-net failure lines" "^net: .*FAIL\|^net_smmu_[a-z]*: .*FAIL\|^virtio_net: .*FAIL\|^virtio_net: not bound" [[ "${failed}" == 0 ]] || net_fail=1 failed=0 helper_rx_after_boot1="$(grep -c '^rx from ' "${hlog}" || true)" # ---- boot 2: no SMMU, fail closed ---- -boot net-nosmmu +boot net-nosmmu nosmmu "${nic_confined}" check "virtio-net DMA denied without an SMMU" "^dma_gate: virtio_net denied (NoSmmu rc=-1), bus master stays off$" check "virtio-net not bound without an SMMU" "^virtio_net: not bound (SMMU DMA isolation not active)$" check_absent "no virtio-net grant without an SMMU" "dma_gate: virtio_net granted" @@ -221,12 +285,31 @@ else echo "FAIL host helper received traffic during the no-SMMU boot"; failed=1 fi [[ "${failed}" == 0 ]] || net_fail=1 +failed=0 +helper_rx_after_boot2="$(grep -c '^rx from ' "${hlog}" || true)" + +# ---- boot 3: SMMU on, NIC without iommu_platform: refused (fail closed) ---- +boot net-noap smmu "disable-legacy=on" +check "SMMU window programmed (the refusal is the driver's, not the SMMU's)" \ + "^smmu_dma_window: virtio_net only iova=0x[0-9a-f]* len=0x[0-9a-f]* rid=0x[0-9a-f]* stream_id=0x[0-9a-f]*$" +check "driver refuses a NIC that does not offer ACCESS_PLATFORM" "^virtio_net: init FAIL (NoAccessPlatform)$" +check_absent "no attach without ACCESS_PLATFORM" "^virtio_net: attached" +check_absent "no datagram sent without ACCESS_PLATFORM" "^net: udp tx" +check "device released (reset, bus master revoked, stream back to abort)" \ + "^smmu: virtio_net stream 0x[0-9a-f]* returned to abort (rc=0)$" +check "devices stage summary (no ACCESS_PLATFORM)" "virtio_net=selftest-failed$" +if [[ "$(grep -c '^rx from ' "${hlog}" || true)" == "${helper_rx_after_boot2}" ]]; then + echo "PASS host helper saw nothing from the no-ACCESS_PLATFORM boot" +else + echo "FAIL host helper received traffic during the no-ACCESS_PLATFORM boot"; failed=1 +fi +[[ "${failed}" == 0 ]] || net_fail=1 release_flag if [[ "${m1_fail}${net_fail}" != 00 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then for s in "${top}"/*/serial.txt; do echo "---- serial console $(basename "$(dirname "${s}")") (net lines) ----" - grep -E '^(virtio_net|net:|dma_gate: virtio|smmu|devices:|stage |report_kind:)' "${s}" | head -40 || true + grep -E '^(virtio_net|net:|net_smmu|dma_gate: virtio|smmu|devices:|stage |report_kind:)' "${s}" | head -60 || true done echo "---- helper log ----"; head -20 "${hlog}" || true fi ```