106 Commits

Author SHA1 Message Date
8f8bb18450 feat(rmapi): display-facing RM support, replay model and identity-keyed notifier maps (display series 2/3) (#695)
* feat(rmapi): display-facing RM support, replay model and identity-keyed notifier maps

Part 2/3 of the display bring-up series:
- gpu/display_model: push-buffer decoder/recorder with the captured stream
  fixture and pinned shape tests;
- gpu/display_maps: KernelMaps<const SLOTS> keyed by object identity
  (owner/client/GPU/handle/VA); publish only confirmed notification
  surfaces (RM object size, not map length); exact-identity retire. The
  regression cases the PR review asked for live here;
- rmapi escape/memory/node/gpu support for the display classes and
  controls, with the memory tests;
- kernel C helpers the Rust side imports (kernel map/unmap video).

Builds and passes the kernel-module gate on top of part 1/3.

* docs(display): engine-progress contract and GET/PUT geometry

* chore(display_maps): position() lookup in register (clippy)

* test(escape): keep master and display kernel-op coverage after rebase

The display series adds kernel_op/status_offset tests while master added
the legacy/VMware escape test; the rebase conflict dropped a brace. Keep
both test suites.

* test(display_maps): drop unused mut in notifier-map tests

* fix(rmapi): mapping provenance, BAR1 base, replay limits and doc truth

Mapping lifecycle:
- production kernel adapter calls execute_full_kernel, so kernel mappings
  are created and torn down through the kernel hooks; unmap chooses its
  teardown from the Mapping's recorded kernel flag, not the current call.
- Mapping records kernel_io for the channel-USERD ioremap made by
  kernel_map_video (no memory-table object): unmap releases it and leaves
  the Pascal USERD cookie path alone.
- restore the native BAR1 identity-window base in map_video,
  kernel_map_video and kernel_video_phys with checked addition; guest/GSP
  keep base 0.

Security/scope:
- class 0x3f remains allocatable by non-admin clients, but non-admin
  mappings are limited to the 64 KiB register-compatibility window; the
  full BAR0 aperture stays an admin mapping. New test covers both sides.

Replay model:
- limit is one emitted-operation counter across pads and data words; Stats
  still scans the whole stream after the limit.
- increment-mode headers advance the method address by four bytes per word;
  fixed-address modes keep the header address. New tests for both.

Docs:
- the progress doc no longer claims the part-3 service worker, 2 ms tick,
  display_tick_ms switch, or the idle handler are present; the idle control
  is pending and returns NOT_SUPPORTED in this revision.
- the parked rt0 task is TASK_IDLE via wait_event_idle_timeout, wakes for
  stop/reset/hshub, and the teardown owner check is still unwired.
- LOCATION_HINT is documented at flags 4:7, matching REA of _nv000741rm
  (shr 4; and 0xf) and the existing extractors/constructors.

Kernel bits 1822 tests, clippy 0, kernel gate green, validate_all
--offline exit 0.

* fix(rmapi): notifier authorization, params validation and pad-aware limit test

- KernelMaps records that the RM object was allocated as a notifier
  (NVOS32_TYPE_NOTIFIER, System.kernel_mapping). is_notify_surface now
  requires that explicit registration as well as a live mapping covering
  the 0x4200-byte object, so an ordinary same-sized buffer is never a
  publication target. New test covers it.
- Kernel NVOS64 SYSTEM/VIDEO derivation checks for a complete
  NV_MEMORY_ALLOCATION_PARAMS block before reading flags or calling
  derive_attrs; a null/undersized block answers INVALID_PARAM_STRUCT
  instead of indexing an empty slice. New test.
- The replay limit test counts every sink callback, padding included:
  limit 0 emits none, limit 1 emits exactly one, and the full stream emits
  all three (two pads).

1804 tests; clippy 0; kernel gate green; validate_all --offline exit 0.

---------

Co-authored-by: Mantle <mantle@forge.patrickwhite.org>
2026-12-06 04:21:35 -08:00
530b912062 rmapi: charge a shared file host pin once, not once per process (refs #523) (#566)
vLLM Host KV maps one /dev/shm pool in every TP worker and registers the whole mapping in each
of them. Charging every registration against the host-pin budget counted one pool once per
process, so the third and fourth registration were refused with NV_RS_STATUS_NO_MEMORY (CUDA
error 2) and Host KV could not start.

A range that lies wholly in MAP_SHARED mappings of one file is now described as an (inode, page
range) extent. Its first registration is charged through the ordinary admission check; later
registrations of the same extent ride on that charge, and the charge is released with the last
record covering the extent, so a record that paid nothing never returns budget it did not
consume. The classification, the charge and the pin all happen under one mmap read lock, so a
concurrent remap of the range cannot inherit the exemption. Private, heap and mixed ranges are
still charged in full.

The classification tests VM_MAYSHARE rather than VM_SHARED: the kernel clears VM_SHARED on a
MAP_SHARED mapping of a read-only file (VmFlags "ms" without "sh" on 7.0.0-44), so such a mapping
of a shared pool was charged once per registration although it shares the same pages.

The areas nv_rs_rmapi_mmap creates are excluded from the classification, and so is any other
mapping of a device node: their pages depend on the open, not on the inode, and two opens of the
control node can map different allocations at the same page offset (tests/vm/rmapi_user_test.c
maps two of them at 0 and at 4096), so an (inode, page range) key would let the second
registration of such an area ride on the charge of the first while pinning unrelated pages. Those
ranges are charged in full.

The extent table grows on demand (64 entries, doubling): a client holds dozens of small shared
mappings before it registers its one large pool, and a fixed table would run out exactly when the
pool needs its charge. A range that needs a new extent while the cap is reached is refused with
NV_ERR_INSUFFICIENT_RESOURCES instead of being charged twice: charged in full and left without a
slot, it would be charged a second time by the registration that later takes the slot that has
freed, while its first charge is still live. The cap counts live extents, not the allocated table,
and is the shared_extent_max parameter (default and maximum 4096), which is how the refusal is
exercised on a test host; a range whose extent already owns a charge keeps riding at any
occupancy.

The charge now comes before the pin's page array: an over-budget range used to allocate and zero
8 bytes per page (205 MiB for a 98 GiB range) and only then be refused. The pin path then starts
again from the "cannot pin" status rather than from the admission step's success, so a pin that
stops early - immediately, or after the first chunk of 1024 pages - is refused instead of
registering a record whose page entries were never pinned.

The ledger now stores the effective charge in each record and subtracts that on removal, instead
of the record's page count; the record nv_rs_rmapi_register_external_sgt() makes (added by #587,
rebased onto) passes the full charge, as it is not shared-file backed. Both new symbols are in the
production Makefile root list and in the EDU guest link's root list.

Two review follow-ups:

A lowered shared_extent_max could be overtaken by an admission already in flight: the sysfs write
did not take the lock that the cap check and the publication of a new extent are under, so one
registration admitted under the old cap could publish an extent above the new one. The parameter is
now written through a setter that takes nv_rs_rmapi_alloc_lock, so the check, the publication and
the write are one critical section and no extent is published above a cap that a write has already
returned from setting. Values are still clamped to 1..4096 and a non-numeric write is still
refused, as the plain module parameter did.

A registration that rode on a live extent allocated its page array (8 bytes per page, 196 MiB for
a 98 GiB range) with nothing counted against any ceiling, so repeated matching registrations of one
shared file were bounded only by kernel memory, where before this branch the pin budget bounded
them. Such a registration is now charged the pages its array occupies - one page of the budget per
512 pages of range - through the same admission check as a private range, and refused with
NV_ERR_NO_MEMORY when it does not fit; the charge rides on the record and returns when the record
is destroyed. The first registration of an extent needs no such charge, because the extent's charge
is its full page count, which covers the array.

Admission and insertion were not one lock hold: the budget was checked, the lock released, the pages pinned (seconds
for a large range) and only then the record inserted, and the insert added its charge without checking again. Two
registrations in flight could both be admitted against the same headroom and both charge, passing the ceiling by the
sum of their charges. The ordinary pin path, the external SG path and the driver page allocation all had that gap;
the shared-extent rider path added a fourth.

An admission now reserves what it admits, and every check counts what is reserved:
nv_rs_alloc_reg_reserve() records the pages in the ledger (reserved_pages, and reserved_user_pinned_pages so the
driver-side budget sees them too), the record takes the reservation over when it is inserted instead of adding a
second charge, and every path that inserts no record - a failed pin, a failed allocation, a refused range, a full
registry - returns it with nv_rs_alloc_reg_unreserve(). Node exit reports whatever is still reserved, which is 0
while the driver is idle. The two ceilings are now enforced on charges and reservations together.

Three more review follow-ups:

A record's per-device DMA map was never charged: nv_rs_rmapi_os_page_dma() and the batch lookup allocate one encoded
address per page and, when the whole allocation maps as one scatterlist, one scatterlist entry per page, and keep
them until the map is destroyed. With every registration charged its full range that was covered 512 times over, but
a promotion that only rode on an extent's charge made repeated maps cheap. A new map is now charged its arrays
(nv_rs_rmapi_dma_map_pages, booked on the side of the budget its record is on) before they are allocated, released
with the map in nv_rs_rmapi_dma_map_destroy(), and a lookup that finds an existing map charges nothing.

The first registration of a shared extent carried no charge for its page array, so a range admitted up to the ceiling
could add that array above it. Every registration of an extent now charges its array, the first one included.

A driver allocation reserved its pages before it took them out of the page pool, and those pages still counted as
unclaimed pool headroom, so a check in that window charged them twice and refused work the budget had room for. A
driver reservation now claims the pool pages it will take (AllocLedger::can_admit), and charges that no record
carries - an extent's pages, a DMA map's arrays - go through AllocLedger::charge_detached / uncharge_detached, so the
same accounting serves both.

Round six:

A batched DMA lookup maps page by page and builds no scatterlist, so charging it the scatterlist's capacity could
refuse a map whose real arrays fit. Each map now stores the charge it was admitted with, the batched path pays for
its encoded addresses only (nv_rs_rmapi_page_array_pages), the single-page path keeps paying for the scatterlist it
can build, and destruction refunds exactly what was paid.

A DMA map's arrays never come from the page pool, but their charge was admitted with the pool passed as zero, so the
retained pages were not counted against the ceiling. AllocLedger::admits_fresh() is the admission for memory that
cannot come from the pool - pinned user pages, page arrays, DMA maps - and counts the pool beside it; the extent's
charge goes through it too.

A driver reservation claimed pool pages, and kept claiming them after the allocation had taken them out of the pool,
so those pages were neither pooled nor claimed and could be handed out twice. The claim is now tracked
(AllocLedger::pool_claim), given up as pages leave the pool (nv_rs_alloc_reg_pool_popped, from
nv_rs_sysmem_pool_pop_page and nv_rs_rmapi_trim_page_pools) and released with its reservation; a contiguous
allocation of more than one page comes from the page allocator and claims nothing, so it pays its full cost.

Round seven:

The driver side of the budget now sees the pool pages nothing has claimed, exactly as the combined ceiling does: a page
a reservation has claimed is already inside reserved_pages, so adding the whole pool to driver_pages counted it twice
and could refuse a request that fits. A pool-reusing allocation is charged against mem_max only for the pages it
cannot take from the pool (count - unclaimed), which is what it actually allocates; a pool that has grown past
mem_max no longer refuses allocations that come out of it, while a contiguous one, which allocates every page, is
still counted in full.

A reservation claims only unclaimed pool pages (min(count, unclaimed)), so two in-flight reservations cannot count on
the same pages and leave a stale claim behind when the pool empties and is refilled.

Both DMA lookups read the record's side of the budget (alloc->user_pinned) under nv_rs_rmapi_alloc_lock and keep it in
a local, instead of reading alloc after the unlock: the lookup holds no reference, so a concurrent final release could
free the record before the refund.

Round eight:

A record admitted up to a ceiling could not pay for the arrays of its first DMA map: the map charge ran the
admission check against the headroom the record's own admission had just consumed, so a record that filled mem_max
(or total_max) failed its first GPU map with NV_ERR_NO_MEMORY, which the GSP route turns into ST_INVALID_STATE. The
encoded addresses of a record's first map - one 8-byte address per page, one budget page per 512 pages of range, the
minimum every mapping needs - are now admitted with the record (nv_rs_alloc_reg_reserve_map, taken over by the map in
nv_rs_alloc_reg_charge_map) and are part of what the record is admitted for. A map on a further GPU is charged on its
own, so only the first is exempt from headroom the record consumed; a map charge that does not fit leaves the record
its reservation rather than spending it.

The scatterlist of a whole-allocation map is charged only when that path is attempted. The first lookup used to be
admitted for the encoded addresses and the scatterlist estimate together and refused outright when the sum did not
fit, although a per-page mapping needs the encoded addresses alone (a 1 GiB range: 512 pages of budget for the
addresses, 2571 for the two together). The estimate is now charged after the addresses, only before the whole-map
attempt, and returned when that attempt fails, so a lookup that cannot afford a scatterlist still maps page by page.

A map this call created and mapped no page for stayed in the registry holding its charge until the allocation was
destroyed, where a lookup on another GPU would find it and its charge would refuse a map the budget had room for. Both
lookups now remove such a map from the registry and destroy it; a map that carries addresses is kept and reused.

The DMA-map refund released nv_rs_rmapi_alloc_lock, which it takes, and freed the map afterwards, so a lookup on
another GPU could spend the headroom while the encoded array that occupies it was still allocated. The charge and the
record's side are read first and the refund is made after the storage is freed.

The pin path and the driver page allocation reserve the record's map array with the record and return it on every
path that inserts no record; nv_rs_rmapi_register_external_sgt() reserves none, as every lookup of an external
record reads its pre-mapped addresses and no map is ever created for it. The new symbols
(nv_rs_alloc_reg_reserve_map, nv_rs_alloc_reg_unreserve_map, nv_rs_alloc_reg_charge_map, nv_rs_dma_reg_remove) are in
the production Makefile root list and in the EDU guest link's root list.

Round nine:

A record that gave up its map reservation and then failed to create the map did not get it back: charge_map() takes
the pages out of the record, and the kvzalloc failure path refunded the whole charge to the budget, as did every
destroy path. The record kept living with nothing reserved, so a retry of its first map had to pass the ordinary
admission, which the budget that had just been released may no longer allow. The charge is now split: charge_map()
reports how many pages came from the record's reservation, the map carries that figure (dm->reserved), and the part
returns through nv_rs_alloc_reg_return_map_charge() - to the record's reservation when the record is still there, to
the budget when it is not, so a map charge is never lost either way. The kvzalloc failure, the registry insert failure
and the removal of a map that mapped no page all go through that path.

The page pool and the claim an in-flight reservation holds on it now move in one critical section.
nv_rs_sysmem_pool_pop_page() and nv_rs_rmapi_trim_page_pools() popped a page under the pool lock and updated the claim
after releasing it, so an admission could read the smaller pool with the larger claim; that state counts the page
which just left as neither pooled nor the reservation's and can admit a request that puts the footprint a page over
the ceiling. Both now take nv_rs_rmapi_alloc_lock around the pop and the claim update. The nesting is safe because
nv_rs_sysmem_pool_len() is a lock-free atomic load, so no admission path holds the pool lock and there is no lock
order to invert; the wrapper that took the lock for the caller is gone, as both callers now hold it.

The new symbol nv_rs_alloc_reg_return_map_charge is in the production Makefile root list and in the EDU guest link's
root list. The ledger's tests cover the retry after a failed map creation, the budget fallback when the record is
gone, and the arithmetic of the pool and its claim - consistent and stale.

Round ten:
- A map charge names its record by token, not by address (4813692270, 4813709504). A per-device map outlives the
  critical section that created it: teardown pops it from the DMA registry and destroys it after that lock is
  dropped, so the allocation can be freed in between and a new allocation can take its address. The refund then
  matched the address and moved the record's reservation to that new record, understating the budget. The map keeps
  `alloc_token`, `charge_map`/`return_map_charge` are keyed by the record's token, and a refund whose record is gone
  returns to the budget under the map's own `user_pinned` class.
- A removed record's charge is released only after its pages are pooled or freed (4813706871). The ledger removals
  (`put_ptr`, `mark_freed_and_put`, `pop_any`) hand the charge back to the C caller, which returns it with
  `nv_rs_alloc_reg_release_charge` at the end of `nv_rs_rmapi_alloc_destroy`; while the pages are in flight they are
  counted twice, as a charge and as pool headroom, instead of not at all, so an admission beside the teardown cannot
  pass the ceiling through the window between record removal and pool insertion.
- Both pool snapshots that feed an admission are read under `nv_rs_rmapi_alloc_lock` (4813706871):
  `nv_rs_rmapi_register_external_sgt` and `nv_rs_rmapi_os_alloc_pages` took theirs before the lock, so a stale pool
  count could be paired with the claim a reservation had already made on it.
- Rebased onto master 3e1bf7b8, whose "batch sysmem pool reuse" replaced the single pool pop with
  `nv_rs_sysmem_pool_pop_batch`. `nv_rs_sysmem_pool_pop_pages` holds the allocation lock around the batch pop and
  reports the whole batch to `nv_rs_alloc_reg_pool_popped`, so the pooled pages and the claim on them still move in
  one critical section. That commit renamed the two pop entry points without updating
  `tools/vm/build_guest_test.sh`, so the guest link failed on master; this commit carries the rename as well.

New ledger tests: `a_returned_map_charge_ignores_a_record_that_reused_the_address`,
`a_removed_record_keeps_its_charge_until_its_pages_are_pooled`, and the six tests that release a record now return its
charge the way the C caller does.

Gate on the rebased tree: `cargo test --workspace --lib` 1645 passed, 0 failed, 153 ignored; clippy
(`-p nv-rs-core` and the workspace, `-D warnings`), `cargo fmt --all -- --check` and
`rustfmt --check src/nvidia/src/rmapi/alloc_registry.rs` clean; `make modules` with
`tools/check_kernel_module.py` passed (largest_stack 984); `tools/vm/build_guest_test.sh` maxframe 1016, 6/6.

Round eleven:
- A record's map charge is now the whole map: the encoded addresses and the scatterlist of the whole-allocation path
  (4813858520). The scatterlist used to be charged when the path was attempted, so a budget near its ceiling skipped
  it and the map fell back to per-page mappings. That fallback loses DMA adjacency, and the display path requires
  consecutive addresses for a span (sysmem_contiguous_dma in src/nvidia/kernel/gsp_route.rs); on an IOMMU only a
  scatterlist mapping of the whole range is placed contiguously. `nv_rs_rmapi_dma_map_pages()` is what admission
  reserves and what the first map takes over, the whole-allocation path is attempted whenever it applies, and when it
  produces no scatterlist those pages return to the record's reservation. A record is therefore refused at admission
  rather than degraded at mapping time. Cost: the reservation per record rises from `count/512` to
  `count/512 + count/128` pages, 0.2% to 0.98% of the range.
- An empty map's charge is returned in the same critical section as its registry removal, in both lookup owners
  (4813858522): a concurrent lookup that found no map had to admit a new one while the removed map's charge was still
  counted, and a budget at its ceiling refused it.
- A retained pool larger than the driver's cap no longer blocks fresh admissions for good (4813858518). A GPU removed
  from under the pool, or `system_memory_pool_retain_mb=-1`, can leave more pooled pages than `mem_max`; the driver
  side is then over its cap and every fresh admission of even one page - a record's map - was refused with nothing
  that reclaims. `nv_rs_rmapi_pool_fit_memory_max()` trims the pool down to the cap and the admission is retried once.
  Retention still governs client close; a hard ceiling is a different trigger.

Gate on this tree: `cargo test --workspace --lib` 1645 passed, 0 failed, 153 ignored; clippy (`-p nv-rs-core` and the
workspace, `-D warnings`), `cargo fmt --all -- --check` and `rustfmt --check` clean; `make modules` with
`tools/check_kernel_module.py` passed (largest_stack 984); `tools/vm/build_guest_test.sh` maxframe 1016, 6/6.

Round twelve:
- The pool reclaim leaves the map its room (4814009540). Trimming to `mem_max` was not enough: a pool at the cap plus
  the one-page reservation keeps the driver side at `mem_max`, so the map's fresh page was still refused and no later
  attempt trimmed at all. `nv_rs_rmapi_pool_fit_memory_max(reserve_pages)` now trims to `mem_max - reserve_pages` and
  the retry passes the record's map charge, so the trim frees the pages the admission still needs. The ledger test
  `a_pool_at_the_cap_leaves_no_room_for_a_records_map` pins the arithmetic the trim target is computed from.
- An empty map's storage is freed before its charge returns (4814010678).
  `nv_rs_rmapi_dma_map_free_locked()` copies the charge fields, frees the encoded-address array and then refunds, all
  with `nv_rs_rmapi_alloc_lock` held, and the caller drops the device reference after the unlock: the order
  `nv_rs_rmapi_alloc_destroy()` keeps for a record's pages. A refund issued while the array is still allocated would
  let a concurrent admission spend headroom the array occupies.
- A DMA lookup that ran out of budget reaches display setup as a resource status (4814011156).
  `nv_rs_core::rmapi::status::display_dma_status()` maps `NO_MEMORY` to `INSUFFICIENT_RESOURCES` (0x1a) and every other
  status to `INVALID_STATE`; `sysmem_contiguous_dma()` uses it for the first page and for every later one, so display
  setup sees a limit it can retry instead of a state error. It sits in the core crate because the kernel crate is built
  by `rustc` from the Makefile, is not a cargo workspace member, and its own `#[test]`s never run.

Gate on this tree: `cargo test --workspace --lib` 1647 passed, 0 failed, 153 ignored; clippy (`-p nv-rs-core` and the
workspace, `-D warnings`), `cargo fmt --all -- --check` and `rustfmt --check` clean; `make modules` with
`tools/check_kernel_module.py` passed (largest_stack 984); `tools/vm/build_guest_test.sh` maxframe 1016, 6/6.

Round thirteen (rebase + review of `bf179c6a` and the round-10 head):

Rebased onto `5875efd7` (#686, #644, #593, #617, #435, #646): the only non-test conflicts were the `-u nv_rs_<name>`
list in `src/nvidia/Makefile` (master added `uvm_iface_access_bits_buf_push_hw_word`, this branch adds its
`alloc_reg_*` and `dma_reg_remove` symbols) and the batch-DMA path in `rmapi_node.c` (master's #644 makes the batch
creator try the whole-allocation map too; kept, with this branch's charge fields). `alloc_registry.rs` merged
master's #644 token scheme (`free_hint`, `slot_of`, open-addressing `DmaMapLedger` with `rehash`/`remove_at`) with
this branch's charge tracking: `mark_freed_and_put`/`put_ptr`/`pop_any` keep the `free_hint` fast path and still
hand the charge back, and `DmaMapLedger::remove` uses `remove_at` so removing one map of an allocation does not hide
the others.

- The display-status mapping was reverted as out of scope (CodeRabbit pre-merge gate, review 6207373045):
  `display_dma_status` and its test leave `status.rs`, and `sysmem_contiguous_dma()` keeps the previous status
  collapse, so page-DMA lookup failures reach display setup exactly as before. If display setup needs a resource
  status, that is a separate PR with its own runtime evidence.
- The pool reclaim now accounts for live driver charges and both budget limits (4813950514, 4814349882).
  `AllocLedger::pool_trim_target()` computes the largest pool at which a failed admission's `count` pages and their
  `map_pages` of fresh metadata fit `mem_max` and `total_max`: the target is `mem_max - map_pages` minus the driver
  pages already charged, and `None` when even an empty pool cannot admit the request - the retained pool is not
  evicted for nothing (4814325992). `nv_rs_rmapi_pool_fit_memory_max(count, map_pages)` calls it through a new
  `nv_rs_alloc_reg_pool_trim_target` ABI. Regression tests cover the live-charge example, the empty-pool quick win,
  and the total ceiling.
- A failed registration frees its page array before its reservation returns (4813858516), on both post-allocation
  failure paths: a shared registration that fails near the combined ceiling cannot leave its array occupying headroom
  that another thread then spends.
- A whole-allocation map that falls back returns only what the record reserved (`back`) to the record; the part the
  fresh budget paid (`sg_pages - back`) returns to the budget (4813950517). Before, all of the scatterlist's pages
  went back to the record even when a later GPU had paid fresh, and the map could hold a charge for pages it no
  longer carries until the allocation is destroyed.
- The DMA-map storage charge now covers the fixed `struct nv_rs_rmapi_dma_map` header, not just the encoded
  addresses: `nv_rs_rmapi_dma_array_pages()` rounds up `struct_size(dm, encoded, count)`, so a map whose encoded
  array sits just under a page boundary cannot pass with one page of headroom and allocate more.

Gate on this tree: `cargo test --workspace --lib` 1681 passed, 0 failed, 154 ignored; clippy (workspace,
`-D warnings`) and `cargo fmt --all -- --check` clean; `make modules` with `tools/check_kernel_module.py` passed
(largest_stack 1016); guest build pending.

Co-authored-by: teskalabs-bot <teskalabs-bot@users.noreply.github.com>
2026-12-06 02:09:27 -08:00
a2395c8faa rmapi: print paramsSize in the rt RM_CONTROL dmesg line (#656)
* rmapi: print paramsSize in the rt RM_CONTROL dmesg line

The rt RM_CONTROL line printed only the command and the status. When a
userspace library from another release sends a control with its own
struct size, the status alone (for example 0x1f INVALID_ARGUMENT) does
not show that. In #501 a system 595 NVML loaded next to 580.178.04
userspace sent 0x2080a612 and got 0x1f; the size would have shown the
mismatch in one line.

The line now prints paramsSize from NVOS54 (offset 24, next to status
at 28). The request.size >= 0x20 check already covers both fields.

* rmapi: place size= after status= to preserve verify_desktop_acceptance.sh grep

---------

Co-authored-by: GrowDev1 <growdev1@users.noreply.github.com>
Co-authored-by: Eric Hartford <eric@quixi.ai>
2026-12-06 00:28:16 -08:00
59ecef28da perf(uvm/rmapi): batch host DMA lookups and index the allocation and DMA-map registries (#644)
* uvm: look up host DMA addresses in batches

Issue #412: [O] the reporter measured 9,000 x 1 MiB cuMemHostAlloc
(PORTABLE|DEVICEMAP) at 19.1 s against 3.3 s on stock, with perf showing
nv_rs_dma_reg_find at 41% and nv_rs_alloc_reg_find at 20%.

map_external_host_pages asked the C side for one DMA address per 4 KiB
page, and each call did two registry lookups. It now fetches up to 64
addresses per call through nv_rs_rmapi_os_page_dma_batch, which does
one lookup per batch, and writes the PTEs after each batch succeeds.
Rollback still covers only the PTEs written on this GPU.

When nv_rs_rmapi_os_page_dma_batch creates a new DMA map it now tries
nv_rs_rmapi_dma_map_whole first, as nv_rs_rmapi_os_page_dma does, and
frees a map it could not register with nv_rs_rmapi_dma_map_destroy.
Before this, a map made by the batch helper used one mapping per page,
so the scalar and batch helpers could give a different layout for the
same allocation. The RM DMA-map path in gsp_route.rs also uses the
batch helper and gets the same layout as the scalar path.

Tests:
- [A] four va_space host tests: 200 pages give batches (0,64) (64,64)
  (128,64) (192,8) and every PTE gets its DMA address; a DMA failure in
  the second batch reports host-dma after 262,144 bytes; a PTE failure
  reports host-pte with the exact bytes written; an unaligned length
  calls nothing. They failed to compile against the per-page signature
  first (E0593).
- QEMU EDU guest (tests/vm/edu_adapter_test.c): the batch helper runs
  first on a fresh 16-page allocation (non-contiguous and contiguous),
  its output must match the scalar helper page for page and keep the
  scalar test's layout rule, and a zero count or a range past the end
  must be refused. With this change the guest module reports no NV_RS_VM_FAIL, with and without
  the emulated IOMMU. On this base, make test-vm-adapters does not
  pass with or without this change: the guest link list still names
  nv_rs_sysmem_pool_pop (now nv_rs_sysmem_pool_pop_batch), and with
  that name fixed locally the userspace RM API test stops at the
  class-list control (rmapi_user_test.c line 439, EINVAL).
- [A] check_kernel_module.py passes; largest_stack is 984 bytes with
  this change, inside the 1,024-byte limit.

Not in this commit: timing on a physical GPU. The issue numbers above
are the reporter's.

* rmapi: find allocation and DMA-map records without a linear walk

Issue #412: [O] the reporter's perf profile of 9,000 x 1 MiB
cuMemHostAlloc (PORTABLE|DEVICEMAP), 19.1 s against 3.3 s on stock,
put nv_rs_dma_reg_find at 41% and nv_rs_alloc_reg_find at 20%. Both
walked every record, and so did the insert paths, so the cost of one
lookup grew with the number of live host allocations.

AllocLedger: a token is now (sequence << 32) | (slot + 1). Find, retain
and mark-freed go straight to the slot and compare the full token, so a
stale token whose slot was reused names nothing until a multiple of
2^32 inserts (the sequence is 32 bits) separate the two inserts at that
slot; every free path except the module-exit drain marks the record
freed first. Tokens are still never
0 and stay inside the kernel (C <-> Rust); the RM API returns no token
to user space. Insert starts its free-slot search at a hint (every slot
below it is in use) and no longer scans for token uniqueness. The
pointer-keyed retain_ptr and put_ptr stay linear; they run on the pin
and teardown paths, not per page.

DmaMapLedger: the slots are an open-addressing table keyed by
alloc_ptr, with linear probing and backward-shift removal. A find or a
miss stops at the first empty slot. The kernel wrapper keeps the table
at most half full and doubles it with DmaMapLedger::rehash. pop_for_dev
stays a scan; it runs only when a device goes away.

Tests (cargo test, nv-rs-core):
- [A] insert_and_find_cost_does_not_grow_with_the_record_count: 1,000
  inserts and 1,000 finds (hit, DMA hit, DMA miss) at 1,000 and at
  10,000 records, best of 5; the ratio must stay below 4. It is
  #[ignore]d because wall-clock timing is not reliable on a loaded
  runner; run it with
  cargo test -p nv-rs-core --release --lib insert_and_find_cost -- --ignored --nocapture
  It failed on the linear code first (both ratios above 4, in debug
  and release builds). With this change both ratios stay below 4 in
  release builds; the exact ratios vary from run to run (two runs under
  different load gave insert x1.00 and x1.47, find x1.02 and x1.66).
- [A] a stale token after slot reuse is refused by find, retain and
  mark-freed; the maps of one allocation stay reachable after removals
  from the middle of a probe run.
  These guard the new layout; they also pass on the old code, so they
  are not fail-first tests.
- [A] rehash into a doubled table keeps every record and refuses a
  table that is too small; a full table (no empty slot) refuses an
  insert, and find, pop_for_alloc, pop_for_dev and the backward-shift
  removal all end.
- QEMU EDU guest: the guest module, which links this registry, reports
  no NV_RS_VM_FAIL with and without the emulated IOMMU. The full make
  test-vm-adapters target does not pass on this base for the reasons
  given in the previous commit, which this change does not touch.

Not in this commit: timing on a physical GPU. The issue numbers above
are the reporter's.

---------

Co-authored-by: GrowDev1 <growdev1@users.noreply.github.com>
2026-12-05 23:23:27 -08:00
42ec794956 rmapi: probe pre-GSP FB/L2/bus-width geometry from BAR0 and keep VPSTATE MCLK above P8 (#631) (#633)
* rmapi: probe pre-GSP FB/L2/bus-width geometry from BAR0 and keep VPSTATE MCLK above P8 (#631)

* rmapi: reject PRI errors on NV_FUSE_STATUS_OPT_HALF_FBPA in FbGeometry::from_registers

---------

Co-authored-by: Eric Hartford <eric@quixi.ai>
2026-12-05 14:54:47 -08:00
3e1bf7b8c8 perf(rmapi/uvm/pcie): batch sysmem pool reuse & UVM DMA drain, roll back PCIe target on retrain failure (#516)
* fix(pcie): restore link target after retrain register failures

Reuse the existing best-effort timeout rollback for every failure after the endpoint target write succeeds, preserving the original error. Fault injection exposes three failing tests on master; all eight targeted tests, workspace tests, clippy and offline codegen checks pass with the correction. No changes to link policy, capability gates or success path.

* perf(uvm): batch DMA mapping cleanup at node exit

Drain up to 16 live records per leaf-mutex acquisition, preserving bucket order and leaving DMA unmap/page/device releases outside the lock. No changes to insert/lookup/device detach, per-page unmap or mapping permissions. Seven paired CPU-only samples from 1 to 262144 records show 1.30x to 20.85x faster ledger cleanup. Workspace 1409 passed, 150 ignored; clippy, formatting, native codegen and Rust kernel object build pass. Full kernel module and physical/guest testing pending.

* perf(rmapi): batch hot system-page pool reuse

Take up to 32 hot pages per pool mutex acquisition, publish the count once, and clear all reused pages outside the mutex. Preserve LIFO order, partial/empty fallback, admission and cache policy, and allocation failure cleanup. Seven paired host benchmarks show up to 4.72x faster bookkeeping and 4.92x p99 improvement for 16384 fully pooled pages, with single-page and empty-pool parity. 1409 workspace tests pass, 150 ignored; strict clippy, codegen audit, Rust kernel object and offline kernel gates pass. Full C module/guest/physical validation pending.

---------

Co-authored-by: Nick <your-email@example.com>
2026-12-05 14:19:17 -08:00
51d7d35c4a rmapi_node: bound external DMA-BUF sgt addresses by the GPU DMA width (#605)
nv_rs_rmapi_register_external_sgt() (GEM_EXPORT_DMABUF_MEMORY bridge,
#587) copied the importer's sg_dma_address() values verbatim into
external_dma_addrs[], which page_dma/page_dma_batch hand straight to
GPU sysmem PTEs. Nothing checked them against the GPU's addressing
width, so on GV11B (dma_bits = 40, platform_driver.c) a scatterlist
mapped for a different/wider device would be silently truncated by
the MMU. Refuse any segment ending past DMA_BIT_MASK(dma_bits) with
-EINVAL, before the RM object is created (caller keeps ownership).

Also derive page_dma_batch's renegotiation width from
nv_rs_rmapi_gpu_dma_bits() like page_dma does instead of a literal 47
(no behaviour change: negotiate already clamps to the node's width).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 07:21:03 -08:00
854741c986 fix(rmapi): answer NV2080_CTRL_CMD_BUS_GET_PCI_INFO_V2 (0x2080183c) on pre-GSP GPUs (#590)
* fix(rmapi): answer NV2080_CTRL_CMD_BUS_GET_PCI_INFO_V2 (0x2080183c) on pre-GSP GPUs (#564)

580.196.07 nvidia-smi / NVML asks for 0x2080183c when it reports
pci.bus_id. It is not in the 580.178.04 export table that control_table.rs
is generated from, so a pre-GSP GPU refused it with NV_ERR_NOT_SUPPORTED
(0x56) and `nvidia-smi --query-gpu=pci.bus_id` printed [N/A]. 580.178.04
userspace never sends it, which is why this went unseen.

The 28-byte layout is NV2080_CTRL_BUS_GET_PCI_INFO_V2_PARAMS from
NVIDIA/open-gpu-kernel-modules main (ctrl2080bus.h): the four words of
0x20801801 followed by pciProgrammingInterface, pciSubClass and
pciBaseClass. The class words come from the PCI class code, which the
PCI probe now passes down in RmapiGpu/nv_rs_rmapi_gpu (pdev->class).

Evidence: stock 580.196.07 replies captured with tools/ioctl_capture on an
EVGA GTX 1080 Ti (3842:6696, bus 01) and gdevenyi's ASUS capture on #564
(1043:85f1, bus 02) are reproduced byte for byte by new unit tests that
go through the RM_CONTROL escape path. The bus number is not part of this
reply; pci.bus_id keeps coming from 0x21b, which already matched stock.

0x2080012f is left alone: stock 580.196.07 also answers 0x56 on this
non-ECC GP102 (#371), and master already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HgXrs8WswQymXpCe2YSiEM

* fix(gsp): keep NV2080_CTRL_CMD_BUS_GET_PCI_INFO_V2 (0x2080183c) host-only on the GSP route

The synthetic descriptor added for pre-GSP GPUs made control_info() know
0x2080183c, so the GSP route's validate() would now pass it and forward it
to GSP-RM for an owned mirrored object. Before this PR the command was
unknown to the tables and answered on the host Node. Add it to the existing
host-only list next to 0x00801401 and 0x20808165 so GSP-RM never sees it.

Reported by CodeRabbit on #590.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HgXrs8WswQymXpCe2YSiEM

---------

Co-authored-by: Dino Vitale <chaotikdino@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 06:30:58 -08:00
f3862b6300 drm: implement GEM_EXPORT_DMABUF_MEMORY (24/24 DRM ioctls ported) (#587)
* drm: implement GEM_EXPORT_DMABUF_MEMORY via RM 0x71 external sgt bridge (24/24 DRM)

* rmapi: enforce external_gpu_id on DMA lookups and mirror forwarded GSP devices

* rmapi: keep locally registered memory RM_FREE on native execute_full path

* rmapi: scope local RM_FREE bypass to local UserPages (0x0071) backings only

* rmapi: mirror forwarded GSP peer device on import_slot and clean up local entries on forwarded FREE

* rmapi: recursively free native subtrees on GSP object free and keep UserPages MAP_MEMORY_DMA native

* rmapi: return NOT_SUPPORTED for UserPages MAP_MEMORY_DMA on legacy gsp_bringup sessions

* rmapi: verify client ownership before returning NOT_SUPPORTED on legacy GSP UserPages MAP_MEMORY_DMA

---------

Co-authored-by: Eric Hartford <eric@quixi.ai>
2026-12-05 04:20:19 -08:00
78f8530140 dma-buf export of VRAM: by RM handle (stock ABI) and by CUDA address (#148)
* dmabuf: export RM video memory by handle

NV_ESC_EXPORT_TO_DMABUF_FD (0xd9) only exported a raw BAR1 range, for
CAP_SYS_ADMIN, ignoring the RM handles in the request. Implement the
stock ABI (nv_ioctl_export_to_dma_buf_fd_t, 2608 bytes):

- resolve each (hClient, hMemory, offset, size) to its VRAM with
  nv_rs_rmapi_resolve_dmabuf_object(), authorized like the original:
  the client belongs to the caller's file or its control file
  (CAP_SYS_ADMIN may export any);
- a non-contiguous allocation (scatter_id != 0) is walked segment by
  segment, each piece of the requested range becoming its own BAR1
  extent, so an export never covers the VRAM between two segments;
- up to 128 objects per call, batched calls (index > 0) for larger
  VMM exports, contiguous extents coalesced, segments capped at 1 GiB,
  at most 2^20 extents per dma-buf; its kernel memory (pins, extents)
  grows with the objects appended, not the declared total, and is
  charged to the caller's memory cgroup;
- the dma-buf is BAR1-backed (the GA10x BAR1 maps VRAM 1:1), mapped for
  importers with dma_map_resource(); bAllowMmap allows a write-combined
  CPU mmap, shared only (a private, copy-on-write mapping of PFN-mapped
  memory is refused: vmf_insert_pfn() BUG()s on one). The raw BAR1
  export stays for h_client == 0 (admin only);
- only GSP-RM GPUs export: their BAR1 maps VRAM 1:1 for as long as the
  GPU is in the RM. A pre-GSP GPU's BAR1 window belongs to the runtime
  engines, which clear it when they stop (suspend, AER) while an export
  would keep its offsets, so those GPUs refuse (NV_ERR_NOT_SUPPORTED);
- the fd is reserved, and installed only once the reply carrying it has
  been copied to the caller: a reply that does not arrive leaves no fd,
  and no pin, behind (the raw BAR1 export included).

A dma-buf must not outlive its memory: once the VRAM is freed it can be
handed to another allocation, and a peer still DMAing into the old
range would write into it. The dma-buf therefore holds the memory, as
the stock driver's exports do. Each exported object's backing is pinned
in the RM memory table (Table::pin_export, the reference the FD exports
already take), and every route that frees memory honours it:
NV_ESC_RM_FREE, NVOS32_FUNCTION_FREE (NV_ESC_RM_VID_HEAP_CONTROL),
freeing a parent or the whole client, file release, and channel USERD
orphan cleanup drop the handle but leave the VRAM, and a non-contiguous
allocation's segment chain, allocated while a pin exists. (The orphan
cleanup released a segment chain without that check; it now has it.)
When the dma-buf is released, a work item drops its pins under the RM
API lock and frees whatever nothing else references; a dma-buf can be
released with that lock held, so its release callback does not take it.
Module unload flushes the work item. Exports resolve their handles and
take their pins under the same lock, so a concurrent free either runs
first, and the export fails, or finds the pin.

Only GPU removal still revokes, as the memory goes away regardless.
It first marks the device as going away: from then until the GPU has
left the RM no dma-buf is created over it (the check and the insertion
into the export list are under one lock hold, so an export is either
listed or refused). Before taking the RM API lock, so that RM calls do
not wait behind the importers, every dma-buf over the device is first
marked revoked (attach, map and mmap then fail with -ENODEV) and its
CPU mappings are zapped; then its importers' mappings are invalidated
(dma_buf_invalidate_mappings), those whose reservation object is free
first; only then are the two waits the kernel-doc asks for done for
each: until the fences on the reservation object retire, and until
every importer mapping has been unmapped. An importer slow to retire
its fences, or holding a reservation object, thus leaves no other
dma-buf readable. A dma-buf whose last reference is already going is
waited for until its release has queued its pins, which are then
flushed, so none is dropped after the GPU is gone. Then,
under the lock and before the GPU leaves the RM, the pins are dropped;
nothing waits there. The CPU zap is unmap_mapping_range(); CPU mappings
are filled in at fault time
(vmf_insert_pfn after checking `revoked` under the dma-buf's lock), not
in .mmap, because the kernel links a new VMA into the file's i_mmap
only after .mmap returns and pages inserted there could escape a racing
zap. After a revoke a CPU access gets SIGBUS.

Only importers that can honour a revoke may attach: peer-to-peer
capable (allow_peer2peer, the scatterlist has BAR1 bus addresses and no
struct pages) and revocable (dma_buf_attach_revocable(): they
invalidate and unmap in bounded time). The NVMe dma-buf I/O path is
both. Kernels without dma_buf_attach_revocable() have no such contract
(move_notify only asks importers to remap as soon as possible), so
there the dma-buf has no importers, only the CPU mmap. The exporter is
dynamic (pin/unpin, a no-op: BAR1 memory never moves), so that no
kernel caches an importer's mapping at attach time, where its unmap
would not reach the exporter.

Built against 7.4 only. dma_buf_attach_revocable(), the
invalidate_mappings rename and enum dma_resv_usage are probed in Kbuild
with fallbacks for older kernels, which have not been compiled.

Tested on an RTX 3050 Laptop (GA107), on a 7.4-rc2 kernel with KASAN
and lockdep, IOMMU in identity mode, with io_uring + NVMe dma-buf reads,
through the export by CUDA address added later in this series. That
shares the dma-buf creation, mapping, pinning and release code with
this ioctl but not its handle loop: libcuda does not issue
NV_ESC_EXPORT_TO_DMABUF_FD on this GPU, so multi-object and batched
exports have not run on hardware. NVMe -> VRAM reads were verified
byte for byte. With the memory freed (cuMemFree, cuMemRelease) while
128 reads were queued, or at points in the middle of a stream, every
read completed without error, and the freed VRAM was not reused: a new
allocation filled before the free stayed untouched. The VRAM stays
allocated while the dma-buf is open (free VRAM did not come back after
the RM free) and is returned when it is closed. A dma-buf whose
exporter exited keeps working, and killing a reader mid-I/O tears it
down. No KASAN or lockdep report. GPU removal (the remaining revoke)
is run on hardware by the test added in the third commit.

These runs used the gpu-prio `preempt 0` policy: on this GPU, master's
default CILP/GFXP preemption policy makes cuCtxCreate fail before any
export (the second channel's compute object allocation returns
NV_ERR_INSUFFICIENT_RESOURCES), with or without this series.

* gsp_route: answer GPU_GET_INFO DMABUF_CAPABILITY as kernel RM does

NV2080_CTRL_GPU_INFO_INDEX_DMABUF_CAPABILITY (0x3d) is answered by
NVIDIA's kernel-side RM, not by GSP-RM: subdevice_ctrl_gpu_kernel.c
returns YES when osDmabufIsSupported(). GSP-RM has no dma-buf and
answers NO, and the GA10x routing passed that through. nvdriver exports
dma-bufs itself (NV_ESC_EXPORT_TO_DMABUF_FD), so answer YES like the
kernel-side RM, on every path that answers the index: GSP-RM's V2
reply, the V2 reply a V1 GET_INFO is translated to, an R620-sized V2
query translated to 580 batches, and nvdriver's native GET_INFO_V2
table.

libcuda 580.178.04 queries this index, but on a GeForce laptop GPU it
still reports CU_DEVICE_ATTRIBUTE_DMA_BUF_SUPPORTED=0 afterwards and
never issues the export ioctl: its decision depends on more than this
answer. This only makes the answer correct.

* uvm: export a CUDA allocation as a dma-buf by GPU address

libcuda only exports a dma-buf through cuMemGetHandleForAddressRange,
and on GPUs it reports CU_DEVICE_ATTRIBUTE_DMA_BUF_SUPPORTED=0 for (a
GeForce RTX 3050 Laptop here) it refuses in user space with
CUDA_ERROR_NOT_SUPPORTED, before asking the kernel. The RM handles that
NV_ESC_EXPORT_TO_DMABUF_FD needs live inside libcuda, so an application
cannot call the ioctl itself.

The UVM node knows them: UVM_MAP_EXTERNAL_ALLOCATION maps (hClient,
hMemory, offset) at a GPU virtual address. Record them in each
ExternalMap (and carry them through uvm_ext_gpu_map_split, the piece
after a hole moving its offset along), and add an nvidia_rs ioctl on
the process's own /dev/nvidia-uvm VA-space fd:

  NV_RS_UVM_EXPORT_DMABUF (0x4e520001)
  { u64 va; u64 size; u32 flags; s32 fd; u32 status; s32 rm_fd; }

[va, va + size) must be page aligned and lie inside one external
mapping; flags bit 0 allows a (shared) CPU mmap. The range resolves to
its RM memory and goes through the same export as
NV_ESC_EXPORT_TO_DMABUF_FD (nv_rs_rmapi_export_dmabuf_object(), a single
extent), so it gets the same lifetime (the dma-buf pins the memory)
and the same authorization: the memory's client must belong to rm_fd,
an RM file the caller holds (or to its control file), the way UVM's
rmCtrlFd names it. The UVM mapping is
not enough on its own: UVM_MAP_EXTERNAL_ALLOCATION also accepts objects
shared through NV_ESC_RM_SHARE, which this export does not. If GPUs'
mappings of the range name different memory, the address is ambiguous
and refused. The lookup takes only the UVM lock (it reads this file's VA
space); the export then resolves the memory again under the RM API lock,
so a mapping changed in between exports memory the caller still owns, or
fails. As for NV_ESC_EXPORT_TO_DMABUF_FD, the fd is installed only once
the reply has been copied out.

tools/nv_rs_dmabuf.h wraps it (nv_rs_export_dmabuf(ptr, size, flags,
&status) finds the UVM and RM fds in /proc/self/fd); tools/
cuda_dmabuf_uvm_export_test.c checks that the dma-buf is the
allocation's VRAM (CPU mmap reads what cuMemcpyHtoD wrote and
cuMemcpyDtoH reads what it wrote, whole and for a sub-range), that bad
ranges and private mmaps are refused, that an export whose reply cannot
be copied back leaves no fd, and that the dma-buf keeps a
freed cuMemMap allocation: an existing CPU mapping still reads its
data, and writes through it never reach a new allocation.

On the RTX 3050 Laptop with io_uring + NVMe dma-buf reads (block layer
support from the io_uring dma-buf series in 7.4; ext4 needs out-of-tree
patches, device-mapper is refused), NVMe reads land in VRAM at the speed
they land in host memory on a Gen3 x4 drive (3.2 GB/s), and at ~75% of
it from a Gen4 x4 drive on another root port (5.1 vs 6.8 GB/s).

tools/dmabuf_unbind_race_test.py (run by tools/dmabuf_unbind_race_run.sh)
exercises the GPU-removal revoke from commit 1 through this export: it
unbinds nvidia_rs from the GPU while an io_uring reader keeps 32 NVMe
reads in flight into an exported buffer, another export carries an
unsignaled sw_sync write fence (signaled HOLD seconds into the unbind),
an RM-call loop runs, and an export loop runs. Its io_uring side is fastsafetensors' io_uring
dma-buf layer (IoUring); the export is its own, the ioctl of
tools/nv_rs_dmabuf.h. The reader exports after the
fenced buffer, so the revoke meets the fence first. On the RTX 3050
Laptop with a 5 s hold (three runs), exports were refused from 9-29 ms
into the unbind, every in-flight read completed with -ENODEV by
24-51 ms (the fenced buffer did not keep the reader's readable), RM
calls kept completing without a failure (slowest call 182 ms) while the revoke waited
for the fence, and the GPU teardown under the RM API lock started right
after the fence was signaled. Lockdep stayed on through the run, with no
KASAN or lockdep report.

---------

Co-authored-by: Arsenova <arsenova@a7snv.com>
2026-12-04 23:05:05 -08:00
7e80ce1b46 rmapi/gsp_route: translate R620 NV_CHANNEL_ALLOC_PARAMS so stock 620.x userspace can create CUDA contexts (#519)
* rmapi/gsp_route: translate R620 userspace RM controls to R580 GSP-RM layouts (#504)

* rmapi/gsp_route: translate R620 NV_CHANNEL_ALLOC_PARAMS (hHandleVASpace) for CUDA contexts

* rmapi: select channel alloc ABI from physical file_owner and hook into lockless prepare_alloc

* gsp_bringup: translate R620 channel alloc params on R580 GSP sessions
2026-12-04 21:47:24 -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
4035bab737 perf(rmapi): cut nv_rs_rmapi_lock acquisitions in half & eliminate hot ioctl heap allocs (#518)
Co-authored-by: morebrackets <19673572+morebrackets@users.noreply.github.com>
2026-12-04 17:03:05 -08:00
06e61c33fd uvm,tools(gv11b): add 40-bit DMA limit and dev:<idx> + NV_RS_CUDA_ARCH suite support (#439)
* uvm,tools(gv11b): add 40-bit DMA limit and dev:<idx> + NV_RS_CUDA_ARCH suite support

* tools(gv11b): reject empty dev: ordinal and handle integrated prefetch/IPC

* uvm,rmapi(gv11b): wire architecture DMA bit width into runtime negotiation

* tools(gv11b): guard cuMemAdvise on concurrent_managed and preserve non-801 IPC errors

* tools(gv11b): emit managed-access capability and skip flags in parity JSON

* kernel(gv11b): move nv_rs_uvm_dma_bits_for_boot0 to rmapi_node.rs and retain in guest VM build
2026-12-04 16:17:28 -08:00
b8c7680284 kernel-open: probe class_create/devnode signatures (RHEL 9 5.14 build) (#552)
a2707a4 guards class_create(name) and the const-device class.devnode
callback in rmapi_node.c with LINUX_VERSION_CODE >= 6.4 / 6.2. RHEL 9
backports both to 5.14, so the #else branch is taken there and the
module fails to build (-Werror=incompatible-pointer-types, too many
arguments to class_create).

Probe include/linux/device/class.h in compat_probes.mk instead, keeping
the version check as the fallback for unprobed (host-fixture) builds,
and record the guard in docs/KERNEL_COMPAT.md.

Co-authored-by: TheWeakShall <22898767+TheWeakShall@users.noreply.github.com>
2026-12-04 16:15:23 -08:00
b52978f2a5 Address round-3 CodeRabbit PR #383 findings (all 12 remaining items) 2026-12-03 16:33:41 -08:00
c5a9dd147d Address round-2 CodeRabbit PR #383 findings across RMAPI, kernel glue, KMS/DRM, and tools 2026-12-03 16:13:36 -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
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
2e86387188 Address CodeRabbit PR #383 review findings across RMAPI, kernel glue, KMS/DRM, and tools 2026-12-03 08:58:32 -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
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
d1596ff615 Merge origin/master into feat/ga102-desktop-master 2026-12-03 01:12:21 -08:00
fdc8b7d053 rmapi/perf: O(1) handle hash indexes, Slab free_hint, alias-preserving video_cache, 4-slot virt_cache, and RM_ALLOC-only iterate_fd 2026-12-03 00:37:19 -08:00
09d2ec6f26 Merge upstream GPU caps cleanup with USERD revocation 2026-12-03 08:13:26 +00: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
6aa10ec587 Serialize Pascal USERD admission and retire mmap cookies 2026-12-03 07:33:07 +00:00
259be4ac7a Merge upstream while preserving Pascal teardown invariants 2026-12-03 07:28:38 +00:00
dafa67e222 Address all 5 CodeRabbit findings on #373 (rmapi/caps, tools)
rmapi/caps: capture caps_dir while holding nv_rs_rmapi_lock and clear the slot
there, so a replacement GPU that already took the same minor cannot have its
directory removed by the outgoing GPU's cleanup. Create the capability tree
outside the gpus/ block: proc_mkdir("gpus") failing must not skip it.

tools: match the readelf row with a regex so a padded single-digit section
index ("[ 5] __versions") is read, not skipped. Use the real struct
modversion_info size, MODULE_NAME_LEN (64) bytes: an unsigned long CRC plus the
name padded to the rest, not 72. When the fallback parse yields no records, fall
through to the original modprobe error instead of returning an empty map.

Verified: on kernel 7.0.0-44 the classic branch reproduces `modprobe
--dump-modversions` exactly for the stock nvidia-uvm.ko (287/287 entries,
0 mismatches); a lone zero byte now yields no records and preserves the error;
both "[ 5]" and "[33]" rows parse. Gates: 10.1.1.200 (1345b1f) UVM 77/77,
modeset 2/2, check_kernel_module.py passed, largest_stack 1016,
test_symbol_conformance.py 12/12. 10.1.1.122 (compact layout, kernel
6.8.0-151) UVM 76/76, modeset 1/1.
2026-12-03 15:07:58 +08:00
a83044ccb0 fix(gpu-nice): address CodeRabbit review 6164579970 findings 2026-12-03 03:41:11 -03:00
cab8b108c9 feat(gpu-nice): automatic Linux nice/renice and desktop priority for TSGs 2026-12-03 03:05:12 -03:00
07d85c4a29 Map Pascal framebuffer USERD through owner-scoped BAR1 pages 2026-12-03 04:47:35 +00:00
63c8309915 Merge origin/master and address CodeRabbit finding in destroy_gpu_va_space
- Resolve conflicts in hwmon_adapter.c, src/nvidia/Makefile, gsp_route.rs,
  rmapi_node.rs, and uvm_node.rs (preserving both #350 security/UVM/hwmon
  checks and master's #266/#349/#360 additions).
- In uvm_node::destroy_gpu_va_space, retain the page tree on any failed
  set_vaspace_page_directory(..., None) across all builds (not only GA10x)
  and flush GPU TLB before tree.destroy() on success.
2026-12-03 04:23:44 +00:00
796e9d984d Merge pull request #266 from morebrackets/ga10x-vulkan-live-parity
feat(ga10x,drm,rmapi): live Vulkan 1.4 compute/transfer + DRM/NVKMS UAPI parity (#148, #172)

Resolved conflicts against master (rmapi/gpu.rs, rmapi/server.rs,
src/nvidia/Makefile, tools/vm/build_guest_test.sh), ran rustfmt on
the PR's rmapi files, and fixed a C90 declaration-after-statement
warning in kernel-open/nvidia/rmapi_node.c.
2026-12-03 03:27:29 +00:00
88998fef1c rmapi/caps: report stock DeviceFileMode and per-GPU mig dirs
Stock 580.178.04 nv-caps.c writes DeviceFileMinor, DeviceFileMode and
DeviceFileModify; mig/monitor is 292 (0444) and every other capability
256 (0400). Without the mode line nvidia-modprobe falls back to its own
438 (0666) default when it mknods /dev/nvidia-caps/nvidia-cap<minor>.

Stock also creates /proc/driver/nvidia/capabilities/gpu<idx>/mig for
every GPU even where MIG cannot exist (observed on a 580.178.04 Volta
host), so create it with the GPU node and remove it with it.

DeviceFileModify stays 0, matching our ModifyDeviceFiles: 0 params line:
nvdriver never creates or chmods a device file, udev and
tools/bind_dev_nodes.sh own the nodes.

Verified against a live stock 580.178.04 host: minors, modes and all
three nvidia-caps/*-minors files (4322 lines) are now byte-identical,
with DeviceFileModify the only intentional difference. Built and gated
on kernel 6.8.0-151 and 7.0.0-44 (check_kernel_module.py passed,
largest_stack 1016; UVM 76/76 and 77/77, modeset 1/1 and 2/2 CRCs), and
the capability tree plus NVML/CUDA were checked on real GV100 hardware.
2026-12-03 11:22:31 +08:00
156657d844 rmapi: auto-negotiate driver_version per-file with strict_version_check fallback 2026-12-02 23:29:38 -03:00
5afae37b80 rmapi/ga10x: fix MAP_MEMORY_DMA dynamic VA/len and direct-scanout ContextDma
Match 580.196.07 RM behavior for two video/Wayland bugs:
- dmaAllocMap_IMPL / dmaMapBuffer_GM107 / virtmemMapTo_IMPL: honor NVOS46_FLAGS_DMA_OFFSET_FIXED (bit 29) instead of treating uninitialized dmaOffset bytes as a requested VA on un-ranged NV01_MEMORY_VIRTUAL, round (mem_offset & 0xfff) + map_len up to page boundaries, and forward NVOS46_FLAGS_PTE_KIND_OVERRIDE (bit 19).
- instmemCommitContextDma_v03_00 / dispchnBindCtx_IMPL / memmgrChooseKind_TU102: store NV01_CONTEXT_DMA flags on Entry, apply (flags >> 16) & 3 block-linear/pitch selection + offset/limit/4K alignment + scatter_id refusal in disp_instmem_bind and modeset_gsp_bind_ctxdma, and normalize Turing+ CLASS_VIDEO 0xfe -> 0x06.
- Add detailed RM_MAP_MEMORY_DMA error logging and unit test coverage.
2026-12-02 16:48:21 -08:00
11782f4a24 Merge origin/master and address Greptile review findings on #266
- Resolve nvidia_rs_drm.c conflict with origin/master (preserving multi-GPU
  per-device DRM slot registration, error propagation, and Vulkan/DMA-BUF ioctls).
- Security (4777606273): add Ga10xMem::map4k_flags() setting MMU v2
  PTE_PRIVILEGE_TRUE (bit 5) and PTE_READ_ONLY_TRUE (bit 6); map all kernel
  GR context buffers privileged in gr_object_alloc() and PRIV_ACCESS_MAP /
  UNRESTRICTED_PRIV_ACCESS_MAP read-only (matching 580.126.09
  kgrctxMapGlobalCtxBuffer).
- Correctness (4777606282): pass eff_offset (ContextDma offset + mem_offset)
  to the second visit_video_range() call in ControlNode::map_memory_dma(),
  with a recording Engine regression test in gpu_tests.rs.
- Resource cleanup (4777606291): roll back duplicated server/memory/space
  entries on any post-dup_resource insertion failure in ControlNode::dup_object()
  and only write dst_handle back on success.
- Host CPU info (4777606296): probe real host CPU topology/features/cache in
  rmapi_node.c via nv_rs_rmapi_set_cpu_info() and have client::system_cpu_info()
  return NOT_SUPPORTED when unprobed instead of fabricating CPU data.
2026-12-02 16:46:36 -08:00
482adcd2fa Merge pull request #203 from morebrackets/feat/idle-pstate-doorbell-telemetry-169
pmu/power: fix GV100 power-cap sync, add activity-wake idle governor, idle_pstate_gpc_khz, and live procfs telemetry (#169, #136, #137)
2026-12-02 16:41:00 -08:00
c079618975 ga10x/rmapi: scatter BAR1 CPU mmap, DMA unmap span precedence, BAR1 WC flush drain 2026-12-02 16:14:57 -08:00
97781cf591 Merge origin/master into feat/rust-lifecycle-cleanup-142 2026-12-02 16:05:05 -08:00
2d5eb284c3 Merge origin/master (ec7c96a) into feat/ga102-desktop-master 2026-12-02 14:08:14 -08:00
a2707a4c99 ga102: Stage 1 desktop bring-up, 0x00da/0x0002 parity, 2M/64K MMU, BAR1 WC PT pool & lockless GSP queues 2026-12-02 13:52:08 -08:00
bc24624481 rmapi/caps: match stock 580.178.04 nvidia-caps minors (IMEX=4323, 8192 range, full mig-minors) 2026-12-02 13:39:26 -08:00