nv-vm: skip unallocated pages during sysmem OOM cleanup - #1278
Open
plopresti wants to merge 1 commit into
Open
Conversation
plopresti
force-pushed
the
fix/nv-vm-oom-cleanup-deadlock
branch
from
August 5, 2026 18:01
09f5331 to
e29578b
Compare
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
force-pushed
the
fix/nv-vm-oom-cleanup-deadlock
branch
from
August 5, 2026 18:04
e29578b to
10ea578
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(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.