From nobody Sat Apr 4 01:49:15 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 A402E2DF6EA for ; Sat, 21 Mar 2026 18:05:53 +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=1774116353; cv=none; b=js/3zZKaNrWzemCFLGUcr2FUOigWYjvexMyzMk7ZiPzOjotBTha6dxk2FLdfYOEE1wGXt1Voo0Ah9wTBT5Ma5JpnMHKNlUd0FHsin8c+1LGgHiCcYXMAnxEmLhWOusjWY5+klMGzosJBqeLZjy47Bg/F1CPn6/NSxZSj+ZQHDNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774116353; c=relaxed/simple; bh=VHLu6lZjuBOtEUS8VdUimMihtKDkPhY/OYWvCSJtAds=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o8yTArJsTye4UZNmnzu2ku1aDbamkimf71jL3lm0xreVAI4E363x5fUgcqGxJ7hAvUvyUZ+DSbj5hKOssR4mrO1xXGfgRya5cCh/q0qivef6v/3jOEWFx/JEHEkZQuSOVu4TSGupJTXgZgaqlvPg5gMNeECyJeDebAthEmFWnF0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M/vgM6tD; 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="M/vgM6tD" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6999AC2BCAF; Sat, 21 Mar 2026 18:05:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774116353; bh=VHLu6lZjuBOtEUS8VdUimMihtKDkPhY/OYWvCSJtAds=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=M/vgM6tDO/uLn0NZ+xX/qS3lo54sgsfsZ3UMyIfwozPXaOpUDusCBITwW8wJMZz6x A0SLA1FsoXSKlI4W+T7/q7GugqkKWbPE4/oRlMDf2KzCBn4YFfEzXe876XBpjumYGN Dc7HsQs3YAlMMbbNb9QMC+3ID3wx2neTOlYmCYvTvubYsnKhJFgAsduDTlfE9ousL9 tVefWu9ah6zX3v3HgiUbTdBA0w9ae0Ndgp8FODiH+g21ZGe2Lm83Qjk4CbHmdC+IFJ FeMnZ1D9ZcAsgOUoXnkpgrT7oxzFaSqflI8x9zxd1aGSrdr26EYAtqwtxvMHj2urGq ZHhSEfdzNho7w== 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 5B38F109448E; Sat, 21 Mar 2026 18:05:53 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Sat, 21 Mar 2026 23:35:47 +0530 Subject: [PATCH v6 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: <20260321-vmalloc-shrink-v6-2-062ca7b7ceb2@zohomail.in> References: <20260321-vmalloc-shrink-v6-0-062ca7b7ceb2@zohomail.in> In-Reply-To: <20260321-vmalloc-shrink-v6-0-062ca7b7ceb2@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=1774116351; l=1250; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=w90h6aByrvZe7M9pbnNSecs/NY6vWML8p6XHr/QXZq4=; b=KexBhgjzhjxhyLbuUOfWatjeAXgA9SkFNWaZp4aArRYDJYWYq1g/pF7XSztMPVb/Ga6zsw3X0 LKH+xk6OfJiAKNWXkgjApLUsIQtI71bg+osn31qBTzXt5AdUOUQtbVH 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 3977398e56e4..7bc7a6892c1a 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4361,7 +4361,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