From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F8C5C433E0 for ; Mon, 15 Mar 2021 16:05:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C12A564EE5 for ; Mon, 15 Mar 2021 16:05:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C12A564EE5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 36A5F6B0036; Mon, 15 Mar 2021 12:05:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31ABD6B006C; Mon, 15 Mar 2021 12:05:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 194426B0070; Mon, 15 Mar 2021 12:05:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id EA9A36B0036 for ; Mon, 15 Mar 2021 12:05:08 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8FB904853 for ; Mon, 15 Mar 2021 16:05:08 +0000 (UTC) X-FDA: 77922582696.30.4CDEE50 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf29.hostedemail.com (Postfix) with ESMTP id 2C2116909A for ; Mon, 15 Mar 2021 15:35:48 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8C8F8AC23; Mon, 15 Mar 2021 15:35:44 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Paul E . McKenney" , linux-btrfs@vger.kernel.org, David Sterba , Vlastimil Babka , Oliver Glitta Subject: [PATCH] [PATCH] mm, slub: enable slub_debug static key when creating cache with explicit debug flags Date: Mon, 15 Mar 2021 16:34:15 +0100 Message-Id: <20210315153415.24404-1-vbabka@suse.cz> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2C2116909A X-Stat-Signature: ga74xn6ednrimikt6z1yis3cq8kwrhpy Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1615822548-835911 Content-Transfer-Encoding: quoted-printable 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: Commit ca0cab65ea2b ("mm, slub: introduce static key for slub_debug()") introduced a static key to optimize the case where no debugging is enable= d for any cache. The static key is enabled when slub_debug boot parameter is pa= ssed, or CONFIG_SLUB_DEBUG_ON enabled. However, some caches might be created with one or more debugging flags explicitly passed to kmem_cache_create(), and the commit missed this. Thu= s the debugging functionality would not be actually performed for these caches = unless the static key gets enabled by boot param or config. This patch fixes it by checking for debugging flags passed to kmem_cache_create() and enabling the static key accordingly. Note such explicit debugging flags should not be used outside of debuggin= g and testing as they will now enable the static key globally. btrfs_init_cache= p() creates a cache with SLAB_RED_ZONE but that's a mistake that's being corr= ected [1]. rcu_torture_stats() creates a cache with SLAB_STORE_USER, but that i= s a testing module so it's OK and will start working as intended after this p= atch. Also note that in case of backports to kernels before v5.12 that don't ha= ve 59450bbc12be ("mm, slab, slub: stop taking cpu hotplug lock"), static_branch_enable_cpuslocked() should be used. [1] https://lore.kernel.org/linux-btrfs/20210315141824.26099-1-dsterba@su= se.com/ Reported-by: Oliver Glitta Fixes: ca0cab65ea2b ("mm, slub: introduce static key for slub_debug()") Signed-off-by: Vlastimil Babka --- mm/slub.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 350a37f30e60..cd6694ad1a0a 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3827,6 +3827,15 @@ static int calculate_sizes(struct kmem_cache *s, i= nt forced_order) =20 static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags) { +#ifdef CONFIG_SLUB_DEBUG + /* + * If no slub_debug was enabled globally, the static key is not yet + * enabled by setup_slub_debug(). Enable it if the cache is being + * created with any of the debugging flags passed explicitly. + */ + if (flags & SLAB_DEBUG_FLAGS) + static_branch_enable(&slub_debug_enabled); +#endif s->flags =3D kmem_cache_flags(s->size, flags, s->name); #ifdef CONFIG_SLAB_FREELIST_HARDENED s->random =3D get_random_long(); --=20 2.30.1