17 Commits

Author SHA1 Message Date
69626f6ecd arm64: fix PAC/BTI ABI flags, host WC flush, NEON/FP checker, ARM64 strip-unneeded, and LP64 guards
Gate objcopy --strip-unneeded to ARM64 only so x86_64 preserves local STT_FUNC symbols required by CONFIG_CALL_PADDING/IBT validation in check_kernel_module.py.
2026-12-03 00:39:54 +01:00
1535e65f63 build: track call-padding settings in a Rust build receipt 2026-12-02 11:45:41 +08:00
10a7abded5 Merge pull request #166 from LN-NG/pr/call-padding-gate
build: support CONFIG_CALL_PADDING and validate padded IBT entries
2026-12-01 21:06:45 -05:00
c6d3e05c10 build: support CONFIG_CALL_PADDING and validate padded IBT entries 2026-12-02 09:40:12 +08: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
30ff549824 Merge upstream/master into pr/edition-2024
Resolve merge conflicts in src/nvidia/kernel/pmu_bringup.rs and
src/nvidia/kernel/rmapi_node.rs against Wave 6/7 (7f7021e), preserving
all upstream logic while keeping Rust Edition 2024 syntax.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-12-02 03:36:42 +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
3670ca66c2 Merge upstream/master into pr/edition-2024
Conflict in pmu_bringup.rs: took upstream's adaptive HBM backoff logic;
converted its new extern block in adapter_start.rs to `unsafe extern`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-12-02 02:15:43 +08:00
32c8728037 Migrate the workspace and kernel crates to Rust edition 2024
Mechanical, behavior-neutral: edition/resolver keys, unsafe extern blocks,
unsafe(no_mangle)/unsafe(export_name), unsafe blocks inside unsafe fn,
r#gen renames, --edition flags in Makefiles/tools, rustfmt style_edition
pinned to 2021 so formatting stays edition-independent, and clippy
collapsible_if allowed workspace-wide (let-chain churn).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-12-02 01:52:38 +08: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
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
2555a0f4d2 build: default LLVM=1 when the target kernel was built with clang (fixes #77)
A kernel with CONFIG_CC_IS_CLANG=y (CachyOS, for one) passes clang-only
flags to external module builds, so 'make modules' failed in the C shims
with gcc. Detect it from $(KERNEL_OUTPUT)/.config, the way the IBT flags
are detected, and leave an explicit LLVM= setting alone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-12-01 08:52:54 -05:00
c5d51ec8f7 build: export RUSTC_BOOTSTRAP=1 when NV_RS_KERNEL_IBT=1 (fixes #31)
Stock 580.178.04 nv-kernel.o_binary unconditionally emits endbr64
(f3 0f 1e fa) prologues so CONFIG_X86_KERNEL_IBT=y kernels do not raise
#CP on indirect calls. utils.mk already enables -Z cf-protection=branch
-C jump-tables=no on IBT kernels, but stable/distro rustc (including
rust-toolchain.toml 1.100.0, Arch rust, Gentoo dev-lang/rust) rejected
-Z without RUSTC_BOOTSTRAP=1.

Exporting RUSTC_BOOTSTRAP=1 inside the NV_RS_KERNEL_IBT=1 block allows
stable rustc to emit ENDBR64 prologues directly (verified on stable
rustc 1.100.0: check_kernel_module.py passed=true, largest_stack=1000,
data_relocation_targets_without_endbr=0,
data_relocations_pointing_inside_a_function=0).
2026-12-01 05:28:22 +00: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
94e9bbfeba Nightly -Z cf-protection=branch so the Rust object gets the ENDBR objtool demands
- utils.mk RUST_KERNEL_FLAGS (x86 kernel target) gains -Z cf-protection=branch; the ARM64 branch be left alone — IBT be an x86 CET feature and no BTI was ordered.
- rust-toolchain.toml moved from pinned stable 1.100.0 to nightly, since the flag be unstable. Verified against the tool: rustc --print=codegen-options on 1.100.0 lists nothing for CF protection, and the unstable book lists none/branch/full for the LLVM backend.
- Make RUSTC explicit so the pinned toolchain is what actually runs:
  - utils.mk: RUSTC ?= $(or $(shell rustup which rustc),$(shell command -v rustc)). Resolves the toolchain pinned in rust-toolchain.toml instead of trusting PATH order; still overridable with RUSTC=..., and no hardcoded ~/.cargo path that may not exist on another box.
  - The gotcha that made this necessary is recorded in the scroll: plain rustc here be the system stable 1.100.0 and rejects -Z. Boxes without rustup still fail - honest limit, no magic.
2026-11-30 17:39:55 +01: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
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