From nobody Tue Apr 7 09:18:43 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF41E282F03 for ; Sat, 14 Mar 2026 09:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773479166; cv=none; b=CU1Tf1iV20aGPeFwpHX5m/k7ys7e5yoZTalRWUecrjH3WYwLTISBxtrMJ2OM25KWZJiGBX7kM9dSuff6HahrKexus+JnagSWx//60ICDNztXdwvHyrQtlmdk8ZUBzT0OusZ4MLdqJz1THbI4dQge4mFmkJm1mJ+qbs3Ra/z/Q94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773479166; c=relaxed/simple; bh=k7MxutspFB0C8aBYZ+Cn6E/z5wK6f9LqrZ6dx5IdwE4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QsuCEZnzBlhoeKIfuxCzTmb2N0fYpFb9K9tSu2OHnuw2rQ3/ZSbn9f0xpqK5td6Sa1auscEKj12dU05UZ42xyfOlU4oqPjtyTVPY1rPnG/Pmz13SrF6sMidBetapXcbDEYdkKkstO/ujHO+PuTjaSwLng051HNCim/avtvgDtWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k0vYIYNN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k0vYIYNN" Received: by smtp.kernel.org (Postfix) with ESMTPS id A7966C19423; Sat, 14 Mar 2026 09:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773479166; bh=k7MxutspFB0C8aBYZ+Cn6E/z5wK6f9LqrZ6dx5IdwE4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=k0vYIYNNUZszXtEF3c7cYvaTfOPFdhfJnGhWlah7FR6LcTBSE3Copuw1Ghl5mNgiT BHLje0y3QWpPBe8L/hxpHHQnx2v7QokXelxssmVQs7+INzIdYkDe01L/+XpWHV6nZ8 GQXjQqDN1W+rek69CgY3TdkUyFCND5eDGdrqHQSYuyGgypuG3LxnkVbI5tLTYC6JU9 CLFJ+q0wi6gjlMJh/XO+21hNv0Mk/Lk4vmb5DzFqcIyR78CFIm3XDe+yO3ztXCPAqR jIManz8ibGa2fCMBZyVgExYgmsJKaXviz2ZReZJHHJD0glahLI44bsfGAAlI8v20kL nH2vdPBpgx7Qw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96A8B106ACF9; Sat, 14 Mar 2026 09:06:06 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Sat, 14 Mar 2026 14:34:13 +0530 Subject: [PATCH v4 1/3] mm/vmalloc: extract vm_area_free_pages() helper from vfree() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260314-vmalloc-shrink-v4-1-c1e2e0bb5455@zohomail.in> References: <20260314-vmalloc-shrink-v4-0-c1e2e0bb5455@zohomail.in> In-Reply-To: <20260314-vmalloc-shrink-v4-0-c1e2e0bb5455@zohomail.in> To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alice Ryhl , Danilo Krummrich , Shivam Kalra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773479164; l=2682; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=Y7LaORkgehK4lKdbYmYreDeAD1S2R1PpyepoUGhj4EQ=; b=xQ9l8MuWzhTsdTNLyNVGABBwcIWNRVDpsUQH14mvklMOUh9yd46JjQO6KBF9FtlZ6okPsu0kW czUwPJswlxfB04TFAQkB2OrJh05VSSHcWuhq0GVTrJEWsO/lg77OPZ8 X-Developer-Key: i=shivamkalra98@zohomail.in; a=ed25519; pk=9Q+S1LD/xjbjL7bEaLIlwRADBwU/6LJq7lYm8LFrkQE= X-Endpoint-Received: by B4 Relay for shivamkalra98@zohomail.in/20260212 with auth_id=633 X-Original-From: Shivam Kalra Reply-To: shivamkalra98@zohomail.in From: Shivam Kalra Extract the page-freeing loop and NR_VMALLOC stat accounting from vfree() into a reusable vm_area_free_pages() helper. The helper operates on a range [start, end) of pages from a vm_struct, making it suitable for both full free (vfree) and partial free (upcoming vrealloc shrink). Freed page pointers in vm->pages[] are set to NULL to prevent stale references when the vm_struct outlives the free (as in vrealloc shrink). Signed-off-by: Shivam Kalra --- mm/vmalloc.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index c607307c657a..b29bf58c0e3f 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3416,6 +3416,38 @@ void vfree_atomic(const void *addr) schedule_work(&p->wq); } =20 +/* + * vm_area_free_pages - free a range of pages from a vmalloc allocation + * @vm: the vm_struct containing the pages + * @start: first page index to free (inclusive) + * @end: last page index to free (exclusive) + * + * Free pages [start, end) updating NR_VMALLOC stat accounting. + * Freed vm->pages[] entries are set to NULL. + * Caller is responsible for unmapping (vunmap_range) and KASAN + * poisoning before calling this. + */ +static void vm_area_free_pages(struct vm_struct *vm, unsigned int start, + unsigned int end) +{ + unsigned int i; + + for (i =3D start; i < end; i++) { + struct page *page =3D vm->pages[i]; + + BUG_ON(!page); + /* + * High-order allocs for huge vmallocs are split, so + * can be freed as an array of order-0 allocations + */ + if (!(vm->flags & VM_MAP_PUT_PAGES)) + mod_lruvec_page_state(page, NR_VMALLOC, -1); + __free_page(page); + vm->pages[i] =3D NULL; + cond_resched(); + } +} + /** * vfree - Release memory allocated by vmalloc() * @addr: Memory base address @@ -3436,7 +3468,6 @@ void vfree_atomic(const void *addr) void vfree(const void *addr) { struct vm_struct *vm; - int i; =20 if (unlikely(in_interrupt())) { vfree_atomic(addr); @@ -3459,19 +3490,7 @@ void vfree(const void *addr) =20 if (unlikely(vm->flags & VM_FLUSH_RESET_PERMS)) vm_reset_perms(vm); - for (i =3D 0; i < vm->nr_pages; i++) { - struct page *page =3D vm->pages[i]; - - BUG_ON(!page); - /* - * High-order allocs for huge vmallocs are split, so - * can be freed as an array of order-0 allocations - */ - if (!(vm->flags & VM_MAP_PUT_PAGES)) - mod_lruvec_page_state(page, NR_VMALLOC, -1); - __free_page(page); - cond_resched(); - } + vm_area_free_pages(vm, 0, vm->nr_pages); kvfree(vm->pages); kfree(vm); } --=20 2.43.0 From nobody Tue Apr 7 09:18:43 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF4EC295DA6 for ; Sat, 14 Mar 2026 09:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773479166; cv=none; b=ZlKfSR93Q+B1EUOJlU+MAdFc65DaKQY6WxuMno/QQFxJh76qTL/LMleC3JnsrztywlzwJiLXL3D+fDoP+sJOxo8mfN71+30wifdxD8hNeQulKrBqysay90Hpyf5kGeyA19Enzp4La5Esz15WxSUuPmqFbZcV8xpJ+xEdDjarB0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773479166; c=relaxed/simple; bh=4qZxeLqHO5fNZfDMKipa9T/OALGStFY6kMWH7o39vXA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q4dfpZGrayymGG9tqeh+tAtG4WEPs1q/hD2MZSFdGwI3YEJJSAejOPt9rKrt59qiRicMX99Dv9pvH+TZYsaph8J8B//iQq7dqJShGZQ4EQNxfwO0WHC6l8DdqkBr2AF/2FOda2mpP83HIozvdeoh8IMN5sZIdg9twgVM5W/KWlY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WTHy3DZJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WTHy3DZJ" Received: by smtp.kernel.org (Postfix) with ESMTPS id B32B8C19425; Sat, 14 Mar 2026 09:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773479166; bh=4qZxeLqHO5fNZfDMKipa9T/OALGStFY6kMWH7o39vXA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=WTHy3DZJ9mYjgPX5Oc1a+hIaBkpS3tYhLgnpt6A56nAagHEB5bK6W2lXigMcjFlFr r/Id6iEUGjW+SlAET/U6y+XgIFhxH2SAwKUxn02q86/wuI1DBbER1OrvxHzBxmMikm 4X9RgCcXssY5u+glZPb6ifyhWN+WGru10A82Nv43hsIht0+ZkOVs4eUm6kuvnMwGkJ ZXXVvSqDMnfZttMsjtTqOAmbJ3UWIrksQj4KPbUYZ9nvcEm6JgpvduUHDBCRyR9UYs XBh5Mw6OopPq65qcLAfiLfSlJsMGNeLY0QnAPMbH59sN7OWllmsgKPK78uQhxkHwdR 4SUPnk8rWtWXQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7DA0105F7B0; Sat, 14 Mar 2026 09:06:06 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Sat, 14 Mar 2026 14:34:14 +0530 Subject: [PATCH v4 2/3] mm/vmalloc: free unused pages on vrealloc() shrink Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260314-vmalloc-shrink-v4-2-c1e2e0bb5455@zohomail.in> References: <20260314-vmalloc-shrink-v4-0-c1e2e0bb5455@zohomail.in> In-Reply-To: <20260314-vmalloc-shrink-v4-0-c1e2e0bb5455@zohomail.in> To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alice Ryhl , Danilo Krummrich , Shivam Kalra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773479164; l=2543; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=qiLrg/KiMgMQgQ06tgY/qjWWfVqF7Moa3eb5azEQPMU=; b=JSgIl8t091y/VKSsQI5DHU6yX/zoZKbxLX6f33+kCAYEstK2d+ExBt3JJ42ubUxhPL/afLIXy 9RqAAyIaL4iDI2wyTUIBa/shktn0Zf1G93hgQP/weRS+R2Zs2taVyZQ X-Developer-Key: i=shivamkalra98@zohomail.in; a=ed25519; pk=9Q+S1LD/xjbjL7bEaLIlwRADBwU/6LJq7lYm8LFrkQE= X-Endpoint-Received: by B4 Relay for shivamkalra98@zohomail.in/20260212 with auth_id=633 X-Original-From: Shivam Kalra Reply-To: shivamkalra98@zohomail.in From: Shivam Kalra When vrealloc() shrinks an allocation and the new size crosses a page boundary, unmap and free the tail pages that are no longer needed. This reclaims physical memory that was previously wasted for the lifetime of the allocation. The heuristic is simple: always free when at least one full page becomes unused. Huge page allocations (page_order > 0) are skipped, as partial freeing would require splitting. The virtual address reservation (vm->size / vmap_area) is intentionally kept unchanged, preserving the address for potential future grow-in-place support. Fix the grow-in-place check to compare against vm->nr_pages rather than get_vm_area_size(), since the latter reflects the virtual reservation which does not shrink. Without this fix, a grow after shrink would access freed pages. Signed-off-by: Shivam Kalra --- mm/vmalloc.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index b29bf58c0e3f..2c455f2038f6 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4345,14 +4345,23 @@ void *vrealloc_node_align_noprof(const void *p, siz= e_t size, unsigned long align goto need_realloc; } =20 - /* - * TODO: Shrink the vm_area, i.e. unmap and free unused pages. What - * would be a good heuristic for when to shrink the vm_area? - */ if (size <=3D old_size) { + unsigned int new_nr_pages =3D PAGE_ALIGN(size) >> PAGE_SHIFT; + /* Zero out "freed" memory, potentially for future realloc. */ if (want_init_on_free() || want_init_on_alloc(flags)) memset((void *)p + size, 0, old_size - size); + + /* Free tail pages when shrink crosses a page boundary. */ + if (new_nr_pages < vm->nr_pages && !vm_area_page_order(vm)) { + unsigned long addr =3D (unsigned long)p; + + vunmap_range(addr + (new_nr_pages << PAGE_SHIFT), + addr + (vm->nr_pages << PAGE_SHIFT)); + + vm_area_free_pages(vm, new_nr_pages, vm->nr_pages); + vm->nr_pages =3D new_nr_pages; + } vm->requested_size =3D size; kasan_vrealloc(p, old_size, size); return (void *)p; @@ -4361,7 +4370,7 @@ void *vrealloc_node_align_noprof(const void *p, size_= t size, unsigned long align /* * We already have the bytes available in the allocation; use them. */ - if (size <=3D alloced_size) { + if (size <=3D (size_t)vm->nr_pages << PAGE_SHIFT) { /* * No need to zero memory here, as unused memory will have * already been zeroed at initial allocation time or during --=20 2.43.0 From nobody Tue Apr 7 09:18:43 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1ED98262FC1 for ; Sat, 14 Mar 2026 09:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773479167; cv=none; b=WBKAFfJAcOobRbp5lmwjwYC1g/OnDzio5mEnEqRpcNoCxMOp7I/5Ye2XYWUGox/lWICQB8RXMrQc+SVBgmVGe5mA/paPRj8pc3i1I3LDJ7A7XyaKFIIHPhyhIwUeSKwiHVCSWBVXxeh7+Qow45Aufrfn2AI93+rS8CA4hKThZxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773479167; c=relaxed/simple; bh=CVIAq93ZteUDhJ/xiIE3C2yFgjiz/OpnbCzoIeyuy5w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o8Y/NpL8MUjtDYc4GdrShK76+SFRDPnxIKsIBCmT56T9HMpyom10OyWE+IrhLPDNsBEdZ9zWKFNFgW4QxMIOdwrr6pPyXyncRt+/3BRUll/iUrj94kpPyn/9fFTDHOXQuteYl0fIl+kBUGZ86mFvdBaRo6H0nGQ0U8d07vphDN4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RQIDyx11; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RQIDyx11" Received: by smtp.kernel.org (Postfix) with ESMTPS id C56C5C2BCAF; Sat, 14 Mar 2026 09:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773479166; bh=CVIAq93ZteUDhJ/xiIE3C2yFgjiz/OpnbCzoIeyuy5w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=RQIDyx11EORmFL29Pp26LQfRhdHc09p871yCeCOnF3/cCzMNDAySIdb0SZls98JkK yShmkGzHZs13Lflmy9KBuXKHaGNZpcm0WolABMBQ4pTEgCh3ZuCAwX6Kmnni4qmo4Q zekeW2ugrBHvPygft/KbBXDVGT/Hb3HUvJW8DqrxC+aC5N6bJj6XdEgHrRyjoyUe4O 57ZEu4+fLmZc5m7uLEv0UczXhvzshBQRaPwTQQLoHF7xQgX1lMsL99oBzJI6SzTFfI 7acFO6IRxZHCl31IYepNlz3AoCwfyHAU7n+toXGMAGpXnIfh+TsGyXw+0fpSRUrjMY pSq5QRZiXkeyA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8826106FD81; Sat, 14 Mar 2026 09:06:06 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Sat, 14 Mar 2026 14:34:15 +0530 Subject: [PATCH v4 3/3] lib/test_vmalloc: add vrealloc test case Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260314-vmalloc-shrink-v4-3-c1e2e0bb5455@zohomail.in> References: <20260314-vmalloc-shrink-v4-0-c1e2e0bb5455@zohomail.in> In-Reply-To: <20260314-vmalloc-shrink-v4-0-c1e2e0bb5455@zohomail.in> To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alice Ryhl , Danilo Krummrich , Shivam Kalra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773479164; l=2680; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=vGtWOd+QVlnd5fUIfOUP0oSJ0Gu3V+AGGjAsUp+yrM4=; b=ZlC06BPiN19E6EC05bRswEeu5zLVKJ2Ai6lAnm/0OA9b5z49oH4h0mOBUldtoDwZpqrM+2dVD wIb8zLxhCqvALIzYJirqqA4dSyII/Gw2jQfRf+pohOSMKj2/dKPaw0I X-Developer-Key: i=shivamkalra98@zohomail.in; a=ed25519; pk=9Q+S1LD/xjbjL7bEaLIlwRADBwU/6LJq7lYm8LFrkQE= X-Endpoint-Received: by B4 Relay for shivamkalra98@zohomail.in/20260212 with auth_id=633 X-Original-From: Shivam Kalra Reply-To: shivamkalra98@zohomail.in From: Shivam Kalra Introduce a new test case "vrealloc_test" that exercises the vrealloc() shrink and in-place grow paths: - Grow beyond allocated pages (triggers full reallocation). - Shrink crossing a page boundary (frees tail pages). - Shrink within the same page (no page freeing). - Grow within the already allocated page count (in-place). Data integrity is validated after each realloc step by checking that the first byte of the original allocation is preserved. The test is gated behind run_test_mask bit 12 (id 4096). Signed-off-by: Shivam Kalra --- lib/test_vmalloc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++ 1 file changed, 52 insertions(+) diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c index 876c72c18a0c..ce2b2777a785 100644 --- a/lib/test_vmalloc.c +++ b/lib/test_vmalloc.c @@ -55,6 +55,7 @@ __param(int, run_test_mask, 7, "\t\tid: 512, name: kvfree_rcu_2_arg_vmalloc_test\n" "\t\tid: 1024, name: vm_map_ram_test\n" "\t\tid: 2048, name: no_block_alloc_test\n" + "\t\tid: 4096, name: vrealloc_test\n" /* Add a new test case description here. */ ); =20 @@ -421,6 +422,56 @@ vm_map_ram_test(void) return nr_allocated !=3D map_nr_pages; } =20 +static int vrealloc_test(void) +{ + void *ptr; + int i; + + for (i =3D 0; i < test_loop_count; i++) { + ptr =3D vmalloc(PAGE_SIZE); + if (!ptr) + return -1; + + *((__u8 *)ptr) =3D 'a'; + + /* Grow: beyond allocated pages, triggers full realloc. */ + ptr =3D vrealloc(ptr, 4 * PAGE_SIZE, GFP_KERNEL); + if (!ptr) + return -1; + + if (*((__u8 *)ptr) !=3D 'a') + return -1; + + /* Shrink: crosses page boundary, frees tail pages. */ + ptr =3D vrealloc(ptr, PAGE_SIZE, GFP_KERNEL); + if (!ptr) + return -1; + + if (*((__u8 *)ptr) !=3D 'a') + return -1; + + /* Shrink: within same page, no page freeing. */ + ptr =3D vrealloc(ptr, PAGE_SIZE / 2, GFP_KERNEL); + if (!ptr) + return -1; + + if (*((__u8 *)ptr) !=3D 'a') + return -1; + + /* Grow: within allocated page, in-place, no realloc. */ + ptr =3D vrealloc(ptr, PAGE_SIZE, GFP_KERNEL); + if (!ptr) + return -1; + + if (*((__u8 *)ptr) !=3D 'a') + return -1; + + vfree(ptr); + } + + return 0; +} + struct test_case_desc { const char *test_name; int (*test_func)(void); @@ -440,6 +491,7 @@ static struct test_case_desc test_case_array[] =3D { { "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test, }, { "vm_map_ram_test", vm_map_ram_test, }, { "no_block_alloc_test", no_block_alloc_test, true }, + { "vrealloc_test", vrealloc_test, }, /* Add a new test case here. */ }; =20 --=20 2.43.0