interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / docs / P3_NVME_WRITE_DMA_REVIEW.md

221 lines · 11646 bytes Raw Blame History Source

D6 - SMMU / DMA review: P3 Native NVMe Write + Flush lane

Repo: aien-dev/aienux, base ef359ec (mirror ~/aienos-nvme-rw). Scope: read-only review of the DMA/SMMU authority that a future write+flush lane would inherit from the existing read substrate. No edits, no cargo, no hardware.

Verdict up front: the read lane already establishes a single, confined DMA authority. Because write and read share the same driver transfer() and the same NativeDma/DmaMemory implementation, a write lane that reuses the existing module inherits that authority unchanged. There is **no write lane in this tree yet** (crates/aienos-kernel/src/nvme/ contains only driver.rs; no nvme_write.rs), so the lane must be added without introducing a second window, a second SMMU policy, or a second BME toggle.


1. Write DMA uses the SAME confined authority as read DMA

1.1 One static arena window for both directions

1.2 Same dma_gate decision for the whole phase

1.3 Same allocator and same DmaMemory path

Confirmed: one window, one SMMU policy, one gate decision, one allocator. No separate or widened window for writes.


2. No unconstrained bus mastering

Confirmed: BME set only after dma_grant Ok; revoked after the phase.


3. Unsafe QEMU bypass cannot enter a hardware-staging image

Confirmed: unbuildable with hardware-staging; banner on every boot; loud warning when active.


4. Cache maintenance on the write path

CPU-writes-cleaned-to-device and device-writes-invalidated-before-CPU-read are both present, and both are issued with a trailing dsb.

Confirmed: correct direction of maintenance for write (clean) and read (clean+invalidate), each fenced with dsb.


5. Gaps / risks specific to the write+flush lane

  1. No write lane exists. nvme_read.rs is explicitly read-only and claims no write/flush (nvme_read.rs:9-11). The lane must add a new module/feature (e.g. nvme-write) and QEMU harness; it must not simply call write_blocks from the read qualification path without its own evidence gates. driver.rs already implements write_blocks/flush, so the driver side is ready.
  2. Arena exhaustion (functional, fail-closed). NativeDma never frees (nvme_read.rs:269-305), and transfer's MDTS chunk cap is 128 KiB (driver.rs:308-316) - exactly ARENA_BYTES (nvme_read.rs:43). Admin queues + identify + I/O queues already consume part of the arena (driver.rs:125-127,196-200), so a maximum-size transfer cannot fit. The write lane must bound per-command chunk size well below the arena (or add arena reuse/free), otherwise writes fail with NvmeError::Dma. Fail-closed, but it caps the lane's usefulness and must be an explicit, tested limit.

  3. BME is not revoked on a panic/fault during the phase. Revocation happens only on the enumerated normal/error returns (nvme_read.rs:473,499,566). fatal_report resets without clearing BME (handoff.rs:1571+), so a fault mid-write leaves BME set until the cold reset. The write lane should clear BME in the fault path (or explicitly accept reset as the only containment).

  4. Flush has no durable evidence yet. flush() submits opcode 0 with cdw10=1 through submit_io (driver.rs:432-439), which only distinguishes Ok/DeviceError (driver.rs:399-403). The lane must emit a distinct NVME_FLUSH_* evidence line and must only claim durability after a successful flush completion; it should also record that all prior writes were submitted serially (they are: each submit_io waits for completion - driver.rs:379-404).

  5. Namespace bounds are enforced before any command (driver.rs:301-307, OutOfRange), so a write cannot escape the namespace. Keep this invariant: do not add a raw command path that bypasses transfer.

  6. Cache-maintenance caveat. The maintenance is unconditional. If the arena mapping were ever Device-nGnRnE rather than Normal memory, dc cvac/civac semantics would be wrong. Today the arena is Normal identity-mapped (handoff.rs:266-270 comment; map_plan identity path). The lane must not change the arena mapping attributes.

Invariants the write+flush lane MUST preserve


Evidence index (file:line)

ClaimEvidence
Single arenanvme_read.rs:43,45-48,75-78
Single SMMU windowhandoff.rs:305,317-327; smmu.rs:713-717,739-746
Single gate decisionnvme_read.rs:413-429; dma_gate.rs:68-82,279-282
BME off before setupnvme_read.rs:201-210; handoff.rs:1790
BME set only after grantnvme_read.rs:409-412,460
BME revokednvme_read.rs:232-247,473,499,566
Bypass compile guardlib.rs:26-33 (and :12-19)
Bypass bannernvme_read.rs:33-36,379-381,443-450
Cache write/readnvme_read.rs:307-324,326-339; arch/aarch64.rs:270-289,291-301
Write/flush driverdriver.rs:293-362,428-439; tests :917-977
No write lane yetnvme_read.rs:9-11; nvme/ contains only driver.rs