From nobody Thu Apr 2 18:53:48 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 7824A3D9059 for ; Fri, 27 Mar 2026 09:48:40 +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=1774604920; cv=none; b=q1eqPNC6gs35QcJORC1nnFWRPc7k1JxEK6DxNbKFQSA45SIsHPwL4TcU8Ox6aOsD1kv/2QpyQWa9raSeCCO5t4YjksRQavBfPy3ZOdN9UHTpuRhvBgvh8qH2ou3kicfMw1NPrhrzjqi5OslVuS7gQIlQdgIUK8VwQy0n7jzQ6c8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774604920; c=relaxed/simple; bh=uC3ozkw98B2T0ybqh69BkU+YKKQ53sm/70mGSobtbU4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QanruJ2MwgVMLsFFL8QqyOJyBO5BEjJRrS7f4ZFhTfJY/cMlJpMiwWSBsWI3TPo3mVDsUzXdV8ZJgu7bTRPRmzo7gyQ3AFeC+kgldI6CD7/k/Ncw1p/TUGzhm1sM0ODqzv0AX3gnNJgjGbNfzsm9TNq5o/MHx1WCHT1nZxMnrNY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XIvuzlww; 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="XIvuzlww" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3AE39C2BCB0; Fri, 27 Mar 2026 09:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774604920; bh=uC3ozkw98B2T0ybqh69BkU+YKKQ53sm/70mGSobtbU4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=XIvuzlww9+w0d3N+thAzXfc9znDZ7WUg7i5xCLoyWEtLfOfydFHUiKoCbuqIGScuU cjxd7jNV+G6KVXi/T9h7XCGn9Cy4WaUT+hdsXQbHIGOIPbZCZZlnu2pzbickCKUQAJ 0+2zCHStXV8hRljkfStdYvK30SLHZXwhiU78qpjocEo5h2PuEawgoPah6iO5NKCEHX /A1YCb0U3SaVBb7EXT5asMWczhzBE7fA4s+muzosnAxa9fXJsCD9pE4TIL6hSVnUFo e0vgySZfaS/bhqN/otzR3YIpRlsnQxGQz2ZMd5x4nrz+qu9OfRBZib0GRWGXRztSvz ElshThRBCn+9w== 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 3068710ED646; Fri, 27 Mar 2026 09:48:40 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Fri, 27 Mar 2026 15:18:38 +0530 Subject: [PATCH v8 2/6] mm/vmalloc: fix 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: <20260327-vmalloc-shrink-v8-2-cc6b57059ed7@zohomail.in> References: <20260327-vmalloc-shrink-v8-0-cc6b57059ed7@zohomail.in> In-Reply-To: <20260327-vmalloc-shrink-v8-0-cc6b57059ed7@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=1774604917; l=1675; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=JBxDN0g82pC84smB7v9qq2A4Kq3XUFnm46m5uC3JQmo=; b=HSIEpP+gWS/CI0lJnxlmSaw0gfljH77Mtt5owCSfUm1SMlxuTzAAVF4GvU7JLLlRDvUW0TnLR 4/ZSGhlJUfKDNiY1tyUWDUeY34dA/y/qK0fs599OWmzNHGaO5xsmhJS 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 Fix 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()). The virtual reservation size (get_vm_area_size()) does not decrease when pages are freed during a shrink operation. Consequently, without this fix, a subsequent grow-in-place operation after a shrink would incorrectly succeed and attempt to access freed pages. Correcting this check is a prerequisite for the upcoming vrealloc() shrink functionality. 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 79a57955345d..133c3b0418fe 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4343,6 +4343,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 /* @@ -4361,7 +4367,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