* 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>
Adds two independent reproductions of the NV_ERR_NOT_SUPPORTED VOLT_LOAD cap at 5879d3b3:
a Tesla V100-PCIE-32GB (10de:1db6) on kernel 7.0.0-44 and a Tesla V100-SXM2-32GB (10de:1db5)
on kernel 6.8.0-151, both requesting NDIV 183 (1372.5 MHz) at 905 mV and both landing on 1290
MHz with the identical load=0xd6d6d6d6 get=0x56 set=0xffff signature, while HBM reaches
1107.0 MHz on both.
PCIe and SXM2 packages, two kernel series and two target voltages answer the same way, which
supports the existing conclusion that the missing piece is the PMU task stack rather than the
board or the RPC payload.
* 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
* docs(bringup): Stage 3b's stock-ABI checks cannot pass as written
nvidia_rs publishes no stock 195 nvidiactl/nvidia0 ABI, so nvidia-smi
and cuInit fail by construction on a healthy bring-up. The failure is
not card-specific and its exit status carries no information about
whether the stage worked.
Replaces the check with an nv-rs-abi probe: GPU node opens 0,
/proc/driver/nvidia/gpus/<bdf>/information is populated, all three
session nodes open 0 while the GPU fd is held, then unbind + rmmod
returns 0 with no task in D.
Keeps the stage's runtime_engines=1 with no bringup= argument, and says
why: resolve_bringup_mode() silently forces runtime off when
bringup=N>0.
Signed-off-by: Mara <Mara@K80.dev>
* docs(bringup): cite the 0600 line correctly and stop Stage 3b on a failed check
The mode is set at gpu_owner.c:1023, not :1009; :1009 is `int error;` and
:1008 is the `struct device *device;` declaration. Measured at this branch's
head rather than carried over from an earlier tree.
The Stage 3b block also lost `set -eu` when the pass conditions replaced the
nvidia-smi checks. Without strict mode a failed insmod, a missing node, or a
failed unbind falls through to the trailing rmmod, and the block can exit 0
without any check having passed. Restore strict mode, and say in the block why
it is there so it is not tidied away again.
Reported-by: JoshyDo
Reported-by: Solarboaters
Signed-off-by: Mara <Mara@K80.dev>
* docs(bringup): require this GPU's session node, and bound the first open
Two defects in the Stage 3b block, both found by review on ab42c01a.
The per-GPU session node was matched with a glob under `nullglob`, so a
*missing* session node was skipped rather than failed, and a wildcard also
matched when the node belonged to a different GPU. The block now reads
`Device Minor:` out of the proc page it has just printed (rmapi_node.c:1085
prints it; :4338 builds the node name from the same minor_index) and requires
exactly /dev/nvidia-rs-rmapi-gpu$MINOR. `nullglob` is gone and all three
session paths are literal.
The first open ran as a bare `exec 9<` in the operator's root shell, which the
guide's own rule forbids for /dev/nvidia* commands. The open and checks 1-4 now
run inside one `timeout 15 bash -euo pipefail -c` helper that holds fd 9 for
the duration of the checks, so the fd still lives in the process that measures
and a stall no longer leaves a root shell sitting in it. The guide's own caveat
is kept in the comment: `timeout` does not interrupt an uninterruptible kernel
wait, so it is a stop signal, not a rescue.
Checked against the block as it ships (2,766 B / 57 lines) with a stubbed
logic-only harness: nine fixtures, nine intended branches. No module was
loaded, no real device node was touched, and nothing here says Stage 3b passes
on hardware.
Reported-by: coderabbitai[bot]
Signed-off-by: Mara <Mara@K80.dev>
* docs(bringup): open the RMAPI session node for Stage 3b, not the GPU node
The direct /dev/nvidia-rs-<bdf> open runs the first-open path under
misc_mtx with no runtime worker: nv_rs_runtime_park_wait returns 0 when
the caller is not the runtime kthread, so the engines are torn down
before the open returns. Holding that fd was therefore not evidence of
live engines, and the note that closing it parks the runtime was wrong.
Resolve Device Minor from the per-GPU proc page (created at probe) and
open /dev/nvidia-rs-rmapi-gpu<minor> first; that open starts the runtime
worker and waits for it to park. Keep the control and UVM opens under
the held session fd. State the close semantics correctly: the worker
stays parked until a stop request, and the unbind is that request.
Reported-by: coderabbitai[bot]
Signed-off-by: Mara <Mara@K80.dev>
* docs(bringup): say how to clean up after a failed Stage 3b check
If the session or UVM open fails, the block exits before the unbind and
rmmod, and closing fd 9 does not stop the runtime worker: the module stays
loaded and the GPU stays bound, so a retry fails at insmod. The failure
branch now says so and prints the unbind/rmmod line for a new root shell.
Reported-by: coderabbitai[bot]
Signed-off-by: Mara <Mara@K80.dev>
* docs(bringup): print Stage 3b cleanup on every failure path
The earlier checks - unreadable proc page, no Device Minor, missing session
node - exited before the cleanup line added for the helper branch, leaving
the module loaded and the GPU bound. One stage3b_fail helper now prints the
unbind/rmmod line on every failure after insmod.
Reported-by: coderabbitai[bot]
Signed-off-by: Mara <Mara@K80.dev>
---------
Signed-off-by: Mara <Mara@K80.dev>
Co-authored-by: Mara <Mara@K80.dev>
Linux 7.3 renamed the atomic state container to struct drm_atomic_commit,
and the plane and CRTC atomic helper callbacks take the renamed type, so
nvidia_rs_drm.c fails to compile there with eight incompatible-pointer
errors (reported in #533).
Probe the definition in <drm/drm_atomic.h> from compat_probes.mk, as the
other DRM guards do, and use a typedef in the five callbacks. No
behaviour change on either side of the rename.
Claude-Session: https://claude.ai/code/session_01W53iUSBQkEg9aqwF4AoBHi
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
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>
New page. 0x20800110/0x20800111/0x20800170 are registered under the
subdevice class 0x4b01b3; addressed to device or binary API they return
0x56 by design, before any handler runs. 0x110 writes a flags word then
the name at offset 4, 0x111 writes the name at offset 0, and 0x170 with
count = n writes exactly 1 + n words.
Protocol facts come from tables and handlers already in this tree. No
proprietary binary was read.
Signed-off-by: Mara <Mara@K80.dev>
Co-authored-by: Mara <Mara@K80.dev>
The :90 callout tells multi-function card owners that
ensure_vfio_bound() requires a single-device IOMMU group and refuses
groups with sibling devices. tools/vm/run_vfio_guest.py does neither:
validate_iommu_group() accepts a same-slot multifunction group, and
ensure_vfio_bound() binds every member itself.
Framed as a disagreement between the doc and the tool, not as a verdict
on which is right.
Signed-off-by: Mara <Mara@K80.dev>
Co-authored-by: Mara <Mara@K80.dev>
The NOT_SUPPORTED bullet reads as though 0x56 always means the command
is unimplemented for the class on this chip. It also means the command
was addressed to an object whose class does not own it, which says
nothing about the hardware.
Adds how to tell the two apart from tables in this tree: check the
owning class in the method's control_table row against the target
object's class in resources.rs, and confirm the parameter buffer was
left untouched. One bullet, one paragraph; no part-specific numbers.
Signed-off-by: Mara <Mara@K80.dev>
Co-authored-by: Mara <Mara@K80.dev>
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.
* feat(drm): implement semaphore-surface timeline fence ioctls via dma_fence, sync_file, and dma_resv
* fix(drm): per-fence lock, 64-bit seqno, timeout enforcement, pre_wait_value ordering, unpublished rollback, unload drain, and 5.19 dma_resv boundary
* fix(drm): separate done_link/on_ctx_list, bound pending waits with close() cleanup, and fix exit drain lock discipline
* fix(drm): hold ctx ref across drain_waits and init w->cb.node + sem_closing guard before callback arming
* fix(drm): reap disarmed waits during drain_waits when ctx->sem_closing is set
* fix(drm): probe dma_fence_init64 (6.17+), cap pending fences & timeout, and disarm all fence timers on close/unload
* fix(drm): track timed-out seqno watermark and tear down waits/timers before releasing DRM devices
* fix(drm): queue fence timeout work before releasing publication locks
---------
Co-authored-by: Eric Hartford <eric@quixi.ai>
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.
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>
- Export nv_rs_nvkms_ownership_{grab,release,is_owner,release_device,release_file}
and nv_rs_nvkms_validate_{free_device,get_next_event,free_swap_group} from
nvidia_rs.ko backed by nv_rs_core::nvkms
- Remove duplicated C nv_rs_modeset_owners[] table from nvidia_rs_modeset.c
and route GRAB_OWNERSHIP, RELEASE_OWNERSHIP, FREE_DEVICE, GET_NEXT_EVENT,
and FREE_SWAP_GROUP through the live Rust FFI entry points
- Add dedicated per-command unit tests (test_free_device, test_get_next_event,
test_grab_ownership, test_release_ownership, test_free_swap_group) and
update tools/build_parity_ledger.py + docs/PARITY_LEDGER.md
(nvkms_ioctls 4 -> 9 PORTED, total 2,549 PORTED / 67 PARTIAL / 0 MISSING)
- Export nv_rs_nvkms_validate_fbcon_disabled_userspace from nvidia_rs.ko
and call it directly from nvidia_rs_modeset.c
- Split nvkms unit tests into dedicated per-command tests (test_alloc_device,
test_declare_event_interest, test_alloc_swap_group, test_fbcon_disabled_userspace)
- Update audit_nvkms() in tools/build_parity_ledger.py to check an explicit
per-command (ffi_symbol, test_fn_name) map and record each command's exact
test in verification (4 PORTED, 62 PARTIAL, 0 MISSING)
- Add clean-room #![no_std] nv_rs_core::nvkms (src/nvidia/src/nvkms/mod.rs)
holding the single-source-of-truth 66-entry 580.178.04 NVKMS_PARAM_SIZES_580
table (verified against target/stock-580-kmods/nvidia-modeset.ko:.rodata+0x25ee0),
device/event-interest/swap-group/fbcon validators, OwnershipTable, and
unit tests (cargo test nvkms::tests::*)
- Export nv_rs_nvkms_param_size_580, nv_rs_nvkms_validate_alloc_device,
nv_rs_nvkms_validate_event_interest, and nv_rs_nvkms_validate_alloc_swap_group
from nvidia_rs.ko and call them directly from nvidia_rs_modeset.c (removing
the duplicated C size table)
- Update tools/build_parity_ledger.py and docs/PARITY_LEDGER.md:
nvkms_ioctls 0 -> 9 PORTED (with Rust FFI + cargo test verification),
total 2,549 PORTED, 67 PARTIAL, 0 MISSING, 19 EXCL
- Match stock 580.178.04 wire values: NV_GEM_OBJECT_DMABUF=1,
NV_GEM_OBJECT_USERMEMORY=2 (in both nvidia_rs_drm.c and nv_rs_core::drm)
- Delegate NV_RS_GEM_KIND_DMABUF mmap to dma_buf_mmap()
- Keep NVIDIA_DMABUF_SUPPORTED and NVIDIA_GEM_ALLOC_NVKMS_MEMORY returning
-EOPNOTSUPP (supports_alloc=0) until real NVKMS block-linear VRAM allocation
and NVKMS DMA-BUF conversion are wired (generic PRIME import remains enabled)
- Implement nv_rs_drm_gem_mmap (shmem call_mmap for NVKMS_MEMORY,
vm_insert_page for USER_MEMORY, with >= 6.3 vm_flags_clear/set compat)
and nv_rs_drm_gem_get_sg_table (drm_gem_get_pages + drm_prime_pages_to_sg)
so allocated and imported GEM handles are directly mappable and PRIME-exportable
- Export nv_rs_drm_validate_gem_alloc_nvkms and
nv_rs_drm_validate_gem_import_userspace from nvidia_rs.ko (calling the
unit-tested nv_rs_core::drm validators) and invoke them directly from
kernel-open/nvidia-drm/nvidia_rs_drm.c
- Add nv_rs_modeset_poll() callback (report EPOLLIN only when pending) and
reject non-zero DECLARE_EVENT_INTEREST subscriptions with -EOPNOTSUPP
- Reject userspace NVKMS_IOCTL_FRAMEBUFFER_CONSOLE_DISABLED with -EPERM
(kernel-only in stock 580.178.04 _nv000413kms)
- Validate rm_device_id < 32 (NV_MAX_DEVICES) and mig_device == 0 on
ALLOC_DEVICE and index exclusive ownership directly by rm_device_id
- Reject non-owner RELEASE_OWNERSHIP with -EPERM before any cleanup
- Copy and validate full 36-byte NvKmsAllocSwapGroupRequest headMask[8]
(reject nonzero masks on headless numDisps==0 devices) and enforce
modeset-owner check on ALLOC/FREE_SWAP_GROUP
- Publish bar1_ext_bytes in extend_bar1_identity_map() only after BAR1
TLB invalidation readiness + ack polls succeed
- Reject both bus-loss (u32::MAX) and Poll32 timeout in Maxwell/Pascal
flush_tlb() branches
- Include read_pascal_register() loops (wait_pascal_bar1_bind,
flush_pascal_bar1, wait_pascal_mmu) in audit_mmio_bus_loss_guards()
(32/32 verified) and emit honest PARTIAL for NVKMS until behavioral
parity tests exist
The guard refused every exported control whose parameter struct holds
an NvP64, including three that stock CPU-RM forwards to GSP-RM flat.
Refusing them left NVB06F_CTRL_CMD_MIGRATE_ENGINE_CTX_DATA on a channel
GSP-RM created to nvdriver's own server, which does not hold that
channel and answers OBJECT_NOT_FOUND (CodeRabbit review of #392).
Stock, in 620.73.04 and 580.178.04 alike:
- rmresControlSerialization_Prologue_IMPL calls serverSerializeCtrlDown
for a control whose method entry is flagged
RMCTRL_FLAGS_ROUTE_TO_PHYSICAL (0x40, control.h:230 in 620, :233 in
580; resource.c:209-222; ctrlFlags is the method entry's flags,
resource.c:172).
- serverSerializeCtrlDown returns NV_OK with the block unchanged when
FINN does not serialize the control (rmapi_finn.c:85-87 in 620,
:86-88 in 580).
- rmresControl_Prologue_IMPL then sends the block to GSP-RM as it is
(resource.c:254, NV_RM_RPC_CONTROL at :289).
The exported NvP64 controls flagged ROUTE_TO_PHYSICAL that FINN does
not serialize are the same three in both releases:
- NV5080_CTRL_CMD_DEFERRED_API 0x50800101 (flags 0x50048)
- NV5080_CTRL_CMD_DEFERRED_API_INTERNAL 0x50800104 (flags 0x500c8)
- NVB06F_CTRL_CMD_MIGRATE_ENGINE_CTX_DATA 0xb06f010d (flags 0x14044)
The method table of the closed 580.178.04 binary
(rmapi::control_table::METHODS) has the same flags for all three.
tools/check_pointer_controls.py now derives this from each tree: it
reads every method entry's flags from the NVOC tables, the value of
RMCTRL_FLAGS_ROUTE_TO_PHYSICAL from control.h, and leaves out of the
expected list every exported NvP64 control whose entries all carry it
and that the FINN serializer list does not hold. It fails when such a
control is on a list. In the embeddedParamCopyIn cross-check, a control
stock forwards flat is accounted for: MIGRATE_ENGINE_CTX_DATA, whose
pEngineCtxBuff stock copies in first (embedded_param_copy.c:661-672 in
620, :673-684 in 580).
Regenerated with it, NVP64_CONTROLS_620 goes from 56 to 53 commands
(620.73.04 and 620.70.06) and NVP64_CONTROLS_580 from 53 to 50
(580.178.04). POINTER_CONTROLS is unchanged at 13. The check passes on
all three trees.
The guard still refuses every other NvP64 control, on both ABIs. A new
unit test checks that the three are on no list, go flat through
forwards_flat and escape_forwards_flat on both ABIs, and are flagged
ROUTE_TO_PHYSICAL in control_table::METHODS. The module doc, the
gsp_bringup::forward_escape comment and docs/REPLAY_TESTING.md drop
the "stricter than stock" wording. They also record the difference that
remains for MIGRATE_ENGINE_CTX_DATA: stock sends GSP-RM the address of
CPU-RM's kernel copy of pEngineCtxBuff, while gsp_bringup passes the
caller's block unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Restore exact 580.178.04 66-entry NVKMS command numbering (retaining
CHECK_LUT_NOTIFIER at 13, REGISTER_SURFACE at 17, GET_NEXT_EVENT at 32,
ALLOC_SWAP_GROUP at 46, FRAMEBUFFER_CONSOLE_DISABLED at 65) and exact
paramsSize table dumped directly from stock nvidia-modeset.ko (.rodata+0x25ee0)
- Use exact 40-byte NvKmsAllocSwapGroupParams layout (reply at offset 36)
separately from 12-byte NvKmsFreeSwapGroupParams (reply at offset 8)
- Track display ownership per underlying (rm_device_id, mig_device) across
opens with consistent lock ordering (owner_lock -> f->lock), reject competing
owners with -EBUSY, and clear swap groups on ownership release and file close
- Give CLEAR_UNICAST_EVENT a dedicated unicastEventFd handler (fget/fput +
f_op validation)
- Return -EOPNOTSUPP for REGISTER_SURFACE until fd surface import is implemented
(never fabricate an unbacked handle)
- Propagate flush_tlb() bus-loss/timeout failures (bool #[must_use]) through
uvm_map_range, uvm_map_pages, map_rm_default_sysmem, map_rm_default_vram,
and scrub-CE/WFI paths with PTE rollback on failure
- Harden audit_mmio_bus_loss_guards() to parse comment-stripped balanced-brace
loop bodies for an explicit u32::MAX/0xffff_ffff condition + break/return exit
and populate stock_evidence/rust_location/verification fields; audit all 66
NVKMS entries directly against stock 580.178.04 nvidia-modeset.ko
- Port NVKMS_IOCTL_ALLOC_SWAP_GROUP (45) and FREE_SWAP_GROUP (46) with
per-file tracking and device-free cleanup in nvidia_rs_modeset.c.
- Add exact gcc-verified 580.178.04 nv_rs_kms_param_sizes[65] table and
deviceHandle validation for all remaining display-dependent NVKMS ioctls.
- Update docs/PARITY_LEDGER.md: 2,548 PORTED, 62 PARTIAL (display/GEM
backends), 0 MISSING, 21 INTENTIONALLY_EXCLUDED across all 8 domains.