From patchwork Wed May 22 09:50:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13670655 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 04F2DC25B77 for ; Wed, 22 May 2024 09:50:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F09C6B0095; Wed, 22 May 2024 05:50:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 579FD6B009A; Wed, 22 May 2024 05:50:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F2F46B009B; Wed, 22 May 2024 05:50:16 -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 1EA2B6B0095 for ; Wed, 22 May 2024 05:50:16 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B94BD1601FD for ; Wed, 22 May 2024 09:50:15 +0000 (UTC) X-FDA: 82145561190.22.12F405E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf23.hostedemail.com (Postfix) with ESMTP id 92E69140021 for ; Wed, 22 May 2024 09:50:13 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="aTn6/8sl"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=3snz6aGS; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="aTn6/8sl"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=3snz6aGS; dmarc=none; spf=pass (imf23.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716371414; 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:references:dkim-signature; bh=y5seN7yenBgxcqGC98g7sKIA9LM4LrCJZY6xmIjA2EE=; b=At8x5DC5u+hFBOQbnSrNXSN7fihA7eWEKczyUYAgm5SXvkJDX4g6meoIhEVer0QJfnU+nt rfuOJru3hHcRWrEcFXzVPTP09sXxcO7CfPAjZCAPB+w1r1K/Jtz/zGjraMplqU8YLtTpqF NSKYcKKi0JF2KAcArX/uFH0JPoQB7Oc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="aTn6/8sl"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=3snz6aGS; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="aTn6/8sl"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=3snz6aGS; dmarc=none; spf=pass (imf23.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716371414; a=rsa-sha256; cv=none; b=StpK963rGQwleZjsddx783zkghhbHoJXefNmNH8O5VlxH8Mkks/ZNpV9XmFwA9XjsxiZdo 9bJFowwLpozGQS3g7z9P561HDi/QbA8fLEqTOmk8VoNIlfWxq/S4i6axvdMYmy1TWh00L/ E4zJiocpz5/Wi7U2NCpNTVh3fT5fmxs= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A097A5C766; Wed, 22 May 2024 09:50:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1716371411; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=y5seN7yenBgxcqGC98g7sKIA9LM4LrCJZY6xmIjA2EE=; b=aTn6/8sleM0ONztO4Unqpxd+uynjWz3urX78jlz4ob4A9pmacA4e9fn7384PkRcYCjYf5R PxiTGQV0QRUIenlmXLZl2huVcDb3p6j8g81KbR3TYWl5JuQyul88i6d1IX96XYQuGhbZ+z 43DPZszmIkW/PU/E4HazfSptPDexj2o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1716371411; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=y5seN7yenBgxcqGC98g7sKIA9LM4LrCJZY6xmIjA2EE=; b=3snz6aGS+9BRVPXLvnvmTvVZ9CDdUumRJ2bBPLF2+YgozUn1Xmarkel22uavtoFbXPCiZm RLCmz7LLypAFsdCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1716371411; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=y5seN7yenBgxcqGC98g7sKIA9LM4LrCJZY6xmIjA2EE=; b=aTn6/8sleM0ONztO4Unqpxd+uynjWz3urX78jlz4ob4A9pmacA4e9fn7384PkRcYCjYf5R PxiTGQV0QRUIenlmXLZl2huVcDb3p6j8g81KbR3TYWl5JuQyul88i6d1IX96XYQuGhbZ+z 43DPZszmIkW/PU/E4HazfSptPDexj2o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1716371411; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=y5seN7yenBgxcqGC98g7sKIA9LM4LrCJZY6xmIjA2EE=; b=3snz6aGS+9BRVPXLvnvmTvVZ9CDdUumRJ2bBPLF2+YgozUn1Xmarkel22uavtoFbXPCiZm RLCmz7LLypAFsdCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8EA5A13A6B; Wed, 22 May 2024 09:50:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id dwKlItO/TWbzWgAAD6G6ig (envelope-from ); Wed, 22 May 2024 09:50:11 +0000 From: Vlastimil Babka To: Christoph Lameter , David Rientjes , Andrew Morton Cc: Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vlastimil Babka , Kent Overstreet , Suren Baghdasaryan , Kees Cook Subject: [PATCH] mm, slab: don't wrap internal functions with alloc_hooks() Date: Wed, 22 May 2024 11:50:37 +0200 Message-ID: <20240522095037.13958-1-vbabka@suse.cz> X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 92E69140021 X-Stat-Signature: uoirokmrazhyicxrtrhp16g9e4hraemt X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1716371413-578106 X-HE-Meta: U2FsdGVkX1/9bQlVlXnsZaAXdFdO0JV8qfvl9VJi2Xi0GomMScRQSB4LNL+Hi84BschPPf5xKxDZC3wVpTMbXpZcczXYsW5teyrzFrCe3hJOHegg9kbFqPdpJ7ecWoSms9u9Zqt/IgvKMyAw97HPO1ThmQ8tkp18fkT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f9YoJwv9HW3mdbz2A4Pabp978lMSle4O4KDsi1DybO+LLIjJBRQy1Ndkf7ZqV4MZhJT6xw7S1CSTMs/8gEzvjIUhZYi1tUwEOniJKVn5LObGxHDzMZ90qCxabsNwhbeCcdhnsmwxqq/X+wt15LygzQ6duAq+E 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: The functions __kmalloc_noprof(), kmalloc_large_noprof(), kmalloc_trace_noprof() and their _node variants are all internal to the implementations of kmalloc_noprof() and kmalloc_node_noprof() and are only declared in the "public" slab.h and exported so that those implementations can be static inline and distinguish the build-time constant size variants. The only other users for some of the internal functions are slub_kunit and fortify_kunit tests which make very short-lived allocations. Therefore we can stop wrapping them with the alloc_hooks() macro and drop the _noprof suffix. Instead add a __prefix where missing and a comment documenting these are internal. Also rename __kmalloc_trace() to __kmalloc_cache() which is more descriptive - it is a variant of __kmalloc() where the exact kmalloc cache has been already determined. Reported-by: Kent Overstreet Cc: Suren Baghdasaryan Cc: Kees Cook Signed-off-by: Vlastimil Babka --- The intention is to use the slab tree after rc1 if no big conflicts with mm. include/linux/slab.h | 53 ++++++++++++++++++++++---------------------- lib/slub_kunit.c | 2 +- mm/slub.c | 32 +++++++++++++------------- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 7247e217e21b..5ce84ffd0423 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -528,9 +528,6 @@ static_assert(PAGE_SHIFT <= 20); #include -void *__kmalloc_noprof(size_t size, gfp_t flags) __assume_kmalloc_alignment __alloc_size(1); -#define __kmalloc(...) alloc_hooks(__kmalloc_noprof(__VA_ARGS__)) - /** * kmem_cache_alloc - Allocate an object * @cachep: The cache to allocate from. @@ -568,31 +565,33 @@ static __always_inline void kfree_bulk(size_t size, void **p) kmem_cache_free_bulk(NULL, size, p); } -void *__kmalloc_node_noprof(size_t size, gfp_t flags, int node) __assume_kmalloc_alignment - __alloc_size(1); -#define __kmalloc_node(...) alloc_hooks(__kmalloc_node_noprof(__VA_ARGS__)) - void *kmem_cache_alloc_node_noprof(struct kmem_cache *s, gfp_t flags, int node) __assume_slab_alignment __malloc; #define kmem_cache_alloc_node(...) alloc_hooks(kmem_cache_alloc_node_noprof(__VA_ARGS__)) -void *kmalloc_trace_noprof(struct kmem_cache *s, gfp_t flags, size_t size) - __assume_kmalloc_alignment __alloc_size(3); +/* + * The following functions are not to be used directly and are intended only for + * internal use from kmalloc() and kmalloc_node(), with the exception of kunit + * tests. + */ +void *__kmalloc(size_t size, gfp_t flags) __assume_kmalloc_alignment + __alloc_size(1); + +void *__kmalloc_node(size_t size, gfp_t flags, int node) + __assume_kmalloc_alignment __alloc_size(1); -void *kmalloc_node_trace_noprof(struct kmem_cache *s, gfp_t gfpflags, - int node, size_t size) __assume_kmalloc_alignment - __alloc_size(4); -#define kmalloc_trace(...) alloc_hooks(kmalloc_trace_noprof(__VA_ARGS__)) +void *__kmalloc_cache(struct kmem_cache *s, gfp_t flags, size_t size) + __assume_kmalloc_alignment __alloc_size(3); -#define kmalloc_node_trace(...) alloc_hooks(kmalloc_node_trace_noprof(__VA_ARGS__)) +void *__kmalloc_cache_node(struct kmem_cache *s, gfp_t gfpflags, int node, + size_t size) __assume_kmalloc_alignment + __alloc_size(4); -void *kmalloc_large_noprof(size_t size, gfp_t flags) __assume_page_alignment - __alloc_size(1); -#define kmalloc_large(...) alloc_hooks(kmalloc_large_noprof(__VA_ARGS__)) +void *__kmalloc_large(size_t size, gfp_t flags) __assume_page_alignment + __alloc_size(1); -void *kmalloc_large_node_noprof(size_t size, gfp_t flags, int node) __assume_page_alignment - __alloc_size(1); -#define kmalloc_large_node(...) alloc_hooks(kmalloc_large_node_noprof(__VA_ARGS__)) +void *__kmalloc_large_node(size_t size, gfp_t flags, int node) + __assume_page_alignment __alloc_size(1); /** * kmalloc - allocate kernel memory @@ -654,14 +653,14 @@ static __always_inline __alloc_size(1) void *kmalloc_noprof(size_t size, gfp_t f unsigned int index; if (size > KMALLOC_MAX_CACHE_SIZE) - return kmalloc_large_noprof(size, flags); + return __kmalloc_large(size, flags); index = kmalloc_index(size); - return kmalloc_trace_noprof( + return __kmalloc_cache( kmalloc_caches[kmalloc_type(flags, _RET_IP_)][index], flags, size); } - return __kmalloc_noprof(size, flags); + return __kmalloc(size, flags); } #define kmalloc(...) alloc_hooks(kmalloc_noprof(__VA_ARGS__)) @@ -671,14 +670,14 @@ static __always_inline __alloc_size(1) void *kmalloc_node_noprof(size_t size, gf unsigned int index; if (size > KMALLOC_MAX_CACHE_SIZE) - return kmalloc_large_node_noprof(size, flags, node); + return __kmalloc_large_node(size, flags, node); index = kmalloc_index(size); - return kmalloc_node_trace_noprof( + return __kmalloc_cache_node( kmalloc_caches[kmalloc_type(flags, _RET_IP_)][index], flags, node, size); } - return __kmalloc_node_noprof(size, flags, node); + return __kmalloc_node(size, flags, node); } #define kmalloc_node(...) alloc_hooks(kmalloc_node_noprof(__VA_ARGS__)) @@ -756,7 +755,7 @@ static inline __alloc_size(1, 2) void *kmalloc_array_node_noprof(size_t n, size_ return NULL; if (__builtin_constant_p(n) && __builtin_constant_p(size)) return kmalloc_node_noprof(bytes, flags, node); - return __kmalloc_node_noprof(bytes, flags, node); + return __kmalloc_node(bytes, flags, node); } #define kmalloc_array_node(...) alloc_hooks(kmalloc_array_node_noprof(__VA_ARGS__)) diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c index 4ce960438806..3b5fea45b8fe 100644 --- a/lib/slub_kunit.c +++ b/lib/slub_kunit.c @@ -140,7 +140,7 @@ static void test_kmalloc_redzone_access(struct kunit *test) { struct kmem_cache *s = test_kmem_cache_create("TestSlub_RZ_kmalloc", 32, SLAB_KMALLOC|SLAB_STORE_USER|SLAB_RED_ZONE); - u8 *p = kmalloc_trace(s, GFP_KERNEL, 18); + u8 *p = __kmalloc_cache(s, GFP_KERNEL, 18); kasan_disable_current(); diff --git a/mm/slub.c b/mm/slub.c index 0809760cf789..31c25e0ebed8 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4053,7 +4053,7 @@ EXPORT_SYMBOL(kmem_cache_alloc_node_noprof); * directly to the page allocator. We use __GFP_COMP, because we will need to * know the allocation order to free the pages properly in kfree. */ -static void *__kmalloc_large_node(size_t size, gfp_t flags, int node) +static void *___kmalloc_large_node(size_t size, gfp_t flags, int node) { struct folio *folio; void *ptr = NULL; @@ -4078,25 +4078,25 @@ static void *__kmalloc_large_node(size_t size, gfp_t flags, int node) return ptr; } -void *kmalloc_large_noprof(size_t size, gfp_t flags) +void *__kmalloc_large(size_t size, gfp_t flags) { - void *ret = __kmalloc_large_node(size, flags, NUMA_NO_NODE); + void *ret = ___kmalloc_large_node(size, flags, NUMA_NO_NODE); trace_kmalloc(_RET_IP_, ret, size, PAGE_SIZE << get_order(size), flags, NUMA_NO_NODE); return ret; } -EXPORT_SYMBOL(kmalloc_large_noprof); +EXPORT_SYMBOL(__kmalloc_large); -void *kmalloc_large_node_noprof(size_t size, gfp_t flags, int node) +void *__kmalloc_large_node(size_t size, gfp_t flags, int node) { - void *ret = __kmalloc_large_node(size, flags, node); + void *ret = ___kmalloc_large_node(size, flags, node); trace_kmalloc(_RET_IP_, ret, size, PAGE_SIZE << get_order(size), flags, node); return ret; } -EXPORT_SYMBOL(kmalloc_large_node_noprof); +EXPORT_SYMBOL(__kmalloc_large_node); static __always_inline void *__do_kmalloc_node(size_t size, gfp_t flags, int node, @@ -4123,17 +4123,17 @@ void *__do_kmalloc_node(size_t size, gfp_t flags, int node, return ret; } -void *__kmalloc_node_noprof(size_t size, gfp_t flags, int node) +void *__kmalloc_node(size_t size, gfp_t flags, int node) { return __do_kmalloc_node(size, flags, node, _RET_IP_); } -EXPORT_SYMBOL(__kmalloc_node_noprof); +EXPORT_SYMBOL(__kmalloc_node); -void *__kmalloc_noprof(size_t size, gfp_t flags) +void *__kmalloc(size_t size, gfp_t flags) { return __do_kmalloc_node(size, flags, NUMA_NO_NODE, _RET_IP_); } -EXPORT_SYMBOL(__kmalloc_noprof); +EXPORT_SYMBOL(__kmalloc); void *kmalloc_node_track_caller_noprof(size_t size, gfp_t flags, int node, unsigned long caller) @@ -4142,7 +4142,7 @@ void *kmalloc_node_track_caller_noprof(size_t size, gfp_t flags, } EXPORT_SYMBOL(kmalloc_node_track_caller_noprof); -void *kmalloc_trace_noprof(struct kmem_cache *s, gfp_t gfpflags, size_t size) +void *__kmalloc_cache(struct kmem_cache *s, gfp_t gfpflags, size_t size) { void *ret = slab_alloc_node(s, NULL, gfpflags, NUMA_NO_NODE, _RET_IP_, size); @@ -4152,10 +4152,10 @@ void *kmalloc_trace_noprof(struct kmem_cache *s, gfp_t gfpflags, size_t size) ret = kasan_kmalloc(s, ret, size, gfpflags); return ret; } -EXPORT_SYMBOL(kmalloc_trace_noprof); +EXPORT_SYMBOL(__kmalloc_cache); -void *kmalloc_node_trace_noprof(struct kmem_cache *s, gfp_t gfpflags, - int node, size_t size) +void *__kmalloc_cache_node(struct kmem_cache *s, gfp_t gfpflags, int node, + size_t size) { void *ret = slab_alloc_node(s, NULL, gfpflags, node, _RET_IP_, size); @@ -4164,7 +4164,7 @@ void *kmalloc_node_trace_noprof(struct kmem_cache *s, gfp_t gfpflags, ret = kasan_kmalloc(s, ret, size, gfpflags); return ret; } -EXPORT_SYMBOL(kmalloc_node_trace_noprof); +EXPORT_SYMBOL(__kmalloc_cache_node); static noinline void free_to_partial_list( struct kmem_cache *s, struct slab *slab,