Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2895435rwi; Fri, 21 Oct 2022 09:04:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6JSfcTOMRx2bvnhRdcQsHDEr+smUqW9GK6w9gR4aKGqNJqdROsZvzc1AaDhPCplqhr9cTi X-Received: by 2002:a17:902:e805:b0:185:52a8:14c2 with SMTP id u5-20020a170902e80500b0018552a814c2mr20441055plg.46.1666368247233; Fri, 21 Oct 2022 09:04:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666368247; cv=none; d=google.com; s=arc-20160816; b=qd43DE+GBZWIj2oyq1Wg35cx6hTkA5ZSEsJSbNxuurs5RAC25I4SZ7Z2qCXJJn0fgY kI10HW/+SpjjkUktxshQID9rS6r/pMQFE2q93zwtb3t3Wi8oilLslEXXkaSeA+uoOKgi 6NehBxUufqHgcEArsAG5pkK30NPzMRXBRZS2DyF/GnmglsYgkjPvIXhjkYlUUY+Q/C9C U69lhxTsKB6fS4Gk7GrWPisOycKQ8KEBZedh9cZPbMhpv3PpyOL08QFIsu/wtA/VNklp 8NteRsyxQGIbAKBWHe539Wl6rM1uQK14d/2ZfSKFoM7ZHyfbtoIbj6wBLYuI4l08sz9w Rivg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=DII+7luap8mc/o2KNlYlLUHPxsLxFa8m0/bo2FeFrWc=; b=rHspp1IQJEQ+is6n8iMViFMsjRd3ffRLD2zA5ZdbbzSlLLFLyjSouO/mYEPU6h6Dk8 y4Ja+eHG44r0RkxBOcXXxSvVwKPOmcqC9yo2GxI8qQrTwM9UtodeV37EU+xYucS1ZAMb ebM5hjrVeLufTVFF1ZHviQUaJ0tRrJtTDVEwNb/ZlFOSrGWlDIgXgodviWc7WCSTH/af m06kXmzw/Id1oDQzesVkHfjvCC7b73RULwrT0Q7U+jG6/eiTzAhtKtnwT0gwCa55+BH5 Ov3NsAtNx0YDrEdS5oAK/LCcM9hoJS5yaee6FTleHew1tLAmym2DfaBqi8kYKUU5ROXU PKVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=ZV1+yQgR; dkim=neutral (no key) header.i=@suse.cz header.b=YJsJVMrE; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z3-20020a17090ad78300b0020cedba54fcsi6144540pju.55.2022.10.21.09.03.46; Fri, 21 Oct 2022 09:04:07 -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=@suse.cz header.s=susede2_rsa header.b=ZV1+yQgR; dkim=neutral (no key) header.i=@suse.cz header.b=YJsJVMrE; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229556AbiJUPvZ (ORCPT + 99 others); Fri, 21 Oct 2022 11:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbiJUPvI (ORCPT ); Fri, 21 Oct 2022 11:51:08 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2DFE16E295; Fri, 21 Oct 2022 08:50:58 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7B17E1F8BA; Fri, 21 Oct 2022 15:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1666367440; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DII+7luap8mc/o2KNlYlLUHPxsLxFa8m0/bo2FeFrWc=; b=ZV1+yQgR0xpwvV6lamom5Ibq+hV6T/KsS7K3EaKO0yCCSmBSXkV+0kRiWuGeS/M7qXyWaE 1/4KjYpuerhzVC6QZSvESKSJ031CNpm/n73JIS3jssM5JusJOeM0ymjBp7YXRjZsyosms9 jKINnM47UttlK5nezUS2x0htPyLLRX8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1666367440; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DII+7luap8mc/o2KNlYlLUHPxsLxFa8m0/bo2FeFrWc=; b=YJsJVMrEDWM3iFfSqdB24dtvyunJ1pk4mK8ZDg1QBCyfA3AF6IkAzDh8SwJ5nLGA497u1l 490sLdmWnNYFu+Cg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 445B71331A; Fri, 21 Oct 2022 15:50:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5gDAD9C/UmPnSgAAMHmgww (envelope-from ); Fri, 21 Oct 2022 15:50:40 +0000 Message-ID: Date: Fri, 21 Oct 2022 17:50:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking Content-Language: en-US To: paulmck@kernel.org Cc: Christoph Lameter , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, rostedt@goodmis.org, Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org References: <20221019224652.GA2499358@paulmck-ThinkPad-P17-Gen-1> <20221019224659.2499511-5-paulmck@kernel.org> <03d5730-9241-542d-76c6-728be4487c4@gentwo.de> <20221021134309.GG5600@paulmck-ThinkPad-P17-Gen-1> <8504f36a-b6bc-4c46-843e-55d8cd5a1dd0@suse.cz> <20221021154224.GJ5600@paulmck-ThinkPad-P17-Gen-1> From: Vlastimil Babka In-Reply-To: <20221021154224.GJ5600@paulmck-ThinkPad-P17-Gen-1> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_SOFTFAIL,URIBL_BLOCKED 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 10/21/22 17:42, Paul E. McKenney wrote: > On Fri, Oct 21, 2022 at 03:50:17PM +0200, Vlastimil Babka wrote: >> On 10/21/22 15:43, Paul E. McKenney wrote: >> > On Fri, Oct 21, 2022 at 09:44:23AM +0200, Christoph Lameter wrote: >> >> On Wed, 19 Oct 2022, 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. >> >> >> >> Sorry but this is not correct and difficult to comprehend. >> >> >> >> 1. You do not need a reference to a slab object after it was allocated. >> >> Objects must be properly protected by rcu_locks. >> >> >> >> 2. Locks are initialized once on slab allocation via a constructor (*not* on object allocation via kmem_cache_alloc) >> >> >> >> 3. Modifying locks at allocation/free is not possible since references to >> >> these objects may still persist after free and before alloc. >> >> >> >> 4. The old term SLAB_DESTROY_BY_RCU is used here. >> > >> > Thank you for looking this over, but Vlastimil beat you to it. How does >> > the update below look? >> >> LGTM. > > May I please have your ack? > > Thanx, Paul > >> > ------------------------------------------------------------------------ >> > >> > commit ff4c536e6b44e2e185e38c3653851f92e07139da >> > Author: Paul E. McKenney >> > Date: Mon Sep 26 08:57:56 2022 -0700 >> > >> > slab: Explain why SLAB_TYPESAFE_BY_RCU reference before locking >> > >> > It is not obvious to the casual user why it is absolutely necessary to >> > acquire a reference to a SLAB_TYPESAFE_BY_RCU structure before acquiring >> > a lock in that structure. Therefore, add a comment explaining this point. >> > >> > [ paulmck: Apply Vlastimil Babka feedback. ] >> > >> > Signed-off-by: Paul E. McKenney >> >> Acked-by: Vlastimil Babka It was there :) >> > 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: >> > >> > diff --git a/include/linux/slab.h b/include/linux/slab.h >> > index 90877fcde70bd..487418c7ea8cd 100644 >> > --- a/include/linux/slab.h >> > +++ b/include/linux/slab.h >> > @@ -76,6 +76,17 @@ >> > * 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_TYPESAFE_BY_RCU without first acquiring a reference >> > + * as described above. The reason is that SLAB_TYPESAFE_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(). >> > + * Alternatively, make the ctor passed to kmem_cache_create() initialize >> > + * the locks at page-allocation time, as is done in __i915_request_ctor(), >> > + * sighand_ctor(), and anon_vma_ctor(). Such a ctor permits readers >> > + * to safely acquire those ctor-initialized locks under rcu_read_lock() >> > + * protection. >> > + * >> > * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU. >> > */ >> > /* Defer freeing slabs to RCU */ >>