From nobody Wed Apr 1 22:13:36 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 2977D47CC87 for ; Wed, 1 Apr 2026 17:16:50 +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=1775063810; cv=none; b=nxLZ4hlrlhbnYhq4U+NJ5ZlZTV6/V6BwNNCWO9Nf8Ci1z8pu07u9/5qvRoGuPFY3bSGFUX6piXwc+4PwJBr10eHDrXbRjeOgL6s3eopnY9uu1EpGOZ3nxWLR5QzehgBa9k81T9jLIZMTlo+rLE/tw5/lNhdL+i4c9nre5wCC6jE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775063810; c=relaxed/simple; bh=NgcWajqEHrBjrpmlHzE3kqeLHOp/AqP67j8VknlwGaM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ksOvjMF5prq/8cYlz2rzGLCmirSzln0aHbn5fyCeqeKgI6C6t1EYSQURRq15Ej08FPS49kv4sxtf8c8luEeZPbUm/gRsCkvZGNW3k1r/3ufGxWOuFsHzUKXkEJ0PGfuNpqsL/dA9rV7MwH6p99QZrnOC2+3ipGhbjH+XZuxUnco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Iya8vXGd; 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="Iya8vXGd" Received: by smtp.kernel.org (Postfix) with ESMTPS id ED531C2BCAF; Wed, 1 Apr 2026 17:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775063810; bh=NgcWajqEHrBjrpmlHzE3kqeLHOp/AqP67j8VknlwGaM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Iya8vXGd+fmwXV88td2Z0XWbPF2NdANMRqUGbEVJIjsCR4oH0KSGqKZsrcigIIxNc ZgnJTwsuQM/lF4seFd8RvToVpXMAcMRrGC63kUuCd2RNNSezWEzU/V2rOcIdgYHFZj F/mfQHJ0ZhwXmYKiNI8tE+ZCfYfPm+3NBipYEu7IP5ezYVhfie8UBTHjM1ZC16sf6V tQ5vO1BozWfkeJRB2OM4fkDOiTtnOPCZ4/4xZ2Igr9EuWikAtqbnR342i/g5poJ9o7 wGWu6ztUuoA4zWgE2oXm2UgBopfxM9AkRjaPFQkmA5RAI5f0bivl8ZSR9oMFv/2hV8 9JOi8m2jU2KRw== 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 DF81C1076381; Wed, 1 Apr 2026 17:16:49 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Wed, 01 Apr 2026 22:46:36 +0530 Subject: [PATCH v9 4/4] 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: <20260401-vmalloc-shrink-v9-4-bf58dfb997d8@zohomail.in> References: <20260401-vmalloc-shrink-v9-0-bf58dfb997d8@zohomail.in> In-Reply-To: <20260401-vmalloc-shrink-v9-0-bf58dfb997d8@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=1775063806; l=2905; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=yP1QXayDidKnNU2S8I7BqJprRzQI2mQyl0fytHsaqPM=; b=K+rvqijkH6LgioddShavqfdDzGqGhFPpOudpCsY2f5P28WR6Xscdt+/cPBZMV4+aWr6Zijp2d Y3sYegmUeZYBuDOhdMAZGuZmXpwWjr78v8g053MOKdoIlCWSUOYYW2B 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). Reviewed-by: Uladzislau Rezki (Sony) Signed-off-by: Shivam Kalra --- lib/test_vmalloc.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 62 insertions(+) diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c index 876c72c18a0c..b23f85e8f8ca 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,66 @@ vm_map_ram_test(void) return nr_allocated !=3D map_nr_pages; } =20 +static int vrealloc_test(void) +{ + void *ptr, *tmp; + int i; + + for (i =3D 0; i < test_loop_count; i++) { + int err =3D -1; + + ptr =3D vrealloc(NULL, PAGE_SIZE, GFP_KERNEL); + if (!ptr) + return -1; + + *((__u8 *)ptr) =3D 'a'; + + /* Grow: beyond allocated pages, triggers full realloc. */ + tmp =3D vrealloc(ptr, 4 * PAGE_SIZE, GFP_KERNEL); + if (!tmp) + goto error; + ptr =3D tmp; + + if (*((__u8 *)ptr) !=3D 'a') + goto error; + + /* Shrink: crosses page boundary, frees tail pages. */ + tmp =3D vrealloc(ptr, PAGE_SIZE, GFP_KERNEL); + if (!tmp) + goto error; + ptr =3D tmp; + + if (*((__u8 *)ptr) !=3D 'a') + goto error; + + /* Shrink: within same page, no page freeing. */ + tmp =3D vrealloc(ptr, PAGE_SIZE / 2, GFP_KERNEL); + if (!tmp) + goto error; + ptr =3D tmp; + + if (*((__u8 *)ptr) !=3D 'a') + goto error; + + /* Grow: within allocated page, in-place, no realloc. */ + tmp =3D vrealloc(ptr, PAGE_SIZE, GFP_KERNEL); + if (!tmp) + goto error; + ptr =3D tmp; + + if (*((__u8 *)ptr) !=3D 'a') + goto error; + + err =3D 0; +error: + vfree(ptr); + if (err) + return err; + } + + return 0; +} + struct test_case_desc { const char *test_name; int (*test_func)(void); @@ -440,6 +501,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