From cb2a3510e9aa489d90dab99d13124a801e1486e9 Mon Sep 17 00:00:00 2001 From: Guzebing Date: Thu, 9 Jul 2026 01:25:51 +0900 Subject: [PATCH] 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 --- kernel-open/nvidia/nv.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel-open/nvidia/nv.c b/kernel-open/nvidia/nv.c index 9ad14f1d91..53a056016e 100644 --- a/kernel-open/nvidia/nv.c +++ b/kernel-open/nvidia/nv.c @@ -411,7 +411,15 @@ nv_alloc_t *nvos_create_alloc( return NULL; } - at->page_table = kvzalloc(pt_size, NV_GFP_KERNEL); + /* + * kvmalloc()/kvzalloc() reject sizes larger than INT_MAX before + * falling back to vmalloc. Large registered system-memory ranges can + * require a page table larger than that, so use vzalloc() directly. + */ + if (pt_size > (NvU64)INT_MAX) + at->page_table = vzalloc(pt_size); + else + at->page_table = kvzalloc(pt_size, NV_GFP_KERNEL); if (at->page_table == NULL) { nv_printf(NV_DBG_ERRORS, "NVRM: failed to allocate page table\n");