Skip to content

nv-vm: skip unallocated pages during sysmem OOM cleanup - #1278

Open
plopresti wants to merge 1 commit into
NVIDIA:mainfrom
plopresti:fix/nv-vm-oom-cleanup-deadlock
Open

nv-vm: skip unallocated pages during sysmem OOM cleanup#1278
plopresti wants to merge 1 commit into
NVIDIA:mainfrom
plopresti:fix/nv-vm-oom-cleanup-deadlock

Conversation

@plopresti

Copy link
Copy Markdown

(This description and fix were AI-generated. I can confirm this avoids the catastrophic failure described in #1277.)

nv_alloc_system_pages() sets pages to UC only after the whole array is
allocated. On an out-of-memory partial allocation it jumps to failed: ->
nv_free_system_pages() before that, which then calls nv_set_memory_type(at, NV_MEMORY_WRITEBACK) based on the requested at->cache_type.

nv_set_memory_type() iterates over all at->num_pages with no unallocated-slot guard, unlike the two loops in nv_free_system_pages() that break at page_ptr->virt_addr == 0. For a large descriptor that failed early, most slots are unallocated (phys_addr == 0), so NV_GET_PAGE_STRUCT(0) yields PFN 0 and set_memory_wb()/ set_memory_array_wb() is invoked on [0x0-0xfff] once per slot. This floods the kernel log with "x86/PAT: freeing invalid memtype [mem 0x0-0xfff]" and spins in an O(num_pages) TLB-flushing loop while holding the RM API write lock (rmapiLockAcquire in serverAllocResource), deadlocking all other threads until reboot.

Bound the cache-type reset to actually-allocated pages by breaking at the first virt_addr == 0, mirroring the existing guards in nv_free_system_pages(). Fully-allocated frees are unaffected; an OOM now returns NV_ERR_NO_MEMORY cleanly instead of wedging the system.

Fixes #1277.

@plopresti
plopresti force-pushed the fix/nv-vm-oom-cleanup-deadlock branch from 09f5331 to e29578b Compare August 5, 2026 18:01
nv_alloc_system_pages() sets pages to UC only after the whole array is
allocated. On an out-of-memory partial allocation it jumps to failed: ->
nv_free_system_pages() before that, which then calls
nv_set_memory_type(at, NV_MEMORY_WRITEBACK) based on the requested
at->cache_type.

nv_set_memory_type() iterates over all at->num_pages with no
unallocated-slot guard, unlike the two loops in nv_free_system_pages()
that break at page_ptr->virt_addr == 0. For a large descriptor that
failed early, most slots are unallocated (phys_addr == 0), so
NV_GET_PAGE_STRUCT(0) yields PFN 0 and set_memory_wb()/
set_memory_array_wb() is invoked on [0x0-0xfff] once per slot. This
floods the kernel log with "x86/PAT: freeing invalid memtype
[mem 0x0-0xfff]" and spins in an O(num_pages) TLB-flushing loop while
holding the RM API write lock (rmapiLockAcquire in serverAllocResource),
deadlocking all other threads until reboot.

Bound the cache-type reset to actually-allocated pages by breaking at the
first virt_addr == 0, mirroring the existing guards in
nv_free_system_pages(). Fully-allocated frees are unaffected; an OOM now
returns NV_ERR_NO_MEMORY cleanly instead of wedging the system.

Fixes NVIDIA#1277

Signed-off-by: Patrick LoPresti <lopresti@gmail.com>
@plopresti
plopresti force-pushed the fix/nv-vm-oom-cleanup-deadlock branch from e29578b to 10ea578 Compare August 5, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System-wide GPU/driver deadlock

1 participant