Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3485310pxf; Mon, 15 Mar 2021 10:33:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBWhIOneaj2ZTimOKzkp+T6zoRvqfjsjChoqBPYw7xTpT7l161svMq8034CqSLy1mDmb5C X-Received: by 2002:a17:907:a042:: with SMTP id gz2mr24597436ejc.174.1615829630897; Mon, 15 Mar 2021 10:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615829630; cv=none; d=google.com; s=arc-20160816; b=HW2mYF3kVjz1A/xq4iUOn1/b00s8llLcacNPeMLcPgG4/SFrV2AN8ONHzcAEG6MHzk tmFTZSgQY6nQzaOeX7yrozNrbpo6asrFlZDWjgNSZ2JwxEveZOb+tRNpSQ5E8hBfx+Ay to6BxgtAkM9mGoMJneZLB1iKazTCP6mFYCj4tbw4nXzjOyLuAx086J+b3QyKx4b9uicd ZQtqXO4+EPXGsaWlKP2MgeX/WaubRlkZ9eVD4LNTEqngeEdyEPu3JI6KCfnQlxIQbPh7 hMQ1Pkpx8HqwMzbxcsjhmcpiKYvmR1Upiuku/+6u0pRQxmb5FVgbvO9jf1kXvcpRUqBb LKNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=CXVIj7xvx9jDZmkS5nTXNCkWfy1y1hRYT6Cut3tk328=; b=W3Zemu3izVUbL48yqmHU1h7YMCX0Z4Q6HtFkFL3AHhTcpJS0VGWxa7kOXIuFUGdnuZ PfkeXhKhwiGKNJhohx+oBqZHPzP6DlitOCmURIoYP2zkqX4mF0VcQNq7VOyENlGl2eTL fWAGPYpMUo6OgVJOKKA39Fii+7rCfI9Xm5asj8U0drL0iTOaHo6fTRlbqOwCug1YMAV8 Ee059TmjA1m+OyiJcToTKjmMXCMygCbn9kfFymciyQeS0ptpvxmY3QA3csFKyzIqskx1 RLVAO6c53+IwTfTigKa97qfOWtUZaZaCXxO6XGPyZKNK+psI35xfpoH7EqhIIbBVHAf4 OdEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ITjF77TL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g16si11754085ejf.96.2021.03.15.10.33.27; Mon, 15 Mar 2021 10:33:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ITjF77TL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236038AbhCORcS (ORCPT + 99 others); Mon, 15 Mar 2021 13:32:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:38934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234836AbhCORcI (ORCPT ); Mon, 15 Mar 2021 13:32:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BE55F64E98; Mon, 15 Mar 2021 17:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615829527; bh=VRcbQL7CvY6cs5rG3WUG31fwN9zEEEuuniKBvXrs38c=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=ITjF77TLcgpBt5MuUWlr0DwatVKlFdMISr/3LmxHyhyFvMKGp6gQn80vGywiW0w31 FpvxijhAGClviF7uDoWK4gaNArg84LppRmlLJXz+bXRoR+3VI0gmSLvMzM1Jm+MI2k dg5X5Vzjqe7zn6MVXxbrVduAvjWqo4i+ifgAhjpEuiRoSMYr3tJI5wEWwJTNa/HqEi 0OCY1UxilLOOXcKbekTTfRzdVb+ikDVwpmIBG4uAdnDY+8YX6CRPv6nNkwRmeqlVBM iNLMRzVpYdBXNd8lOlY0wv4gXJ3TXHPQLHcGR2m8m/W9g52M3h5dKTLxxL6HXZU8aJ 94TUcdCYK9HNg== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 67894352261C; Mon, 15 Mar 2021 10:32:07 -0700 (PDT) Date: Mon, 15 Mar 2021 10:32:07 -0700 From: "Paul E. McKenney" To: Vlastimil Babka Cc: David Rientjes , Andrew Morton , Christoph Lameter , Pekka Enberg , Joonsoo Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, David Sterba , Oliver Glitta Subject: Re: [PATCH] [PATCH] mm, slub: enable slub_debug static key when creating cache with explicit debug flags Message-ID: <20210315173207.GN2696@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20210315153415.24404-1-vbabka@suse.cz> <2d80f81a-ed85-a36f-6527-b75da3ae209e@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 15, 2021 at 06:28:42PM +0100, Vlastimil Babka wrote: > On 3/15/21 6:16 PM, David Rientjes wrote: > > On Mon, 15 Mar 2021, Vlastimil Babka wrote: > > > >> 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. > >> > > > > Since this affects 5.9+, is the plan to propose backports to stable with > > static_branch_enable_cpuslocked() once this is merged? (I notice the > > absence of the stable tag here, which I believe is intended.) > > I was thinking about it, and since the rcutorture user is only in -next (AFAICS) > and btrfs user was unintended, it didn't seem to meet stable criteria to me. But > I won't mind if it's backported. I had better ask... Should rcutorture be doing something different? Thanx, Paul > >> [1] https://lore.kernel.org/linux-btrfs/20210315141824.26099-1-dsterba@suse.com/ > >> > >> Reported-by: Oliver Glitta > >> Fixes: ca0cab65ea2b ("mm, slub: introduce static key for slub_debug()") > >> Signed-off-by: Vlastimil Babka > > > > Acked-by: David Rientjes > > Thanks! > > >> --- > >> 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, 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(); > > >