Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2786024rwi; Fri, 21 Oct 2022 07:56:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4RpPApY1NlzkZd896SeXUuX4DccQuBGViZva+5ErrXIaHhf0RcUzauXC16ekDPIC+hz9GF X-Received: by 2002:a17:902:edcd:b0:17a:6fa:228d with SMTP id q13-20020a170902edcd00b0017a06fa228dmr19714643plk.29.1666364189187; Fri, 21 Oct 2022 07:56:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666364189; cv=none; d=google.com; s=arc-20160816; b=eCziU/y8CJqcYleSP+mxfbNlvubnU7hUnE0xFJCsJJdYayLYcu8BBg/MMrx21r16NA L6xAa4i6Bi4WgbH19im4vsR3cPgSJtcJBcFN/oMtLejmlz5jUY31yCBPy5S1lJ5h8jVM dhWWHMk7rI58Sxu9OHlglr3M+i6JUPQ/KmXPH091V/VgvWFskn9MzuAzPt4q9rX0U/Kj gaZQS3TB4fSXqpn088Lnqx+XI50JATW0kSnofpvFdZQW9y0uFiEbXHSkxCZazIjyrorn KO4hEnnlkHtx6Gn8N7mrpyGSUVM1Rh4y8x9W4qDs3VjpGCkRG8ESJzn6t76GQclR5noc ut1Q== 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=52+XSCFwlMADDtkLiX19EF6vTQJl2O9f027xZLvwVcs=; b=hy04XaZnwqT3LHXPaj/nf0d2QMuAybqSK/mo3ev9XXkxTbDx6drD+p5H9gqG2rl7v2 6vvKZfKG/TWLqr6W900/ycXJvPyqabG0mTi03R7z05qHG+ICecdRw2qaJWCQlRDAXYFW Va2kDnb3eT3Vb8Wfcx5jpJMeoZlabjnp39zIJJG17gPk7lISw0aGmtt7NvzsB3I32xgs 3WXu+F1F2o0fHuLM/OTfaTF4i0/OKJBWr3irpHVgnUL6vR63nUjqwi3LRTCwGv59y8gi R7RSpJs9R5kJLS4zbNLrZ9iR4pEQgP0OUG5W+LijzwT9rm3GZlRlzd1t2wQhIDtuITTn HKHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=hR9+lF5W; dkim=neutral (no key) header.i=@suse.cz; 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 ml6-20020a17090b360600b00200b7acfaa6si5934821pjb.115.2022.10.21.07.56.13; Fri, 21 Oct 2022 07:56:29 -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=hR9+lF5W; dkim=neutral (no key) header.i=@suse.cz; 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 S230252AbiJUNu1 (ORCPT + 99 others); Fri, 21 Oct 2022 09:50:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229788AbiJUNuY (ORCPT ); Fri, 21 Oct 2022 09:50:24 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 700F51D93E8; Fri, 21 Oct 2022 06:50:19 -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-out1.suse.de (Postfix) with ESMTPS id BEDDA219C8; Fri, 21 Oct 2022 13:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1666360217; 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=52+XSCFwlMADDtkLiX19EF6vTQJl2O9f027xZLvwVcs=; b=hR9+lF5W88X7dPunQ9qH12qpIXwbBHgIQm6M1oruIRx+4IpMWcAF62LCaQRfxDLqi6QWbQ dkkaYG4FBcTQs04j8f5dduv4gOme3KNYpeODqcj4ChFrBRSWdQgueoKkdkKdDw6UD4+9CC mrQbRTPDzOSM4edBXrI+cUW/zqyo+Kw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1666360217; 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=52+XSCFwlMADDtkLiX19EF6vTQJl2O9f027xZLvwVcs=; b=7vT+QMr+lniBsnyY5+/gvxzD17hl9ND9mP8k9zXzlx8cRN6Sd5u//l7GTILQr4tE/efZw9 x+dD1n0ObwDMQ2CQ== 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 8C42F1331A; Fri, 21 Oct 2022 13:50:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YPOWIZmjUmNIDwAAMHmgww (envelope-from ); Fri, 21 Oct 2022 13:50:17 +0000 Message-ID: <8504f36a-b6bc-4c46-843e-55d8cd5a1dd0@suse.cz> Date: Fri, 21 Oct 2022 15:50:17 +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, Christoph Lameter Cc: 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> From: Vlastimil Babka In-Reply-To: <20221021134309.GG5600@paulmck-ThinkPad-P17-Gen-1> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,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 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. > 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 > 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 */