From nobody Fri Apr 3 16:14:03 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 3B3DF3E024E for ; Tue, 24 Mar 2026 10:00:33 +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=1774346433; cv=none; b=bH4Qv2CGYKwmbgAgzO80Eajte8roQWpyCbwfz54P8418XNZxTxlaPE3Z++hjB+GPVnqlSyP9jWE1ok6Uo2im3+fK6A6lpE7b1UeDjBwNLqrDLp6t4n16IA4HThg5EyuxwRLbL9vham+kIHtMIMWMMt3E3atUBeIq64GAoHUV+NA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774346433; c=relaxed/simple; bh=uC3ozkw98B2T0ybqh69BkU+YKKQ53sm/70mGSobtbU4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MdCC6WQunAef80SUGY8n79nOOCqNqtVsJPpqa7jA+0OGDqAh1UJcjr4Nyn5fujCD3p828VicKxhSKuvcL7jX3t9XkRPKHvpljrCfJgnd1hq2N76vE+Bn9XIx8G24dneqYzOLlcfvd1s69REH19Hr3lLuLlhrqgymIARmwLF+zKA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Tc4DToxI; 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="Tc4DToxI" Received: by smtp.kernel.org (Postfix) with ESMTPS id B5A42C2BCB4; Tue, 24 Mar 2026 10:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774346432; bh=uC3ozkw98B2T0ybqh69BkU+YKKQ53sm/70mGSobtbU4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Tc4DToxIV3GStb+nL3sBLMs9W86XVJT2Kcvl21vGHCt6oAWSFwHHqPTKBOMyv0dGA tbZ7Eaux4csRP4w/j6UOQrLLFK8APCL/Ykx4wDwcF2uem9f6KBcnfME0H1IH6hezLh FfnALjwuW9iXPsVlH5pkaZB62UTKlnqUp/3yEcIAe6hPt+7lzCWjBerkZK7U/vPquy 901D19Hc0gX9w54SvGtuqgwidzmmg4v3nUq3YedV4gLCmhmIB0hdpEvdy6vVpCdulf WIDWnIga/zrm3jsI8XwTENVvmJuAgjtdK13BsKF21t8LyTM4+4JM6plAvC1y9JYuJ8 9CvtBnoycEgtQ== 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 A7B81E9A756; Tue, 24 Mar 2026 10:00:32 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Tue, 24 Mar 2026 15:30:27 +0530 Subject: [PATCH v7 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: <20260324-vmalloc-shrink-v7-2-c0e62b8e5d83@zohomail.in> References: <20260324-vmalloc-shrink-v7-0-c0e62b8e5d83@zohomail.in> In-Reply-To: <20260324-vmalloc-shrink-v7-0-c0e62b8e5d83@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=1774346430; l=1675; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=JBxDN0g82pC84smB7v9qq2A4Kq3XUFnm46m5uC3JQmo=; b=ToQEc7W3F4dNaO9NS6e2EhJdVXvhUeyMcRZr8rpKG784fzxPhhFR4MxXuZliL3GRgONMCpgmM B7Z3kphVsrNDcB5h2un8LpXbgHAS6kTepiP/iKs2WIkhXvjwazEsxDl 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