Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3474133pxf; Mon, 15 Mar 2021 10:18:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvgzhUorIZa2N3PxI+fESXIoRd9S2m/pz9h3TALESJ1+VMfhdthLr+5D6CG1aAn4IOnwIs X-Received: by 2002:aa7:d44a:: with SMTP id q10mr30687574edr.278.1615828713386; Mon, 15 Mar 2021 10:18:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615828713; cv=none; d=google.com; s=arc-20160816; b=EThIfQAZ0vxVghMrNGI/vy+rhgXkCw5Cb5VDAn9qcxvdOR+7iznACyDRev6evAlPug wP+nmMieaaJviqCQMVoDx1Okxgr1g098j+GcDjE/9cdsYXheO/uwDnNDxUvL3v53+EWt snmOc4sEGQGjc80IPcSJnQSrQN4QnhW+msq227VKm3Dc3xXnUNnkq0cVJ/vZ9wEJs/0K 3zycd0+0lfyXO9wc62Id8tDnLpl0hn4K5pY6CDbtC9EwXUq3A/GBpuHNp3pxDxZQfxGI VZE3PgETtFmJLkWHUwEQErH2Lp1Sa7FaIT5c6GL+z6eT2YO3PoJdl+F5u0MBl3j9lvuF zblA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=vkbgOXNRjmxTcw1oc4wVA8/mmcZsN9FbZ3cSv6WDfss=; b=OwZzs9f0wO5TvbSeRP+N95lv0Qm33ZcIVy0LxQ3jtwx8/4vkCI1uvqi+wBPdqpr8FJ fkHs2/IhnYCMJ5Wdlzjm+E1SQaKVnBkC1O1SvlHJzLfk2jfwUDpwZl2QoDqJpX6wIXnB UPj9H97Hr0umOsvo5E2DNG1o2zlMYsQBvepguPawPDwFRzpG6NmA9CNh02TRfJe/1JfS 6NK2paNTEveXNm/r+tX6gMfZEXIniK5bCeMoVDr84ZDMWbdD2TaupfSc9L9AT+SczX/G CtttmjFq3I8IecnQAq+M9vTStHSjCEfqa3mU4mhxG3W9EE864GVNruvZGQJ2hjynFep8 z5Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vHGrIXtb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w14si11353818edu.225.2021.03.15.10.18.10; Mon, 15 Mar 2021 10:18:33 -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=@google.com header.s=20161025 header.b=vHGrIXtb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235947AbhCORQT (ORCPT + 99 others); Mon, 15 Mar 2021 13:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235060AbhCORQP (ORCPT ); Mon, 15 Mar 2021 13:16:15 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B93FC06175F for ; Mon, 15 Mar 2021 10:16:15 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id ha17so8401304pjb.2 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=jFK2ggqeckPmxp+j1/KED1KXUJb+XNVHqHVON3v6rDm6xhZnknojHqRw+n96xBwhEd P2Lv4RMMg0A8MGGvemWF5GSQ4zBobCmLEsa0r40L4crF1q+0Uew9qUx4ckDTz5KIh7Q0 jxOhXpEvP/Pdny9TTvAjLDkz3bK+DRTEN4C7gZni8dQV9yUPqBTKMQM453wxq5+Xj5HW R9VYug6ruaywqImbNg9wcQe6sfwDZ4jT/FN7mivRKOM9DGSznQaFrj35Uv/X4CfI/iMb NLuw69iiNqzctOwayWIcWORN1iG/BV1n5cob0enzv42Bh5MD2dErQWBIR+jtRtuOyy1S ZDTQ== X-Gm-Message-State: AOAM533IH20Fr5jauh/yzUihz1n+q9U5roLJgcvCttKtZPjdP3/kOIOA hbmR4bycQEkJIIJi47cSAn4MTQvlYWSOCg== 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-kernel@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();