From patchwork Tue Jul 30 18:49:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13747779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79174C49EA1 for ; Tue, 30 Jul 2024 18:51:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8B506B0085; Tue, 30 Jul 2024 14:51:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B76B76B0089; Tue, 30 Jul 2024 14:51:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A17076B008A; Tue, 30 Jul 2024 14:51:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 81A3F6B0085 for ; Tue, 30 Jul 2024 14:51:00 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 34025A0447 for ; Tue, 30 Jul 2024 18:51:00 +0000 (UTC) X-FDA: 82397311080.25.8062DEF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id 7CE2D14000A for ; Tue, 30 Jul 2024 18:50:58 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MaVod01S; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722365417; a=rsa-sha256; cv=none; b=4AXBR59kmq5vNFllTJ2Z44EmWwG8zERdbL12B1IBBifX3ZkBlDHkdsbZgFfwnoPNzSoNe8 En4y+XipGWfgUCJpYPBpIB9nACwNxc71pmAp7H1JHKWvXZFvcH9kD+ZxgwRR2CAc3pt7Rz zxOh5Qi958ZPbWt+mvFwlQekkPig/jA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MaVod01S; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722365417; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yIgIvlGX5TcMoH+qnhpq+tghEwRjhrL3nwgRdBJ9NMU=; b=ft743mp74FD2O4P7bN8rWleiLhhTYMqs2kc1cG2tNiBpbNYwQOFGr4elmIlIoU0FTl4SPE 83TMgaN1ZXRy8Pk71EhTFbSr3MSL46V1hkyx8GIMdAmE7pp3ZRW07A/6JSzC/Q83xbiGpp K2BbOgAroD3M9SK8acIdKwVD7pAAd1s= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 86D1E6203E; Tue, 30 Jul 2024 18:50:57 +0000 (UTC) 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7CE2D14000A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: yqwj7dp6cipykwqhgdi4tj669r1889tc X-HE-Tag: 1722365458-813207 X-HE-Meta: U2FsdGVkX1+Q9AyaJpwURAMzta5Y2WbZajaGJNFIDr2nmNh0py2Nfo7+pVn7RNV6j8tCzlGD8dmWcjnKA9EC92gej7mmUfQv9zK7wd8Z0wfYQI9yFFLJ8NX5t//rWG7KnNRNMUFuQc0yy3+27AhYzqem/YrkV//hrAaXYCj/GdEkYHGEVa50nHNGSLIGfLj3imHOihAi2SJarygTcJdlYIm1MPTXMWzGAusQArQZ+DC728Z6zN0zOMVwQJC5plXOM93nfzFKxxwTuw0J4QIwB4fVAzgYLJGvhGbxOFO6oAsVnWCvC/WKmyHRrluFxwmITeT5vjEDKcnBwT2y3oqNIqHl+WFvomE2jgF45t3lDtKIUcE5RAU0thMS+MBu0Nx/6ual2nx3fnaZLf/Na+Pa9jQEMJ5lmNr2PYAzzoZ/epYaf42njnv0Wlzu5dkAifcdLXBTzd2Mdj6LyzbGE9JNQMN4SL/cdq7HwjHkL/oncw3ysglnpt6+oYlCkDCe3PAxHC9GhCvKCQFETAI048IEmCGV1r5jecIAiy1i33LoJMQ/9nU/TGh5v/ddtdDj8uKaavWBVHqTePZ0+uPpOYIxAJw88Be6a1L+z+gdmci3tiyTgCNC01wE7RkFpLuHiUu+U4n7RNO43TGWBg/gPCjCLl4TUA1gh99SUs9tFbvt0aTM4YjC3N0oJO99q8YTakKmqtJJd7cbDazzs9QiC7vPiw2mgl31twyEQsG7zWFV6nFOUBacEekheBasEXR8id6MhOKCGcSjNiXHpcaMdBT3eCfiDAEruUIowQDyfq2nXAd8bI+/9DZSFyWiRqUEPZMxVi9KVDcK99jlQJiVwJGGG3kLBvQAnhapZTeNKBeXa+5JIAyO/0NcShbkAReacAD1QbHrbhtzo2aHP0p9v3KwyoQ+8bzyxpPleglg/DltfzUrnx68M7BPwXxEdxmpFmmthY+z7yyYfM6jDzEZ17X YJDY91iY FSfdggCxuegBT5cHrFdo/J5vcZDDBlqQ7DqOWoj8KGS+XKCOHtaCzwt9j9oBek9g6sgOiiBiHDlLdb0EyA6XN+ZK4sPxpLU0RtquqtW6TrwMIWJmRU1eytiMNeiqhgdxP/Hd6o+Ft7K7zNAsqvsVuGOLoueazg+pBirMp9jSU0z4SB4ewhU3YK33NCD0Kx7vwVwutwWa7KRdNTwPgbMwDgf1Q0I1E9oJSt111kR0qf29fDuU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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) 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); } } From patchwork Tue Jul 30 18:49:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13747781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FE51C52D1D for ; Tue, 30 Jul 2024 18:51:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33B936B0089; Tue, 30 Jul 2024 14:51:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2ECFD6B008A; Tue, 30 Jul 2024 14:51:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B42B6B008C; Tue, 30 Jul 2024 14:51:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F3C476B0089 for ; Tue, 30 Jul 2024 14:51:02 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 67138160441 for ; Tue, 30 Jul 2024 18:51:02 +0000 (UTC) X-FDA: 82397311164.21.23F525B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id C277AA000D for ; Tue, 30 Jul 2024 18:51:00 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AOgF+9qB; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722365399; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ew056S4HBySpe0eFO22xy2n+QYBibltBTyZ8JZz+eZg=; b=s8XWLuHQDZNPtd8tMR5MkWdPERMtTMvdbGteNbtaHlrh8Ufk+ZEnocZp3GHnSBmvpaV9pJ /9K/LSKwFId3vHsko+b3bAzRvdzXlNL2r3E/EunHBpQeH60UdJ1UYEDHl/fh3T/vbKXIHQ 9KBviuAL7OCbUNNAEzadjfkXfrZ2o24= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722365399; a=rsa-sha256; cv=none; b=Iqr7apGc3lmnzBrWW4D1i6OcwT5gkFMrIjrNRTajxmOOoL+cKiEkX1zRHX/1a0M+JNc072 wEe6wP4FzWjyNfi4lAm1qf9pCf1eRAmsyHmNFzSrg4m3Nbc6DMa6MpI0DkIE4E4p8YEYpD HnDeBduBca4XlB/qKqyPxmyyB3tboGc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AOgF+9qB; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E2D0662039; Tue, 30 Jul 2024 18:50:59 +0000 (UTC) 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> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C277AA000D X-Stat-Signature: 3u7wn7nefasrxmmy3yaa6kuzskou5tkz X-Rspam-User: X-HE-Tag: 1722365460-233280 X-HE-Meta: U2FsdGVkX1+NbQBgX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KuTRwmyDzFAlpUAR++nkNEMUVQAx4z4GrgyH+qIzKT8PPnzOF0DmOE1ZIy2xdgObs/5UShZgfY/Odjg16e6s2KpvGHvqLvKC8bOoszw97aXzLZAm5x1jvPKrZu6Gb16RS4yMFKTkkx9k2lPdUniIC2x8wSNgaEn2wU2l3Y+S1s4SyV2atsstZsqNUxClY X-Bogosity: Ham, tests=bogofilter, spamicity=0.000223, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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, gfp_t flags) old_size = get_vm_area_size(vm); } + /* + * 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 <= 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; } From patchwork Tue Jul 30 18:49:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13747782 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F7E6C3DA49 for ; Tue, 30 Jul 2024 18:51:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DF3E6B008C; Tue, 30 Jul 2024 14:51:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 02D416B0092; Tue, 30 Jul 2024 14:51:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E12CE6B0093; Tue, 30 Jul 2024 14:51:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BBEA06B008C for ; Tue, 30 Jul 2024 14:51:04 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 728F01204A5 for ; Tue, 30 Jul 2024 18:51:04 +0000 (UTC) X-FDA: 82397311248.21.4157995 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id D4923140010 for ; Tue, 30 Jul 2024 18:51:02 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZyPXR6Sa; spf=pass (imf23.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722365390; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CY+supgkZE9e2vuOlgj/vU2It/36aM8i5ue5rYaMbyw=; b=pmygJTa88tIsmULqJJgGg/Nl6rovAxK0sv+xMFxh7j9R43OHmr03gZ3PTytK/vzPapQd6O j7OrkvZDSCnFBIbKuHAtDEvGPyKXMOQz7HGTsEpkq8XzSSnrXN1b0v41K8sLGT6gQc3HXX 5KRAMNm38IVFOwkxByDo4XKpry+LwJc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZyPXR6Sa; spf=pass (imf23.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722365390; a=rsa-sha256; cv=none; b=zvP3+WxVbKPyoEh/ZilZ/sFx9b/NmiBSrITCNjSJEelqggqilQYytMZdnEfM7qZRx+R63i QvKLakGG+n6EZ6zgbAdCBp9xOVB+icV8Am261TEu7yBs1PWoRjKipFZrO3b6pjnZfjlqC2 5XW6VlIfp0W1hKvdiXrrT1LGn7IXRBs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0A41D62004; Tue, 30 Jul 2024 18:51:02 +0000 (UTC) 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> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D4923140010 X-Stat-Signature: 8se694n4qwegk69cxw1rhe7burwgdenb X-Rspam-User: X-HE-Tag: 1722365462-560529 X-HE-Meta: U2FsdGVkX19LFpzus/IdTE1MhP04UXKhISYgghL0GrP39ZpChchj8fTvMEMhNzDOjdMEa+Bz2jXM0ypyUxElthKk9M3A/wosIK21W8VMiL4J4a1Pq+iDEx/GChgGBPcT2xYK13q5bDqIFv3PhLVFE38XqnHWdhfske8czByFWg9H6d27VAHnyyXtLwO2oxEktsL9HcezVRqth94i+ZOQeh1bvHDqpNT2sQ0SQhf3W4gqvNLy9tfP92qIf4FprMHQo9rmQwSmC3gAa4YrUWKeBmCEvw18/CcgNtW1OPZ+UMZFTO7RQLh8RI70bwnXjd1kz/zL1UufjkrG+S+anrkHUrtHy50F9f5qpY9UV9pXSM24JPmsK+7XxY4Q+2foXapc5+F3sDBhtM+baAmTScCoU+HWuz5jyK0Nk3Q8oGM/H51avwrviK8UKhKTncDBf96EuHJRVCIRxB6q2TygKm77n7Fsmz6wZQPvTMlhzd1prx9dO1R8bQ7ekdL7cwXUmzBda169oINF94uRBMZPzBb69pxhdzpJmD6Up0UvNSOTfxdz39WuJd5ZbvY11k9AsULI8dCEUWt9+6boPBUDf6EkmqZ+awLvac3EOhmLrPqt4tUSiIE2hAgpo8IPcYoDGGrgjrBOURI1/k2xH43qdxQUulSuIUbuXa4ku8Li8hkminaPH3MjYcqN58Ko0+rHyi5cjOvUxSmCWfuy4nWxM8xg8XqZPuymlxRIKY3rvjAMoenBOuZaRnIVe6l9Qm2b2auxEwnE0snwl9A02n0jYVT0/9VB7VifnGIDlsoCcLZUK2oCUVhSM/TcUwnRlepjHsGbYU95t5BmV87CWt6muuLfXxlyLGi07bR2DL0WS7tHzf8XiI38Mjb+aKJfkZp1bl+8C6BeJ3hhVxxNyKQ+ltJCFVvso6oV6Y8nIKxAhNJaYnR8o2eyTOnqIc5DPygtljWP0ZLCQcTw0FcBAXe5+9N XFdqS6Wg xRbcPXHsQnVLfcuWL4AGbro50PnRNHkqg6YrvCOPBkmEQ0u28y9fE/reXTfMXUiw3hRkSBsdZV0V9W6bg/Yjeup9tPvPAe6cODTtvoRHG9MGgMhCAqbxDLG0+yjQpAy8eAjF3PV349JyszK9/UtGs8fXxbbhqwBbowwlMHqaZCmvH3Jz7nInabPfCbmRzUcPpSAg18paJ9BjiXOGk8ChMTDSAir23tcFLn2H2ev1SF6eo5O+nisx6ghuAcfUyAnR0QBfme7Bm2tX0p7/cDxekD8pCxhzu/rRaL50r X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 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. + * + * 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() for the * same memory allocation. * From patchwork Tue Jul 30 18:49:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13747783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4188AC49EA1 for ; Tue, 30 Jul 2024 18:51:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 782256B0092; Tue, 30 Jul 2024 14:51:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 731CA6B0095; Tue, 30 Jul 2024 14:51:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D3406B0096; Tue, 30 Jul 2024 14:51:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3B34B6B0092 for ; Tue, 30 Jul 2024 14:51:07 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EA513160441 for ; Tue, 30 Jul 2024 18:51:06 +0000 (UTC) X-FDA: 82397311332.20.5B103B4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 463CB160016 for ; Tue, 30 Jul 2024 18:51:05 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MB49LOJn; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722365420; a=rsa-sha256; cv=none; b=6NWORibKiZ7mGbhezZmJi7sQgEB9Sfy45jnSBsaIDurqnEK8pKLLsaGqUyZFI1efgg8wK0 UKPY9XcYF6UgaXYvuAyyn6h4gJhl/Eb6oG2nL66j/tZEb98GwJd4P/uM0Myi2tNsqIehqv EX3+D+RsnbZ5mz9cgy8LuZUakC7Rp8s= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MB49LOJn; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722365420; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=XMRLNLiTM0AVkiAwykusY/ZI/wVK4OHI5IKc8SVQ0jM=; b=F5WylQHHX3Lz8AlpKOaQBm1A3p434+smd+zpODKOPZNOMj4zs1yL0taKWcCniIc7RgByt1 1jhK9BytOUAILKiFOxkNtnnQnkdWilrD8VWv7Aji2ckBDKcG26Y+OC0QnjVWi5aenws3Zg ig+HlefxcmtMesLwSzAlp9t8kiBG4ms= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 64A6162020; Tue, 30 Jul 2024 18:51:04 +0000 (UTC) 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> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 463CB160016 X-Stat-Signature: sfamac4br4y7x1hyc7kus47y4doiksqp X-Rspam-User: X-HE-Tag: 1722365465-726655 X-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V4k+E0gmsucXx2CUmeNZ61ug1s0w0AuKMlThrbzd9l3p1CW/Zja64R7FsEJt9EPCZTvPWShnjjJT+ihAdoosvyH8M6chTqscWdKU9sRuwzVn4tN7xmR8obRbQ6Km3MPfbyIcL7Zj/gS1QQGYXnBEchuOD9yJecWG/gGY69+8qfZeK97yg36dz6hZHy2HqK4mSB X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 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 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. + * + * 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() for the * same memory allocation. *