Commit Graph

14 Commits

Author SHA1 Message Date
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
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
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
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
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
31f91a223f kernel-open: drop the literal '(' from the Kbuild ifeq probe
make counts every '(' inside $(shell ...) regardless of shell quoting, so
'pci_resize_resource\(struct pci_dev' leaves the ifeq unbalanced and every
build fails with 'Kbuild:5: *** invalid syntax in conditional'.

Match on the function name and let the existing -A2 context + grep for
exclude_bars keep the original intent.
2026-12-01 07:24:43 +03:00
46d15daf43 Merge pull request #42 from kubuntugamer/fix/kernel-open-6.17-7.3
kernel-open: build on 6.17+ kernels (BTF Rust object, of_gpio removal)
2026-11-30 23:16:29 -05:00
53677879d7 kernel-open: build on current kernels (BTF Rust object, of_gpio removal)
Two independent upstream changes broke the kernel-open modules on current
kernels, both reported against this tree (issue #34 and #18):

- <linux/of_gpio.h> is gone from current headers, so uvm_bridge.c failed to
  compile before any of its code was read. Probe for the header and fall back
  to <linux/gpio/consumer.h>, where the legacy OF GPIO helpers now live; the
  bridge itself references no of_* or gpio_* symbol, so either include keeps
  the same declarations available.

- pahole cannot recode rustc's DWARF for BTF and aborts with
  "tag__recode_dwarf_type: couldn't find ... (inlined_subroutine)", which fails
  the BTF step of module linking on CONFIG_DEBUG_INFO_BTF kernels. Strip the
  Rust object's debug info when BTF is enabled; code, relocations and exported
  symbols are unchanged.

struct drm_driver.date needs no change: it was removed upstream in 6.14
(cb2e1c2136f7) and is already guarded, so nvidia_rs_drm.ko builds as-is.

Verified on Linux 7.3.0-11-generic: make modules (all four modules, checks
pass), make uvm-bridge now links nvidia_rs_uvm_bridge.ko, and pahole -J on the
linked nvidia_rs.ko exits 0 and writes .BTF where it previously aborted.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-30 22:05:36 -06: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
0d6d2520eb Implement Round 6 580.178.04 ports (DP AUX/DPCD, GSP CrashCat decoder, ACPI NBCI mux/power, standalone nvidia_rs_modeset.ko) 2026-11-30 16:04:52 +00:00
1da14ed862 Implement Round 5 580.178.04 ports (NVLS Multicast 0x00fd, RC Watchdog, VRR/G-Sync, standalone nvidia_rs_drm.ko & nvidia_rs_peermem.ko) 2026-11-30 15:54:18 +00:00
c69af41f1b Add 7 community unlocks: Ada Tensor, DynBAR1 P2P, dma-buf/P2PDMA, CMP, ECC/unpriv-prof, hwmon+live sysfs, ARM64 2026-11-29 18:39:33 +00:00
4b6a77d90f Clean-room Rust NVIDIA 580.178.04 driver: GV100 0-diff parity (8-GPU PyTorch/NCCL/llama.cpp, H.264+HEVC NVDEC/NVENC, 2,096/2,096 RM controls, stock UVM/modeset bridges, artificial restrictions unlocked) 2026-11-27 20:45:30 +00:00
4526e6a816 Baseline: validated 30/30 tree with passing Level 7 hardware regression
- Updated tools/post_reboot.sh to check kernel oops taint bit and stuck driver tasks instead of <86400s uptime
- Level 7 hardware regression passed on 0000:b3:00.0 (module 37e6fa430835eee2b426019db3ad70eeb7a9e9070c09c84bd9b973cf56cbe529, 107 inventory words, 0 static mismatches, CUDA baseline verified before and after)
- Updated .gitignore to exclude build archives (*.a, *.rlib), __pycache__, and raw trace dumps
2026-11-23 23:48:38 +00:00