From 8c70afee5a66782e43db17436fd8bc7011cd4fc3 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 29 May 2025 06:56:01 +0000 Subject: [PATCH] Revert "mm: vmalloc: support more granular vrealloc() sizing" This reverts commit 2910019b04ebb200b03761f0d1eefe9c3599f5d5 which is commit a0309faf1cb0622cac7c820150b7abf2024acff5 upstream. It breaks the Android kernel abi and can be brought back in the future in an abi-safe way if it is really needed. Bug: 161946584 Change-Id: I6e4ea0fd56032a331849525d3342d9679e3a384d Signed-off-by: Greg Kroah-Hartman --- include/linux/vmalloc.h | 1 - mm/vmalloc.c | 35 +++++++++-------------------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 2a4d9a0cacda..9a2710df972c 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -62,7 +62,6 @@ struct vm_struct { unsigned int nr_pages; phys_addr_t phys_addr; const void *caller; - unsigned long requested_size; ANDROID_OEM_DATA(1); }; diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ab171a2ee6ef..4a2bef7681bb 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1944,7 +1944,7 @@ static inline void setup_vmalloc_vm(struct vm_struct *vm, { vm->flags = flags; vm->addr = (void *)va->va_start; - vm->size = vm->requested_size = va_size(va); + vm->size = va_size(va); vm->caller = caller; va->vm = vm; trace_android_vh_save_vmalloc_stack(flags, vm); @@ -3133,7 +3133,6 @@ struct vm_struct *__get_vm_area_node(unsigned long size, area->flags = flags; area->caller = caller; - area->requested_size = requested_size; va = alloc_vmap_area(size, align, start, end, node, gfp_mask, 0, area); if (IS_ERR(va)) { @@ -4084,8 +4083,6 @@ EXPORT_SYMBOL(vzalloc_node_noprof); */ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags) { - struct vm_struct *vm = NULL; - size_t alloced_size = 0; size_t old_size = 0; void *n; @@ -4095,17 +4092,15 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags) } if (p) { + struct vm_struct *vm; + vm = find_vm_area(p); if (unlikely(!vm)) { WARN(1, "Trying to vrealloc() nonexistent vm area (%p)\n", p); return NULL; } - alloced_size = get_vm_area_size(vm); - old_size = vm->requested_size; - if (WARN(alloced_size < old_size, - "vrealloc() has mismatched area vs requested sizes (%p)\n", p)) - return NULL; + old_size = get_vm_area_size(vm); } /* @@ -4113,24 +4108,12 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags) * would be a good heuristic for when to shrink the vm_area? */ if (size <= old_size) { - /* Zero out "freed" memory. */ - if (want_init_on_free()) - memset((void *)p + size, 0, old_size - size); - vm->requested_size = size; - kasan_poison_vmalloc(p + size, old_size - size); - return (void *)p; - } - - /* - * We already have the bytes available in the allocation; use them. - */ - if (size <= alloced_size) { - kasan_unpoison_vmalloc(p + old_size, size - old_size, - KASAN_VMALLOC_PROT_NORMAL); - /* Zero out "alloced" memory. */ + /* Zero out spare memory. */ if (want_init_on_alloc(flags)) - memset((void *)p + old_size, 0, size - old_size); - vm->requested_size = size; + memset((void *)p + size, 0, old_size - size); + kasan_poison_vmalloc(p + size, old_size - size); + kasan_unpoison_vmalloc(p, size, KASAN_VMALLOC_PROT_NORMAL); + return (void *)p; } /* TODO: Grow the vm_area, i.e. allocate and map additional pages. */