From patchwork Mon Jul 15 20:29:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13733874 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 71163C3DA4B for ; Mon, 15 Jul 2024 20:29:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA53A6B009B; Mon, 15 Jul 2024 16:29:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D50A6B00AA; Mon, 15 Jul 2024 16:29:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CCC46B009E; Mon, 15 Jul 2024 16:29:43 -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 9CEB96B00A5 for ; Mon, 15 Jul 2024 16:29:43 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 41BD1121385 for ; Mon, 15 Jul 2024 20:29:43 +0000 (UTC) X-FDA: 82343127846.23.880C2FF Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf03.hostedemail.com (Postfix) with ESMTP id CA70320029 for ; Mon, 15 Jul 2024 20:29:40 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=SwlIHH5d; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="o3BTn/mj"; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=SwlIHH5d; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="o3BTn/mj"; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721075361; a=rsa-sha256; cv=none; b=n8kyQ4kphARKuWg93XQu/scyPQrIsykJtLvHxpnKbPr7iEUjxmbkNQkI5gzKvdy12z6PPH ASSYskFbbDQmIthpWApuqZlpTGyqN4ewBKYJFVXoL/C8byeS4jj622hn+tpGYT7KRmD6aD 6t/uuBzAMutDEKSlcs6oZsfsjb3jDto= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=SwlIHH5d; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="o3BTn/mj"; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=SwlIHH5d; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="o3BTn/mj"; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 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=1721075361; 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=NU1ukOjEPV7zEMcpTecl7WdxnTW88aCY09Hfdb+DK10=; b=uqQkQJYRZPfG9c7OmzzvHwSV8ANsJNo/Zc8AcD9YjYFDBfs2QX2dryzbrssjGetUvrVvyV kWtaYWEfYtdV7o79JizPtD+T7jtdXQEUFRMFJ9XILvircSUmah7gHBJpOB07A/B8/dcqVE afhP6CVK2Xhu4FFffDRf322JXWDjGo4= 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-out1.suse.de (Postfix) with ESMTPS id 161FB21BCE; Mon, 15 Jul 2024 20:29:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1721075379; 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=NU1ukOjEPV7zEMcpTecl7WdxnTW88aCY09Hfdb+DK10=; b=SwlIHH5d0ynfQ2BNBAJQLY3/sIgnYBrQFJjZOlOwPEVsX3LKgz9QDz/5pEvFogKr8ImAr3 uDSCuxn3SbLkgB0p6T5MXVnoZpkRoCxI0ZUjMLC+UWX1kYFRnwq85/vXupm0TkfoW6BEhh ucAONbfc+WVe/TH5KP+axsZGc9U6vpY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1721075379; 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=NU1ukOjEPV7zEMcpTecl7WdxnTW88aCY09Hfdb+DK10=; b=o3BTn/mjXjGJHsMvmm/YT9CypKvUmnDz59+qTmH6ye4Cy6nFtkAELn3eaYsl2cPgg2PfgP KtKQz92g/45hsCBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1721075379; 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=NU1ukOjEPV7zEMcpTecl7WdxnTW88aCY09Hfdb+DK10=; b=SwlIHH5d0ynfQ2BNBAJQLY3/sIgnYBrQFJjZOlOwPEVsX3LKgz9QDz/5pEvFogKr8ImAr3 uDSCuxn3SbLkgB0p6T5MXVnoZpkRoCxI0ZUjMLC+UWX1kYFRnwq85/vXupm0TkfoW6BEhh ucAONbfc+WVe/TH5KP+axsZGc9U6vpY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1721075379; 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=NU1ukOjEPV7zEMcpTecl7WdxnTW88aCY09Hfdb+DK10=; b=o3BTn/mjXjGJHsMvmm/YT9CypKvUmnDz59+qTmH6ye4Cy6nFtkAELn3eaYsl2cPgg2PfgP KtKQz92g/45hsCBw== 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 EACBD1395F; Mon, 15 Jul 2024 20:29:38 +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 kEgRObKGlWbvUwAAD6G6ig (envelope-from ); Mon, 15 Jul 2024 20:29:38 +0000 From: Vlastimil Babka Date: Mon, 15 Jul 2024 22:29:30 +0200 Subject: [PATCH RFC 4/6] mm, slab: simplify kmem_cache_release() MIME-Version: 1.0 Message-Id: <20240715-b4-slab-kfree_rcu-destroy-v1-4-46b2984c2205@suse.cz> References: <20240715-b4-slab-kfree_rcu-destroy-v1-0-46b2984c2205@suse.cz> In-Reply-To: <20240715-b4-slab-kfree_rcu-destroy-v1-0-46b2984c2205@suse.cz> To: "Paul E. McKenney" , Joel Fernandes , Josh Triplett , Boqun Feng , Christoph Lameter , David Rientjes Cc: Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Julia Lawall , Jakub Kicinski , "Jason A. Donenfeld" , "Uladzislau Rezki (Sony)" , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, rcu@vger.kernel.org, Vlastimil Babka X-Mailer: b4 0.14.0 X-Rspamd-Action: no action X-Spamd-Bar: / X-Stat-Signature: njpsopsbxuqsgegebhny8t94zri3ukam X-Rspamd-Queue-Id: CA70320029 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1721075380-85854 X-HE-Meta: U2FsdGVkX1+qdUmWH+yqp2452bLn+LWWdfx6QoDoXbbPYO01XmzmK4q8mlT85YTq8hUgWheaex1cxaYUJQZl66RZ0elJhenykSl+nqZt5hxsEE6UQ+3bW5/dKSvVOZqgX0LeahZggh5bQM8MptDBmRp9lF91NYyDzPl81lkJ2ihBnVxwNjBlc3Ex9Lr7qgfOgrs9vEeKWZoTssPwZYFt/BvCPOzme+Q0BGhtPZeS9g4U5LQ2n7l8Svn3XfGWWyG+kmrNf4anWSrrvfwmr207NRtoNIS9IUxe48rlpXAiuBL1C9IC6W3zJyGTycimemNEBaIFEkH8S2l7zHlMPzWTGVEhUNVh+Ys3yhNQdG4zAVQbfiNQ0AXi4LFprPrJ6TIpl5B/zo7v+hW09AEeVHNhhnqYgG4IiKdhpjc2ZDQ2bPA2eJfOwsLJjLzVtmCXDd8dk5qzup2Xm3eGq0qMN6cVYwt48l9yNnd/l+C1j3KDyT30q9U8vPx1zVZ7MWbopvbFPlUKanx4U+sMhkWKz7p4N8XlsJLb6pQvlOJ8w+gMlPQGUqUFpABoYjKCcicycoc/0hes7Ga/bWJIW1REuKUFQvBMAOGed9MiNWk1gOcMR/OUoS7ue+xTDFoTw9z7RSps921Y3YPLRAFX9qYSaj9iUVhWoZPaF/GVDaGuKzgJRt0Q4Ec8dcqsWV7WHJbC6Tm05qGkx1K/fPIK2GCvYeiDODxrPEkHvhxsLjZlZZqpfmhX6o3BezSRV3af9/d+Bjtfu9Nvst2ZI5ROCkhCagrq+jub4QAgO1b7VxAelbZr41dysPGKqSUtxkC8rZdgb55yCJdzO1FGNNOrrM4bHj33PLKuQ2OXLdGNSpnD6h0scg/upQrBzwjHyrT2z9QVOclmSF5Pk8DNUYbwFDHEiLPL0XbJ/+ol1H+h6pZW3Vdf0fbsc6iiCQV5cNsZfDhkUL+YxGbLLycLboHSmGDCRUw efVnK3D9 nD5xuUcnpBmzkc39rfELQUGvX9EgLj4n3+7V0THyrOdZF7gpZpuctE5ARbWvlZVfEDPmH9/WB5gGKI3e29opab7vnEMridmuTz4+DOkUcepLRL7Wsi9iQ3q9jOQprGdDi1xn799fSVhD0VbrOX3PqG7S8aWqSEPhvPhVFNW4CfAstAxvo9F7CXKC3RhXM0bATVzdtfZa98i+UlV9Y65eyv2fooU0HO7eUkdfzwYbdfTR9d+oYM2ZXnk2nWmpaDAvUQUJ1z0b5/mXJxQ3PhnA+1mO13OCYyLCQwLyapoW/pOjuWIDQnrAEDVexvejwUZI1X0lC3M6iuGkTXuIMvsZgs0649A== 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: kfence_shutdown_cache() is now called always just before kmem_cache_release() so move it there. Also replace two variants of the functions by using __is_defined(SLAB_SUPPORTS_SYSFS). Signed-off-by: Vlastimil Babka --- mm/slab_common.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 2eef5ad37fa7..57962e1a5a86 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -486,7 +486,6 @@ kmem_buckets *kmem_buckets_create(const char *name, slab_flags_t flags, } EXPORT_SYMBOL(kmem_buckets_create); -#ifdef SLAB_SUPPORTS_SYSFS /* * For a given kmem_cache, kmem_cache_destroy() should only be called * once or there will be a use-after-free problem. The actual deletion @@ -495,18 +494,12 @@ EXPORT_SYMBOL(kmem_buckets_create); */ static void kmem_cache_release(struct kmem_cache *s) { - if (slab_state >= FULL) { + kfence_shutdown_cache(s); + if (__is_defined(SLAB_SUPPORTS_SYSFS) && slab_state >= FULL) sysfs_slab_release(s); - } else { + else slab_kmem_cache_release(s); - } -} -#else -static void kmem_cache_release(struct kmem_cache *s) -{ - slab_kmem_cache_release(s); } -#endif static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work) { @@ -531,10 +524,8 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work) rcu_barrier(); - list_for_each_entry_safe(s, s2, &to_destroy, list) { - kfence_shutdown_cache(s); + list_for_each_entry_safe(s, s2, &to_destroy, list) kmem_cache_release(s); - } } void slab_kmem_cache_release(struct kmem_cache *s) @@ -591,7 +582,6 @@ void kmem_cache_destroy(struct kmem_cache *s) schedule_work(&slab_caches_to_rcu_destroy_work); mutex_unlock(&slab_mutex); } else { - kfence_shutdown_cache(s); kmem_cache_release(s); } }