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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 D217CC2B9FD for ; Wed, 12 May 2021 16:19:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B405561C8D for ; Wed, 12 May 2021 16:19:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235235AbhELQTb (ORCPT ); Wed, 12 May 2021 12:19:31 -0400 Received: from mx2.suse.de ([195.135.220.15]:51850 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236026AbhELPgl (ORCPT ); Wed, 12 May 2021 11:36:41 -0400 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 19A58B1B8; Wed, 12 May 2021 15:35:30 +0000 (UTC) Subject: Re: [PATCH 5.10 518/530] mm, slub: enable slub_debug static key when creating cache with explicit debug flags To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org, Oliver Glitta , David Rientjes , Christoph Lameter , Pekka Enberg , Joonsoo Kim , "Paul E. McKenney" , Andrew Morton , Linus Torvalds , Sasha Levin References: <20210512144819.664462530@linuxfoundation.org> <20210512144836.780038842@linuxfoundation.org> From: Vlastimil Babka Message-ID: Date: Wed, 12 May 2021 17:35:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210512144836.780038842@linuxfoundation.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/12/21 4:50 PM, Greg Kroah-Hartman wrote: > From: Vlastimil Babka > > [ Upstream commit 1f0723a4c0df36cbdffc6fac82cd3c5d57e06d66 ] > > Commit ca0cab65ea2b ("mm, slub: introduce static key for slub_debug()") > introduced a static key to optimize the case where no debugging is > enabled for any cache. The static key is enabled when slub_debug boot > parameter is passed, 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. > Thus 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 > debugging and testing as they will now enable the static key globally. > btrfs_init_cachep() creates a cache with SLAB_RED_ZONE but that's a > mistake that's being corrected [1]. rcu_torture_stats() creates a cache > with SLAB_STORE_USER, but that is a testing module so it's OK and will > start working as intended after this patch. > > Also note that in case of backports to kernels before v5.12 that don't > have 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@suse.com/ > > Link: https://lkml.kernel.org/r/20210315153415.24404-1-vbabka@suse.cz > Fixes: ca0cab65ea2b ("mm, slub: introduce static key for slub_debug()") > Signed-off-by: Vlastimil Babka > Reported-by: Oliver Glitta > Acked-by: David Rientjes > Cc: Christoph Lameter > Cc: Pekka Enberg > Cc: Joonsoo Kim > Cc: "Paul E. McKenney" > Signed-off-by: Andrew Morton > Signed-off-by: Linus Torvalds > Signed-off-by: Sasha Levin Uh, rather not release this to stable without the followup fix: https://lore.kernel.org/linux-mm/20210504120019.26791-1-vbabka@suse.cz/ > --- > mm/slub.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/mm/slub.c b/mm/slub.c > index 05a501b67cd5..e4f7978d43c2 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -3779,6 +3779,15 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order) > > 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 = kmem_cache_flags(s->size, flags, s->name); > #ifdef CONFIG_SLAB_FREELIST_HARDENED > s->random = get_random_long(); >