#516 renamed the Rust export nv_rs_sysmem_pool_pop to
nv_rs_sysmem_pool_pop_batch (rmapi_node.c now calls the batch form) and
updated the module keep list in src/nvidia/Makefile, but the guest build's
copy of the list in tools/vm/build_guest_test.sh still forced the old
name with -u. ld -r then leaves nv_rs_sysmem_pool_pop as an undefined
symbol and drops the batch export, so modpost fails on nv_rs_edu_test.ko
and validate_all.sh's guest_build (and initramfs/guest/guest_iommu after
it) fail on master 3e1bf7b8.
nvidia_rs.ko is byte-identical with and without this change.
Claude-Session: https://claude.ai/code/session_01W53iUSBQkEg9aqwF4AoBHi
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* 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>
* ada/desktop: adapt Stage 1 & Stage 2 desktop video for RTX 40 series (AD102-AD107)
Stage 1 & Core Ada GSP-RM / RM fixes (verified against stock 580.196.07):
- ga10x_gsp.rs: stop downgrading Ada's configured 580.x release string when
no bundled 580.178.04 Ada booter exists, add 580.196.07 -> 580.178.04
gsprm_load fallback, read NV_FUSE_STATUS_OPT_DISPLAY at 0x820c04 on
Ampere/Ada+ (_nv030373rm) and propagate display_fused_off into hw facts,
and fail explicitly (instead of silently skipping) when cold-boot Ada
scrubber-580.bin is missing.
- display.rs, display_channels.rs, gsp_boot.rs, ga10x.rs: fix Ada
DispSfUser BAR0 offset (0x6f0000 for all NvDisplay v03_00+ per
_nv005909rm/_nv040109rm), fix Ada copy_engine class (0xc7b5
AMPERE_DMA_COPY_B), enable ce_class_db filtering for ArchFamily::Ada,
and pass real boot0 to configure_live_display().
- gsp_route.rs, rmapi_node.rs, modeset_ffi.rs, modeset_bridge.c: intercept
NV_ESC_RM_BIND_CONTEXT_DMA (0x59) in pre() for host-side 0x0002 ->
NvDisplay channel binds, keep modeset_gsp_alloc_ctxdma 100% host-side
with Node RM video memory lookup via nv_rs_modeset_query_rm_mem, prevent
double GSP memory registration, purge MODESET_MEMS/MODESET_CTXS on
NVOS00 free, validate Stage 1 nv_rs_modeset_get_rm_ops against the
configured 580.x driver_version, and fix NVOS64 debug status trace.
Stage 2 Ada NvDisplay v4.1 (0xc77d/0xc67e) & DRM pipeline fixes:
- nvidia_rs_modeset.c:
- Separate full Core modeset/link-training from fast Window-only page
flips and cursor-only Core updates; program Core FIRST on full modeset.
- Resolve imported compositor/Vulkan/EGL VRAM handles via
nv_rs_modeset_query_rm_mem and bind host-side NV01_CONTEXT_DMA to Core
and Window channels for scanout.
- Enforce BAR1 window bounds on 0x0040 allocations (falling back to
BAR1-constrained nv_rs_modeset_vram_alloc on non-ReBAR 256 MiB GPUs)
and propagate block-linear pte_kind.
- Query NV0073_CTRL_CMD_SPECIFIC_OR_GET_INFO (0x0073028b) for SOR
sublink A/B (DP_A/DP_B, SINGLE_TMDS_A/B, DUAL_TMDS), promote HDMI
>600 MHz to SOR_PROTOCOL_HDMI_FRL (0xc), bracket DP link training with
NV5070_CTRL_CMD_SET_SOR_FLUSH_MODE (0x50700457), support DP 1.4a HBR3
(0x1e) via DP_GET_CAPS (0x00731369), and retry with FALLBACK_CONFIG.
- Honor HSYNC/VSYNC polarity and 10 bpc depth in HEAD_SET_CONTROL_OR,
emit HEAD_SET_CONTROL / PCLK_CFG / USAGE_BOUNDS / STORAGE_CURSOR,
fix WIN_SET_PLANAR_STRG0 13-bit mask (& 0x1fff), add XBGR16161616F,
and back off synthetic vblank timer when real HW vblank IRQs arrive
(removing the 4 ms floor for 240/360 Hz displays).
- nvidia_rs_drm.c: fix VRAM BAR1 mmap vma->vm_pgoff bounds/offset,
validate explicit FB modifiers and reject compressible modifiers, add
XBGR16161616F, remove unimplemented NV12, set preferred_depth=24 and
<6.13 allow_fb_modifiers=true, and pair drm_kms_helper_poll_init/fini.
- install_desktop_boot.sh, reload_stage1.sh: add Ada (ad102) GSP boot &
scrubber firmware preflight check with extract_gsp_boot_ucode.py hint.
- Add unit tests in display.rs, gsp_boot.rs, nvdisp_pushbuf.rs, and
gpu_tests.rs covering Ada classes, fuse register, and pushbuffer encode.
* ada/desktop: resolve all CodeRabbit review findings for RTX 40 desktop video
* ada/desktop: address round-2 CodeRabbit review findings
* ada/desktop: address final CodeRabbit review findings
* ada/desktop: track explicit fb modifiers, order disable before vblank_off, reserve Window room up front
---------
Co-authored-by: morebrackets <19673572+morebrackets@users.noreply.github.com>
[T] Observed live on physical silicon (Tesla P100 SXM2, host-native
nvidia_rs lanes, kernel 6.12.105, driver 8f5bf596):
do_namespace() reads /proc/<getppid()>/ns/mnt unconditionally. When the
launcher is started through a container-runtime or supervisor chain
(incus exec, docker exec, systemd wrappers) the spawning process can
already be gone or invisible in the PID namespace, getppid() reports
pid 0, and the readlink aborts the launcher with:
FileNotFoundError: [Errno 2] No such file or directory: '/proc/0/ns/mnt'
before any mount step runs. This reproduced on every lane start in that
setup until the guard was made tolerant.
Fix: fall back to the namespace init's mount ns (/proc/1/ns/mnt), which
is the original mount namespace the app process must diverge from, and
if even that link is unreadable (hidepid / ptrace checks under a
non-root test run) degrade to the self-comparison alone. The guard
stays fail-closed in all three paths: if unshare() did not create a
private namespace, now == before still aborts.
Verification (both on the patch, python 3.12):
- non-root, getppid() -> 0: launcher now passes the guard and stops at
unshare(CLONE_NEWNS) EPERM (was: FileNotFoundError crash at the guard)
- root, getppid() -> 0: do_namespace() completes, in_private_namespace
True, ns id differs from before (guard + unshare + check all work)
- unchanged behavior when getppid()'s ns is readable (first path taken)
Signed-off-by: Patrick Hamid <phamid@users.noreply.github.com>
Co-authored-by: Patrick Hamid <phamid@users.noreply.github.com>
* 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>
- Add exact 580.178.04 ABI Rust decoders/validators and unit tests (69/69)
in src/nvidia/src/nvkms/mod.rs + kernel FFI exports in modeset_ffi.rs,
modeset_iface_exports.c, and src/nvidia/Makefile for all remaining NVKMS
ioctl commands.
- Wire per-command exact 580 ABI + handle validation in
kernel-open/nvidia-modeset/nvidia_rs_modeset.c, returning honest -EINVAL
(missing disp/head/framelock/swap-group) or -EOPNOTSUPP for unbacked
display, framelock, permissions, deferred FIFO, swap-group join/leave/clip,
and unicast-event handlers rather than fake success.
- Update tools/build_parity_ledger.py to inspect C handler function bodies
and exclude -EOPNOTSUPP handlers from PORTED (keeping nvkms_ioctls honestly
at 14 PORTED / 52 PARTIAL).
Co-authored-by: morebrackets <19673572+morebrackets@users.noreply.github.com>
Master at 5a8ebbee fails three gate steps (`fmt` and `guest_build`, with
`initramfs`, `guest` and `guest_iommu` skipped as a result):
- #385 made rmapi_node.c include rmapi_plat_io.h, but the guest build
copies rmapi_node.c into its staging directory without that header.
- #518 added the nv_rs_rmapi_prepare_alloc export, which the guest's
`ld -r --gc-sections -u ...` keep list does not name, so modpost reports
it undefined.
- Two test blocks (ga10x_gsp.rs, legacy_hal.rs) are not rustfmt-clean
under the pinned 1.100.0 toolchain.
Copy the header, keep the symbol, run cargo fmt. The fmt changes are in
#[cfg(test)] code only; nvidia_rs.ko is byte-identical to master's
(sha256 f2274473...). tools/validate_all.sh: 34 PASS, gsp_620_headers and
gp106_oracles SKIP, on kernel 7.3.6.
Claude-Session: https://claude.ai/code/session_01W53iUSBQkEg9aqwF4AoBHi
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* 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
- Harden nv_rs_fb_create() and nv_rs_crtc_atomic_flush() so imported
NV_RS_GEM_DMABUF objects always validate single-segment contiguous sgt
backing and scan out via import_sgt rather than kms_mem.
- Return -EOPNOTSUPP in nv_rs_ioctl_gem_export_nvkms_memory() if the
export_memory_fd hook is unavailable instead of silently succeeding.
- Validate arguments and import_sgt in nv_rs_ioctl_gem_export_dmabuf_memory()
and return -EOPNOTSUPP until an RM external DMA-BUF memory wrapper with
independent attachment lifetime retention exists (avoiding a fake 0x003e
sysmem allocation or premature drm_prime_gem_destroy on GEM close).
- Update tools/build_parity_ledger.py and docs/PARITY_LEDGER.md to mark
nv_drm_gem_export_nvkms_memory_ioctl PORTED (backed by RM 0x00003d05)
and keep nv_drm_gem_export_dmabuf_memory_ioctl honestly PARTIAL (23/24).
Co-authored-by: morebrackets <19673572+morebrackets@users.noreply.github.com>
* 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
* 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
engine_construct.rs stated OBJTMR's fields as constants because its
constructor had no body. Port _nv059547rm and the pool initialiser
_nv049710rm it calls (timer/construct.rs) from the disassembly in
reports/objtmr-construct-rea/: byte +251c, the spinlock at +2500 (stored
before its null test; a null lock returns 0x1a), the null list heads
+250/+258, the 96-entry alarm pool from +268 and the 36-entry pool from
+2078 with their free-list heads, the +24b-gated +24f8 event, the retry
count +2510 = 3 and +2520 = 0.
gv100() runs it between Intr and OBJBUS. The engine live oracle now
records these fields (`construct` bytes and new `construct-pointer`
lines) and a focused oracle test compares every store with the object
the original constructs in emulation.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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>
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.
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.
* 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>
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>
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>
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>