Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3483898pxf; Mon, 15 Mar 2021 10:31:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMA0WO5lXNCZeQVhe+PbPlL7jQ02xd66yi/EWYf9JlNtonnzrw4RacI8l4kBpTOqkbv740 X-Received: by 2002:a17:906:4a19:: with SMTP id w25mr24451615eju.180.1615829509806; Mon, 15 Mar 2021 10:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615829509; cv=none; d=google.com; s=arc-20160816; b=TtaOMlzIfsyzzp2gcGOQM7pdBGNotBMz/Fx3eqTdRj0to4+0rt+5ybGPQGQ+UqCKH+ doir72sRkfWVyubfRAZrNt9f5WBp9NPl+MTPa1yY7hbE0MVtK4rLV8OY6WzvUONSDUHR lxozm0G/WfJJO2s9usBcLAnTw1lJsZ1iOVIh23xKp8AtO0HdvclKmnPIm93L0NB4y5fL I+J/lLj4467tNPONIAEfgLAf2gEY+RT0Vxk1xZaFvIcXnmGpIP0HjuhVU6wfwOOdgs00 56kBkHmFUMlCWVxigVFXfkno8c22gGlTU4YMj6b8BC/SegQOfqUezIcCOismpldsxLDB AQcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=kg5mcnjRJ7CQDCjjsHfeSV1kr1Sf/OmY8AoSqDaNDic=; b=Z+LwG5KmO78jXUcG8yUGm3eh+7FEz/DDiuS6DHk8MfTVcChsqP5u8uyG0TTt1/0Vpb N7xVRrN+cXsgFf/hFc/UVz/S86Rwef7yx5l511wqqT5TDHXMIWW3ZYGtXKo441RVaaZB yOCGkwm+CtoXjkk5JcjcfE/x+30/R9aLu+3v3CnzNdEc8Hcmu3s/vsz7NQHAFjvOVJoC dqUj2ZlqktTyoa/LW/ckB18Vs2cZyfs2SRmuRVgSNWiV/cV6DhW4U3asNhljKRGeVuZU GaiHtzSuKe+mJUF5L8WCpGqVbumKbXvCTlfih1XXnmWpm/TTT7798k38FbrobhDt5M0Q sP5w== 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 g16si11754085ejf.96.2021.03.15.10.31.26; Mon, 15 Mar 2021 10:31:49 -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 S236234AbhCOR3Q (ORCPT + 99 others); Mon, 15 Mar 2021 13:29:16 -0400 Received: from mx2.suse.de ([195.135.220.15]:48748 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236043AbhCOR2s (ORCPT ); Mon, 15 Mar 2021 13:28:48 -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 B2785AE3D; Mon, 15 Mar 2021 17:28:46 +0000 (UTC) Subject: Re: [PATCH] [PATCH] mm, slub: enable slub_debug static key when creating cache with explicit debug flags To: David Rientjes 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 References: <20210315153415.24404-1-vbabka@suse.cz> <2d80f81a-ed85-a36f-6527-b75da3ae209e@google.com> From: Vlastimil Babka Message-ID: Date: Mon, 15 Mar 2021 18:28:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <2d80f81a-ed85-a36f-6527-b75da3ae209e@google.com> 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 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. >> [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(); >