Files
nvdriver/kernel-open
Arsenova c65b7c440c uvm_node: take the RM API lock before the UVM lock
nv_rs_uvm_ioctl() and nv_rs_uvm_release() took nv_rs_uvm_lock and then
nv_rs_rmapi_lock. Two other orders already exist:

  rmapi -> mmap_lock   nv_rs_rmapi_os_lock_user_pages() calls
                       pin_user_pages_fast() with the RM API lock held
                       (NV01_MEMORY_SYSTEM_OS_DESCRIPTOR, cudaHostRegister)
  mmap_lock -> uvm     the kernel calls nv_rs_uvm_mmap() and
                       nv_rs_uvm_vma_close() with mmap_lock held

so uvm -> rmapi closes a cycle. lockdep reports it as soon as a CUDA
process pins host memory while another thread mmaps the UVM node, and a
multi-threaded process can really deadlock on it:

  WARNING: possible circular locking dependency detected
  cuda_dmabuf_exp/4377 is trying to acquire lock:
   (&mm->mmap_lock){++++}-{4:4}, at: gup_fast_fallback+0x51f/0x2bc0
  but task is already holding lock:
   (nv_rs_rmapi_lock){+.+.}-{4:4}, at: nv_rs_rmapi_ioctl+0x64c/0x2f50
  Chain exists of:
    &mm->mmap_lock --> nv_rs_uvm_lock --> nv_rs_rmapi_lock

Take the RM API lock first in both places. Nothing under the RM API lock
takes the UVM lock (only the UVM file operations and module init/exit
do), so the order is now rmapi -> mmap_lock -> uvm everywhere. The fault
worker only trylocks, so it could not deadlock, but it now tries the two
locks in the same order as well.

The other way out would be to pin the pages before taking the RM API
lock in the OS-descriptor path; this keeps the change local to the UVM
node.

Observed on an RTX 3050 Laptop (GA107) under a lockdep kernel
(7.4.0-rc2) running a CUDA dma-buf test.
2026-12-02 07:27:28 +08:00
..