mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
Isolated kernel validation of OS adapters Run make test-vm-adapters on this workstation. It builds a guest-only test module from the production PCI, DMA and IRQ C sources, creates a minimal BusyBox initramfs and boots the installed Linux kernel in QEMU/KVM. The test module is admitted only to QEMU's EDU device (1234:11e8). No host GPU or PCI device is passed through. The production build's NVIDIA admission predicate is not replaced: NV_RS_PCI_TEST_EDU exists only in this guest test build. The guest verifies BAR MMIO, coherent allocation and a 64-byte DMA round trip, MSI and shared INTx delivery, interrupt acknowledgement and clean unload. A second boot enables an emulated Intel IOMMU and requires a DMA-translating Linux domain for both IRQ tests. Interrupt remapping is disabled in that scenario, so it is not covered. MSI-X is covered by mocked adapter tests only; the EDU device does not provide the production GPU's MSI-X layout. Definitions: https://www.qemu.org/docs/master/specs/edu.html The installed QEMU version and its -device help are authoritative for local configuration. Guest sources check actual results; kernel panic or absence of success/unload markers is a failed run. The runner also checks QEMU's exit status and records hashes of the kernel, initramfs and module inputs. Results are reports/vm-adapter-validation.json and reports/vm-adapter-iommu-validation.json, with complete serial logs. The guest also runs the actual Rust LinuxDma, unpublished page-table and coherent instance backing, GPU lifetime and SystemMemory preparation paths. Synthetic V100 metadata admits the EDU-backed lifetime fixture; no NVIDIA register access or engine initialization is exercised. Prepared GPU state continues to reject SystemMemory allocation as unready. Removal is tested with an outstanding external GPU lease and SystemMemory owner. After owners drain, an injected one-time DMA-context close failure must retain the final cleanup reference and schedule a delayed retry. Queue destruction begins before waiting for that retry, exercising the production teardown wait and clean module unload. This finite fault does not establish recovery from permanent failure or physical GPU removal. The runner requires exactly131 distinct assertions (38 probe, twice11 transfer,71 GPU lifetime), at least35 Rust checks,11 register-owner checks, 22 operation-mutex checks, 9 process-context OS-service checks,12 owned-thread-state checks, and at least8 hard-IRQ OS-service checks, one cleanup retry, the expected DMA domain, both IRQ modes and clean unload. It also requires16 prepared-GPU registry checks and1 separate cleanup retry for a failed duplicate probe. The duplicate caller holds its own PCI reference; that reference remains usable after failure. Registry retirement rejects stale keys before releasing the driver base, while existing leases remain valid for cleanup. Publication alone does not establish hardware readiness. Every DMA-status polling read is still checked, but the variable iteration count is reported separately as dma_poll_reads (minimum2). Earlier raw check counts included repeated polling and therefore were scheduling-dependent. tests/vm/test_result_gate.py mutates saved observations to ensure missing retry, incomplete checks, a false parity claim or missing unload fails. The owned Rust register backend writes/reads only EDU's documented inversion register. GPU removal rejects its reads/writes even before the C PCI removal mark. It then retains GPU/PCI/module lifetime after other owners drop, and the final register-owner drop triggers the deliberately failed cleanup/retry. This uses synthetic V100 admission metadata, not physical NVIDIA registers. The operation-mutex fixture holds LockedGpuRegisters on the probe task while a kthread begins removal. It requires an observed mutex waiter and incomplete removal, verifies GPU removal rejects new and existing Rust access while C PCI access remains live, then drops the guard on its acquiring task. The worker finishes PCI removal and is joined before its stack context is released. An acquisition with IRQs disabled must fail before attempting the held mutex. A separate acquisition task is queued first while the holder is active; the fixture observes one waiter before starting removal and two afterwards. When the holder unlocks, that pre-existing acquisition must reject removed state after its lock wait. Both tasks receive references before wakeup and are joined before the fixture releases their stack contexts. Guards remain task-local. This proves this bounded lock/drain sequence, not the original RM lock hierarchy or hardware engine quiescence. Nonblocking context diagnostics do not replace the caller's sleepable-context and lock-order obligations. These tests establish emulated OS-adapter and Rust ownership behavior, not NVIDIA register, engine, firmware, CUDA, or full hardware parity. The owned ordinary-thread registry fixture uses the actual Linux allocation, retained task/module and IRQ-saving spinlock adapters. It checks duplicate registration, registered timeout access and FIFO callback cleanup before module unload. Its timeout database is explicit fixture configuration, not an invented production RM global. Registry ISR routing and GPU deferred work are not covered. The ninth process OS-service check calls the actual Linux wall-clock adapter, validating a nonzero current seconds sample and canonical microseconds. The exact seconds-wrap/usecond-truncation policy is separately compared against compiled unchanged shipped Linux source. No PTIMER initialization registers are written on EDU; the selected init backend uses MMIO/clock recorder leaves in its owned GPU host fixture. Physical timer programming remains untested. Firmware-copy Linux validation The guest compiles the actual SYS firmware-copy adapter and uses real buddy allocations, set_memory_uc/wb, PFN enumeration, direct-map PTE observation, and streaming DMA. Each IRQ/IOMMU mode requires947 firmware predicates: 133 UC and2 cached allocation-page observations,135 WB-before-free page observations, one deliberately failed WB call with retained UC pages/retry, and retained-resource cleanup after logical PCI removal. These are page observations, not counts of distinct reused PFNs. Device DMA reads all12305 source bytes through an independent coherent return buffer, using interior 2KiB EDU scratch transfers (QEMU6.2 rejects a full4096-byte end boundary). The512KiB UC case additionally checks64KiB DMA alignment. Test-only hooks return raw PTE/PFN facts and observe WB immediately before physical free; the production module contains none of those hooks. Initial crashed full- scratch attempts remain archived in reports/rom-fw-first-window*-serial.log. Guest PFN/PTE facts do not establish host-physical contiguity, effective MTRR cache policy, forced SWIOTLB target backing or physical NVIDIA support. Removal is a logical adapter mark with the PCI device still present; physical PCI hot-unplug/IOMMU detach remains untested. The unsafe FW close contract requires actual device-consumer quiescence before unmap/free. The fault shared-word fixture runs45 separate predicates per guest mode. EDU writes a32-byte packet into real coherent DMA memory: payload first, then the valid header word in a separate completed DMA command. The actual production read-word API observes invalid/valid, then reads every word after dma_rmb. The write-word API clears every packet word before dma_wmb, and EDU reads the entire cleared packet back into a separate range for comparison. Alignment, bounds, overflow and stale mapping identities reject access. Logical PCI removal then rejects word accesses while explicit unmap/free/close succeeds. Retained memory has no active producer before removal. These are actual Linux primitives and emulated device DMA, not a physical NVIDIA fault producer or a full guest run of the Rust LinuxFaultRing/backend-to-IRQ integration. The latter has separate actual Rust/C host fixtures with mocked OS allocation and register ownership. The nano-timer test executes actual Rust-owned Linux CLOCK_MONOTONIC relative hrtimers. All four guest modes require29 timer predicates. IRQ-disabled start, pending cancellation, real IRQ callback delivery, idempotent cancel, rejected IRQ-disabled close, retained callback storage and subsequent close are checked. A second timer survives logical GPU/PCI removal and the release of every other external GPU lease. Cleanup retry cannot begin until that timer is canceled and closed; its callback is destroyed before the payload allocation and GPU/module pin release. The existing delayed-cleanup retry must then run and join before module unload. Callback payloads are synthetic atomic counters. RM ISR registration, deferred work, event lists and StateLoad are not implemented by this fixture. No active NVIDIA timer or other physical GPU register is programmed. Cancel-during-a-blocked-callback stress remains additional validation work. The CPU-only ROM storage fixture allocates524289 bytes through the actual Linux kvzalloc/kvfree adapter, verifies every byte was zero, and traverses the full allocation with volatile pattern writes/reads. Zero and above-U32-size requests reject before allocation. Five predicates per guest mode establish this size boundary for CPU storage; they do not change PROM acquisition or physically contiguous firmware DMA bounds. The registry predicates also compare captured Linux PCI domain/bus/slot/function and VF status to the actual guest PCI device, and check the original32-bit GPU ID encoding. This identifier is separate from private keys and RM instances. The native memory fixture adds24 checks using actual coherent Linux DMA: seven SYS pages, GV100 page tables and instance backing, shader/CB0/GPFIFO readback, freeze pins, refusal to free frozen backing and explicit unpublished quiescence before cleanup. All four IRQ/IOMMU variants pass. The GV100 probe identity is synthetic on EDU; no root, channel or runlist is installed in hardware and no shader executes. See reports/native-memory-vm-validation.json.