From nobody Fri Dec 19 22:01:18 2025 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 CECA2189906 for ; Tue, 30 Jul 2024 18:50:57 +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=1722365457; cv=none; b=gbP3aUROlXZ9qgPn/j6eNUOlPOtmMd/ZJhVY0Bo6HE+x3yw8QqpyHXKWyj5w1XeO68Pp5SRUvBu9WAXu7V6/lx71/tqVj7pE/HKegm0rdLfwkCNMNWfZY4EiLV/2I6NkMXFUvMdEr02zORish+aRF5v13hApwwwM0MlAsGexqZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722365457; c=relaxed/simple; bh=B7lCvXux7f94TaAbBTbtx+OfILAdRrodvDeXA9EjfZA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hx9bUmHW9HxXpZG3FeU/ep3F6n2nJBDrJuVmri8sniq45d5k+lI395ybNfDhubHfpAtTsv/IwOTtuMxZwtpl5ON1+QELblBFZB/hYxTAqLdOrqCUyP9AXCKRYiziLMOpePKB37ZWMioxrVHGnoSmvzJb3AYwY7G/6kDSgbroO4s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MaVod01S; 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="MaVod01S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85885C4AF0B; Tue, 30 Jul 2024 18:50:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722365457; bh=B7lCvXux7f94TaAbBTbtx+OfILAdRrodvDeXA9EjfZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MaVod01SJZfxHuSLw4OhC4FdwSCUEEQ47Ao5XAdKEYBAi63urmfePKXZ23RqHviS5 mrhutwU2sUgZIg2tN/SyHx0zfVxqx0G4o0kof5Qe5uO8Y9sr+bI9FKnJgN7EojkVIs /Hp6cFAR5/0dCpDgIQMcTtXtH2A8x8JeP8GzIdp3gayBj2E7Y1CtTRCeWMfTj4KYY9 aeZzPqkrdUN8Gl6j7iLrRJ7YpJmypGPJzR8cIzDmn1Kikt88N+GTzvZOIsxL7I2Aok Z2gTQoXD5fAeVxahAeb/LeYpXEKxzQYOlBg4JYaa5mXN5VDaEpxETu2uNsmx/KIHfI PLWrlUUOHwrNg== From: Danilo Krummrich To: akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, vbabka@suse.cz Cc: mhocko@suse.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Danilo Krummrich Subject: [PATCH 1/4] mm: kvrealloc: disable KASAN when switching to vmalloc Date: Tue, 30 Jul 2024 20:49:41 +0200 Message-ID: <20240730185049.6244-2-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730185049.6244-1-dakr@kernel.org> References: <20240730185049.6244-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Disable KASAN accessibility checks when switching from a kmalloc buffer to a vmalloc buffer. Fixes: 923a26b4c679 ("mm: kvmalloc: align kvrealloc() with krealloc()") Signed-off-by: Danilo Krummrich --- mm/util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/util.c b/mm/util.c index 29ae93f6344f..bfb2d69b6434 100644 --- a/mm/util.c +++ b/mm/util.c @@ -753,7 +753,10 @@ void *kvrealloc_noprof(const void *p, size_t size, gfp= _t flags) =20 if (p) { /* We already know that `p` is not a vmalloc address. */ - memcpy(n, p, ksize(p)); + kasan_disable_current(); + memcpy(n, kasan_reset_tag(p), ksize(p)); + kasan_enable_current(); + kfree(p); } } --=20 2.45.2 From nobody Fri Dec 19 22:01:19 2025 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 093AA18B494 for ; Tue, 30 Jul 2024 18:50:59 +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=1722365460; cv=none; b=LCS7CKJBKQnoNIuc/N/nMknDnCULAKAnHuvmYUH0Hre76sZfHM9A1TwSoPi1+FUUTsPp5sl2OvFCRr9rxizxtVgewApWLJxuq6lcdO3CH0/4fcNmMBrc35o03xU7qMSc+zsD7KTBLMChCauHz1MgWnXrerlsudLyRmGKZBGZVuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722365460; c=relaxed/simple; bh=pqmv76F1WcFutmWjI3wHquYQ2ukivLAaozJiVBwDm7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i85Kb95LBWXMjqO87xGfFGNI7/Tm4J7aT+LURq+sZIxJPT0O37fDkXSBK3wyX04NEGhxT33ELWSdDaZmSKd6Ah5yJnLD1B098w9P2KkWjTRRdodWVGpQjCZ+xxsXYlQKoliwZv9D12FTbH+JX33kfjag2lwbMuCDoUEHv1VUnns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AOgF+9qB; 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="AOgF+9qB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C974BC4AF0A; Tue, 30 Jul 2024 18:50:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722365459; bh=pqmv76F1WcFutmWjI3wHquYQ2ukivLAaozJiVBwDm7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AOgF+9qBGFqKxJ8z4A6PgTFI5uYlUNekNx9SPS/SqWo35zBpPaiN87qT3ktO1zdzc QMYeHnTcqQxbUhysQGYmIJuey8q1zASAdVZHZpDbQ4KXgeW8lS5IAeIzAW5X/JpYj0 b7QuzOIKrpAu8L5rZHQzMcFcCt7JqP852MttQgYl1iRORwFDUhmGoLvRzpOjR6etsA XrX9PPOBBOMCeKCm517hKCADyt6UPMZwI+v7THiGeG8m4+I1h7XwuwyfVv6zs0JqLW 6pQZCszlfzoYzSgVnhz4MwQ1sQJINCMAjFtLcTETveHdGHdo7+v/nb1ukBSVJrfJKt EpnCk755lK3gA== From: Danilo Krummrich To: akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, vbabka@suse.cz Cc: mhocko@suse.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Danilo Krummrich Subject: [PATCH 2/4] mm: vrealloc: consider spare memory for __GFP_ZERO Date: Tue, 30 Jul 2024 20:49:42 +0200 Message-ID: <20240730185049.6244-3-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730185049.6244-1-dakr@kernel.org> References: <20240730185049.6244-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Zero spare memory when shrinking a buffer with __GFP_ZERO. Fixes: 1f39ee9615a8 ("mm: vmalloc: implement vrealloc()") Signed-off-by: Danilo Krummrich --- mm/vmalloc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 2a6d4ce57b73..6a2fef6378e4 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4077,12 +4077,15 @@ void *vrealloc_noprof(const void *p, size_t size, g= fp_t flags) old_size =3D get_vm_area_size(vm); } =20 + /* + * TODO: Shrink the vm_area, i.e. unmap and free unused pages. What + * would be a good heuristic for when to shrink the vm_area? + */ if (size <=3D old_size) { - /* - * TODO: Shrink the vm_area, i.e. unmap and free unused pages. - * What would be a good heuristic for when to shrink the - * vm_area? - */ + /* Zero out spare memory. */ + if (want_init_on_alloc(flags)) + memset((void *)p + size, 0, old_size - size); + return (void *)p; } =20 --=20 2.45.2 From nobody Fri Dec 19 22:01:19 2025 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 4BDB918C91D for ; Tue, 30 Jul 2024 18:51:01 +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=1722365462; cv=none; b=VawD4HgEbOD3mzLDzbY8mFPTzJxuWQv/h84Do/Znc2eRfZe2cm3XGK+h9wczo9gBVvNLmXwj2lkZPTkG9KUgHK4HzL6L8Ij7fgGdRfsGj824cdWN0x5mFBkA23m7+WAQ8GZ65uzd00xCVwfP4XBPjquqGAY3VZMXBFCXCi0rBiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722365462; c=relaxed/simple; bh=GszPI8ByV+1qtGMCf/91ybTKQ8raCzOdvtpEYU0MI+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M/SvurnayyAaBMRgFLK5HM+zvery71f26V6HBiNACZKMy5oPo9XwILk6N9DvWqzmgRL3fPy1vziEME5D14oGqCg2UP+jEzLZec+d5liOz+kkhVWPSX2uBXT6yz3De5MHHHH450AV3XeSoTlkgfVltbyx2jHsaopQmSF94fwdInM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZyPXR6Sa; 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="ZyPXR6Sa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F798C4AF0F; Tue, 30 Jul 2024 18:50:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722365461; bh=GszPI8ByV+1qtGMCf/91ybTKQ8raCzOdvtpEYU0MI+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZyPXR6SaSqI0F9wenpqipaQ6eymbMTrxBfG7CUNsILMrxtXzoF59HoD/rB34noBng GqC1WjTj4nSG3OFM2vk7pJsF7ZWFZjuhgUtVG4okRj51/vSKSZEz2wuuysJqSeEnBo YTBnoYBeKDlmwBJFr1Afgwpj6W0t2MRMJ2SjM01JAhhm+SnVZFnAYFDXesiku/aQGT lsF3giHR0Qb9pC7sgEx0Zxz5+L850wX3Dq0RJNeAXXHUV1pW2JYbtmsyDRZjpfx4ON R36cynKzYELGkdyX4UfarNSz/i2FJtQC2TR1GoApn7mCnn6sv7/QY5BRHxFCIgu/Gb cNV3RlUzrimGg== From: Danilo Krummrich To: akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, vbabka@suse.cz Cc: mhocko@suse.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Danilo Krummrich Subject: [PATCH 3/4] mm: vrealloc: properly document __GFP_ZERO behavior Date: Tue, 30 Jul 2024 20:49:43 +0200 Message-ID: <20240730185049.6244-4-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730185049.6244-1-dakr@kernel.org> References: <20240730185049.6244-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Properly document that if __GFP_ZERO logic is requested, callers must ensure that, starting with the initial memory allocation, every subsequent call to this API for the same memory allocation is flagged with __GFP_ZERO. Otherwise, it is possible that __GFP_ZERO is not fully honored by this API. Signed-off-by: Danilo Krummrich --- mm/vmalloc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 6a2fef6378e4..48cc10dd06c0 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4043,12 +4043,17 @@ EXPORT_SYMBOL(vzalloc_node_noprof); * @size: the size to reallocate * @flags: the flags for the page level allocator * - * The contents of the object pointed to are preserved up to the lesser of= the - * new and old size (__GFP_ZERO flag is effectively ignored). - * * If @p is %NULL, vrealloc() behaves exactly like vmalloc(). If @size is = 0 and * @p is not a %NULL pointer, the object pointed to is freed. * + * If __GFP_ZERO logic is requested, callers must ensure that, starting wi= th the + * initial memory allocation, every subsequent call to this API for the sa= me + * memory allocation is flagged with __GFP_ZERO. Otherwise, it is possible= that + * __GFP_ZERO is not fully honored by this API. + * + * In any case, the contents of the object pointed to are preserved up to = the + * lesser of the new and old sizes. + * * This function must not be called concurrently with itself or vfree() fo= r the * same memory allocation. * --=20 2.45.2 From nobody Fri Dec 19 22:01:19 2025 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 395A018C93B for ; Tue, 30 Jul 2024 18:51:04 +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=1722365464; cv=none; b=OW0Zbdo/dBiGphJ5NKRp9GzLeprNI5lfrVIiKlXqcLSiiej/T2VU51Z8CfU0jOlI49hK6fCHr/GmqLQnM0eucY0GuXtsh9da4FRyOo5nADNEec0vDoYtN+CfwvlsGwNCNGQh+pvR0OdaLTHJPgt4GNNezX1A3FmH19/JzDN20vY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722365464; c=relaxed/simple; bh=BHHTORiqnQEnevgg1pb2AO84I1O2tlm7LAzk7DzpiX8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jdPk69qnpGfw6xpJwkZ3NIeXd61Bm8Wy+sH7P1KkWftlQBLNF/p8MjTalbcwHEQKEUmzKxcUu2tTNxiQQSjw9EmPIHzSJUScqdHlzrvzds73TXqYs+NTCvFXpEc8QXduCNgzfaf6X8xznjttd7Zahdc9Wj4AmUakCohRJyuJxvI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MB49LOJn; 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="MB49LOJn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A8A7C4AF15; Tue, 30 Jul 2024 18:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722365464; bh=BHHTORiqnQEnevgg1pb2AO84I1O2tlm7LAzk7DzpiX8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MB49LOJnSd0dC4i1DwOZpB6+J6dWDCYVb4aSAN6rq0/ja5W5I7SYG+wE1+aCIUFzd qLTmTZJeY7DM4oAUSLBwxmJlYBSkMKJ4Lgy38nAr8xtUz3tDqG7PFRd9EkHPTSsXgp uiNANAfLVkyCrv++Py4nHn2Qc70r9BsXtBvAYYGIYrcGRd9Gbx5rbHEMA/NjfAJIHg oiAan8YjdJEtq65lpESfuPIXm/LAHoAVVCpWsYBypKKRkqiKCSs3nOxmd7zcttkvdy WjHTBWA9p73oJdDGNxRP4CgozeSPolMLJrOFaVt0O5mDaoLu5lsAtRrn0K9LPNHYm8 FkwzOtJa9/qqg== From: Danilo Krummrich To: akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, vbabka@suse.cz Cc: mhocko@suse.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Danilo Krummrich Subject: [PATCH 4/4] mm: kvrealloc: properly document __GFP_ZERO behavior Date: Tue, 30 Jul 2024 20:49:44 +0200 Message-ID: <20240730185049.6244-5-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730185049.6244-1-dakr@kernel.org> References: <20240730185049.6244-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Properly document that if __GFP_ZERO logic is requested, callers must ensure that, starting with the initial memory allocation, every subsequent call to this API for the same memory allocation is flagged with __GFP_ZERO. Otherwise, it is possible that __GFP_ZERO is not fully honored by this API. Signed-off-by: Danilo Krummrich --- mm/util.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/util.c b/mm/util.c index bfb2d69b6434..f899b0f984a0 100644 --- a/mm/util.c +++ b/mm/util.c @@ -726,12 +726,17 @@ EXPORT_SYMBOL(kvfree_sensitive); * @size: the size to reallocate * @flags: the flags for the page level allocator * - * The contents of the object pointed to are preserved up to the lesser of= the - * new and old size (__GFP_ZERO flag is effectively ignored). - * * If @p is %NULL, kvrealloc() behaves exactly like kvmalloc(). If @size i= s 0 * and @p is not a %NULL pointer, the object pointed to is freed. * + * If __GFP_ZERO logic is requested, callers must ensure that, starting wi= th the + * initial memory allocation, every subsequent call to this API for the sa= me + * memory allocation is flagged with __GFP_ZERO. Otherwise, it is possible= that + * __GFP_ZERO is not fully honored by this API. + * + * In any case, the contents of the object pointed to are preserved up to = the + * lesser of the new and old sizes. + * * This function must not be called concurrently with itself or kvfree() f= or the * same memory allocation. * --=20 2.45.2