From nobody Wed Apr 1 22:34:46 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 193F347CC80 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=Mx5tF67fFJLrH8qRhlxIVhzkMPNWPzax01+OWfkUJAObx0LDLU++qWmJEEFfgez2bvNsRKLM37MblZ5hlu6tCjsT7T+TWTPEJBme9WH5GIgujxVyy+BhS1l/Bo6Hn/igxqcPSc1fbJztZ096+eqTy8TX1acug4ehx9BZIIW64OY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775063810; c=relaxed/simple; bh=GrrsWD02UPmYCvEAvfamqo/z+5NYjFR4VRPRWEY5O04=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lxGPbnLs+LwWPXzfwkBSNUTiRlJ1G1YVe4r6Won468nzqda2zA0AficS04QztpFND5UCtv6PxFGy3sdcpIdA1tk1/Mk77Wu4GSYiWdjA7vyJs8cFeUnXv7uDuDYVwn1C4bS+fK0iN4ipCAXsrgtzggUvVviedrxG9GLaPQWu5ws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E1aIlH2k; 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="E1aIlH2k" Received: by smtp.kernel.org (Postfix) with ESMTPS id CFE87C2BCB0; 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=1775063809; bh=GrrsWD02UPmYCvEAvfamqo/z+5NYjFR4VRPRWEY5O04=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=E1aIlH2kYe2i9+lJwfjPQSrN5fsrlDGqenwzf9L6nbwZFFvrepe17+wQgkus3TKKt P1imQbvVhuX/95M4hKQoqXmVbv1oqAXk6L89Q/MAkQ/ga79yVJyBKxosnYAPc44lyz dNcBjt9I+ZuuSYJ7cmSGdo25AL1KQTRG/KCyEd9tVopN1svAZb8iwNfxuUK8DbGb+U RXplXw9Yx9xdNnM3WKJKC2y+FH/qqRwLBEvWG7ALYkKdUIdi076sraDxJCH617v/55 Vu8MMx3P2Akqkcy0x7rY8i5v00zjE6LQx5FbVZQmE5ew5vM9XVowPwiFsi0NfGwdDa rnEHChoFnR/sw== 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 C071A1076389; Wed, 1 Apr 2026 17:16:49 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Wed, 01 Apr 2026 22:46:34 +0530 Subject: [PATCH v9 2/4] mm/vmalloc: use physical page count for vrealloc() grow-in-place check 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-2-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=1719; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=fkV50pSgKJcZXtbHtu5lgbydbnDdREie8wZ4ZapTlb4=; b=07524EnqAQ3AQ7TUxkiDJWQW8JwTQO/aXl40dY1cG4TPB+DhNnC4jyalYGNX251n728AQwiKI h4eXxb6A1k6DP/F2SFwNfxWSFWtWLf8wwg0f88CirLI4EX8Tx3rR3M6 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 Update the grow-in-place check in vrealloc() to compare the requested size against the actual physical page count (vm->nr_pages) rather than the virtual area size (alloced_size, derived from get_vm_area_size()). Currently both values are equivalent, but the upcoming vrealloc() shrink functionality will free pages without reducing the virtual reservation size. After such a shrink, the old alloced_size-based comparison would incorrectly allow a grow-in-place operation to succeed and attempt to access freed pages. Switch to vm->nr_pages now so the check remains correct once shrink support is added. Signed-off-by: Shivam Kalra --- mm/vmalloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index fe8700270139..1c6d747220ce 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4351,6 +4351,12 @@ void *vrealloc_node_align_noprof(const void *p, size= _t size, unsigned long align if (unlikely(flags & __GFP_THISNODE) && nid !=3D NUMA_NO_NODE && nid !=3D page_to_nid(vmalloc_to_page(p))) goto need_realloc; + } else { + /* + * If p is NULL, vrealloc behaves exactly like vmalloc. + * Skip the shrink and in-place grow paths. + */ + goto need_realloc; } =20 /* @@ -4369,7 +4375,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