From patchwork Tue Feb 20 16:58:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13564276 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 16E06C48BC3 for ; Tue, 20 Feb 2024 16:58:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73EEE6B0075; Tue, 20 Feb 2024 11:58:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C9356B007E; Tue, 20 Feb 2024 11:58:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 540C16B0080; Tue, 20 Feb 2024 11:58:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3FC9D6B0075 for ; Tue, 20 Feb 2024 11:58:49 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0D530A09F2 for ; Tue, 20 Feb 2024 16:58:49 +0000 (UTC) X-FDA: 81812791578.08.CEA4D45 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf26.hostedemail.com (Postfix) with ESMTP id 09837140010 for ; Tue, 20 Feb 2024 16:58:46 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708448327; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bDwZLyEk1WMILC8wJ4ZtAG5w+ulImAgRHCRAxEjy7QI=; b=fmY316u/yyDsjLLAZNYd4we8leASwNIOyGvdXJpIc8LzUTyaenw2QIkKvKoWCyq0M02ChA xBkmRfm3cVP/wTAOGEQDZM0eycYrECtRrUfRa2rJeDOf6hChkm2x8aGju8KRUl5k1NiUya zlgHd43P/Th8vWI06irCCO1PtpQ8STo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708448327; a=rsa-sha256; cv=none; b=JJ3xhF72MVqDNuh7iHbzPlVme6bEBfcGbwlJKnMp+wxDhW6q4h/2OO4ATQ4+3agKTEVlg7 JzIyyJZ67vxaoMFtLb6IM9ko1a47/KKVuOjXz2dC4Gi+yVvoFuxcjLApXu6FAchpcIJzM7 Bh/K78AWjie4VNznYyk/HDm2t+0nHyA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 7BAC91F8AC; Tue, 20 Feb 2024 16:58:45 +0000 (UTC) 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 578FD139D0; Tue, 20 Feb 2024 16:58:45 +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 CEsVFUXa1GVKXQAAD6G6ig (envelope-from ); Tue, 20 Feb 2024 16:58:45 +0000 From: Vlastimil Babka Date: Tue, 20 Feb 2024 17:58:27 +0100 Subject: [PATCH 3/3] mm, slab, kasan: replace kasan_never_merge() with SLAB_NO_MERGE MIME-Version: 1.0 Message-Id: <20240220-slab-cleanup-flags-v1-3-e657e373944a@suse.cz> References: <20240220-slab-cleanup-flags-v1-0-e657e373944a@suse.cz> In-Reply-To: <20240220-slab-cleanup-flags-v1-0-e657e373944a@suse.cz> To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino Cc: Zheng Yejian , Xiongwei Song , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Vlastimil Babka X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3299; i=vbabka@suse.cz; h=from:subject:message-id; bh=8dSL5GfjNj31WZBzU1RArK2AdDIYjJIAED64yK7aPeY=; b=owEBbQGS/pANAwAIAbvgsHXSRYiaAcsmYgBl1NpC+Ron5uAKKATthXFJII/xHLgqduJBWbRQt JULEgGEAwCJATMEAAEIAB0WIQR7u8hBFZkjSJZITfG74LB10kWImgUCZdTaQgAKCRC74LB10kWI mt6zB/9ix1+cbRLwfxeQ4PhmyOPOXIy8AuaLRA62hsETFxjPOeumiQBXsvdbnzwsuTrbTPtKCkZ d9K8yRw2rpCG80loeAT/9uGKYzkw3j1XJrIDpXnpsp8/Jtb8zF38E0za2jDekAKVKziUs+xQQ1c VGAgxP7oyKW/Scrkzja41qVLuoQIjHK0k+XLXLFgkgs+iCPInGvRs4Nw50YuoG4okbZHICuchYX EJ07EGSqae4vCKCv3jipCwptC1gLJZ1gNSnfYu6Xla4IZmsWsXnVgCegTbcY8e9LdmySCBYecUL 5FttxJXT+6E5QTHUN3Tw59fKT1yFq1PkGQFvhgv0TDslB5er X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Rspamd-Queue-Id: 09837140010 X-Rspam-User: X-Stat-Signature: 55qzuw3f3dt1ota44ouo4mcgbza4qh78 X-Rspamd-Server: rspam03 X-HE-Tag: 1708448326-558054 X-HE-Meta: U2FsdGVkX19Sbru8GdILSwduyYCD8y11yJlC8IYYubD6olWcLA9P4IpXtlVDSPRB8lExtR2/kcXGsPF4EMrCvrSlC8oNGj6dJLXA768GMzZVXCE1/BFW7jy9yGgU3MKrhtYGnHqpH5ZBY5IJSl0nHxxe/rY9efVRScWQie/fdzlrcGUuW6DOi+7QkphzJsLoLXqnXNnmprIlQWELnB7uJGewABfVus+CvZ6Sk+s4Pcd7GxK2VX/j/9KS5ebQyKoZWKz58RVwaLjp0HpnohmlvQ8VTUiilTygF1TIMSRFuqhjyFq4DyEWFj4H/CIkgNFOBqswQqQkM7Q9dqg+7G7RIs1OWso2fhKYR1YRXyfT0otNS3LtLPK7GJ0g3qhRG/PEspWQ59LCrbSEW5NU2n/IB+73SPwZ4P+k8kptE2qJ2dYSw04B6dEMoiOOq8fRa5SslaeTA+ILKtSbI9pcT/s4VlvO6YVDgXmzRZxWyFchkdOGdqvKL95sP5coiWigMsj++vd0j5IDNdqpmBskqRARnuZkmFV0AjEWIdf+DERhd6DtOLHWI2NGMz2jvq8pdIkQl06+tocdqGsvM74D2xCnmHVIMaTBEEKUUgXxhFAcc9Yz3lwsvtvu4yy6ODTZgWjv89ByKiGwJKYyKsrQnXWlN5O6zBDySEihMnuChcaaDk4ct82U6WFpHZ+A5DHqgpdRwdFQMmrQAFyUofToWdVqSn8pxfcNHXBTFaaKiYgmg3g3FAPD8EFKKPRvW58aCv4k4I1eHlsgy7C7Sd/b8TYmdF5fYffeIYFgneAsViiCHtlvAzKt0BSKj9XUbJikP6UC/A7tHmdl3zpVzQEtRel7mED4/TnXJ5IVV/MYSeJp5utr1L3UB5nvxtSYV67wv/CJu6UFoqn0avdlUH+TigfUFYoIH9ALdhO0 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 SLAB_KASAN flag prevents merging of caches in some configurations, which is handled in a rather complicated way via kasan_never_merge(). Since we now have a generic SLAB_NO_MERGE flag, we can instead use it for KASAN caches in addition to SLAB_KASAN in those configurations, and simplify the SLAB_NEVER_MERGE handling. Signed-off-by: Vlastimil Babka Tested-by: Xiongwei Song Reviewed-by: Chengming Zhou Reviewed-by: Andrey Konovalov --- include/linux/kasan.h | 6 ------ mm/kasan/generic.c | 16 ++++------------ mm/slab_common.c | 2 +- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index dbb06d789e74..70d6a8f6e25d 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -429,7 +429,6 @@ struct kasan_cache { }; size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object); -slab_flags_t kasan_never_merge(void); void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, slab_flags_t *flags); @@ -446,11 +445,6 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache, { return 0; } -/* And thus nothing prevents cache merging. */ -static inline slab_flags_t kasan_never_merge(void) -{ - return 0; -} /* And no cache-related metadata initialization is required. */ static inline void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index df6627f62402..d8b78d273b9f 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -334,14 +334,6 @@ DEFINE_ASAN_SET_SHADOW(f3); DEFINE_ASAN_SET_SHADOW(f5); DEFINE_ASAN_SET_SHADOW(f8); -/* Only allow cache merging when no per-object metadata is present. */ -slab_flags_t kasan_never_merge(void) -{ - if (!kasan_requires_meta()) - return 0; - return SLAB_KASAN; -} - /* * Adaptive redzone policy taken from the userspace AddressSanitizer runtime. * For larger allocations larger redzones are used. @@ -372,13 +364,13 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, /* * SLAB_KASAN is used to mark caches that are sanitized by KASAN * and that thus have per-object metadata. - * Currently this flag is used in two places: + * Currently this flag is used in one place: * 1. In slab_ksize() to account for per-object metadata when * calculating the size of the accessible memory within the object. - * 2. In slab_common.c via kasan_never_merge() to prevent merging of - * caches with per-object metadata. + * Additionally, we use SLAB_NO_MERGE to prevent merging of caches + * with per-object metadata. */ - *flags |= SLAB_KASAN; + *flags |= SLAB_KASAN | SLAB_NO_MERGE; ok_size = *size; diff --git a/mm/slab_common.c b/mm/slab_common.c index 238293b1dbe1..7cfa2f1ce655 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -50,7 +50,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work, */ #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \ - SLAB_FAILSLAB | SLAB_NO_MERGE | kasan_never_merge()) + SLAB_FAILSLAB | SLAB_NO_MERGE) #define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \ SLAB_CACHE_DMA32 | SLAB_ACCOUNT)