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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94223C433FE for ; Thu, 6 Oct 2022 06:21:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF8366B0071; Thu, 6 Oct 2022 02:21:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA83C6B0073; Thu, 6 Oct 2022 02:21:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6F808E0001; Thu, 6 Oct 2022 02:21:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BFB3A6B0071 for ; Thu, 6 Oct 2022 02:21:05 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8924B1207B2 for ; Thu, 6 Oct 2022 06:21:05 +0000 (UTC) X-FDA: 79989526890.03.A4F01D5 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf08.hostedemail.com (Postfix) with ESMTP id 3602116001B for ; Thu, 6 Oct 2022 06:21:05 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id i7-20020a17090a65c700b0020ad9666a86so3487956pjs.0 for ; Wed, 05 Oct 2022 23:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=DNCHcypAqACyuqWx+p7IPwXAi8YgHbhoRcWSFbyaQks=; b=ZEpegq5D07sSgQNEZyxGsXiMR57KikRoeFDL1sOXN3CbkKPCi6sI4u9gbG4bL/Hl2F UTgcpmqU7XbCrAyR2WfDDdtcgsqIeLaSac7XV272DQXP4hLDjCizRoTsZH600bu4pCQk rKd4DNrlMueGNq9OwAXpLiYWENn00op+fsKtk9L9wQof+mRmo/InZ5kDNxGdbHAkQHhs Jhb5c1QH8CVE0lYM3wbSuxyI7uMFhh+lRRJdM+hhTJXGfGnArGi7WcssLfrczZfD3HE2 vjJ8ix/gt/7oZcQwkP2qSOKN/MpoUp1T9Ws7AoVBB0v9K+FTKqnDqCyUr2aEP06a9rva hvzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=DNCHcypAqACyuqWx+p7IPwXAi8YgHbhoRcWSFbyaQks=; b=VyCrz7iLNYlcywiamMgDDHFX//IbK1G6nGAEuRvXqmYMN4EkY8999MJioeSoZHJkx/ +U44MMxIOXJMXGRSo4C081tFazofc4rVx2StUZNJRDZ9g3JH34f10b7ntyFgsVDU7P4u tElNZEgcnKsMxOVlfqJhwbEJzf9+q0+Mzlwn7+NkxUcA5OQt84bkGnU9mQQBSoO1ISai lcFppaPgWDlOL2WbrzRxmpbKU4RuiM4f3PFE8fJEcud6IauYCgl+NBq6mgVOqHWe4z/W V9+Iu1ZXiw9O+k5STuvNOccQ2WwWhP9lbsjsEA2uGkmajk2ZofLJn7xF0+ukqQvT8RCB PUTw== X-Gm-Message-State: ACrzQf3Wr5PddsphpHWc9GwDYI75eaYRzhjYKn6Q4eRvxyfN7qTWihHu 8LZPfeo6X2FX9gUAoAmYR9k= X-Google-Smtp-Source: AMsMyM7of5BeQtui09w593FobXfInNH4J8ZMlYDsuKxXQ1hfC9UspE+10JpDFYTxfiMVag84FGI8rg== X-Received: by 2002:a17:90a:ce82:b0:20a:b20f:6d0e with SMTP id g2-20020a17090ace8200b0020ab20f6d0emr8866340pju.125.1665037264223; Wed, 05 Oct 2022 23:21:04 -0700 (PDT) Received: from hyeyoo ([114.29.91.56]) by smtp.gmail.com with ESMTPSA id s13-20020a17090302cd00b00172dc6e1916sm11436708plk.220.2022.10.05.23.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 23:21:03 -0700 (PDT) Date: Thu, 6 Oct 2022 15:20:57 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Rasmus Villemoes Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: slub: remove dead and buggy code from sysfs_slab_add() Message-ID: References: <20220930084742.771804-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665037265; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DNCHcypAqACyuqWx+p7IPwXAi8YgHbhoRcWSFbyaQks=; b=oIQpqHWjs/OS/Klm6sBDQXgmOIzwGboA5RXMSu5QTUVBoi+rEmhSvZ9avBnh5ueAipjeYA 65v2/xF4Z4SLSBb5WKvpT7RCrpb38cMiQvI0QAntjX3idgRe1gZWsBzO5R2AczU16ZDaJQ fwfR+eRJ4SWUpbMhOdAjIVKQxY+Z3Rk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZEpegq5D; spf=pass (imf08.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665037265; a=rsa-sha256; cv=none; b=g/g7tu5tVtpblqTZwtYqlf2AkztBTawkj0GXI+w22lYNGXBqw31cRuv5ODIcp8ASMW9WCs D4NanONicTww/D18Cb5xXpf5VKLaWPCBVwYgneHzQLm+Z26u8PARFmtdElim9cqVlv8EGB y9tNm9PrS2ixYHkm2iPSj2uiHYYMu6U= X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZEpegq5D; spf=pass (imf08.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: t4rf9tebm5ybef1cj7s36eaxktiu6iwp X-Rspamd-Queue-Id: 3602116001B X-Rspamd-Server: rspam02 X-HE-Tag: 1665037264-311214 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, Oct 03, 2022 at 11:38:30AM +0200, Rasmus Villemoes wrote: > On 03/10/2022 09.02, Hyeonggon Yoo wrote: > > On Fri, Sep 30, 2022 at 10:47:42AM +0200, Rasmus Villemoes wrote: > >> The function sysfs_slab_add() has two callers: > >> > >> One is slab_sysfs_init(), which first initializes slab_kset, and only > >> when that succeeds sets slab_state to FULL, and then proceeds to call > >> sysfs_slab_add() for all previously created slabs. > >> > >> The other is __kmem_cache_create(), but only after a > >> > >> if (slab_state <= UP) > >> return 0; > >> > >> check. > >> > >> So in other words, sysfs_slab_add() is never called without > >> slab_kset (aka the return value of cache_kset()) being non-NULL. > >> > >> And this is just as well, because if we ever did take this path and > >> called kobject_init(&s->kobj), and then later when called again from > >> slab_sysfs_init() would end up calling kobject_init_and_add(), we > >> would hit > >> > >> if (kobj->state_initialized) { > >> /* do not error out as sometimes we can recover */ > >> pr_err("kobject (%p): tried to init an initialized object, something is seriously wrong.\n", > >> dump_stack(); > >> } > >> > >> in kobject.c. > >> > >> Signed-off-by: Rasmus Villemoes > >> --- > >> mm/slub.c | 5 ----- > >> 1 file changed, 5 deletions(-) > >> > >> diff --git a/mm/slub.c b/mm/slub.c > >> index 4b98dff9be8e..04a7f75a7b1f 100644 > >> --- a/mm/slub.c > >> +++ b/mm/slub.c > >> @@ -5937,11 +5937,6 @@ static int sysfs_slab_add(struct kmem_cache *s) > >> struct kset *kset = cache_kset(s); > >> int unmergeable = slab_unmergeable(s); > >> > >> - if (!kset) { > >> - kobject_init(&s->kobj, &slab_ktype); > >> - return 0; > >> - } > >> - > >> if (!unmergeable && disable_higher_order_debug && > >> (slub_debug & DEBUG_METADATA_FLAGS)) > >> unmergeable = 1; > >> -- > >> 2.37.2 > > > > I assumed that it's hit when SLUB failed to initialize slab_kset in > > slab_sysfs_init(). (Yeah, it is too unlikely, though....) > > No, it is not, because if the creation of slab_kset fails, > slab_sysfs_init() returns early, and hence slab_state never transitions > to FULL. Yeah, you are right ;-) I misread that. > I don't see anywhere else where slab_state could become FULL > (of course in slab.c and slob.c, but those are not built when slub.c > is), so I do believe my analysis in the commit log is correct. Right. > > And obviously it's a bug if sysfs_slab_add() is called early than > > slab_sysfs_init(). > > Yes, and that's already what the existing slab_state check guards. > > Rasmus Looks good to me, Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Thanks! -- Thanks, Hyeonggon