From nobody Mon Apr 6 18:23:58 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 3A4412848A8 for ; Sat, 4 Apr 2026 08:37:16 +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=1775291836; cv=none; b=njNYKouWZYy2QxLkjmUr48c3SpzlEFkR8wpTnJNmloaLBfWO6LNSZerr9jKV7H9DnEYZJdI5UO7A7AQ0zasBUeBGf+erszR0zVdoNSd3YpajygpRSz3B4zVhZLNFHI/YmNHwO21YuLB8wJw3AByaNyiWszVqP8IhszTJ+2JqUH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775291836; c=relaxed/simple; bh=WVbjKtJOze0is7NfE71xoEUfsefgsKodZwF/gpCaG4I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V2TS5h3gyuGtG1zIZA35D/cheXERMo1n3mGd3Glr7FaxOi+6JQhSUKhkmK0JV5d8D3dSsOZhpIlE5h4YsnGIV4B1m8F8RJOZMF/0tP5FhmBGBplkLKo5ibvCFuuzD2iAsPUBvtpUEukBLeEvfwQiIQ+KMEv3jegyZZ1ksxOqtHk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QFH7J/Y9; 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="QFH7J/Y9" Received: by smtp.kernel.org (Postfix) with ESMTPS id E6CF7C19424; Sat, 4 Apr 2026 08:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775291836; bh=WVbjKtJOze0is7NfE71xoEUfsefgsKodZwF/gpCaG4I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=QFH7J/Y9tX4y0YRt8oW1fPQf7QU4bR1hYlGC7zz1EygJ0EIx51/Usrdo3lpT9yJ6a AD5u7ZjiHXYInYoTAvf6tGN09p3y5DS7S75M/lhq8KXt4Puk5voWCNUmy1E3Hx2ktf KWU1gIiP8jxmQiBIiQJzM96QcdulWZG3rFjkp3xOMB3Qj0U2pvFZxts7OtxGw1fBiT JEegmVp9C58l7P6unIAs7GG1ipQYV0DfVw3D3ZuArhb6B6rVPdrMPoJQmClbRbPlEg 7Pwk36HiJdN13FDprIwJJUFtqSx442TYK9b8uj2m9roI4I84BfoIFBssUbEe7X2O7z uKG/sraYij9fQ== 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 DE214E88D8B; Sat, 4 Apr 2026 08:37:15 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Sat, 04 Apr 2026 14:06:58 +0530 Subject: [PATCH v10 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: <20260404-vmalloc-shrink-v10-2-335759165dfa@zohomail.in> References: <20260404-vmalloc-shrink-v10-0-335759165dfa@zohomail.in> In-Reply-To: <20260404-vmalloc-shrink-v10-0-335759165dfa@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=1775291829; l=1719; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=xFhoJw4VuJmdvCHLk875WygxZhGJrQEEk01VRX1BGPc=; b=M/8QbhgSmBFZzu1NbR1WSvEBdyJKUP+HMOfMdENN8sNw+NcvDEXBOA29TwzBIdI/JzBpUJkLP W8ObSAyZTgDCf25iW+/f6ivvhvfSUcsgBLmLF4px+HO7wEBUtYiNQ4l 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 8dd7df79c5c5..d0ebe16b584a 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