From patchwork Tue Jul 30 19:42:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13747822 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 A5BA3C3DA49 for ; Tue, 30 Jul 2024 19:42:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B3856B0082; Tue, 30 Jul 2024 15:42:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 164736B0083; Tue, 30 Jul 2024 15:42:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 003AE6B0085; Tue, 30 Jul 2024 15:42:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D63136B0082 for ; Tue, 30 Jul 2024 15:42:28 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 87C091204CE for ; Tue, 30 Jul 2024 19:42:28 +0000 (UTC) X-FDA: 82397440776.28.C6E52CC Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf20.hostedemail.com (Postfix) with ESMTP id 4769A1C0021 for ; Tue, 30 Jul 2024 19:42:25 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Hz3I3PPg; spf=pass (imf20.hostedemail.com: domain of dakr@kernel.org designates 145.40.73.55 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=1722368491; 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=a5ocU4KAyrFKyR1RuDmhZKkk0avy0OYrZVsZgIhVomk=; b=3w8VBW0L+QUDqol6c9pk+SIKNWb6DT62DroWi6tGbW8jfsFGN+hzabihg4u2lbRPSqOItH mPXW/8TFVW7ghLWsLaneSTpcYmWrwgbzUdFl87PQS7wAnSoC2OvSRtdT3rs8mR8/d9NSB+ c14ZA5wO8kS7SV6jPdCBda+x+jl4280= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722368491; a=rsa-sha256; cv=none; b=d6sGmx1PFbxiXngOLgRDGlrdudDYDDVcRzpQFWRQXecahS2RtjcYjX7py08MgZUXnt3Xb2 RWzdAQGmELmvcWMcIT74K9t7ytZ9O4OBIN2/yvrbfTUtXOPmayVL6FAmT0oTxNnnGIuXFp 6ecXJtOP+3Y9WOhcq9HqSMpdOnGnoLw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Hz3I3PPg; spf=pass (imf20.hostedemail.com: domain of dakr@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 6819CCE11DF; Tue, 30 Jul 2024 19:42:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FA1AC4AF0A; Tue, 30 Jul 2024 19:42:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722368542; bh=M76h9UGEvDOvQR6+2Hn3EAWaBbezIN4frYXV3T3puu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hz3I3PPgpwhw3lVSMpgtM9ztVA3tbfI3MKtbxzj+0dqVYZnDDiwozDj8zEop394Cg Lo4e9zEyKWlHpuwes3fvlngGhlKbyJ3hEfxUckaBRS8L4XYmHhfNGkGrHH4LwRFp2d gmSUg53aPKuRhlU2exxn36PshWOinMgX2bl3ZpmINY16Two2v7FM5XcCx7ZuG6yqX/ t7DVl5p2nTwixIb9yqcJSqSlsM8NlCBn8hPAzkCGpqgAD39qhx/7JPa8R3zbLAdF3e 8F+baNJp21sb5CKXM0Ya0JuaXP5kaEj7OWUc7KsCsbju0tjkN4OsaAYA3D8bOUJ57y Pt0i6ic5OCsEQ== From: Danilo Krummrich To: akpm@linux-foundation.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Danilo Krummrich Subject: [PATCH 2/2] mm: krealloc: clarify valid usage of __GFP_ZERO Date: Tue, 30 Jul 2024 21:42:06 +0200 Message-ID: <20240730194214.31483-2-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730194214.31483-1-dakr@kernel.org> References: <20240730194214.31483-1-dakr@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 1zoek19t3srq4orsjekq75fe3nhorh9n X-Rspamd-Queue-Id: 4769A1C0021 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722368545-562309 X-HE-Meta: U2FsdGVkX18MXnr5CmMPz+8qWQjEopMLy5kqyyNVelcy4Wm8VXkEXV7hxGdJZBFQTbBt1W64vHUhQ/W41Yjsby+bYY64yoHonWf0HKKDodwY3HAYZfE+Q1mONjgCkLMB5mjhY69U2STMHyl1SnhJCyOE3pPWuOacgcGQeQUimpXWGlXtWSZBamUktI1PTtRtexy4Zfnm74ymanAdIKbcKQUMR1C76B5nG/IZGSu2sl2kGjo+Jkxk9iJA4q7Jl3hFLlN838JCosdWiZn2A+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osity: 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 --- include/linux/slab.h | 8 ++++++++ mm/slab_common.c | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index c9cb42203183..26f14c04000a 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -733,6 +733,14 @@ static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz * @new_n: new number of elements to alloc * @new_size: new size of a single member of the array * @flags: the type of memory to allocate (see kmalloc) + * + * 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. */ static inline __realloc_size(2, 3) void * __must_check krealloc_array_noprof(void *p, size_t new_n, diff --git a/mm/slab_common.c b/mm/slab_common.c index cff602cedf8e..faa13f42b111 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1301,11 +1301,17 @@ __do_krealloc(const void *p, size_t new_size, gfp_t flags) * @new_size: how many bytes of memory are required. * @flags: the type of memory to allocate. * - * The contents of the object pointed to are preserved up to the - * lesser of the new and old sizes (__GFP_ZERO flag is effectively ignored). * If @p is %NULL, krealloc() behaves exactly like kmalloc(). If @new_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. + * * Return: pointer to the allocated memory or %NULL in case of error */ void *krealloc_noprof(const void *p, size_t new_size, gfp_t flags)