4.4 KiB
Contributing to nvdriver
Thank you for contributing to nvdriver (nvidia_rs.ko)! This guide outlines our engineering standards so pull requests stay clean, verifiable, and safe to merge.
Core Principles
- Clean-Room MIT Implementation: Never copy proprietary NVIDIA source code or machine code into the repository. Derive exact algorithms, register sequences, struct layouts, and error-status ordering through static reverse engineering (REA) of NVIDIA
580.178.04(and620.xwhere applicable), then implement them cleanly in#![no_std]Rust. - Exact-Logic Parity (No Guessing or Stubs): Before modifying RM controls, class constructors/destructors, UVM ioctls, MMU page-table formats, FIFO/runlist/CCSR logic, or GSP-RM boot sequences, verify exact field offsets, bitmasks, status codes, and hardware register sequences against the original driver.
- No Artificial Restrictions: Match hardware behavior faithfully, but do not reproduce NVIDIA's software-only product-tier, brand, virtualization, or chipset lockouts (see docs/PARITY_AND_UNLOCKS.md).
- Keep C Minimal & Stateless: New tables, refcounting, and lifecycle state machines belong in
#![no_std]Rust (src/nvidia/src/andsrc/nvidia/kernel/). Keep C inkernel-open/limited to thin Linux kernel header wrappers (see #142). - Keep Evidence Categories Separate: In commit messages, PR descriptions, and comments, distinguish static analysis/emulation (
[A]/[D]/[E]), observed stock behavior ([T]/[O]), software QEMU EDU guest tests, and live physical silicon runs. Never claim physical-silicon verification that was not actually run.
Strict Kernel-Module Hygiene Rules
nvidia_rs.ko links #![no_std] Rust directly into a Linux kernel module and enforces strict static checks via tools/check_kernel_module.py:
- Zero
R_X86_64_GOTPCREL/ unsupported GOT relocations - Zero compiler-emitted calls to
memcpy,memset,memmove, orstrlen - Zero SIMD / x87 instructions (x86_64) or NEON/FP instructions (ARM64)
- Zero unwind tables (
.eh_frame,.gcc_except_table) - Every function stack frame <= 1,024 bytes (
#[inline(never)]+ heap workspace for large buffers) - Mitigation clean under
CONFIG_MITIGATION_RETHUNK,CONFIG_MITIGATION_SLS,CONFIG_X86_KERNEL_IBT, andCONFIG_CALL_PADDING
Local Validation Gate
Before opening a pull request, run the offline build and test commands (these do not require sudo or load any kernel module):
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
make modules
make -C src/nvidia audit-codegen
python3 tools/check_native_codegen.py
NV_RS_KERNEL_IBT=1 python3 -m unittest tests/kernel-module-gate/test_gate_cases.py
python3 tests/kernel-module-gate/test_kernel_archive.py
On a dedicated/disposable test machine where loading experimental kernel modules is acceptable, you can run the full validation suite including live sudo insmod/rmmod of nvidia_rs.ko and /dev/nvidia-rsctl smoke tests:
sh tools/validate_all.sh
When modifying kernel C adapters (kernel-open/), DMA/IOMMU paths, or PCI/owner lifecycle code, also run the software QEMU EDU guest tests (no physical GPU required):
sh tools/vm/build_guest_test.sh
sh tools/vm/build_initramfs.sh
python3 tools/vm/run_guest.py
python3 tools/vm/run_guest.py --iommu
Hardware Testing Safety
- Prefer disposable VFIO QEMU/KVM VMs (
tools/vm/run_vfio_guest.py --bdf <bdf> --driver rust) over bare-metal testing whenever IOMMU isolation is available. - Never issue a sysfs PCI reset (
.../reset) on a GPU bound to stocknvidia.ko, and never runmmiotraceacross workloads on stocknvidia.ko. - Check
dmesgand clean module unload (rmmod nvidia_rs) after hardware runs, and report exact commit SHA, kernel version, GPU PCI ID, and logs in your issue or PR.
Pull Request Guidelines
- Keep PRs focused and atomic: One issue or tightly related change per PR so reviews and rebases against active
masterstay fast. - Stay in sync with
master: Fetch and rebase onorigin/masterbefore pushing. - Add unit tests: Every bug fix or new subsystem behavior should include host unit tests (
cargo testortests/Python tests) that fail without the fix and pass with it. - Kernel compatibility: Read docs/KERNEL_COMPAT.md before adding any Linux kernel version guard.