Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1208525rwi; Thu, 20 Oct 2022 09:49:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Ad2KkM1RG1uHtbnAho7C0Zru6KstfQhD69FiPAT5KfPdB6sXZjx27zZoaYXesxl8Ou5Qg X-Received: by 2002:a17:906:db02:b0:780:24e:cf9 with SMTP id xj2-20020a170906db0200b00780024e0cf9mr11722264ejb.460.1666284566406; Thu, 20 Oct 2022 09:49:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666284566; cv=none; d=google.com; s=arc-20160816; b=KQ7wJ09GZwHx0JpzaGLbE4vk1uaED8/o7GfuLUoLcTXK4McfyHZjqPNhH11ImOm5xC 3TpT+MhcgNdsPAfRM0gsBrnGCdXtuam+q4YtdUmkOfQy5yTAVjHCEVLJItmNX137rNU+ WlzxpS+FDUsvXtlNcoAQpwiaUaOx0gxc/Xoq/olOuyKHPa4Ely3weVkyXuljv9YDaxCT MFAYPfq+rboRTwbVmx5tk9ZPSylcktlx6wQ199asEuJliwF9BgAdQ/MTyrI/+2br6mt9 EpltBDshKs3b9qTXbOe6s/QOAM5lfuamNyqdPS/A+LhRIzYlMZ1i97G4svJ18qdkDKUf mLrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=26wwB9l8jZyjbsspbR1YHc0x6MH6I1F0/J4sg4MmqD8=; b=gi3mni2exOknyaYHkAgoXQnQ86Id3TUFHMAQQgIuwJ5K/XCabxETQ0cDOGXy1OMFWj dNJiqv1hzwk2uKCGYYgRNT3iY9JRkj+vEE1m9ZAWjpHDhSVT9gS8RIzbAIClw9PHBhqY ntWcdXcBifAyhClYk6MZj+whZDjs5EM4I+OhfXrFkCWWRoMFxIMIg8LqgIRFkDlmrTmI YcAqU/2ai5tnwQllNAKgaE7vLkzJKNgTJqpGZDRMqYZZ8fZg4RoJM2TKkHoRyzOHNf34 evpK/xlRJUYe/Vs3yIz167bU5AFvLYmw/7axp0udCR+Am4chHADhGUMBbN8bSNzPnw4P RPAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PIucaDp1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m18-20020a509992000000b0045c1782d77esi16450595edb.532.2022.10.20.09.48.57; Thu, 20 Oct 2022 09:49:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PIucaDp1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229849AbiJTQcD (ORCPT + 99 others); Thu, 20 Oct 2022 12:32:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229664AbiJTQcB (ORCPT ); Thu, 20 Oct 2022 12:32:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF84B1AFABF; Thu, 20 Oct 2022 09:31:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7A62161C55; Thu, 20 Oct 2022 16:31:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C54E3C433C1; Thu, 20 Oct 2022 16:31:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666283518; bh=m0e5s+7vjQK6i5I/82ZYyoeq25NadpHcQ6GXllTid18=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=PIucaDp1d5kUDRaubYsxusNCAuDLzpDrQg7XAAKUe9nrcLJT93KOsjevUkIYF6EmQ uu6qrTdk/2zLKxOZMPq/tl5OdS9BXAVTZI48XhBRneYRp4zaW0sbWipBMKjjs1BrLh PQbNGFIcoD5XNbZBR00fKVsinXtbd9/zzk8aJ6xBv2fhejhScTNAebmzYsGq10Zwst 81cWXGN+stTDtL4IHBG22EVq7UvxJd9yPEz9WhhJY0AjN9AITfEWgIfEoqDhZc6Hxs V/egd3ESGZWdk7C16Cre2i9NykIKIWec5ULpASlJNh0cwE+gJsG+7cp+Vt5A/eXvGQ xjrERUBjBE8WQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 62E865C04D0; Thu, 20 Oct 2022 09:31:58 -0700 (PDT) Date: Thu, 20 Oct 2022 09:31:58 -0700 From: "Paul E. McKenney" To: Vlastimil Babka Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, rostedt@goodmis.org, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org Subject: Re: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking Message-ID: <20221020163158.GP5600@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20221019224652.GA2499358@paulmck-ThinkPad-P17-Gen-1> <20221019224659.2499511-5-paulmck@kernel.org> <4a29b39a-b9b5-9c95-e43a-9e5f87801786@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4a29b39a-b9b5-9c95-e43a-9e5f87801786@suse.cz> X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 20, 2022 at 09:10:49AM +0200, Vlastimil Babka wrote: > On 10/20/22 00:46, Paul E. McKenney wrote: > > It is not obvious to the casual user why it is absolutely necessary to > > acquire a reference to a SLAB_DESTROY_BY_RCU structure before acquiring > > a lock in that structure. Therefore, add a comment explaining this point. > > s/SLAB_DESTROY_BY_RCU/SLAB_TYPESAFE_BY_RCU/ in subject, commit log and the > added comment? :) Boy, I was certainly living in the past when I did this patch, wasn't I? Thank you, will fix on next rebase. > > Signed-off-by: Paul E. McKenney > > Cc: Christoph Lameter > > Cc: Pekka Enberg > > Cc: David Rientjes > > Cc: Joonsoo Kim > > Cc: Andrew Morton > > Cc: Vlastimil Babka > > Cc: Roman Gushchin > > Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> > > Cc: > > --- > > include/linux/slab.h | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/include/linux/slab.h b/include/linux/slab.h > > index 90877fcde70bd..446303e385265 100644 > > --- a/include/linux/slab.h > > +++ b/include/linux/slab.h > > @@ -76,6 +76,12 @@ > > * rcu_read_lock before reading the address, then rcu_read_unlock after > > * taking the spinlock within the structure expected at that address. > > * > > + * Note that it is not possible to acquire a lock within a structure > > + * allocated with SLAB_DESTROY_BY_RCU without first acquiring a reference > > + * as described above. The reason is that SLAB_DESTROY_BY_RCU pages are > > + * not zeroed before being given to the slab, which means that any locks > > + * must be initialized after each and every kmem_struct_alloc(). > > + * > > Wonder if slab caches with a constructor should be OK here as AFAIK it > should mean the object has to be in the initialized state both when > allocated and freed? It does look that way, thank you! And __i915_request_ctor(), sighand_ctor(), and anon_vma_ctor() actually do this, initializing a lock in the process. The ctor function could just initialize the locks, and all would be well. In addition, this makes sequence-lock-like approaches a bit easier, as in "just use a sequence lock". I will update with attribution. Thanx, Paul > > * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU. > > */ > > /* Defer freeing slabs to RCU */ >