Skip to content

Commit cb2a351

Browse files
nvidia: use vzalloc for oversized page table allocations
nvos_create_alloc() allocates at->page_table as a single array of nvidia_pte_t entries: pt_size = num_pages * sizeof(nvidia_pte_t) For very large registered system-memory ranges, pt_size can exceed INT_MAX. For example, a 512 GiB range with 4 KiB base pages requires 134,217,728 entries. With 16-byte nvidia_pte_t entries, pt_size is 2,147,483,648 bytes. kvzalloc() rejects sizes larger than INT_MAX before falling back to vmalloc, so nvos_create_alloc() can fail even though the page table is CPU-side metadata and does not require physical contiguity. Use vzalloc() directly when pt_size exceeds INT_MAX, while preserving the existing kvzalloc() path for smaller allocations. The existing kvfree() release path remains valid for both kvzalloc() and vzalloc() allocations. Signed-off-by: Guzebing <guzebing1612@gmail.com>
1 parent 2ccbad2 commit cb2a351

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

  • kernel-open/nvidia

kernel-open/nvidia/nv.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,15 @@ nv_alloc_t *nvos_create_alloc(
411411
return NULL;
412412
}
413413

414-
at->page_table = kvzalloc(pt_size, NV_GFP_KERNEL);
414+
/*
415+
* kvmalloc()/kvzalloc() reject sizes larger than INT_MAX before
416+
* falling back to vmalloc. Large registered system-memory ranges can
417+
* require a page table larger than that, so use vzalloc() directly.
418+
*/
419+
if (pt_size > (NvU64)INT_MAX)
420+
at->page_table = vzalloc(pt_size);
421+
else
422+
at->page_table = kvzalloc(pt_size, NV_GFP_KERNEL);
415423
if (at->page_table == NULL)
416424
{
417425
nv_printf(NV_DBG_ERRORS, "NVRM: failed to allocate page table\n");

0 commit comments

Comments
 (0)