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_FLUSH_REVIEW.md

128 lines · 7387 bytes Raw Blame History Source

D2 Flush Review - AIENOS P3 NVMe Flush lane

Base: aien-dev/aienux @ ef359ec (read-only mirror ~/aienos-nvme-rw). Files read in full: crates/aienos-kernel/src/nvme.rs, crates/aienos-kernel/src/nvme/driver.rs, crates/aienos-kernel/src/block.rs. Companion tests: nvme-rw-subagents/d2/nvme_flush.rs (target crates/aienos-kernel/tests/nvme_flush.rs).

1. Is flush() a correct NVMe Flush command?

Implementation (driver.rs:432 - 439) builds a zeroed Submission, sets CDW0 opcode = 0 and CDW1 NSID = 1, then hands it to submit_io (driver.rs:364 - 406).

Verdict: the command layout and completion handling are a correct NVMe Flush.

2. Are BlockDevice::flush semantics honest?

BlockDevice (block.rs:11 - 17) declares flush(&mut self) -> Result<(), BlockError> with no documented durability contract. Two implementors differ sharply:

Additional honesty concerns:

3. What does QEMU's emulated NVMe do with Flush?

QEMU does not ignore it. In hw/nvme/ctrl.c (upstream, v1.4-capable):

So a successful Flush completion in QEMU means the flush reached the block backend and the backend reported success. Whether that persists to the host file depends on the drive's cache mode:

Net: emulated Flush is real and reaches the backend; host-level durability is only as strong as the drive's cache configuration. The AIENOS driver correctly treats a nonzero completion as failure.

4. Flush must not be faked as a no-op

A silent flush() -> Ok(()) in a real NVMe driver is a durability bug: it reports success without ever telling the controller to commit its volatile write cache, so a power loss can lose acknowledged writes. The current NvmeController::flush avoids this by issuing opcode 0x00 and requiring a zero-status completion. The tests in nvme_flush.rs enforce this directly: they assert an I/O SQ doorbell write occurs, that the parsed command reaches the simulator, that a nonzero status yields DeviceError, and that a missing completion yields Timeout - i.e. flush can never silently succeed. The RamDisk no-op is acceptable only because RAM is inherently volatile and must never be treated as the pattern for a persistent device.

NEEDS-FIX / observations

  1. Hardcoded NSID 1 (driver.rs:437). flush() should target the active namespace ID (or support NVME_NSID_BROADCAST like QEMU) rather than a literal 1, or the trait should document the single-namespace restriction. Currently consistent only because the driver identifies/uses NSID 1 exclusively.
  2. No durability contract on BlockDevice::flush (block.rs:11 - 17). Document that flush is a cache-commit barrier, that write_blocks is not implicitly durable, and that RamDisk::flush is a deliberate no-op with no persistence claim.
  3. write_blocks has no FUA path (driver.rs:349 - 353). Either document that callers must flush() for durability or add an FUA option for single-write durability.
  4. Flush uses the same 1001×1 ms poll budget as data I/O (driver.rs:379). Real media flushes can take longer; consider a dedicated (longer) flush budget.
  5. Status detail is lost (driver.rs:399 - 403). DeviceError discards DNR/SCT/SC; acceptable for the coarse enum but consider preserving it for diagnostics.
  6. No regression test in-repo yet. nvme_flush.rs should be dropped into crates/aienos-kernel/tests/ and run with cargo test -p aienos-kernel (not run here per constraints).

Test coverage added (nvme_flush.rs)