Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3393952pxf; Mon, 15 Mar 2021 08:37:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMnAfEf/MAiNidtCFHna25LVY7bicrSXQQwa9/AbHYWYCTojPevnl/QaLRUqpf/URc/Mww X-Received: by 2002:a05:6402:17af:: with SMTP id j15mr30719482edy.50.1615822642264; Mon, 15 Mar 2021 08:37:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615822642; cv=none; d=google.com; s=arc-20160816; b=tfHUZoxszKsrzc+V4LCmFX/Ue2Xck7lSycxSRDK4NZcn2k3QffTt4aHcLqeuJ8OSXN 307c7Z9t5RS9t4NrjK7fbSWJDvNnb3eQaIqbWej6UPRxJuzwa5Gb4R0Fb40e45mLYMSY 2wwgbhWBG1S+nC+qjzE0SF26TGnr7okc3ki+NWsnsQY0jiybGntj4WyE+Q0Wa1GEbgLY +WOoWH/kekUvXR0fW0atu8CkvDnYlCCPs0Jelt/qsG+cAEqkN7H5O6RKMe614IIYrwzb efLAqlFDT0nix1+6Y4Lp/m1/yLGtq9TfwTKFNipCr8qwjYtxg0f2ekXA9fECr2B9aGdX IrPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=3RMPkqajQyf5SSRys5hvDsqAluKPf1nB/Q1IiySZrqo=; b=Hu/j1dNIy/Hu5QKeXSR/BB8Y5gQcofqIGJzWyKqZQ+bHYOv8qk1Q95IIJfEPbclTbN CU8zrAEygaKEWZZG+K7MOC2iZzCnE3ZnxwnqnwfryqdK74dobf3z2AXfwzsOzpQIDnMQ eVEPy2dnv44V1pLbGA2Kcrkmze0nS621Pz6HRq/ZFS124DXEFPCEbfKu5nHQxLUcIQSi pbfiO1+yjHmSSvNHnYHXeP1wJvV4sSOhwO78q3mbOwA19GpuKDLNSmhxV3g3Lm85Hcd8 Mzwi62j1gwFgYKYUX8Q+A0tMOWMMDnbKS9sLZMKtl9o24MAcVOyEaXONPNyBjvgx6SV5 CSNw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si11718724ejt.685.2021.03.15.08.36.56; Mon, 15 Mar 2021 08:37:22 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232740AbhCOPgA (ORCPT + 99 others); Mon, 15 Mar 2021 11:36:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:51336 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233668AbhCOPfp (ORCPT ); Mon, 15 Mar 2021 11:35:45 -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 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/ 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, 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(); -- 2.30.1