287 Commits

Author SHA1 Message Date
40b15f121a rmapi/vm: fix master gate clippy and EDU guest FB geometry fixture (#631) (#646)
* rmapi/vm: fix clippy int_plus_one and EDU guest FB geometry register fixture

* tests/vm: use exact V100-SXM2-32GB FbGeometry register values in EDU fixture

---------

Co-authored-by: Eric Hartford <eric@quixi.ai>
2026-12-05 16:52:34 -08:00
dfda0a29a4 dma: device-owned coherent DMA contexts for GV11B platform GPUs (#606)
Add nv_rs_dma_context_create_dev(struct device *, bits, **) and
LinuxDma::from_device so Tegra194 GV11B platform GPUs, which have no
nv_rs_pci lease, can own a coherent DMA context.

ctx->pci is now optional. Creation, close and force_close share
context_init/context_destroy/context_release_owner: a PCI-owned context
releases its DMA user count and PCI reference exactly as before, a
device-owned context drops its get_device() reference with put_device().
Removal checks go through context_removed(), which consults
nv_rs_pci_is_removed only when ctx->pci is set. The PCI path keeps its
check order and errno values (-EINVAL, -ENODEV, -ERANGE, -ENOMEM).

The dma-mock fixture models get_device/put_device and covers the
device-owned lifecycle, every create failure path, force_close, and
independence from PCI removal state.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 07:20:57 -08:00
cb60725ce0 hwmon: close unregister drain race and add CONFIG_HWMON=n register_dev stubs (#598)
* hwmon: close unregister drain race and add CONFIG_HWMON=n register_dev stubs

* hwmon: preserve failure invalidation and return -ENODATA on removal
2026-12-05 07:20:51 -08:00
Jo
cc6c5bae65 fix(hwmon): invalidate stale telemetry after acquisition failures (#567)
* hwmon: WIP temperature freshness correction with host-fixture tests

WIP contribution addressing #561 (temperature readings stay valid
after acquisition failures). Not ready for merge; submitted for
contributor review.

- Failed acquisitions invalidate the live channels they cover
  (provider bits on failure are untrusted); a failed poll no longer
  extends the freshness window and does not count as a successful
  poll; retries are rate-limited and unsupported providers are
  retried rather than latched.
- Per-channel acquisition stamps bound the served age (2 s cap) and
  per-channel publication sequences provide same-tick ordering
  between polls and mirror publications; reads take validity, stamp
  and value in one critical section.
- Mirror snapshots are incremental: they never invalidate channels
  they do not carry.
- Static limits (temp_max/temp_crit/power_cap) supplied by successful
  polls are applied and preserved across failures.

Regression coverage: host fixture tests/hwmon-mock/ compiles the real
hwmon_adapter.c against a kernel API mock - 71/71 assertions (17
registration + 54 behavioral). Kernel build on 7.0.0-44-generic
headers: module gate 18/18.

Feedback incorporated from dcr000 on #561 (sample timestamps,
failed-poll semantics; the GP100 self-poll provider is intentionally
left out of this patch). Independent review: Codex (2f67d67e) - GO
for these two corrections, with the legacy-provider compatibility
limitation (ENODEV from the GA10x-only provider can invalidate recent
legacy-mirror data) and physical qualification remaining outstanding.

Prepared with AI assistance; operator-reviewed.

* hwmon: retain bounded mirror data when no active acquisition is possible

Addresses CodeRabbit's finding on the draft PR and the legacy-provider
compatibility gap recorded by Codex (2f67d67e): an -ENODEV poll (no
GA10x/GSP owner - mirror-only GPUs such as GP100, or a runtime that
has not started yet) no longer invalidates recent mirror publications.
Such polls are not acquired-channel errors: the mirror samples are
retained and expire by their own per-channel age bound, the provider
is retried every window and is never latched, and a runtime that
appears later acquires normally.

Real acquisition failures (non-ENODEV) keep the immediate
per-channel invalidation, and all freshness, ordering, static-limit
and incremental-mirror semantics are unchanged. Fixture updated:
ENODEV retains recent mirror data within its age bound, expiry still
applies, retries happen per window, and recovery works once the
provider appears (72/72 PASS: 17 registration + 55 behavioral).

* hwmon: align accepted poll intervals with the served-age bound

Addresses the remaining trivial CodeRabbit finding: with poll
intervals above roughly 500 ms, a healthy active provider's reading
expired under the 2 s served-age cap before the next poll could run,
producing artificial -ENODATA periods (merge-base kept the value).
The freshness limit itself is unchanged; instead the accepted maximum
poll interval is now aligned with it: NV_RS_HWMON_POLL_MAX_MS is 500
(the largest interval whose uncapped active age formula, 2*poll+1000,
stays within the 2 s bound), larger configured values are clamped
rather than refused so polling keeps working, and the clamp is
documented in the module parameter description. A static_assert ties
the interval and age constants together at compile time. Regression
tests: oversized intervals are clamped and stay fresh; the default
interval never starves a healthy provider (no re-poll inside the
rate-limit window, exactly one poll in the next). 83/83 PASS.

* hwmon: revert the polling clamp; document long-interval -ENODATA behavior

Per independent review (cdaf3ee0), revert the v7 polling clamp: the
established minimum-interval contract is preserved and hwmon_poll_ms
is again honored up to 60000 ms. The 2 s served-age bound is
unchanged and is never extended to bridge a long polling interval:
with hwmon_poll_ms above the age bound, cached samples legitimately
expire and reads return -ENODATA between eligible acquisitions. This
is now documented in the served-age comment and in the module
parameter description.

Configuration regression tests updated: long intervals honor the
requested minimum (no clamp, no re-poll inside the window) and expose
-ENODATA once the cache expires, then refresh at the next eligible
poll; intermediate intervals (1000 ms) return -ENODATA after expiry
and recover on the next eligible read; the default interval keeps a
healthy provider fresh without extra polls. 92/92 PASS.

* hwmon: allow immediate cold-start acquisition; keep failures rate-limited

Addresses the second CodeRabbit minor finding (verified against
b6f657b4): the zero-initialized attempt timestamp was a sentinel, not
a real attempt, so a freshly registered slot could be throttled before
its first poll when the Linux tick counter was below the poll
interval. A separate 'attempted' flag now gates the retry deadline:
the first attempt always runs (cold start acquires immediately, as the
merge base did), while subsequent attempts - successes, failures and
unsupported providers alike - remain rate-limited by the configured
interval. mark_polled also marks an attempt so a Rust-side poll
completion keeps its throttling semantics. Regression test: cold
start with a small tick counter acquires on the first read with
exactly one poll, and the window still suppresses further polls.

The first CodeRabbit minor finding (transport-latency vs acquisition
age on a late-RPC timeout) is an existing upstream producer-contract
limitation, not a regression of this patch: the merge base served the
delayed value indefinitely; this patch bounds it to the 2 s served
age. Producer-side acquisition timestamps remain the documented
follow-up.

* hwmon: partial-poll retention, separate loop index, C89 declarations, stale-bit clear

One minimal revision addressing the latest CodeRabbit minor finding and
dcr000's review items at 60112a59:

- Partially available telemetry: a successful poll that did not
  acquire a channel no longer erases a still-fresh cached value for
  that channel (a partial batch must not invalidate an unrelated
  fresh mirror reading); the cached value is cleared only once it is
  already past its served age. Failed acquisitions still invalidate
  immediately.
- Separate loop index in nv_rs_hwmon_update_sample so the channel
  stamp loop no longer reuses the enclosing slot index.
- The sysfs show helpers declare their locals at function top,
  keeping kernels before 6.5 (-Wdeclaration-after-statement)
  buildable.
- Timestamp expiry and wraparound: the first stale read clears the
  channel's valid bit (publication-sequence guarded), so a jiffies
  wraparound cannot revive an ancient reading; a new publication
  restores it. Regression test added with a simulated 32-bit wrap.

Configurable freshness limits remain a separate design decision for
the maintainers (not changed here); the GP100 self-poll provider
stays with dcr000. Fixture 103/103 PASS; kernel-object gate 18/18.

* hwmon: conservative partial-poll semantics, in-lock expiry, wrap-safe age, strict-C89 helpers

Addresses Codex 36419308's four findings:

1. Partial-poll retention reverted: with the existing provider API an
   absent channel cannot be told apart from a failed acquisition, so
   successful polls conservatively invalidate channels they did not
   acquire (v9 error semantics restored); per-channel acquisition/
   error status from the provider remains the documented follow-up.
2. Read-side expiry evaluation and the stale-bit clear now happen
   inside the same sample_lock critical section as the snapshot, so a
   concurrently published sample (poll or mirror) is never discarded.
3. Age comparison uses the wrap-safe unsigned jiffies difference;
   on every supported target (x86_64, arm64) stamps are 64-bit and
   cannot compare young again. Fixture covers observed expiry, a huge
   dormant offset and recovery.
4. The five sysfs helpers now declare locals before any statement;
   verified with -Werror=declaration-after-statement on the guest.

Fixture 102/102 PASS (22 registration + 80 behavioral), also passing
under the strict declaration check; kernel-object gate 18/18.
2026-12-05 06:30:40 -08:00
19a84a4392 fix(validation,tests,docs): live.log skip reason (#580), controls.tsv capture check (#579), Ampere/Turing parity docs (#578) (#582)
* fix(validation,tests,docs): record live.log skip reason (#580), verify controls.tsv (#579), update Ampere/Turing parity rows (#578)

* docs(parity): attribute Turing live [O] results strictly to RTX 2060 (TU106)

---------

Co-authored-by: morebrackets <19673572+morebrackets@users.noreply.github.com>
2026-12-04 23:35:52 -08:00
e8ba298d38 Verify stock requirements in UVM and modeset bridge checks (#462)
* Verify stock requirements in UVM and modeset bridge checks

* fix(tools): require stock pair check for explicit --stock-symvers and check access-bits from stock_uvm_und

---------

Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Eric Hartford <eric@quixi.ai>
2026-12-04 21:08:46 -08:00
4f3029ebd7 tools/docs: NixOS portability for first-open runner, bind_dev_nodes, pahole, and live-swap udev freeze (#506)
* tools/docs: NixOS portability for first-open runner, bind_dev_nodes, pahole, and live-swap udev freeze

* docs: note udev queue restart on failed or aborted live swaps

* docs: drain in-flight udev workers with udevadm settle before freezing queue
2026-12-04 20:28:24 -08:00
6435d65112 fix(rmapi/modeset): rmmod refcnt leak (#491), modeset RM ops (#466), runtime logs/fw warning (#501) (#513)
* fix(ga10x/rmapi/modeset): R620 control translation, rmmod refcnt, modeset RM ops (#504, #491, #466, #501)

* chore(pr513): drop gsp_route R620 hunk in favor of live-verified #514

* fix(gpu_owner): balance get_task_struct with put_task_struct after kthread_stop

* fix(gpu_owner/irq): wait for runtime worker join & pin/teardown failed runtime IRQ close

Addresses CodeRabbit review findings on PR #513 (and #491/#528):
- gpu_owner.c: Wait for runtime_stopped in a 10s warning loop and always join
  via kthread_stop() + put_task_struct() so an unpinned runtime worker can
  never outlive module text during PCI removal / rmmod.
- irq_adapter.c: When nv_rs_irq_close() fails to quiesce an unpinned
  runtime-kthread IRQ owner, acquire THIS_MODULE before returning the error
  (or force-disable/synchronize/free handlers if the module is already
  unloading so no callback can outlive module text).
- ga10x_events.rs: Check nv_rs_irq_close() status in stop() and restore e.irq
  on failure instead of discarding the handle.
- tests/irq-mock: Cover both live-pin and unloading-force-teardown paths.

* fix(pci,irq): disable PCI INTx on forced IRQ close and bound AER/shutdown runtime stop

Address follow-up review findings on #513:
- In nv_rs_irq_close() forced teardown (unpinned runtime worker after mask
  failure), call pci_intx(owner->pdev, 0) for legacy INTx mode so the
  device stops asserting its level-triggered line without disabling a
  shared IRQ line for other devices, and add an irq-mock regression test.
- Add nv_rs_gpu_owner_runtime_stop_bounded(owner, timeout_ms) preserving
  runtime_task and runtime_stopping on timeout (preventing restart races
  and allowing a later nv_rs_remove() stop to complete the join).
- In nv_rs_shutdown() and nv_rs_aer_error_detected(), call pci_clear_master()
  first for immediate DMA containment, then use a bounded runtime stop so
  shutdown and PCIe AER callbacks never wedge indefinitely.

* fix(pci,pm): bound runtime_lock wait, reclaim retired worker on start/AER, and reassert BME clear

Address follow-up review findings on #513:
- Include runtime_lock acquisition inside nv_rs_gpu_owner_runtime_stop_bounded()'s
  deadline via bounded mutex_trylock() polling so shutdown/AER cannot hang when
  startup holds runtime_lock waiting for runtime_ready.
- Reclaim a retired worker in nv_rs_gpu_owner_runtime_start() via
  nv_rs_gpu_owner_runtime_reclaim_locked() and in nv_rs_aer_resume() so a
  timed-out bounded stop never strands runtime engines unavailable after recovery.
- Reassert pci_clear_master(pdev) after the serialized stop attempt in
  nv_rs_shutdown() and nv_rs_aer_error_detected() so in-flight GPU bring-up
  cannot leave Bus Master enabled.
- Use nv_rs_gpu_owner_runtime_stop_bounded() in PM suspend/runtime_suspend with
  full state rollback on timeout so suspend cannot wedge indefinitely while
  nv_rs_remove() keeps the unconditional join required before module unload.

* fix(pci): keep Bus Master enabled during bounded GSP unload on shutdown

Address final review comment on #513:
- In nv_rs_shutdown(), invoke nv_rs_gpu_owner_runtime_stop_bounded(owner, 10000)
  before pci_clear_master(pdev) so an active GSP session can complete its
  DMA unload RPC during clean shutdown, then clear Bus Master Enable once
  the stop finishes or hits its bounded deadline.

* fix(pci,pm): return DISCONNECT on AER stop timeout and keep full PM suspend stop

Address review findings on #513:
- In nv_rs_aer_error_detected(), return PCI_ERS_RESULT_DISCONNECT rather than
  PCI_ERS_RESULT_NEED_RESET if nv_rs_gpu_owner_runtime_stop_bounded() times
  out, preventing a PCIe slot reset while a live runtime worker could still
  issue MMIO or re-enable Bus Master.
- In nv_rs_pm_do_suspend() and nv_rs_pmops_runtime_suspend(), wait for worker
  retirement via nv_rs_gpu_owner_runtime_stop() before entering D3hot rather
  than half-aborting after modeset suspend and USERD VMA revocation.

---------

Co-authored-by: morebrackets <19673572+morebrackets@users.noreply.github.com>
2026-12-04 19:48:23 -08:00
cb15715316 kernel-open: add opt-in Tegra194 GV11B platform_driver and bus-agnostic rmapi_node registration (#385)
* kernel-open: add opt-in Tegra194 GV11B platform_driver and bus-agnostic rmapi_node registration

* rmapi_node: support platform dev in nv_rs_rmapi_mmap

* platform(gv11b): skip reset_control when Tegra genpd pm_domain owns GPU reset

* kernel-open(gv11b): fault-map and revoke platform BAR IO VMAs on GPU removal

* kernel-open(gv11b): extract rmapi_plat_io.h and test platform BAR VMA revocation in host fixture

* kernel-open(gv11b): propagate and report actual platform DMA mask in proc gpu info

* kernel-open(gv11b): document plat_io pgoff/BDF assumptions and harden !live release

* kernel-open(gv11b): clean up orphaned plat_io mappings on file release

* kernel-open(gv11b): resolve duplicate boot0/dma_bits fields after rebase

* kernel-open(gv11b): gate file_ref_get() on Linux >= 6.13 or NV_RS_HAVE_FILE_REF
2026-12-04 17:03:17 -08:00
Kev
034d12a8d6 gpu: run GP104 Devinit before framebuffer discovery (#547)
* Run GP104 VBIOS Devinit before framebuffer discovery

Run the stock-derived Devinit sequence on uninitialized Tesla P4 and GTX 1070 cards before the normal Pascal runtime reads VRAM. Extract the signed PMU boot loader from the stock 580.178.04 object and retain DMA if the PMU fails to quiesce.

* Reuse the Pascal firmware pack and recover incomplete GP104 bring-up

* Recover retained GP104 PCI owners and reconcile bus setup on rebind

* Preserve the next driver's bus mastering after a Devinit drain
2026-12-04 17:03:00 -08:00
618a270c09 tools: fail the module check on Rust-object calls to memcpy/memset/memmove (#478)
CLAUDE.md, AGENTS.md, docs/GPU_BRINGUP_GUIDE.md and CONTRIBUTING.md say
tools/check_kernel_module.py fails on calls to memcpy, memset and memmove.
It had no such check: its only undefined-symbol test looks for private
nv_rs_/Rust runtime names, and prepare_kernel_archive.py removes the
compiler_builtins copies of these helpers, so a lowered copy or fill in
Rust would bind to the kernel's symbol and the gate would stay green.

Add no_Rust_object_calls_to_memcpy_memset_memmove. It reads the Rust
object (nv-rust.o_binary), not nvidia_rs.ko: the thin C adapters
legitimately call the kernel's memcpy/memset (dma_adapter.o, rmapi_node.o,
gpu_owner.o, ...). A call is any relocation against one of the three names
or the name left undefined, whether or not the object also defines it.
Every REL/RELA section counts, .rela.debug_* included, which errs toward
refusing. The check also runs under --object-only. The offending names
are printed on stderr and listed under
rust_object_calls_to_memcpy_memset_memmove in the stdout JSON in every
mode, and in the committed report on a no-argument run.

Blind spot: a call to a local or hidden definition in the same section
resolves without a relocation and is not seen. That cannot happen with
today's build, because prepare_kernel_archive.py deletes the
compiler_builtins copies.

strlen is allowed on purpose and the comment says so: 456fafd2 removes
the precompiled compiler_builtins strlen so Rust's core::ffi::CStr calls
(kernel/irq.rs ColdPciPolicy::resolve) bind to the strlen Linux exports.
CONTRIBUTING.md:18 disagrees: it also lists strlen. That is left as a
question for the maintainers rather than changed here.

Test: test_gate_cases.py assembles a caller of each of memcpy, memset,
memmove and strlen, with and without a local definition. Before this
change the three mem* cases error (no such check). After it, the new
check is false for them, the JSON lists exactly that name and stderr
says "calls <name>;". For strlen the check is true, the list is empty
and stderr names nothing. On the current tree the Rust object's only
libc-style import is strlen, so make modules passes.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 16:16:11 -08:00
d394ce4b64 Require exact llama-bench workloads before reporting throughput (#498) 2026-12-04 16:16:06 -08:00
824859b1c5 tools: require CUDA model offload in llama.cpp parity runs (#536)
Co-authored-by: shiaho <222622008+shiaho777@users.noreply.github.com>
2026-12-04 16:16:01 -08:00
9b579c4d11 tools: stop dual-GPU parity when the process list is unavailable (#538)
Co-authored-by: shiaho <222622008+shiaho777@users.noreply.github.com>
2026-12-04 16:15:48 -08:00
9c42cf5dae build: restore hardware fixture verification after the repository move (#535)
Co-authored-by: shiaho <222622008+shiaho777@users.noreply.github.com>
2026-12-04 16:15:43 -08:00
8a63855c5f tests: compile C fixtures as position-independent objects (#550) 2026-12-04 16:15:36 -08:00
416c8eb9f1 Merge origin/master (a52af77e, PRs #438/#467/#473/#474/#475/#485) into feat/ga102-desktop-master 2026-12-03 16:47:17 -08:00
f37f127306 build: audit modules against the target kernel configuration (#473)
Pass the resolved Kbuild directory to the module audit so an offline or DKMS build uses the target kernel mitigation settings.
2026-12-03 15:14:51 -08:00
7f1ebf4aa1 install: preserve CDI mounts when adding /dev/char (#474)
Edit the global CDI mount list as YAML and atomically publish a complete spec. Retain the generated content when parsing fails or an existing mount conflicts.
2026-12-03 15:14:46 -08:00
d1bd9fd428 tools: validate complete NCCL collective payloads (#475)
Compare every rank payload with the expected float32 contents. Exercise the public CLI verdict with deterministic offline fixtures.
2026-12-03 15:14:41 -08:00
5a1b9a659e Merge origin/master (ca3d44e3, NVKMS surface FFI #471 + DRM PAGE_SIZE #458) into feat/ga102-desktop-master 2026-12-03 13:10:52 -08:00
9a52945efb Merge origin/master (41f02168, PRs #388/#432/#437/#443) into feat/ga102-desktop-master 2026-12-03 09:27:23 -08:00
37a6e160ae tools: run the GP106 oracle areas from validate_all.sh
The 19 areas of tools/gp106/check.sh, which hold all 26 GP106 opt-in
(#[ignore]) comparisons against the 580.178.04 instructions, were run by
nothing: not by validate_all.sh, not by the Makefile. They only ran when
someone typed the loop from reports/gp106-core-validation.md, and that
loop left out pte-policy.

check.sh gains an `all` area that runs every area in order and stops at
the first failure. validate_all.sh runs it as the optional step
gp106_oracles, next to gsp_620_headers. Missing prerequisites follow the
existing optional-step rule (exit 2 is SKIP, as in test_native_compute.sh
and oracle_gsp_620.py): `all` exits 2 before running anything when the
interpreter cannot import Unicorn and pyelftools, or when
resolve_580_binary() finds no original object. A present object with the
wrong digest, a generator error or a Rust mismatch is still FAIL. The
interpreter default is the top-level Makefile's REA_PYTHON default.

The report now documents `check.sh all` in place of the hand-written
loop. The step count in AGENTS.md, CLAUDE.md and docs/GPU_BRINGUP_GUIDE.md
is set to 36, the number of PASS/FAIL/SKIP lines validate_all.sh prints
with this step; those files said 31, 30 and 31 while the script already
printed 35.

Tests: tests/gp106/test_check_all.py covers both exit-2 paths and the
usage line with stand-in interpreters; tests/vm/test_validate_guest_steps.py
covers PASS, SKIP and FAIL of the new step. All six fail on master.

No driver logic changes. On this host `check.sh all` passes all 19 areas
(90 Rust tests, 0 failed) in about 4 minutes cold, 3 minutes warm; BAR2
and the two framebuffer generators are most of it.
2026-12-03 11:24:34 -06:00
4ff8c5f42b Merge origin/master (0fe8fd1c, GB20x/FSP/MMU v3) into feat/ga102-desktop-master 2026-12-03 09:12:44 -08:00
41f02168fc Merge pull request #388 from ChrisMythos/pr/sysmem-scatterlist-dma-memtypes
rmapi_node: scatterlist DMA mapping and UC/WC memtypes for RM API system memory
2026-12-03 09:11:51 -08:00
b89fb55783 Merge pull request #415 from Fardid021/edu-zbc-class
tests/vm: GF100_ZBC_CLEAR (0x9096) constructs since #266
2026-12-03 08:44:41 -08:00
76ca4abcc5 GB20x (RTX 50): GSP boot through the FSP, MMU v3 and CUDA on a GB205 (#416)
* GB20x (RTX 50): GSP boot through the FSP, MMU v3 and CUDA on a GB205

A GB205 (RTX 5070) stopped at "boot failed" (EIO): its GSP is started by the
FSP, not by booter_load on SEC2, and its page tables are format version 3.

- gpu/fsp.rs: the FSP command channel (EMEM queue, MCTP/NVDM headers), the
  chain-of-trust message with the FMC image and its signature, and the checks
  of the reply. extract_gsp_boot_ucode.py also takes the GB20x FMC out of the
  580.178.04 module.
- MMU format version 3 for the kernel-side tables and the UVM node: PDE4 root
  with 2 entries, PCF field, 16-byte PDE0.
- Context buffers placed by their own sizes: a GB205's attribute CB is 50 MiB.
- Work submit token with RUNLIST_DOORBELL (bit 30).
- BLACKWELL_USERMODE_A with bBar1Mapping: the doorbell is mapped through BAR1
  (PTE kind SMSKED_MESSAGE). Rung through BAR0, about one CUDA start in four
  waited forever for its first work.
- Classes 0xcec0, 0xce97 and 0xc761; copy engines from the class database.

Tested on an RTX 5070 (10de:2f04, VFIO guest, 580.178.04 userspace).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* uvm: a PTE kind that does not fit MMU format 3 gives an invalid entry

V3 has four bits for the kind. A kind like 0x1f became 0xf, a reflected SKED
entry without an address, and 0xdb became 0xb. Such an entry is now invalid, so
that an access faults instead of using another kind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* GB20x: review fixes

- ga10x_mem: a BAR1 of 2 MiB or less has no room for the doorbell slot and is
  refused before anything is allocated. The check word stays out of that slot.
  If the window is taken back and the invalidate does not complete, its tables
  stay allocated.
- ga10x_gsp: a boot that fails before the message to the FSP (for example
  because the FMC file is missing) gave no falcon an address, so its memory is
  freed and the next open can try again without a GPU reset.
- uvm_node: VA bit 56 picks the PDE3 page in MMU format 3.
- mmu_v3: a system address above bit 51 gives an invalid entry.
- fsp: use the HWCFG2 and NVDM helpers that exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 17:38:13 +01:00
b60c3dd220 Merge origin/master into feat/ga102-desktop-master 2026-12-03 07:55:02 -08:00
0a9a7cbf67 tests/vm: GF100_ZBC_CLEAR (0x9096) constructs since #266
Next to #419's check of a class without a constructor. It shares a CHECK with
0x90e6, so that the recorded reports keep their number of checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 01:47:44 +11:00
6a0253216b rmapi_node: a pinned record holds each allocation once, at most 1024
CodeRabbit on #388 (comment 4784402535): nv_rs_rmapi_pin_scan added the
full source list of a pinned owner once for every area of it the range
covered, and nv_rs_rmapi_pin_retain took a use per copied entry. A mapping
split in two areas (mprotect of part of it, a second mmap next to it) held
its allocation twice; a record pinned through two areas of a mapping of
that record held it four times, doubling with every level while the pinned
pages stayed few.

Stock keeps no such list: os_lock_user_pages only pins the pages under the
mmap lock and refuses an unpinnable range with NV_ERR_INVALID_ADDRESS
(580.178.04 os-mlock.c:216-309; 620.73.04 os-mlock.c:231-322). The list is
this driver's own, so that no allocation restores write-back, pools or
frees its pages while a record maps them.

- PinnedSources (alloc_registry.rs, nv_rs_core): two sorted sets in caller
  storage. An allocation whose mappings the range lies in is looked at
  once, however many of its areas the range covers; a mapping of a pinned
  record adds the allocations that record holds; what the new record holds
  is each allocation once. Exported as nv_rs_pinned_sources_add.
- nv_rs_rmapi_pin_scan gathers the set under the mmap lock (no global
  lock), into room for NV_RS_PINNED_SOURCES_MAX (1024) allocations seen
  and 1024 held. Past either bound the range is refused with
  NV_ERR_INSUFFICIENT_RESOURCES (0x1a, nvstatuscodes.h:55 in 580.178.04
  and 620.73.04). A range no one mapping type fits is still refused with
  NV_ERR_INVALID_ADDRESS first.
- nv_rs_rmapi_pin_retain takes exactly one use per gathered allocation
  into a list of exactly that length; teardown (nv_rs_rmapi_put_sources)
  drops one use per entry, unchanged.

Tests:
- host: pinned_sources_tests (split mapping pinned through to depth 40
  holds the allocation once; an allocation reached through several
  records and its own mapping once; the bound refuses one past it, in
  held allocations and in mapped ones).
- guest (edu_adapter_test.c rmapi_user_pages_split_check): an uncached
  allocation's mapping split in two areas at page 8 is pinned (record 1),
  record 1's mapping split the same way is pinned (record 2), and both
  mappings together (record 3): each holds one entry, the allocation.
  Before this change the guest check fails with "record 1 holds 2
  entries". Record 1 alone keeps the pages UC- after everything else is
  released; when it goes they are write-back again (6.6+).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:08:34 +01:00
b9de5a2c25 rmapi_node: write-combined mappings for a range pinned through write-combined user mappings
From CodeRabbit's third review of #388: a range pinned (class 0x71) wholly through
user mappings of a write-combined (cache type 2) allocation got UC kernel and UC-
user mappings, while the user mapping it was pinned through is WC.

Stock, checked first:
- The kernel linear map of write-combined system memory is UC-, as for uncached:
  nv_alloc_system_pages calls nv_set_memory_type(at, NV_MEMORY_UNCACHED) for every
  cache type but NV_MEMORY_CACHED (580.178.04 nv-vm.c:583-584), which ends in
  set_pages_array_uc / set_memory_uc (nv_set_pages_array_type :106-128,
  nv_set_contig_memory_type :130-149); 620.73.04 does the same through
  nv_set_memory_type(at, NV_FALSE) (nv-vm.c:1056-1058, :31-139). Neither has a
  write-combined page attribute.
- nv_vmap has only PAGE_KERNEL and PAGE_KERNEL_NOCACHE (580.178.04 nv-vm.c:634-656),
  so the allocation's own kernel mapping is UC for both types (nv.c:3762-3763).
- nvidia_mmap gives the user mapping the allocation's type (nv-mmap.c:699-708,
  nv_encode_caching :328-394).
- nv_register_user_pages gives every pinned range NV_MEMORY_UNCACHED (nv.c:3390)
  and never changes the pages' attribute; nv_alloc_kernel_mapping vmaps user
  memory of any size (isUserAllocatedMem, nv.c:3722-3732).

This branch already matches the first three; unchanged here.

Change:
- nv_rs_rmapi_pin_scan counts the bytes of the range in uncached and in
  write-combined user mappings of this node separately (nv_rs_rmapi_user_cache,
  the type nv_rs_rmapi_mmap applies). PinnedRangeCache::of in nv_rs_core decides:
  none: cached; all uncached: uncached; all write-combined: write-combined;
  any other mix (WC with UC, WC or UC with write-back) is refused with
  NV_ERR_INVALID_ADDRESS, as mixed ranges already were.
- A write-combined record vmaps with pgprot_writecombine(PAGE_KERNEL) and its
  user mappings use pgprot_writecombine. An uncached record keeps
  PAGE_KERNEL_NOCACHE / pgprot_noncached. The source allocation's own vmap stays
  PAGE_KERNEL_NOCACHE and its linear map UC-, as stock.
- A pinned record is always vmapped, also for one page, as stock vmaps user
  memory; before, a one-page record used the page's linear address.
- Differences from stock: stock maps every pinned range uncached; here a range
  pinned through write-combined mappings is mapped write-combined, and the
  linear map stays UC- under it, as it is under the source's own WC user
  mapping in stock.

Tests:
- Host (pinned_range_tests): write-combined ranges, WC+UC / WC+WB / all three
  refused in either order, the NV_MEMORY_* values. Three of them fail with the
  previous decision (write-combined counted as uncached).
- EDU guest: rmapi_user_pages_memtype_check runs for cache type 1 and 2. It maps
  the source and an allocation of the other type side by side next to anonymous
  memory, checks the linear maps (UC-), the source's vmap (UC), the user
  mappings, refuses four mixed ranges, pins the source range, checks the
  record's kernel mapping (WC or UC), maps the record and checks that mapping,
  pins through it, and keeps the lifetime checks of the previous version. The
  kernel-mapping check needs nv_rs_rmapi_os_kernel_address, compiled only with
  NV_RS_PCI_TEST_EDU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:08:34 +01:00
839d9a8b54 rmapi_node: refuse mixed pinned ranges; a pinned record holds the allocation it was pinned through
Two cases d3a6cb7a left open (CodeRabbit on #388):

1. A class 0x71 range across a user mapping of an uncached allocation of this node and ordinary write-back
   memory got uncached kernel and user mappings for the whole range, so they aliased the write-back pages.
2. The pinned record held only page pins. When the allocation's RM object and then its mapping file went
   first, its teardown restored write-back and freed or pooled the pages while the record still mapped them
   uncached. A pooled page could then go to another allocation while the pins and the record's mappings
   remained.

What stock does (580.178.04 kernel-open; 620.73.04 where it differs):
- os_lock_user_pages (os-mlock.c:216-309) pins under the mmap lock and looks at nothing else. A range it
  cannot pin fails with NV_ERR_INVALID_ADDRESS (:298-304).
- nv_register_user_pages gives every pinned range NV_MEMORY_UNCACHED (nv.c:3390): kernel mapping
  PAGE_KERNEL_NOCACHE (nv.c:3762-3763), user mappings uncached. Write-back anonymous pages are mapped
  uncached too, so stock has no rule for a mixed range.
- A system-memory mapping sets NV_VMA_PRIVATE(vma) = at (nv-mmap.c:706). Only the area holds at
  (nvidia_vma_open / nvidia_vma_release, nv-mmap.c:66-113). The pinned record does not hold the allocation.
  nv_free_system_pages restores write-back and frees the pages while they are still pinned (nv-vm.c:619-620).
  620.73.04 hands freed pages to its pool (nv-vm.c:962-963) without looking at their references.

Stock has no safe answer for either case. This commit takes the fail-safe behaviour:

- nv_rs_rmapi_os_lock_user_pages scans the areas of the range under the mmap lock the pages were pinned under.
  - nv_rs_core decides from the bytes inside user mappings of allocations with an uncached kernel mapping
    (PinnedRangeCache, pinned_area_bytes in rmapi/alloc_registry.rs):
    - none of the range: cached;
    - all of it: uncached;
    - otherwise the import is refused with NV_ERR_INVALID_ADDRESS (0x1e), the status of a range stock cannot
      pin.
- The record holds a use of every allocation of this node whose user mapping the range was pinned through
  (AllocLedger::retain_ptr, export nv_rs_alloc_reg_retain_ptr).
  - nv_rs_rmapi_alloc_destroy unpins first and drops those uses afterwards. Until then no such allocation
    restores write-back, pools or frees its pages.
  - A mapping of another pinned record counts for the allocations that record holds, so records never hold
    records and teardown stays one level deep.
  - Ranges without such mappings hold nothing, as before.
- New exports nv_rs_alloc_reg_retain_ptr, nv_rs_pinned_area_bytes and nv_rs_pinned_range_cache, added to the
  -u lists in src/nvidia/Makefile and tools/vm/build_guest_test.sh.

Tests:
- Host (nv_rs_core):
  - rmapi::alloc_registry::pinned_range_tests (4): mixed in either order, one page or many, refused; whole
    ranges cached or uncached; areas clipped to the range.
  - tests::pinned_record_keeps_the_allocation_it_was_pinned_through: RM free and file release leave the
    allocation alive until the pinned record goes.
  - tests::retain_ptr_needs_a_record_and_a_free_count.
- EDU guest, rmapi_user_pages_uncached_check:
  - maps a 16-page uncached allocation from the control node over the upper half of an anonymous mapping of
    the insmod process (mapping context, then mmap);
  - expects 0x1e for the 32-page and the 2-page range across both;
  - pins the uncached half, writes through the record and reads the byte back from user space;
  - frees the RM object, unmaps and releases the file (__fput_sync), then expects the pages still UC- in the
    linear map, and write-back once the record is unlocked.
  - Without this commit the load fails with "NV_RS_VM_FAIL rmapi pinned uncached mapping: -52" (mixed
    range accepted). With only the retention disabled it fails with -116 (pages write-back while still
    pinned).
  - With this commit the module loads and unloads in both IRQ modes, with and without --iommu. The guest's
    user-space test still stops at rmapi_user_test.c:318 (errno 22), as master 6a8a0bc1 does in both
    modes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:08:34 +01:00
8e9e351e5a rmapi_node: no write-back alias when a pinned range maps uncached system memory
Since da41c9ca a class 0x3e allocation of cache type 1 or 2 has an uncached kernel mapping and UC/WC user
mappings. A class 0x71 object can pin a range of such a user mapping. Its record kept cache type 0, so its
vmap (PAGE_KERNEL) and its user mappings were write-back over pages whose linear mapping is uncached
(CodeRabbit on #388).

Stock gives every pinned range NV_MEMORY_UNCACHED (nv_register_user_pages, 580.178.04 nv.c:3390), so its
kernel mapping is PAGE_KERNEL_NOCACHE (nv_alloc_kernel_mapping, nv.c:3762-3763 -> nv-vm.c:647) and its user
mappings are uncached (nv_encode_caching). It never maps such pages write-back.

Changes:
- nv_rs_rmapi_os_lock_user_pages pins under the mmap read lock with pin_user_pages, as os_lock_user_pages
  does (580.178.04 os-mlock.c:252-296), instead of pin_user_pages_fast. Under the same lock it looks at the
  areas of the range. If one is a user mapping of this node whose allocation has an uncached kernel mapping,
  the record gets cache type 1 and kernel_uc: vmap PAGE_KERNEL_NOCACHE, user mappings pgprot_noncached.
  Other ranges stay cached, as before. The pages' attribute stays their allocation's.
- nv_rs_rmapi_mmap sets vm_private_data to the allocation, as stock sets NV_VMA_PRIVATE(vma) = at
  (nv-mmap.c:706). The area holds its file, whose mapping context holds the allocation.
- pin_user_pages lost its vmas argument in 6.5. kernel-open/compat_probes.mk defines
  NV_RS_PIN_USER_PAGES_HAS_VMAS from the declaration in mm.h, as stock's NV_PIN_USER_PAGES_HAS_ARGS_VMAS
  (nv-mm.h:53-59). docs/KERNEL_COMPAT.md lists it.
- EDU guest: rmapi_start pins 16 pages of an anonymous mapping of the insmod process, writes one byte
  through the kernel mapping of the pinned range and reads it back from user space, then checks that the
  unmapped range is refused with 0x1e. With the expected byte changed, the module load fails with
  "NV_RS_VM_FAIL rmapi pinned user pages: -71" as it should.

Not tested: a pinned range inside a UC/WC mapping of this node. The guest's user-space RM API test stops at
rmapi_user_test.c:318 on this host (master too) before its memory slice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:08:33 +01:00
9ea8afd9c9 rmapi_node: uncached kernel mapping and UC/WC user mappings for non-cached system memory
RM API system memory (class 0x3e) recorded its NV_MEMORY_* cache type but ignored it: every
allocation kept a write-back kernel mapping, a PAGE_KERNEL vmap and write-back user mappings,
also for the uncached (1) and write-combined (2) types libcuda requests
(NVOS32_ATTR_COHERENCY_WRITE_COMBINE).

Stock, for an allocation that is not NV_MEMORY_CACHED:
- makes the kernel mapping of its pages uncached when it allocates them:
  nv_alloc_system_pages -> nv_set_memory_type(at, NV_MEMORY_UNCACHED), 580.178.04
  nv-vm.c:583-584 -> nv_set_pages_array_type, nv-vm.c:106-128 (set_pages_array_uc on x86);
- restores write-back before it frees them: nv_free_system_pages, nv-vm.c:619-620;
- vmaps them PAGE_KERNEL_NOCACHE: nv_alloc_kernel_mapping -> nv_vm_map_pages(cached =
  cache_type == NV_MEMORY_CACHED), nv.c:3762-3763 -> nv_vmap, nv-vm.c:634-656;
- maps them to user space with that type: nvidia_mmap -> nv_encode_caching before
  nvidia_mmap_sysmem, nv-mmap.c:328-394 and 699-708 (620.73.04 nv-mmap.c:346-363 and 617-622
  use pgprot_writecombine / pgprot_noncached).

The same now happens here, on x86 (CONFIG_X86), where stock's conftest finds set_pages_array_*.
On other architectures allocations stay cached, as before (stock still applies its uncached
pgprot to user mappings there).

Deviation, on purpose: stock ignores the result of set_pages_array_uc. That call can fail after
it changed the attribute of some pages (it releases only the memtype reservations), and a
write-back user mapping must not alias an uncached page. Here a failed conversion is undone with
set_pages_array_wb and the allocation stays cached everywhere; if that restore also fails, the
allocation fails and its pages are leaked. On free and on the registry-insert failure path, pages
whose write-back attribute cannot be restored are leaked too, never pooled or freed.

The decision logic is in nv_rs_core (alloc_registry.rs: sysmem_make_uncached,
sysmem_may_release) with host tests; the kernel calls stay in rmapi_node.c
(nv_rs_rmapi_os_pages_uc / _wb), joined by two exports in rmapi_memory.rs
(nv_rs_sysmem_make_uncached, nv_rs_sysmem_may_release), added to both -u lists.

Tests:
- cargo test sysmem_memtype: 4 tests. With the 31ca25ca behaviour (no restore after a failed
  set_pages_array_uc, pages freed whatever the restore returns) 3 of the 4 fail.
- EDU guest: a 16-page write-combined allocation has a UC- kernel mapping after allocation and
  write-back after free, and its vmap (kernel_write) works; with set_pages_array_uc reported as
  failed after it ran, the guest restores write-back and the check fails as expected.

GPU PTEs are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:08:33 +01:00
cab767ae5f rmapi_node: DMA-map a system-memory allocation in one scatterlist, as stock does
nv_rs_rmapi_os_page_dma mapped RM API system memory for a GPU one 4 KiB page at a time
(dma_map_page per page, on first use). Behind a translating IOMMU every page got its own IOVA,
allocated top-down, so the pages of one allocation were neither in order nor in one range.

Stock maps every allocation of more than one page with one scatterlist and reads each page's
DMA address back from the DMA segments, which the mapping may have merged:
- 620.73.04 nv-dma.c:486-559 nv_dma_map_pages -> nv-dma.c:356-399 nv_dma_map_scatterlist
  -> nv-dma.c:327-354 nv_load_dma_map_scatterlist;
- the table comes from sg_alloc_table_from_pages_segment with NV_DMA_MAX_SEGMENT_SIZE (2 GiB),
  nv-linux.h:1059-1068, and the probe raises the device's max segment size, nv-pci.c:1277.
580.178.04 does the same with sg_alloc_table_from_pages in submaps of up to 4 GiB
(nv-dma.c:326-369, nv-linux.h:1163 and 1175-1180) and no dma_set_max_seg_size.

Changes:
- The first DMA request for an allocation and GPU maps the whole allocation that way
  (nv_rs_rmapi_dma_map_whole). If that fails, pages are mapped one by one as before. Teardown
  unmaps the table, or the pages mapped one by one. The insert-failure path now unmaps too.
- nv_rs_pci_open calls dma_set_max_seg_size(dev, U32_MAX) as the 620.73.04 probe does.
- The EDU guest test allocates 16 pages through nv_rs_rmapi_os_alloc_pages and checks their DMA
  addresses for the listed device: one ascending IOVA range with --iommu, the physical address
  without. With the scatterlist path disabled the --iommu run fails this check (-ERANGE).

GPU PTEs are unchanged: they stay 4 KiB for this memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:08:33 +01:00
299a2b8d75 Merge pull request #404 from ThingsCouldGetDicey/fix/control-table-generator-parity
fix(rmapi): preserve existing memory controls in table generator
2026-12-03 15:01:13 +01:00
3d89891454 Merge pull request #419 from ChrisMythos/pr/guest-rmapi-probe-class
tests/vm: probe NOT_SUPPORTED with 0xa0e0 now that 0x9096 constructs
2026-12-03 15:00:19 +01:00
25e34f8ab4 tools: let the first-open gate run without the stock driver (#57)
The runner read /proc/driver/nvidia/version while building its report at
module level.  On a clean testbench, or in a VM built for this gate, that
file does not exist, so the script died with FileNotFoundError before
argparse output or a single step.  Read it through proc_text(), which
returns None when the file is absent, and record that in the report.

Adds a regression test that runs the real script with the stock-driver
read raising FileNotFoundError and asserts the report still completes
with original_version null.
2026-12-03 14:49:59 +01:00
ec1b15efdc tests/vm: probe NOT_SUPPORTED with 0xa0e0 now that 0x9096 constructs
The QEMU EDU guest's RM API userspace test has failed on master in both
plain and --iommu mode since 915ed42a ("feat(ga10x,drm,rmapi): live
Vulkan 1.4 compute/transfer + DRM/NVKMS UAPI parity (#148, #172)"):

  NV_RS_VM_RMAPI_FAIL line 318 errno 22

Line 318 is the "class without a constructor answers NOT_SUPPORTED"
probe, CHECK(make(fd, client, hsub, 0, 0x9096, NULL) == 0x56). It is not
the 0x90e7 check on line 319, and the errno is stale (left over from the
earlier mmap EINVAL checks near line 284). 915ed42a gave GF100_ZBC_CLEAR
(0x9096) a constructor on purpose: it is now in the BinaryApi
plain-child list.
The alloc therefore succeeds. In the guest, ioctl returns 0 with status
0x0 and generated handle 0xcaf00002. The test still expected 0x56.

The driver now matches the open stock RM here. In 580.178.04 and
620.73.04 resource_list.h, GF100_ZBC_CLEAR is a ZbcApi with parent
Subdevice, RS_NONE params and ALLOC_NON_PRIVILEGED. zbcapiConstructHal
resolves to an inline NV_OK in both versions (580: _56cd7a, 620:
_ac1694 in g_zbc_api_nvoc.h). So the test is what needs to change, as
77c9ad20 did when 0x208f was implemented.

The new probe is GK110_SUBDEVICE_GRAPHICS (0xa0e0; the name comes from
the FINN interface IDs in g_finn_rm_api.h). In resources.rs, which is
generated from the 580.178.04 proprietary metadata, it is a
GenericEngineApi with parent Subdevice, no parameters and no privilege
flag. The driver has no constructor for it, and the GV100 class DB
(class_db_gv100.rs, from the oracle record) does not list it. The open
580/620 trees do not register the class at all. Their resource factory,
resservResourceFactory in alloc_free.c, returns NV_ERR_NOT_SUPPORTED
("Skipping unsupported class") before any constructor runs when
!gpuIsClassSupported(). So on a GV100 the original should answer 0x56
here too. This is inferred from the open source and the class DB. The
closed binary was not disassembled.

GF100_SUBDEVICE_INFOROM (0x90e7) on the next line is unchanged and
correct. Stock makes it a GenericEngineApi under Subdevice, and
genapiConstruct allows one instance per class per parent. GV100's class
DB lists 0x90e7, and the driver constructs it as before.

The assertion count stays 457, and the generated-handle counter advances
the same way as before 915ed42a, because a failed constructor still uses
up one handle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 13:25:22 +01:00
f56b1f68bc fix(rmapi): retain memory control descriptors during table regeneration 2026-12-03 11:32:18 +00:00
d1596ff615 Merge origin/master into feat/ga102-desktop-master 2026-12-03 01:12:21 -08:00
23db150755 Merge pull request #382 from Selten23/pascal-p100-p104
Pascal P100/P104 bring-up and hardware validation
2026-12-03 00:29:32 -08:00
f595d3b853 Merge pull request #375 from lukeallister/p4-bringup
vm: fix the VFIO harness on Debian/PVE hosts (5 portability defects, with tests)
2026-12-03 00:21:42 -08:00
7e0f2a9d65 Address Greptile findings: dynamic phys-bits for multi-GPU, full SGEMM check, P4 setup docs 2026-12-03 00:14:20 -08:00
09d2ec6f26 Merge upstream GPU caps cleanup with USERD revocation 2026-12-03 08:13:26 +00:00
afd40e820a Merge pull request #153 from Solarboaters/fix/first-open-runtime-verdict
tools: distinguish runtime and diagnostic first-open outcomes
2026-12-03 00:11:15 -08:00
a995d84892 Merge pull request #373 from didiniao/fix/rmapi-caps-mode-and-compact-modversions
rmapi/caps: stock DeviceFileMode + per-GPU mig dirs; tools: read compact __versions
2026-12-03 00:10:53 -08:00
258c03d903 Merge master and address review findings on VFIO harness and P4 smoke 2026-12-03 00:08:37 -08:00
936159ae95 fix(tools): derive effective first-open mode from both runtime_engines and bringup 2026-12-03 00:03:34 -08:00
5c68e1813d test(conformance): cover compact and classic __versions layouts and modprobe EINVAL fallback 2026-12-03 00:02:07 -08:00