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

65 lines · 10384 bytes Raw Blame History Source

D1 - NVMe Controller-State Audit (AIENOS P3 Native NVMe Read Substrate)

Repo: aien-dev/aienux @ baseline ff5de9c Mirror (read-only): ~/aienos-p3 Scope: crates/aienos-kernel/src/nvme.rs, crates/aienos-kernel/src/nvme/driver.rs, crates/aienos-kernel/src/block.rs Reference model: NVMe Base Specification (CAP / VS / CC / CSTS / AQA / ASQ / ACQ register layout; Identify Controller/Namespace layouts).

Status legend:

Register / behavior table

#Assumptionfile:lineWhat the code doesSpec-correct?RiskRecommended minimal fixStatus
164-bit CAP assemblynvme/driver.rs:107Cap((read32(4) as u64) << 32) \| read32(0) as u64Yes - high dword at 0x04, low at 0x00NoneNoneSUPPORTED
2CAP.MQES enforcementnvme.rs:37-39; driver.rs:115-118, 174-196MQES decoded (mqes()) but never compared to ADMIN_DEPTH (8) or caller I/O depth; AQA/QSIZE written unconditionallyOnly if depth-1 <= MQESA spec-legal controller with small MQES gets an out-of-range AQA/QSIZE → command abort / undefined behaviorReject at init if ADMIN_DEPTH > cap.mqes(), and in create_io_queues if depth > cap.mqes()UNSAFE-IF-DEVIATES
3CAP.TO units (500 ms)nvme.rs:40-42; driver.rs:108timeout_ms = cap.timeout_units().max(1) * 500Yes - TO is bits 31:24 in 500 ms units; TO==0 treated as 500 ms defaultNone material; TO=0 means "not reported", a host default is reasonableNoneSUPPORTED
4CAP.DSTRD / doorbell mathnvme.rs:31-36, 45-47stride = 4 << DSTRD; offset = 0x1000 + (2*qid + completion)*strideYes - SQqTDBL at 0x1000+2q·stride, CQqHDBL at +1·strideu32 math can overflow only for absurd qid·stride; no real pathOptionally use u64 in doorbell_offsetSUPPORTED
5CAP.MPSMIN / CAP.MPSMAX / MPSnvme.rs:27-43; driver.rs:12,43,123MPSMIN/MPSMAX never read; CC.MPS=0 (4 KiB) and PAGE_SIZE=4096 hard-codedNo - if CAP.MPSMIN>0 the controller requires MPS ≥ 2^(12+MPSMIN); programming MPS=0 is illegalHigh: on a controller with MPSMIN>0 the enable sequence is non-conformant and ASQ/ACQ/PRP alignments are wrongExtract MPSMIN ((cap>>48)&0xff) / MPSMAX; require MPSMIN==0 else program the correct MPS and align to 2^(12+MPSMIN)UNSUPPORTED
6CAP.CSS / CC.CSSdriver.rs:42,123CC.CSS=0 (NVM) hard-coded; CAP.CSS never checkedOnly if NVM command set supported (CAP.CSS bit 0)Low on real NVMe drives; non-conformant on a device not advertising NVM CSSRead CAP.CSS (bits 52:45); fail init if bit 0 clearUNSUPPORTED
7CAP.AMS / CC.AMSdriver.rs:42,123CC.AMS=0 (Round Robin) hard-coded; CAP.AMS never checkedRound Robin is the base mechanism, but not validatedLowRead CAP.AMS (bits 18:17); assert bit 0 set or select a supported mechanismUNSAFE-IF-DEVIATES
8VS (0x08) read/validatednvme.rs:9 (constant only)REG_VS defined; never read. No version gateBase register model compatible across 1.x/2.x; reading VS is not required to initLow / informational; a future major-version incompatibility goes undetectedOptionally read VS, log/reject unsupported majorUNSUPPORTED
9CC reset → configure → enable orderdriver.rs:109-125Clear CC.EN, wait RDY=0, program AQA/ASQ/ACQ, write CC(EN=1), wait RDY=1Yes - admin queues programmed before EN; correct sequencingNoneNoneSUPPORTED
10CSTS.CFS handlingnvme.rs:70-72; driver.rs:32-34Any poll that sees CFS returns Failed immediatelyYes - CFS = fatal controller statusNoneNoneSUPPORTED
11CSTS.SHST-Never readNot required for bring-upNoneNoneSUPPORTED
12Readiness poll bound / off-by-onedriver.rs:30-39for _ in 0..=timeout_ms { read; if ready return; delay(1ms) }Bounded, but delays once after the final read → total (TO+1)*1msTrivial extra ms past CAP.TOfor _ in 0..timeout_ms (or check-after-delay)UNSAFE-IF-DEVIATES
13AQA field packingdriver.rs:115-118((DEPTH-1)<<16) \| (DEPTH-1) = 0x0007_0007Yes - ASQS bits 11:0, ACQS bits 27:16Field width not masked; only safe because DEPTH=8Mask with 0xfff / 0xfff<<16 if depth ever exceeds 4096SUPPORTED (conditional on #2)
14ASQ/ACQ 64-bit writesdriver.rs:119-122Low dword at 0x28/0x30, high dword at +4; before ENYesNoneNoneSUPPORTED
15ASQ/ACQ alignmentdriver.rs:112-114Allocated with alignment PAGE_SIZE (4 KiB)Only if MPSMIN=0; spec requires alignment to min memory page size 2^(12+MPSMIN)Tied to finding #5Align ASQ/ACQ (and all DMA used in PRPs) to 2^(12+MPSMIN)UNSAFE-IF-DEVIATES
16Queue entry sizes 64/16, PAGE=4096nvme.rs:81,159; driver.rs:12,44-45,123CC.IOSQES=6→64 B, CC.IOCQES=4→16 B; matching buffersYes for SQ/CQ sizes; MPS assumption is #5SQ/CQ sizes correct; page size tied to #5None beyond #5SUPPORTED
17Admin completion poll bounddriver.rs:15,222,228Fixed ADMIN_TIMEOUT_MS=1000 × 1 ms, independent of CAP.TOBounded; CAP.TO governs readiness but not command waitA slow but conformant admin command could exceed 1 sDerive from CAP.TO (e.g. cap.timeout_units()*500)SUPPORTED (note)
18I/O completion poll bounddriver.rs:362,369for _ in 0..=1000 with 1 ms delayBounded; fixed policySame as #17Make configurable / CAP.TO-derivedSUPPORTED (note)
19MDTS handlingdriver.rs:150,291-302MDTS byte 77; limit = (PAGE_SIZE<<MDTS).min(128KiB), MDTS=0 → 128 KiBUnits under-stated if MPSMIN>0 (safe: more splitting); MDTS=0 self-capped (safe)Conservative in the safe direction; no overflowUse 2^(12+MPSMIN) as the MDTS unit; keep the 128 KiB self-capSUPPORTED (conservative)
20Identify Controller MDTS offsetdriver.rs:150bytes[77]Yes - MDTS at byte 77NoneNoneSUPPORTED
21Identify Namespace block countdriver.rs:156NSZE = u64 le bytes[0..8]Yes - NSZE bytes 0-7None (uses NSZE not NCAP; correct as last-address + 1)NoneSUPPORTED
22FLBAS indexdriver.rs:157bytes[26] & 0x0fYes - FLBAS byte 26, low 4 bits = format indexNoneNoneSUPPORTED
23LBA format descriptordriver.rs:158-159descriptor = 128 + flbas*4; lbads = bytes[descriptor+2]Yes - LBAF array at 128, LBADS at +2NoneNoneSUPPORTED
24LBADS lower bounddriver.rs:162Rejects only lbads >= 32; accepts lbads 0..8No - valid LBA data sizes are 2^9…2^31 (LBADS 9..31)A malformed identify yields a 1-byte block size and a huge block_count; silent miscomputeRequire 9 <= lbads < 32UNSUPPORTED
25Command layoutsnvme.rs:96-156Identify CDW10=CNS, NSID=CDW1; R/W opcodes 0x02/0x01, NLB-1 in CDW12, LBA in CDW10-11, PRP1/2 in DW6-9YesNoneNoneSUPPORTED
26CID handlingdriver.rs:212,353CID in CDW0 bits 31:16, low 16 preserved; wrapped modulo 16 bitsYesNoneNoneSUPPORTED
27Completion status decodenvme.rs:173-175; driver.rs:234-239status>>1, SCT=(status>>8)&7, SC=status&0xff; phase=bit0YesNone (More/DNR bits not inspected)Optionally surface More/DNRSUPPORTED
28Phase trackingnvme.rs:219-254; driver.rs:136,227,368CQ consumer starts phase=1, toggles on ring wrapYesNoneNoneSUPPORTED
29Hard-coded NSID 1driver.rs:145,150,156, 184-185, 333-335, 419All identify/read/write/flush use namespace 1Assumes NSID 1 exists and is the targetMedium: a controller whose active namespace is not 1 (or multi-namespace) fails or targets the wrong storeEnumerate active NSIDs (Identify CNS=2) and use the discovered NSIDUNSUPPORTED
30Queue-create CDW11 (PC/IEN/CQID)nvme.rs:106-127CQ: CDW11=1 (PC=1, IEN=0, IV=0); SQ: CDW11=1\|(cqid<<16)YesNoneNoneSUPPORTED
31CQ head doorbell after consumedriver.rs:246-249,380-381Advances cq_head, writes CQqHDBLYesNoneNoneSUPPORTED
32Completion SQID not checkeddriver.rs:231,372Only command_id matched; SQID ignoredSpec requires matching SQID+CIDLow robustness; a stale/misrouted completion could be acceptedAlso compare completion.sq_id() (0 admin / 1 I/O)UNSAFE-IF-DEVIATES
33Flush commanddriver.rs:415-422Opcode 0, NSID 1, via I/O queueYes (aside from NSID assumption #29)Tied to #29NoneSUPPORTED
34PRP list capacitydriver.rs:314-331; nvme.rs:258-303One 4 KiB list page allocated when len/PAGE > 2; max chunk 128 KiB ⇒ ≤512 entriesYes for the self-imposed 128 KiB capNoneNoneSUPPORTED
35DMA 64-bit address widthdriver.rs:119-122, nvme.rs:90-91Always writes full 64-bit PRP/ASQ/ACQ addressesYes for 64-bit-capable controllers; no checkLow; base NVMe ASQ/ACQ are 64-bit by definitionNoneSUPPORTED

Summary of non-SUPPORTED items

FindingStatusSeverity
CAP.MPSMIN/MPSMAX ignored; MPS + PAGE_SIZE + ASQ/ACQ alignment hard-coded to 4 KiBUNSUPPORTEDHigh
CAP.MQES not enforced for admin/I/O queue depthsUNSAFE-IF-DEVIATESHigh
CAP.CSS not validated; CC.CSS hard-coded NVMUNSUPPORTEDMedium
Hard-coded NSID 1 (no active-namespace enumeration)UNSUPPORTEDMedium
LBADS lower bound not validated (accepts 0..8)UNSUPPORTEDMedium
CAP.AMS not validated; CC.AMS hard-coded Round RobinUNSAFE-IF-DEVIATESLow
Readiness poll delays once after the final read (off-by-one vs CAP.TO)UNSAFE-IF-DEVIATESLow
Completion SQID not verified against expected queueUNSAFE-IF-DEVIATESLow
VS (0x08) never read/validatedUNSUPPORTEDInformational