Skip to content

Commit 3bd4e0a

Browse files
rpptakpm00
authored andcommitted
execmem: add fallback for failures in vmalloc(VM_ALLOW_HUGE_VMAP)
When execmem populates ROX cache it uses vmalloc(VM_ALLOW_HUGE_VMAP). Although vmalloc falls back to allocating base pages if high order allocation fails, it may happen that it still cannot allocate enough memory. Right now ROX cache is only used by modules and in majority of cases the allocations happen at boot time when there's plenty of free memory, but upcoming enabling ROX cache for ftrace and kprobes would mean that execmem allocations can happen when the system is under memory pressure and a failure to allocate large page worth of memory becomes more likely. Fallback to regular vmalloc() if vmalloc(VM_ALLOW_HUGE_VMAP) fails. Link: https://lkml.kernel.org/r/20250713071730.4117334-6-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Daniel Gomez <da.gomez@samsung.com> Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org> Cc: Petr Pavlu <petr.pavlu@suse.com> Cc: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 888b5a8 commit 3bd4e0a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

mm/execmem.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ static int execmem_cache_populate(struct execmem_range *range, size_t size)
291291

292292
alloc_size = round_up(size, PMD_SIZE);
293293
p = execmem_vmalloc(range, alloc_size, PAGE_KERNEL, vm_flags);
294+
if (!p) {
295+
alloc_size = size;
296+
p = execmem_vmalloc(range, alloc_size, PAGE_KERNEL, vm_flags);
297+
}
298+
294299
if (!p)
295300
return err;
296301

@@ -462,7 +467,7 @@ void *execmem_alloc(enum execmem_type type, size_t size)
462467
bool use_cache = range->flags & EXECMEM_ROX_CACHE;
463468
vm_flags_t vm_flags = VM_FLUSH_RESET_PERMS;
464469
pgprot_t pgprot = range->pgprot;
465-
void *p;
470+
void *p = NULL;
466471

467472
size = PAGE_ALIGN(size);
468473

0 commit comments

Comments
 (0)