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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 E6791C433DB for ; Mon, 15 Mar 2021 17:16:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB19164EFC for ; Mon, 15 Mar 2021 17:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235080AbhCORQT (ORCPT ); Mon, 15 Mar 2021 13:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234337AbhCORQP (ORCPT ); Mon, 15 Mar 2021 13:16:15 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A7C2C06174A for ; Mon, 15 Mar 2021 10:16:15 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id o10so3431794plg.11 for ; Mon, 15 Mar 2021 10:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=vkbgOXNRjmxTcw1oc4wVA8/mmcZsN9FbZ3cSv6WDfss=; b=vHGrIXtbAnB0hsWFkRVsBVtDapqSeQHP9YPXjdXzuGzaReV6xIo5HCJXKVwi7/3Eij cJSNy9cqf2x5xni7GXxxGfmNtjAglgbxHox2FOwrJ6vR2XDTBSzeAa4lgZR+3JgoksTT mDzdOjPd15zKTeTQFlf4RHgdBM0r62m9L+juaXMmZbB8yKsS1JvyIsgUJhaNveU6ktLF MmD/d60dPSRQKAseQOCk15PbyOx25nN6AgjMebpx9+jdWJjap/u0L1Rc9va8LuZp/cez 5j4vr76o6VEwT9epPVvwtyF9OQUfTOgFJR8G3fFTt4iYkrRWe3BnUYiX1WVPUlBKte5u agQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=vkbgOXNRjmxTcw1oc4wVA8/mmcZsN9FbZ3cSv6WDfss=; b=MxE3QEP++IHK5+I5+XB7C5X3lND997WMiajf3oGgjulX0c2B+00c6MJbemp3s8EMaw WtfFmWfEDEkVPUlY1Ya1iHFJMoQxklwrD9/6kD2nDubo6bjyQ+7z5TTn08hunEKpmBwh /G2EuMY6Cu0fiTTzFZCFi7ft6UMavNywUIXJBjnG4dy6sEIkLYIPLKLYK79k9kAcqT1r FeiuStjCh2csJC12OuFhwvlbQ39GtvpYt/LRUAVS/ynfL0ZlyQHXHTBlRhcRlSc78GLs tSFNrBQbkW+qGIggUpT5yBdkbbzNrw83bl0zSq5UjuqKhMpT1jwr9ifEGDMd8nJvQuFS +fFQ== X-Gm-Message-State: AOAM533uDjX6NRUEUcisrz9kopVQtXkNtzfrwFIpsEhBq42dCBJKZye+ P97m/FXHk4SiMOYtY7QGNYwXEg== X-Google-Smtp-Source: ABdhPJynimVWlz2D9pxTZJUTa2nWLBJAmcFtq7xh/TIQTYYAUqAXCU+Nu07rPMO12pC4brn1UhRr1Q== X-Received: by 2002:a17:90a:b293:: with SMTP id c19mr58684pjr.193.1615828574415; Mon, 15 Mar 2021 10:16:14 -0700 (PDT) Received: from [2620:15c:17:3:15aa:7e35:d042:44e5] ([2620:15c:17:3:15aa:7e35:d042:44e5]) by smtp.gmail.com with ESMTPSA id h6sm14006271pfb.157.2021.03.15.10.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 10:16:13 -0700 (PDT) Date: Mon, 15 Mar 2021 10:16:13 -0700 (PDT) From: David Rientjes To: Vlastimil Babka cc: Andrew Morton , Christoph Lameter , Pekka Enberg , Joonsoo Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Paul E . McKenney" , 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 In-Reply-To: <20210315153415.24404-1-vbabka@suse.cz> Message-ID: <2d80f81a-ed85-a36f-6527-b75da3ae209e@google.com> References: <20210315153415.24404-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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.) > [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 > --- > 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(); 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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 2FC45C433DB for ; Mon, 15 Mar 2021 17:39:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BAF8864F0C for ; Mon, 15 Mar 2021 17:39:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BAF8864F0C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 437A96B0036; Mon, 15 Mar 2021 13:39:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40E976B006C; Mon, 15 Mar 2021 13:39:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D6346B0072; Mon, 15 Mar 2021 13:39:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0127.hostedemail.com [216.40.44.127]) by kanga.kvack.org (Postfix) with ESMTP id 112A56B0036 for ; Mon, 15 Mar 2021 13:39:57 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B6C96181AF5C6 for ; Mon, 15 Mar 2021 17:39:56 +0000 (UTC) X-FDA: 77922821592.14.62C3DA5 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf30.hostedemail.com (Postfix) with ESMTP id C11C2E03856C for ; Mon, 15 Mar 2021 17:16:15 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id t18so9152859pjs.3 for ; Mon, 15 Mar 2021 10:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=vkbgOXNRjmxTcw1oc4wVA8/mmcZsN9FbZ3cSv6WDfss=; b=vHGrIXtbAnB0hsWFkRVsBVtDapqSeQHP9YPXjdXzuGzaReV6xIo5HCJXKVwi7/3Eij cJSNy9cqf2x5xni7GXxxGfmNtjAglgbxHox2FOwrJ6vR2XDTBSzeAa4lgZR+3JgoksTT mDzdOjPd15zKTeTQFlf4RHgdBM0r62m9L+juaXMmZbB8yKsS1JvyIsgUJhaNveU6ktLF MmD/d60dPSRQKAseQOCk15PbyOx25nN6AgjMebpx9+jdWJjap/u0L1Rc9va8LuZp/cez 5j4vr76o6VEwT9epPVvwtyF9OQUfTOgFJR8G3fFTt4iYkrRWe3BnUYiX1WVPUlBKte5u agQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=vkbgOXNRjmxTcw1oc4wVA8/mmcZsN9FbZ3cSv6WDfss=; b=KjNYaWtHqOAPjPj/YiMscSa8xAQLZT0rRBDh+9yrY9GDYZ04lsSKg1sNOB15y81P7K tAP3tNcg1OcOrsR5ihWHgYUNdTQySK0wFUj3EP8qFdQ/ABu/czH1Wad9MszgPusH/gZS Q27poig7oyDWu9WtaMgUW/iqopeLGbB40dSscE4/gjRDvLEUwZNjF5P5V2sdKZwkIR1N kd0kETsukPmvNvEh2FC74lhhewwGo/rxQHL1j2jPlRZ1IPjFvLu83o+m68YGeuVeLvZ2 XP8ROjkaNgKaINH8twybfCXexDAEyOe/qq85hlAZ3C5+VwH4wOlLWSJgqeb5haWTlgJc SBXw== X-Gm-Message-State: AOAM531FjDgxaEFbBk4ObcDFeYd8obMokCSDCxz7ykhQ08Cfqca0tS+v eoCMY/JFYY+W0EOAazMTa7ExwQ== X-Google-Smtp-Source: ABdhPJynimVWlz2D9pxTZJUTa2nWLBJAmcFtq7xh/TIQTYYAUqAXCU+Nu07rPMO12pC4brn1UhRr1Q== X-Received: by 2002:a17:90a:b293:: with SMTP id c19mr58684pjr.193.1615828574415; Mon, 15 Mar 2021 10:16:14 -0700 (PDT) Received: from [2620:15c:17:3:15aa:7e35:d042:44e5] ([2620:15c:17:3:15aa:7e35:d042:44e5]) by smtp.gmail.com with ESMTPSA id h6sm14006271pfb.157.2021.03.15.10.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 10:16:13 -0700 (PDT) Date: Mon, 15 Mar 2021 10:16:13 -0700 (PDT) From: David Rientjes To: Vlastimil Babka cc: Andrew Morton , Christoph Lameter , Pekka Enberg , Joonsoo Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Paul E . McKenney" , 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 In-Reply-To: <20210315153415.24404-1-vbabka@suse.cz> Message-ID: <2d80f81a-ed85-a36f-6527-b75da3ae209e@google.com> References: <20210315153415.24404-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Stat-Signature: rjonpcgumkw1s3f4t1isj6yhzny6cn9u X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C11C2E03856C Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf30; identity=mailfrom; envelope-from=""; helo=mail-pj1-f50.google.com; client-ip=209.85.216.50 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615828575-251718 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: 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.) > [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 > --- > 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();