Commit Graph

68 Commits

Author SHA1 Message Date
38993210b9 fix(#158,#159,#160,#165) + feat(#168,#169,#173,#174): Docker/CDI devnodes, safe V100 HBM default & per-GPU backoff, GV100 NV6 LCE4 routing, and opt-in PCIe/idle/tensor/VRAM unlocks 2026-12-02 02:55:05 +00:00
cbaa0fe20f gsp: proactive multi-gen Turing-Blackwell parity (Wave 7C) 2026-12-02 01:55:50 +00:00
0658135d16 Wave 7B: Pre-GSP Maxwell & Pascal full parity (#141, #81, #84)
Fixes every root cause behind #141 (4x Tesla P100), #81 (GTX 1080 Ti), and #84
(GM206 Maxwell):
- Broaden gpu_needs_attach_registers from GV100-only to all pre-GSP GPUs
  (Facts::is_pre_gsp) and allow engine_stage() fallback to Stage::Swept(fuse)
  on Maxwell/Pascal when GV100 PCE2LCE is absent.
- Add architecture-aware class_db::map_class_for_arch / records_for_arch /
  class_list_for_arch so Maxwell (0xb06f/0xb0c0/0xb1c0/0xb0b5) and Pascal
  (0xc06f/0xc0c0/0xc1c0/0xc0b5/0xc1b5/0xb069) expose their real classes and
  omit Volta-only 0xc361.
- Parameterize gr_info_for_arch (0x20801201) and gr_global_sm_order_for_arch
  (0x2080121b) for 1 SM/TPC on Maxwell/Pascal and exact SM_VERSION
  (0x500/0x502/0x600/0x601/0x700).
- Allow hUserdMemory == 0 in channel_alloc for Maxwell/Pascal BAR1 USERD slots.
- Replace nv_rs_runtime_park with a 1 Hz nv_rs_runtime_park_wait telemetry loop
  in boot_maxwell_pascal_pre_gsp, fix attach-time 0x20400 integer °C decode,
  disable Pascal fault IRQ on teardown, and bound nv_rs_gpu_owner_runtime_stop
  wait_for_completion_timeout to 10s.
- Fix broken 8-byte Maxwell/Pascal runlist translation in rmapi_engine.rs
  (tsg_len from header[1], scale/timeout from header[0][19:16]/[31:24], CHID
  from entry[2][11:0]).

Validated: cargo fmt/clippy/test (958+2), NV_RS_KERNEL_IBT=0 & 1 make modules +
check_kernel_module.py (largest_stack=1000), QEMU EDU verify_rust_guest.py.
2026-12-02 01:44:09 +00:00
d5e0b9bb87 Wave 7A: Proactive P0 lock/UAF fixes and kernel build/compat hardening
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.
2026-12-02 01:34:46 +00:00
1939319a6a Merge pull request #147 from 7z0423arsenova/pr/ga107-gsp
ga10x: fail the boot on a GSP_INIT_DONE error; GspSystemInfo ACPI data (GA107 / RTX 3050 Laptop)
2026-12-01 18:52:44 -05:00
5c01435f8d ga10x: fill GspSystemInfo ACPI method data and bIsPrimary
GSP_SET_SYSTEM_INFO went to GSP-RM with acpiMethodData and bIsPrimary
left zero. On an Optimus laptop nouveau (r535/r570_gsp_acpi_info) and
OpenRM fill them from the GPU's ACPI node: the _DOD display list, the JT
_DSM capabilities and the NVOP Optimus capabilities. Do the same, at the
580.178.04 GspSystemInfo offsets (acpiMethodData 0xa0..0x344, bIsPrimary
0x380), and log what was found:

  ga10x: ACPI sysinfo: primary=0 dod=0(n=1) jt=0(caps=20016003) opt=0(caps=19000059)

This did not by itself fix the GA107 boot (the sysmem flush page did,
programmed since #145),
and it has not been tested in isolation; it brings the system info in
line with what the other drivers send on Optimus systems. Only x86 with
CONFIG_ACPI evaluates the methods.

bIsPrimary comes from video_is_primary_device() where <asm/video.h> has
it (6.9+, probed in Kbuild) and from the VGA arbiter's default device
before that.

Also report an I/O BAR to GSP-RM only when PCI_COMMAND_IO is enabled:
the GA107 exposes an I/O BAR that the platform leaves disabled.
2026-12-02 07:27:28 +08:00
c65b7c440c uvm_node: take the RM API lock before the UVM lock
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.
2026-12-02 07:27:28 +08:00
3ada318df4 Drop-in UX (#133), Maxwell/Pascal ACR FW, Hopper/Blackwell split-RM, and #142 Phases 3-4
- Zero-friction first-run UX (#133): default runtime_engines=1 and pci_target=*
  in nvidia_rs.ko (with explicit bringup=N precedence via resolve_bringup_mode);
  install.sh auto-extracts pre-GSP firmware packs + GSP blobs, installs
  /etc/modprobe.d/nvdriver.conf (install nvidia /bin/false, char-major-195-*
  alias), /etc/modules-load.d/nvdriver.conf, and /etc/udev/rules.d/70-nvdriver.rules,
  and enables BIND_DEV_NODES=1 by default.
- Maxwell & Pascal real firmware loading (GM10x-GP108): extend
  tools/extract_gv100_firmware.py (--family gm20x|gp100|gp10x|all) using
  REA-verified 580.178.04 ACR/PMU bundles (_nv016827rm/_nv016828rm/_nv016888rm)
  with a shared pack_container() builder; wire LoadedPack::request_legacy and
  HS Falcon IMEM/DMEM upload + execution into boot_maxwell_pascal_pre_gsp.
- Unified Hopper/Blackwell split-RM routing: add GspFirmwareChipFamily::boot_mode()
  (FwsecBooter vs Fmc) as a single source of truth; integrate GH100/GB10x/GB20x
  FMC BootROM handshake into Ga10xGsp::boot/unload via PciRegIo so every GSP-RM
  GPU from Turing through Blackwell runs on the unified gsp_route.rs split-RM.
- Issue #142 Phases 3-4: add FileMappingLedger and GpuSlotLedger (+ unit tests)
  to src/nvidia/src/rmapi/alloc_registry.rs + rmapi_memory.rs FFI, removing
  struct nv_rs_rmapi_mapping and redundant bar0/bar1/numa_status fields from
  kernel-open/nvidia/rmapi_node.c.

Validated: cargo fmt/clippy/test (957+2), NV_RS_KERNEL_IBT=0 & 1 make modules +
check_kernel_module.py (largest_stack=1000), test_gate_cases.py (18/18),
extract_gv100_firmware.py --check, and QEMU EDU verify_rust_guest.py (non-IOMMU
and --iommu, maxframe=984).
2026-12-01 23:03:43 +00:00
e3c196cd49 gsp/rmapi/tools: zero GSP boot refusal stubs (#74/#127), DmaMapLedger in Rust (#142 Phase 2), host-portable validate_all.sh (#64) 2026-12-01 22:27:32 +00:00
10b4b44ee8 rmapi/uvm/pmgr: Rust alloc registry (#142), uvm_ext_gpu_map_split (#134), PMGR power limit (#136), per-BDF clocks (#130), .ko.zst & bare-metal docs (#133) 2026-12-01 21:39:34 +00:00
7f7021e218 Wave 7: complete RM escape dispatch (0x27-0x5f/0xd5/0xd8) and x86_64/ARM64 kernel hardening gates 2026-12-01 19:19:30 +00:00
e83dd0ee5f Wave 6: live channel teardown, hot-unplug UAF fixes, PCE2LCE topology, real FBPA ECC + HbmSession 2026-12-01 19:03:54 +00:00
9021e9d78e rmapi_node: avoid LIST_POISON oops in nv_rs_rmapi_alloc_put (#118)
Wave 1 (c553930f) moved list_del_init(&alloc->link) into
nv_rs_rmapi_alloc_put() and updated nv_rs_rmapi_os_free_pages() to set
alloc->freed = true instead of unlinking early.

Two remaining callers still ran bare list_del(&alloc->link) right before
nv_rs_rmapi_alloc_put(alloc):
- nv_rs_rmapi_os_unlock_user_pages(): poisons alloc->link before
  nv_rs_rmapi_alloc_put() checks !list_empty(&alloc->link) and calls
  list_del_init(&alloc->link), causing a GPF on LIST_POISON2
  (0xdead000000000122) during Server::free (reproduced live with
  llama-server on a V100-PCIE-32GB under Linux 7.0). Mark
  alloc->freed = true to match nv_rs_rmapi_os_free_pages().
- nv_rs_rmapi_node_exit(): same poison hazard when draining leaked
  allocations on module exit. Use list_del_init(&alloc->link) so
  nv_rs_rmapi_alloc_put() sees list_empty(&alloc->link) == true.

Refs #117
2026-12-01 13:06:21 -05:00
ea8b4af427 fix: CE scrub retire polling (#63), Maxwell FECS/park (#84), rethunk/retpoline (#78), admission log (#80), rustup lookup (#56)
- rmapi_engine.rs (#63): poll NV_PFIFO_ENG_RUNLIST PENDING bit (bit 20) after submit_runlist and poll CCSR idle flags before failing stop_scrub_ce(); clear scrub_ce.retire_pending on deactivate().
- adapter_start.rs (#84): filter 0xbadfxxxx PRI error codes from FECS golden context size discovery and call nv_rs_runtime_park + deactivate_runtime in boot_maxwell_pascal_pre_gsp.
- utils.mk (#78): auto-enable -Z function-return=thunk-extern and -Z retpoline-external-thunk when CONFIG_(MITIGATION_)?RETHUNK/RETPOLINE=y in target kernel .config.
- pci_driver.c (#80): log rejected pci_admitted tuple (class, subclass, vendor, device, subsys) via dev_info instead of failing silently.
- tools/vm/verify_rust_guest.py (#56): resolve rustup via shutil.which('rustup') / Path.home() instead of hardcoded /home/geodd.

Validated: fmt, IBT=1 & IBT=0 modules + check_kernel_module.py (with rethunk+retpoline enabled), test_gate_cases.py (16/16), QEMU EDU non-IOMMU + IOMMU.
2026-12-01 17:43:07 +00:00
373e801f8c rmapi/drm/uvm: multi-arch RMAPI, PCI-bound DRM atomic/syncobj/NVIDIA ioctls, and 5 R620 UVM symbols (Wave 5)
- src/nvidia/src/rmapi/gpu.rs: remove GV100-only gate (line 5250) and add chip-derived GPU names across Maxwell, Pascal, Volta (Titan V / Quadro GV100), Turing, Ampere, Ada, Hopper, and Blackwell.
- kernel-open/nvidia-drm/nvidia_rs_drm.c: bind real NVIDIA PCI GPUs when present (platform fallback), enable DRIVER_SYNCOBJ | DRIVER_SYNCOBJ_TIMELINE | DRIVER_MODESET | DRIVER_ATOMIC, and implement core DRM_IOCTL_NVIDIA_* ioctls matching stock nvidia-drm-drv.c.
- interface_dispatch.rs, uvm_interface_ffi.rs, src/nvidia/Makefile, uvm_iface_exports.c, uvm_bridge.c: implement and export all 5 new R620 nvUvmInterface* symbols (AccessBitsBufAlloc/Free/Dump, RegisterUvmEvents/DeRegisterUvmEvents -> 81 total exported symbols).
- Update HANDOFF.md and docs/PARITY_AND_UNLOCKS.md with Wave 1-5 summary.

Validated: fmt, clippy -D warnings, 1067/1067 nv-rs-core tests, IBT=1 & IBT=0 modules + check_kernel_module.py (largest_stack: 1016, 0 GOT/memcpy/SIMD), uvm-bridge, QEMU EDU non-IOMMU + IOMMU.
2026-12-01 17:05:11 +00:00
c553930fd7 wave 1: kernel/ARM64/Clang/DKMS compat, IOMMU/PCI lifecycle, and RMAPI/UVM isolation
Proactive 100% parity Wave 1 (REA-grounded vs stock 580.178.04):
- Kernel/build compat: Kbuild header probes for timer_delete_sync, vm_flags_set,
  vma_flags_set_word; remove broken UTS_UBUNTU_RELEASE_ABI guard on
  pci_resize_resource; guard x86 set_memory_uc/wb under CONFIG_X86; remove
  illegal ARM64 dma_sync_single_* on coherent DMA; gate nvidia_rs_drm on
  CONFIG_DRM; default LD=ld.lld/OBJCOPY=llvm-objcopy under LLVM=1; fix dkms.conf
  (KDIR support, all 4 modules, 0.2.0) and install.sh (all 4 modules, non-0000
  PCI domains, KREL override).
- IOMMU & PCI lifecycle: switch gsp_route error notifier to per-device DMA
  (nv_rs_rmapi_os_page_dma); add PCI .shutdown (pci_clear_master + udelay(1))
  and AER .err_handler; keep freed rmapi_allocs on list until users==0 for
  hot-unplug DMA teardown; drain nv_rs_uvm_cpu_dma_ht on exit; lock BAR0 fill
  under p->access; raise MAX_BRIDGE_GPUS to 32.
- Security & isolation (REA _nv000655rm / _nv000663rm): enforce cross-process
  share policy on NV_ESC_RM_DUP_OBJECT & NV_ESC_RM_SHARE; refcount shared memory
  backings on release (eliminating dup UAF); scope UVM ManagedFaultMapper by
  faulting GPU & SysmemPageTree.owner; pass real task_tgid_vnr into Caller.pid.
2026-12-01 16:16:09 +00:00
f6981c138c kernel-open: log when the streaming DMA mask is raised, or cannot be
nv_rs_pci_widen_dma is called once per mapped client page, and its callers in rmapi_node.c and uvm_node.c drop the
result, so a GPU stuck at the probe's 32-bit streaming mask was only visible through its symptoms: swiotlb bouncing,
or, behind a translating IOMMU, IOVA exhaustion in the 4 GiB below the mask (a field report on a V100 under VT-d
without iommu=pt: NO_MEMORY at the fifth 264 MiB pinned map).

The widen now says so in the kernel log: one info line when it raises the mask (with the width the leases and the
coherent mask keep), and one warning per device when the DMA API refuses it. The host fixture checks both, with a
refusing dma_set_mask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 14:57:04 +01:00
82100998b2 ga10x_events: post what an IRQ thread could not, once the node's lock is free
When the RM API node's lock stayed busy past an IRQ thread's tries (about 200 ms in one go), the event slots stayed
pending until the next interrupt of one of the GPU's engines; on an idle GPU the waiter then woke only on libcuda's
own 100 ms re-check. The tries are bounded on purpose (on a V100 the same thread runs nvdriver's stall service, and
teardown waits for it), so the thread now hands over instead: it schedules a delayed work item (rmapi_node.c) that
takes the lock with a trylock, posts every slot still pending on a GA10x GPU or a V100 whose events are on
(nv_rs_gpu_events_retry), and tries again every 5 ms while the node stays busy. It never blocks on the lock, so a
teardown holding it cannot wait on the work; GA10x GPUs are found through the slot table under the lock (a GPU is
freed only under it), V100 entries are static. Node exit cancels the work after the GPUs are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 12:05:05 +01:00
d3670c9ce3 kernel-open: widen only the streaming DMA mask, leases keep their width
74ce0e5 raised the device's DMA mask with dma_set_mask_and_coherent and recorded the new width as the lease width.
With the probe's 32-bit lease still held, every later 32-bit lease (nv_rs_pci_dma_acquire) then failed with EBUSY, and
a DMA context opened at 32 bits could get coherent memory above 4 GiB, which its own range check refuses.

The swiotlb bounce that 74ce0e5 fixes is in the streaming path only (dma_map_page of client pages). So
nv_rs_pci_widen_dma now raises just the streaming mask (dma_set_mask, never lowered) and leaves the coherent mask and
dma_bits alone: existing and new 32-bit leases keep working, coherent allocations stay where their context expects them.
On a GA10x GPU the boot's own buffers come from a 32-bit context then (the 47-bit request is refused while the probe's
lease holds; the existing fallback takes 32 bits). The host fixture covers it (mock gets a separate streaming mask).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 12:05:05 +01:00
61f6529bf6 GA102 (RTX 3090) on GSP-RM 580.178.04 in MIT Rust; split-RM routing; RM events
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>
2026-12-01 10:01:46 +01:00
74ce0e545d kernel-open: widen the GPU's DMA mask while the probe's 32-bit lease holds
nv_rs_rmapi_gpu_negotiate_dma asked nv_rs_pci_negotiate_dma for a new mask, which refuses any change while a DMA
lease exists, and every GPU keeps its probe's 32-bit lease for its lifetime: the mask stayed at 32 bits. With the
strict IOMMU DMA path (#16) each client system-memory page is mapped with dma_map_page, so on a host with memory
above 4 GiB every such page goes through swiotlb. The GPU's semaphore writes land in the bounce buffer, the CPU
never sees them and libcuda spins at context creation (seen on a V100 with plain master on an 8 GB host: 26,624
swiotlb slabs in use during the hang).

nv_rs_pci_widen_dma raises the mask under the same lock and never lowers it, so every address handed out under the
old mask stays valid. nv_rs_rmapi_gpu_negotiate_dma uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 09:57:19 +01:00
faf69d5275 gsp: honor gsp_abi in boot/recovery RPCs, fix 6.12+ guest header, clarify driver_version
- Fixes #47: dispatch wait_for_rm_init_done_with_abi, execute_gsp_boot_with_abi,
  boot_gsp_rm, and GspRpcSession::rpc_call through the active session
  GspAbiVersion (matching REA _nv041450rm dispatching via pRpc->rpcRecvPoll),
  with end-to-end R620 MCTP/NVDM boot unit test.
- Fixes #52: guard <linux/unaligned.h> vs <asm/unaligned.h> on 6.12+ in
  tests/vm/edu_adapter_test.c so validate_all.sh guest_build passes on 6.12+/7.x.
- Fixes #49: clarify in MODULE_PARM_DESC and README.md that driver_version
  (default 580.178.04 for userspace NVML/libcuda matching) is independent of
  gsp_abi (GSP-RM wire protocol framing).
2026-12-01 05:59:57 +00:00
9fc7c1b7aa Merge pull request #51 from kubuntugamer/fix/gsp-abi-value-validation
Thanks @kubuntugamer for tightening gsp_abi validation so typos warn instead of silently selecting 620 framing!
2026-12-01 00:16:47 -05:00
0986771c78 Merge pull request #30 from kubuntugamer/gsp-radix3-run-list
gsp: back the radix3 data pages with a non-contiguous run list

Resolved small conflict with #36 (GspAbiVersion parameter in
boot_payload_sizes / write_boot_payloads). Also lands #27 cleanly.
2026-12-01 05:06:01 +00:00
3692231d0b gsp: reject gsp_abi values other than 580 or 620
The module parameter selects the GSP-RM wire framing, but the setter treated
every value other than 580 as 620, so a typo such as gsp_abi=0 or gsp_abi=62073
silently switched protocols with nothing in dmesg to explain it.

Parse the parameter strictly in GspAbiVersion::from_module_param, leave the
active ABI untouched on an unknown value, and warn once from module init.

Fixes #48.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-30 23:05:09 -06:00
53352b85fd Merge pull request #32 from SolarAquarion/master
kernel: detect pci_resize_resource exclude_bars from pci.h
2026-11-30 23:16:22 -05:00
c9c47069db rmapi: add OS-event posting/poll wakeup and GA10x RM facts & usermode/shared-data classes
Cherry-picked MIT-clean pieces from PR #25:
- rmapi_node.c/.h: add nv_rs_rmapi_file_post() and report posted dataless OS events once in nv_rs_rmapi_poll() (EPOLLPRI | EPOLLIN, matching stock nvidia_poll).
- rmapi/gpu.rs: add GpuFacts::is_ga10x(), allow GA10x in MMU v2 vaspace/video memory paths, add Turing/Ampere usermode window 0xc461/0xc561 (0xbb_0000), and RM_USER_SHARED_DATA (0xde).

Co-authored-by: Kamil Skowron <1019893+Cinderella-Man@users.noreply.github.com>
2026-12-01 01:55:26 +00:00
4095aeb81a gsp: gate buffer release on the family reset and never re-boot a live session
Review follow-ups on the scattered-payload path:

- `dma_adapter.c` no longer claims the TU10x path asks for one 30,539,776-byte
  buffer; the page tables are a separate 69,632-byte allocation and the image
  arrives in 2 MiB runs, so the 64 MiB cap is only a general sanity bound.
- `kflcnResetHw` is virtual: `kgspResetHw_TU102` toggles `ENGINE.RESET`, while
  `kgspResetHw_GH100`/`_GB100` also poll `ENGINE.RESET_STATUS` for ASSERTED and
  DEASSERTED. Only the Turing sequence exists here, so `stop_gsp_engine` and both
  session paths now keep their buffers allocated for any other family instead of
  freeing them on a reset that does not prove the engine stopped.
- A boot that never took the register lease never handed GSP an address, so the
  failure path releases and closes without a reset; previously a lost lock skipped
  both the reset and the release and leaked on every attempt.
- A second open of a device node that already owns a live session returns without
  booting again. Boot-then-teardown in `install` used to reset the engine under the
  session the same open had just created.
- The tail-padding test now uses a 0x2001-byte image so the zero-padded last data
  page is asserted, instead of comparing an empty slice.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-30 19:54:26 -06:00
31a915e05f Merge pull request #26 from kubuntugamer/fix/gsp-boot-payloads
gsp: build radix3 page tables and give boot payloads their own DMA (issue #3)
2026-11-30 20:27:47 -05:00
2be365241d kernel: detect pci_resize_resource exclude_bars from pci.h
exclude_bars arrived in 6.19 and was backported to 6.18 stable, so a
LINUX_VERSION_CODE >= 6.19 check misses those trees. Key the fourth
argument off the declaration in include/linux/pci.h, the same way
PCI_IRQ_INTX is keyed off the macro.

- kernel-open/Kbuild defines NV_RS_PCI_RESIZE_EXCLUDE_BARS when pci.h
  declares exclude_bars.
- pci_adapter.c prefers that macro, then the 6.19 and Ubuntu checks.
- docs/KERNEL_COMPAT.md records the guard.
2026-11-30 20:23:04 -05:00
5a02e03a79 Merge pull request #16 from morebrackets/fix/v100-16gb-iommu-irq-linux7
Fix 16GB V100 VRAM sizing, strict IOMMU DMA, IRQ deadlock, and Linux 7.0 build
2026-11-30 20:00:37 -05:00
33ff608a88 Add MIT LICENSE and unify repository SPDX/Cargo/module licensing
- 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.
2026-12-01 00:20:02 +00:00
caef37fa93 kernel: add RHEL 9.8+ (5.14) compat guards, firmware install, boot kit, and driver_version= param
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>
2026-12-01 00:09:44 +00:00
87cbefa8b0 gsp: stop leaking boot DMA and accept the real payload size
Review findings on the payload split: the DMA adapter rejected anything over
16 MiB, so the real 30,539,776-byte radix3 container failed before a single byte
was written; and the non-install path, session teardown and the slot-exhausted
install path all freed GSP-visible DMA without stopping the engine first, which
can let a running GSP write into pages the kernel has already reused.

Raise the cap to 64 MiB with the bounds checks intact, and reset the GSP
(kgspResetHw_TU102) before returning any GSP-visible buffer to the allocator,
including the WPR and queue rings. When that reset cannot be confirmed nothing is
released: leaking the buffers is preferable to a device writing into freed
memory. Teardown keeps the reference ordering, since kgspTeardown_TU102 resets
before FWSEC-SB and Booter Unload.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-30 17:36:46 -06:00
6a1a63e8bc Close DMA publish/remove and UVM page-unmap teardown races
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.
2026-11-30 11:25:52 -08:00
bf60e3a72e Harden raw BAR1 dmabuf export, unmap DMA on GPU removal, and fix 6.3/pipefail checks
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.
2026-11-30 11:15:49 -08:00
2c09a6b64b Address review feedback on DMA mask, fault mapping, and PMA cursor
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.
2026-11-30 10:58:06 -08:00
87a26a2aee Support 0x2080a61d power limit query and non-root /dev/nvidia* access
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.
2026-11-30 10:53:36 -08:00
2d90287ede Fix 16GB V100 VRAM sizing, strict IOMMU DMA, IRQ top-half deadlock, and Linux 7.0 build
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.
2026-11-30 10:53:36 -08:00
4472b75ccd Follow-up to PR #10/#11: auto-gate IBT flags, fix RUSTC fallback & section-reloc gate, align stock 580.178.04 compat/FOLL_LONGTERM
- 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.
2026-11-30 17:19:30 +00:00
c54b529053 Merge pull request #10 from arabek/kernel_compat
Add kernel 6.3-6.16 API compat guards and ENDBR/IBT build gate
2026-11-30 12:13:45 -05:00
6cca7388b1 MODULE_IMPORT_NS wants a string literal from 6.13 — the identifier form be dead
- Boundary proven at the tags: v5.16 `MODULE_IMPORT_NS(ns) MODULE_INFO(import_ns, #ns)`, v6.6/v6.12 `__stringify(ns)` (so an identifier worked), v6.13 `MODULE_INFO(import_ns, ns)` — with MODULE_INFO static_asserting sizeof(info)-1 == strlen(info), so the argument must be a literal. The running 7.3.6 headers show in-tree callers passing "PWM" and "PWM_MC33XS2410", confirming it.
- Kept the existing >=5.16 existence guard as an #elif; the literal form only became legal at 6.13, and the stringifying side must NOT be handed a literal (it would embed the quotes and change the namespace name).
2026-11-30 17:39:55 +01:00
b0cbb6c192 PCI_IRQ_LEGACY was renamed PCI_IRQ_INTX in 6.10 — same bit, new name
- Boundary proven at the tags: pci.h through v6.9 carries PCI_IRQ_LEGACY, v6.10 has only PCI_IRQ_INTX; INTX itself exists from v6.8 and both be (1 << 0), so no value changed — only the spelling.
- One compat define (NV_RS_PCI_IRQ_INTX) feeds both call sites instead of two clunky inline guards in expressions. The project already calls the flag NV_RS_IRQ_INTX, so the naming lines up.
- <linux/version.h> added inside the non-fixture branch; note the fixture builds do not see version.h, so they land on the old-name side and the mocks must keep PCI_IRQ_LEGACY.
2026-11-30 17:39:55 +01:00
ed430cf001 from_timer rotted in 6.16 — timer_container_of does the same job
- Boundary proven at the tags: timer.h defines from_timer through v6.15 and only timer_container_of from v6.16 (and the running 7.3.6 kernel).
- Same shape: timer_container_of(var, callback_timer, field) is container_of(callback_timer, typeof(*var), field) — a drop-in, no semantic change to the jiffy callback.
2026-11-30 17:39:55 +01:00
d9a08da230 hrtimer_init got buried in 6.15 — hrtimer_setup takes the job
- Boundary proven at the tags: hrtimer.h still declares hrtimer_init through v6.14 and not at v6.15/6.16/6.17; hrtimer_setup is there from v6.13. Guarded at the death point (6.15), so the old side stays valid for everything below.
- New side sets the callback in the call: hrtimer_setup(&owner->timer,fire,CLOCK_MONOTONIC,HRTIMER_MODE_REL); old side keeps init + owner->timer.function=fire. Same behavior, one less foot.
- <linux/version.h> added (the file had no guard before).
2026-11-30 17:39:55 +01:00
ee3f7ebcbf MAX_ORDER be six feet under since 6.8 — NR_PAGE_ORDERS takes over, no off-by-one
- Boundary proven at the tags: mmzone.h at v6.7 carries #define MAX_ORDER 10, v6.8 has MAX_PAGE_ORDER + NR_PAGE_ORDERS instead, and the running 7.3.6 kernel agrees.
- NR_PAGE_ORDERS == MAX_PAGE_ORDER + 1, and the old test was `order >= MAX_ORDER`, so the guarded test be exactly the same range check. Anyone writing `order > MAX_PAGE_ORDER` from memory would have shifted the limit by one — not here.
- <linux/version.h> added to the file (it had no guard before).
2026-11-30 17:39:55 +01:00
91ef1e1b6f vm_flags be const from 6.3 — five writes now use the helpers, ye blind bilge rats
- 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.
2026-11-30 17:39:55 +01:00
c55ca81524 Guard the dead no_llseek for kernels >= 6.12 — the mangy symbol is two years six feet under
- 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.
2026-11-30 17:39:55 +01:00
349860e14b rmapi: count retained sysmem pool pages against the combined ceiling
With system_memory_pool_retain_mb=-1 released pages stay in the pool and
left nv_rs_rmapi_alloc_total, so pins and allocations could exceed 7/8 of
RAM. Pin admission now adds the pool; allocation admission counts the pool
once as max(pool, count), since the pool is reused first.
Not compiled locally (no kernel toolchain).

gstephan-enhanced
2026-11-30 17:26:41 +01:00
dddd715884 rmapi: keep pins and driver allocations under one 7/8-of-RAM ceiling
The previous commit gave pinned user pages their own 7/8-of-RAM limit next
to the RAM/2 budget of the driver's own allocations, so the two together
could reach ~1.4x RAM. Both now also count against one combined ceiling of
7/8 of RAM (nv_rs_rmapi_total_max_pages), checked in os_lock_user_pages and
os_alloc_pages.

gstephan-enhanced
2026-11-30 17:14:53 +01:00