From patchwork Fri Feb 23 18:27:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13569864 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 D507CC54798 for ; Fri, 23 Feb 2024 18:27:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CE6B6B0080; Fri, 23 Feb 2024 13:27:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 980776B007E; Fri, 23 Feb 2024 13:27:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F8C16B0080; Fri, 23 Feb 2024 13:27:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 695CE6B007D for ; Fri, 23 Feb 2024 13:27:46 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 32F771611C5 for ; Fri, 23 Feb 2024 18:27:44 +0000 (UTC) X-FDA: 81823902048.11.0B0544D Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf10.hostedemail.com (Postfix) with ESMTP id 0B872C0005 for ; Fri, 23 Feb 2024 18:27:40 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=TwrUziIB; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=mbWlmygY; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=TwrUziIB; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=mbWlmygY; dmarc=none; spf=pass (imf10.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=1708712862; 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:dkim-signature; bh=YO6OeAHEfcyOnMDaYbuFQtLgT98NdTKboW4QLF6GI08=; b=DaRWII7kafswJQPt2NE4aCnCnJzCs3/oUtzHe10CE9dswASeTCyQD1HxevyHS9OIMEMv2V ftWc1rGYztkvBZzzs2CxbNaj6JckNNg5ZTxaUPGCv2huH3bUAHzxWSJ0GFyoCYGk64N0Sf 44OtLn/7AmHW81lST4jHbbi6ex+lDCo= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=TwrUziIB; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=mbWlmygY; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=TwrUziIB; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=mbWlmygY; dmarc=none; spf=pass (imf10.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=1708712862; a=rsa-sha256; cv=none; b=OJqGtGCuWhiYfsk9hCJaoIsUMEkTj8K0HTK3KkFDViLcOPkJgjFpIgD3pk3lrZy+J0C9o+ 8UQ6tOhchGOogTZlCwSGlXA8oF9A7g75sgR5k90GFidfCSBfQ8RP03EPznIaTgpHy13vJR eNOtB4NypEE23wuW/OZm2jBBNgQIqT0= 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 73D011FCDA; Fri, 23 Feb 2024 18:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1708712859; h=from:from:reply-to: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=YO6OeAHEfcyOnMDaYbuFQtLgT98NdTKboW4QLF6GI08=; b=TwrUziIBFL2uhqrYSUuzeqP1mcryO/cH+SQcX9cKxgX421rEJSZDVz8bSHpKcIKnaFXAh7 m/RoZT+NLMEfqrPdUKV+abvPpKptQvBy7Dt+kmk6EXfEPzlRYZKphP3d1AKg9uxSttWO/D ArBfDXSAO52TfrFGDOXnhm2KRxQboxE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1708712859; h=from:from:reply-to: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=YO6OeAHEfcyOnMDaYbuFQtLgT98NdTKboW4QLF6GI08=; b=mbWlmygYPYsRAT01nQRdqI8oW+QZYkRiQuVUxB9vdh0Bd/jgLEHbcWcPEeQzTFvH+NA7WE vhzuuiS1Yo9j3vAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1708712859; h=from:from:reply-to: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=YO6OeAHEfcyOnMDaYbuFQtLgT98NdTKboW4QLF6GI08=; b=TwrUziIBFL2uhqrYSUuzeqP1mcryO/cH+SQcX9cKxgX421rEJSZDVz8bSHpKcIKnaFXAh7 m/RoZT+NLMEfqrPdUKV+abvPpKptQvBy7Dt+kmk6EXfEPzlRYZKphP3d1AKg9uxSttWO/D ArBfDXSAO52TfrFGDOXnhm2KRxQboxE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1708712859; h=from:from:reply-to: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=YO6OeAHEfcyOnMDaYbuFQtLgT98NdTKboW4QLF6GI08=; b=mbWlmygYPYsRAT01nQRdqI8oW+QZYkRiQuVUxB9vdh0Bd/jgLEHbcWcPEeQzTFvH+NA7WE vhzuuiS1Yo9j3vAg== 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 41879133DC; Fri, 23 Feb 2024 18:27:39 +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 kPmxD5vj2GUaTQAAD6G6ig (envelope-from ); Fri, 23 Feb 2024 18:27:39 +0000 From: Vlastimil Babka Date: Fri, 23 Feb 2024 19:27:19 +0100 Subject: [PATCH v2 3/3] mm, slab, kasan: replace kasan_never_merge() with SLAB_NO_MERGE MIME-Version: 1.0 Message-Id: <20240223-slab-cleanup-flags-v2-3-02f1753e8303@suse.cz> References: <20240223-slab-cleanup-flags-v2-0-02f1753e8303@suse.cz> In-Reply-To: <20240223-slab-cleanup-flags-v2-0-02f1753e8303@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=3708; i=vbabka@suse.cz; h=from:subject:message-id; bh=oc217rqjv84A6cygyOWMLvkkVYYlf8fIgIHPUe4CqEI=; b=owEBbQGS/pANAwAIAbvgsHXSRYiaAcsmYgBl2OOY129UnZyUFxvKzDcfwYdqEhJtST9zIVQhR OzNq64oBqmJATMEAAEIAB0WIQR7u8hBFZkjSJZITfG74LB10kWImgUCZdjjmAAKCRC74LB10kWI mm6xB/4/euNwci9dIao8KK+SBBEedcYnZYBkvv/tfVj0jHJLbQRkDU7o18IDmCMksxzsn6GOBXY hWU77hCw7WZR01TCB62xaMRW0zCLIA0G06bqY9dvz33jRvBJCH9VBwzyNBAfZ/LcGTpL1GR/5sx zB/Zgky+tvMiAeSElsMcqFukRRZ++nF6UNa9NdGkSbr9Ox6qkWHuEPN96iNvR5yTCICx0egsZcj nd017gUj/VcmHvW3qxXHRIigA5JksKXUSLxXyaUT03QrYIfSlFxwFjslF2KknX6AGoDV7kJWqCo 9nYV61PnjZAKDEeC69HZCBItCBliGzH3GGI89D6yycYnxU83 X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0B872C0005 X-Stat-Signature: jnqxswin7hrq4qsba6hy4mgrzyqzc44b X-HE-Tag: 1708712860-538814 X-HE-Meta: U2FsdGVkX1+vedgQ68aApUPjfrb3Elo2X9IpJ/9sq1MAyyVBk3+TSsQ7V4ziiSNoAkBhJttPorKC/xOkIix2/V+xxg4D34OyjFyQMSY4PlHEeUfUiO7lYEWmuJ94+GmtBNZziJpC2PZnzFSStEoSnbJogY9pfI0KeDkOz6TC0yoKBO8ObtoLxU0MsUZTILtRRhWTlRBvn7az+yW4rqJS5oItpDR3+CDYBxOl7WBUNjAEAeXCVTtJKz2DvSOphAJHUUNmL+TpId253bEu7Qx+3KmVZyg8f0F6Q/hSyW6UZdTS0BWvLmxL7MJ2q6b46hYTYqg7XX6U7hGKPd6ZV25LoHyJF7psxuAoLWshkS5+H6TdNtD73J6aj/pQLY4e9RxbYpFjNgsqhuayF/RmK9AddAyWtlaZtMXZqtyopTmDsIN4r8WrKVpkG2BibmznzF06qWAfWJl/ihyby2+Eyaq7B5lMNk6mLXtuFzl+kWeMDrfDtjfG++hOPiZNzLcrBQ3c63zO5zNkuMZi0RH2XaCJWeiYZBMz023SPMN426kSH2f9WDqHgasXWUfw2gnw9SCBZ6H9lQ8QqgA6Qma/sP4fjdCaNIdgjjHOI+HKMQHsF3O1ww/APp62MmEO5jT9k94yp0jq7a/C7Yrb3Odf5VaPfLkZ7gKJu932bFUV9wo9Zp9VkMbjN0ksm1iMepOtE45fjEEOCFIOL9FnmNBVgps72RkZ9q2Bj+cL/Mk1GqdMaw6UQj26zFhn5aW76AGIHhkRtd9FL4Rls9ntAlRV5OHrdTVkVMs4Uh/kUIyyUPWJUtXRayfDalnw2rFvX/H2DXwWc2aNja1eyaMqZ/Lv/oQ+qfetva1j5KJ768atKu9qdVm2ED8naKUBv3LAZ5lYfdPyQPfxXRORS6K1KpMdTbCWJnGaXyiL4hPhuumX/44wpMy08U8SyipxgEoBbfmr68H1q4lD+rEsEkDqOSWdxiX NSas7lbL VoIZS02G4SxBTIo4BosF+fB4e8cCGNaup97T4fJeCPNQCOKE= 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. Tested-by: Xiongwei Song Reviewed-by: Chengming Zhou Reviewed-by: Andrey Konovalov Signed-off-by: Vlastimil Babka Tested-by: David Rientjes --- include/linux/kasan.h | 6 ------ mm/kasan/generic.c | 22 ++++++---------------- mm/slab_common.c | 2 +- 3 files changed, 7 insertions(+), 23 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..27297dc4a55b 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. @@ -370,15 +362,13 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, return; /* - * 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: - * 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. + * 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 + * slab_ksize() to account for per-object metadata when calculating the + * size of the accessible memory within the object. 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)