Cluster 2 (RMAPI/UVM/Locking/Memory P0s):
- Convert runtime_start_users to atomic_t so wait_event() in
nv_rs_rmapi_node_gpu_remove never calls mutex_lock while !TASK_RUNNING.
- Guard all 6 unlocked nv_rs_alloc_reg_find() call sites in rmapi_node.c with
nv_rs_rmapi_alloc_lock.
- Run nv_rs_rmapi_rc_recover_fault while nv_rs_rmapi_lock is held from
nv_rs_rmapi_node_trylock() in nv_rs_uvm_fault_work_fn (no blocking re-lock).
- Filter MANAGED_RANGES and PAGE_TREES by UvmFile owner in uvm_node.rs to
prevent cross-process managed_unmap UAF; use flush_gpu_tlb_trylock() +
TLB_FLUSH_PENDING deferral so .mmap/vm_ops->close never touch LIVE_ENGINES
without nv_rs_rmapi_lock.
- Pin FD-exported memory backings in memory::Table::export_pins and check via
shared backing_shares_resource() so export -> free original -> import never
UAFs; release orphaned backings on FD owner close.
- Fix Backing::System map_protection(flags), deduplicate video_allocated_bytes,
and unmap Backing::Register in drop_mappings.
Cluster 4 (Kernel Build Hygiene & Linux 5.15-7.3 Compat P0s):
- Factor shared kernel-open/compat_probes.mk for Kbuild + build_guest_test.sh
(fixing Linux 5.15 char *date probe and Linux 7.0+ guest_build).
- Extend tools/prepare_kernel_archive.py to strip all kernel-exported
compiler_builtins mem/string members (strlen/memcpy/memmove/memset/memcmp/bcmp)
and wire it into tools/vm/build_guest_test.sh.
- Fix tools/check_kernel_module.py no_unhardened_sls_return to check per-ret
int3 succession instead of file-wide has_int3.
- Set AR=llvm-ar / NM=llvm-nm under LLVM=1 in utils.mk, LC_ALL=C and non-rustup
fallback in verify_rust_guest.py/check_native_codegen.py, and 1024 MiB guest RAM.
Validated: cargo fmt/clippy/test (958+2), test_gate_cases.py (24/24),
test_kernel_archive.py (5/5), NV_RS_KERNEL_IBT=0 & 1 make modules +
check_kernel_module.py (largest_stack=1000), QEMU EDU verify_rust_guest.py.
nv_rs_uvm_ioctl() and nv_rs_uvm_release() took nv_rs_uvm_lock and then
nv_rs_rmapi_lock. Two other orders already exist:
rmapi -> mmap_lock nv_rs_rmapi_os_lock_user_pages() calls
pin_user_pages_fast() with the RM API lock held
(NV01_MEMORY_SYSTEM_OS_DESCRIPTOR, cudaHostRegister)
mmap_lock -> uvm the kernel calls nv_rs_uvm_mmap() and
nv_rs_uvm_vma_close() with mmap_lock held
so uvm -> rmapi closes a cycle. lockdep reports it as soon as a CUDA
process pins host memory while another thread mmaps the UVM node, and a
multi-threaded process can really deadlock on it:
WARNING: possible circular locking dependency detected
cuda_dmabuf_exp/4377 is trying to acquire lock:
(&mm->mmap_lock){++++}-{4:4}, at: gup_fast_fallback+0x51f/0x2bc0
but task is already holding lock:
(nv_rs_rmapi_lock){+.+.}-{4:4}, at: nv_rs_rmapi_ioctl+0x64c/0x2f50
Chain exists of:
&mm->mmap_lock --> nv_rs_uvm_lock --> nv_rs_rmapi_lock
Take the RM API lock first in both places. Nothing under the RM API lock
takes the UVM lock (only the UVM file operations and module init/exit
do), so the order is now rmapi -> mmap_lock -> uvm everywhere. The fault
worker only trylocks, so it could not deadlock, but it now tries the two
locks in the same order as well.
The other way out would be to pin the pages before taking the RM API
lock in the OS-descriptor path; this keeps the change local to the UVM
node.
Observed on an RTX 3050 Laptop (GA107) under a lockdep kernel
(7.4.0-rc2) running a CUDA dma-buf test.
The C port (ga102_gsp.c, ga102_rm.c, ga102_glue.c) is replaced by Rust under src/nvidia/ with a thin MIT C adapter:
- src/nvidia/src/gpu/ga10x_gsp.rs (core, no unsafe): VBIOS / FWSEC / Booter parsing with every offset
bounds-checked, signature choice from the fuse version, FWSEC DMEM patch (FRTS, SB), FB and WPR2 layout, radix3,
LibOS arguments, queue headers, element framing and checksum, system info, registry, static info. Unit tests use
the 3090's numbers.
- src/nvidia/src/gpu/gsp_ucode.rs: GA10x bootloader and Booter Load/Unload from NVIDIA's MIT bindata at 580.178.04
(licenses/gsp-rm-boot-ga102-mit.txt).
- src/nvidia/kernel/ga10x_gsp.rs: the live boot (FWSEC-FRTS, Booter Load, RISC-V bootloader, LibOS, CPU sequencer,
INIT_DONE), the RPC transport on GSP-RM's shared-memory queues, and the unload (UNLOADING_GUEST_DRIVER,
FWSEC-SB, Booter Unload; falcons reset before any DMA memory is freed).
- src/nvidia/kernel/ga10x.rs: per-GPU state and RM RPCs. The slot table publishes a GPU with a release store only
after every field is written (FREE -> BOOTING -> ACTIVE -> ENDING); readers acquire; a second boot of the same
GPU backs off. This replaces install_external_session and its publication race.
- src/nvidia/kernel/ga10x_mem.rs, ga10x_objects.rs: the kernel side of split RM (heap split, BAR1 1:1, VA spaces,
TSG, ctxshare, channel, golden context, work submit token, time correlation).
- src/nvidia/kernel/ga10x_events.rs: RM events through irq_adapter (GA10x MSI; GV100 chained around
LIVE_IRQ_OPS), posted from the IRQ thread.
- src/nvidia/kernel/gsp_route.rs: routing of the client's RM calls, with NVIDIA's control flags enforced (INTERNAL
refused, PRIVILEGED needs admin, kernel-only refused, parameter size, owner).
- kernel-open/nvidia/ga10x_adapter.c: log lines, sleep, PCI info and config, BAR0 fill, CPU clocks, credentials,
three module parameters: ga10x_gsp (default 1; 0 leaves GA10x to gsp_bringup's own path), ga10x_events,
gsp_route_trace.
rmapi/gpu.rs: the usermode window (0xc561) is allowed on GA10x too; c9c4706 allowed the class but not the window.
Tested on an RTX 3090 + V100: CUDA on both, P2P both ways, NCCL all_reduce over P2P, blocking sync through RM
events, NVIDIA's 580 back after every unload, 0 Xid.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add root LICENSE (MIT License, Copyright (c) 2026 QuixiAI / Eric Hartford).
- Set license = "MIT" in workspace Cargo.toml and member crates (zero non-MIT dependencies).
- Update all kernel-open/ and tests/vm/ SPDX headers to MIT and EXPORT_SYMBOL_GPL -> EXPORT_SYMBOL.
- Use MODULE_LICENSE("Dual MIT/GPL") in Linux .ko modules so Linux modpost permits linking against the kernel's own EXPORT_SYMBOL_GPL symbols while keeping the repository source 100% MIT.
Closes#12.
Cherry-picked and adapted from PR #9 onto master:
- RHEL 9.8+ backport guards: #ifndef PCI_IRQ_INTX in irq_adapter.c, RHEL_RELEASE_CODE in vm_flags_set/clear (rmapi_node.c, uvm_node.c) and DMA_BUF namespace import (dmabuf_p2p.c). (nano_timer_adapter.c container_of() and rom_fw_adapter.c MAX_PAGE_ORDER were already landed on master.)
- install.sh: install extracted target/firmware/nvidia-rs/*/*.fw packs into /lib/firmware before depmod.
- contrib/rhel-5.14-boot/: boot persistence setup for RHEL 9 (modprobe/dracut/udev/systemd/nodes.sh), with empty-vs-wildcard pci_target guard in nodes.sh.
- driver_version= module parameter (default 580.178.04): overrides /proc/driver/nvidia/version, NV_ESC_CHECK_VERSION_STR, and RM 0x101/0x13e identity replies at load time so hosts running newer 580.x userspace (e.g. driver_version=580.196.07) work without breaking 580.178.04 parity.
Co-authored-by: Gaël STEPHAN <gstephan@wyplay.com>
Recheck that the GPU device is still live under nv_rs_rmapi_alloc_lock before inserting a new DMA record in nv_rs_rmapi_os_page_dma(), and hold a struct page reference across each cached UVM CPU-to-DMA mapping until after dma_unmap_page() completes.
Require CAP_SYS_ADMIN for NV_RS_ESC_EXPORT_TO_DMABUF_FD now that RMAPI nodes are 0666, unmap retained RMAPI and UVM DMA mappings in nv_rs_rmapi_node_gpu_remove() before PCI teardown, bump the nv_vma_start_write() guard to Linux 6.4+ (6.3 doesn't have vma_start_write), and switch bind_dev_nodes.sh from lsmod|grep to /sys/module checks so pipefail SIGPIPE can't bypass the stock-driver guard.
Route the 47-bit DMA mask negotiation in rmapi_node.c and uvm_node.c through nv_rs_pci_negotiate_dma() under p->access so active DMA leases and dma_bits stay consistent. Also require the faulting GPU's own page tree to map before returning Mapped in ManagedFaultMapper, and keep set_gpu_pma_base() monotonic on re-registration.
btop queries nvmlDeviceGetPowerManagementLimit, which hits RM control 0x2080a61d and was falling through to NOT_SUPPORTED. Wire it up next to 0x2080a61f to return the 300W limit.
Also switch the RMAPI and UVM misc devices to mode 0666 (matching stock /dev/nvidia*) and add a small bind-mount helper (wired optionally via BIND_DEV_NODES=1 in install.sh) so tools like btop, nvidia-smi, and non-root services can use nvidia_rs directly without a mount namespace.
Tested on 4x Tesla V100-SXM2-16GB (Dell PowerEdge C4130) running Ubuntu
7.0.0-44-generic with Intel VT-d enabled (no iommu=pt).
Fixes#2 and a few other things that showed up once 16GB cards came up:
- Derive the GV100 runtime VRAM window, RMAPI VideoRegion ceiling, NVENC
ucode staging address, and UVM descriptor/PMA base from the real FB size
in placement::Placement::usable instead of hardcoding 32 GiB constants.
Also pass the detected VRAM size through fb_info_v2_with_usable so
cards with a smaller BAR1 still report the right total memory.
- Switch LiveEngine::irq_top_half, live_irq_mask, and live_irq_unmask to
the lockless nv_rs_pci_{read,write}32_irq helpers. Using the normal
nv_rs_pci_{read,write}32 path acquires p->access inside hardirq context
and self-deadlocks when an IRQ lands on the same CPU running
irq_thread_service.
- DMA-map sysmem pages per GPU instead of putting raw physical addresses
in GPU page tables and rings: lazy per-GPU dma_map_page for RMAPI
allocations and CPU-mapped UVM semaphore/managed pages, dma_alloc_coherent
for SysmemPageTree and the replayable fault ring, and a live coherent
flush page in 0x100c10 across ACR load/runtime/unload so SYS_MEMBAR does
not hit stale unmapped IOVAs left behind by stock nvidia.ko.
- Add version-guarded compatibility wrappers for Linux 6.3-7.0 API changes
(noop_llseek, vm_flags_set/clear, PCI_IRQ_INTX, timer_container_of,
hrtimer_setup, MAX_PAGE_ORDER, MODULE_IMPORT_NS("DMA_BUF"), and
drm_driver.date).
Verified with cargo fmt/clippy/test (918 passed), make modules +
check_kernel_module.py (10/10, largest_stack 1000), native-hello,
uvm-replayable-fault-test, 4-GPU cuda-multigpu-parity (matches stock
580.178.04), and llama-bench on 1 and 4 GPUs with zero DMAR faults and
clean unbind/rmmod.
- utils.mk: search ~/.cargo/bin in rustup lookup and fall back to ~/.cargo/bin/rustc; auto-gate -Z cf-protection=branch -C jump-tables=no on CONFIG_X86_KERNEL_IBT=y (overridable via NV_RS_KERNEL_IBT=0/1).
- rust-toolchain.toml: restore default stable 1.100.0 (IBT kernels build with RUSTUP_TOOLCHAIN=nightly-2026-11-29).
- tools/check_kernel_module.py: resolve section-symbol relocation targets against disassembled function-entry addresses (avoiding false mid-function failures on valid .text+<entry_off> relocs) and enforce the x86 endbr64 gate when IBT is configured or emitted.
- Stock 580.178.04 parity: omit .llseek across fops (matching nv.c/uvm.c), use container_of() in nano_timer_adapter.c (matching nv-timer.h), use #if defined(MAX_PAGE_ORDER) in rom_fw_adapter.c (matching nv-linux.h), and pass FOLL_LONGTERM in nv_rs_rmapi_os_lock_user_pages (matching os-mlock.c).
- Docs: remove scratch docs/HISTORY.md and update docs/KERNEL_COMPAT.md.
- Boundary proven by fetching mm.h at the tags: vm_flags_set/vm_flags_clear absent at v6.2, present at v6.3, and the running 7.3.6 kernel has them. rmapi_node.c x4 and uvm_node.c x1 take the helpers on the >=6.3 side, plain |= / &= below.
- Reads be untouched: a const member is still readable, so vm_get_page_prot(vma->vm_flags) and the shared_rw test stand as they was.
- The kernel took no_llseek out tree-wide in cb787f4ac0c2 (v6.12, 2024-09-27); the 7.3.6-gentoo build choked on the dead name, same as the in-tree drivers mechanically scrubbed.
- All 5 file_operations llseek initializers in kernel-open (diagnostic.c, gpu_owner.c, uvm_node.c, rmapi_node.c x2) now take no_llseek on kernels < 6.12 and noop_llseek on >= 6.12, with <linux/version.h> pulled in.
- Boundary proven from the kernel git itself + headers at the tags: 868941b14441 (v6.0) turned no_llseek into #define NULL, cb787f4ac0c2 (v6.12) took the name out. noop_llseek survived and is what in-tree DRM/accel use.
- Galley scroll docs/KERNEL_COMPAT.md + mast pointer line, per the chart law.
- The lseek behavior difference (noop_llseek returns f_pos, old side failed with -ESPIPE) is documented in the scroll — no silent semantics smuggled aboard.
Apply PR #7 review: UVM node keeps stock -ESPIPE, docs stop lying about seek mode
- uvm_node.c ≥6.12 branch: noop_llseek -> NULL. Verified stock 580.178.04 uvm.c uvm_fops carries NO llseek callback, so stock lseek() be -ESPIPE; noop_llseek returned f_pos — a bloody parity break against the exact-parity law. NULL keeps -ESPIPE because fs/open.c clears FMODE_LSEEK for nodes with NULL llseek (verified at the v6.12 tag and the running 7.3.6 kernel).
- docs/KERNEL_COMPAT.md: the behavior difference applies ONLY to nodes whose open path leaves seek mode enabled. The diagnostic node and both RMAPI nodes call nonseekable_open() in their open callbacks (diagnostic.c:78, rmapi_node.c:740,800), so they keep returning -ESPIPE on ≥6.12 — the old blanket claim was a lie. The GPU open node (open_gpu clears no seek mode) be the only node where lseek succeeds on ≥6.12.
- Other kernel branches unchanged, as the review asked.
GPU open node keeps stock -ESPIPE: kill the lie that stock used no_llseek
- gpu_owner.c >=6.12 branch: noop_llseek -> NULL. Stock ground truth at tag 580.178.04 (kernel-open/nvidia/nv.c:236 nvidia_fops) carries NO .llseek field at all -> NULL -> FMODE_LSEEK cleared at open -> lseek() = -ESPIPE, on every kernel version. Tags 470.256.02/535.104.05/550.144.03 show zero llseek references, so stock never had a llseek handler. Our noop_llseek there made lseek() SUCCEED (returns f_pos) — a real parity break, and CodeRabbit let it slide because it only looked at the handler name, not the open path. open_gpu clears no seek mode, so the handler actually runs.
- Retracted: 'U no_llseek' in reports/kernel-module-codegen-validation.json is OUR OWN module's undefined-symbol list, not stock evidence. No blob-level proof exists on this box: nv-kernel.o_binary is not shipped in the repo, no stock nvidia*.ko under /lib/modules/7.3.6-gentoo, and reports/original-live-init-pt-3/runtime-code/kcore covers only 2 PT_LOAD segments (0xffffffffaea00000+0x1003000, 0xffffffffc03a0000+0x25bc000) — nvidia_fops at 0xffffffffc7858ee0 falls outside, so the struct bytes can't be read. Only kallsyms proves the symbol exists in the live module.
- Docs seek-mode law rewritten: noop_llseek may only be used where seek mode is already disabled (the three nonseekable_open() nodes); nodes leaving FMODE_LSEEK set (uvm_node.c, gpu_owner.c) must take NULL. Verified mechanism: fs/open.c:969 clears FMODE_LSEEK for NULL llseek at v6.12; vfs_llseek returns -ESPIPE when the mode is clear and dereferences the handler only when set; on v5.15 no_llseek is the fallback for a NULL handler. no_llseek (NULL since v6.0) and NULL be behaviorally identical, so the pre-6.12 side be untouched as the review asked.