Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1741264rwb; Thu, 15 Dec 2022 13:54:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Rl/qSkUFdk7WuVS86qzo5kPNplhZvJAwVUj4yVKKxPHs4bKhgCgjWPQRCcZnJVbD+N9xk X-Received: by 2002:a17:902:eb83:b0:18e:4121:4b46 with SMTP id q3-20020a170902eb8300b0018e41214b46mr23262316plg.25.1671141289512; Thu, 15 Dec 2022 13:54:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671141289; cv=none; d=google.com; s=arc-20160816; b=IEYLBx8Sly6EcW7Kw28AhIRWUlCXqleypIhf21zYSoqpFsF557bR1GmmSmEAkhmSCh heBbUR6hLUAL+mTXsMdKAOr6EwJkURlpIU0vP9huB0xMll1H3BSAxTlbfVYqMZqAK70r h5ASO/qG1DgyunnIxWAzqtFmwIiWqWUobjo7LSzQ2yrtHn2y+KOkKIEnEIf4H6yNBG8q T8IqIQHixBnN6hoM+pC0a0F18sFq/JRkF8ELfIzWi8RYVsQOmv+Y9aEUOFQ9BZgz57rP cw4WSUWD1E+SlKR6jCINm2KYKJ/yC0oIr8mDbcnw2pgCMFku2kHexZ6TxHa+JBF1HkEu g7qg== 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=XepfERibTqGte7ogCxTSAVyHXXjXMiLwQudRTG5e7YM=; b=kJSHB7EVMRyCfl1fo0TUeXDyu7AlvYd+A8GdWskHIRb1hrPH+SB1l725KsSfElWrY7 O/cmqbx0NXmBlo2cnDL6MAaJIBK4znisREyi8d6Oe2ITskaIu2Hz+pYP5XjJdyAppY8j kaZH5dcLKynixdTkJgUg8bc5oS1Ov9yzT/M0qyS+oMitSRWllUiHcFD7wtbZYMXKKv9T CFXuKSPsVukYPohj8N0N0fmGey7pMwDw3GWlt6M92s8BTKYEqsRUv7pIiM/z22aIrMgx B/1QVUtwbzCL6PGF+rTYtKrQfM8hnpHlKFpOHg2WsXQaQb9J9MqMjOqSKF2nJeSE1Xn3 0IYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f84yWDjm; 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 g8-20020a656cc8000000b00478c967a865si693882pgw.125.2022.12.15.13.54.40; Thu, 15 Dec 2022 13:54:49 -0800 (PST) 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=f84yWDjm; 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 S229611AbiLOVjG (ORCPT + 68 others); Thu, 15 Dec 2022 16:39:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiLOVjE (ORCPT ); Thu, 15 Dec 2022 16:39:04 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB25E2BB21; Thu, 15 Dec 2022 13:39:01 -0800 (PST) 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 67DCF61F26; Thu, 15 Dec 2022 21:39:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2FADC433EF; Thu, 15 Dec 2022 21:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671140340; bh=KLN4u/CdDUK5RCz8K9nt56ZrKSnN4zE+POw0bXmlcTY=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=f84yWDjmxw4Wk21gxFCvLpp1CpBdO6kK9BN73rgQ442W+IZjdO/1l+gksPzbJMOEZ sUhC8UnNVS1KZGe58WXjQvWfGybbwpVu+1In1QMMlzqClx/mfT8waHdskqr8r/hCz0 DpYW3sbeUwtkXyaJEKFIc1nFzjTpvAlkXej3HuK9ad7wmW/oMLbdPUY60I/Tr0Qagw jhZlYt/QrLNJBbfxFmsOg2ZwCUIfRZtKKm0ctvYpwa36pkldC/Np7/D4SLIC2WZpNd PzfvMO8zhEOc/to3+Ubdgji1WGAIU8AFLwbS9AxwVYlKoHo5iCFD+d4fYKeU+hzB8W BMNBEIS6jydbw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 6351B5C1C5B; Thu, 15 Dec 2022 13:39:00 -0800 (PST) Date: Thu, 15 Dec 2022 13:39:00 -0800 From: "Paul E. McKenney" To: Joel Fernandes Cc: Frederic Weisbecker , boqun.feng@gmail.com, neeraj.iitr10@gmail.com, urezki@gmail.com, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC] srcu: Yet more detail for srcu_readers_active_idx_check() comments Message-ID: <20221215213900.GQ4001@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20221214191355.GA2596199@paulmck-ThinkPad-P17-Gen-1> <20221215165452.GA1957735@lothringen> <20221215170834.GH4001@paulmck-ThinkPad-P17-Gen-1> <20221215195854.GL4001@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 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, Dec 15, 2022 at 03:33:39PM -0500, Joel Fernandes wrote: > On Thu, Dec 15, 2022 at 3:03 PM Joel Fernandes wrote: > > > > Hi Paul, > > > > On Thu, Dec 15, 2022 at 2:58 PM Paul E. McKenney wrote: > > [...] > > > > If the first read section's srcu_read_unlock() and its corresponding > > > > smp_mb() happened before the flip, then the increment of old idx > > > > would happen only once. The next srcu_read_lock() will read the new > > > > index. If the srcu_read_unlock() and it's corresponding smp_mb() > > > > happened after the flip, the old_idx will be sampled again and can be > > > > incremented twice. So it depends on how the flip races with > > > > srcu_read_unlock(). > > > > > > I do understand that a number of people like reasoning about > > > memory-barrier ordering, courtesy of the sequentially consistent portions > > > of the C and C++ memory models, but thinking in terms of the accesses > > > surrounding the memory barriers has been far less error-prone. > > > > Sure, but we are already talking in terms of the access to idx right? > > That's what we're saying is visible by memory barriers and we are > > trying to reason here about the ordering (flip does the write to idx > > and followed by smp_mb(), and there is corresponding read of idx on > > the srcu_read_lock() side. So we are indeed talking in terms of > > access, but let me know if I missed something. > > > > > > Also, since this is all hard to reason about I started making some > > > > diagrams, LOL. For your amusement, here is why need to scan both idx > > > > during grace period detection: https://i.imgur.com/jz4bNKd.png > > > > > > Nice! > > > > > > I suggest placing a gap between GP 2 and GP 3. That way, you can make it > > > very clear that Reader 1's critical section starts after the end of GP 2 > > > (thus clearly never blocking GP 2) and before GP 3 (thus possibly having > > > a reference to some data that is going to be freed at the end of GP 3). > > > > > > I also suggest coloring Reader 1 red and Reader 2 green, given that the > > > color red generally indicates danger. > > > > Thanks for these suggestions! I will make the update. I am planning to > > make a number of diagrams for other scenarios as well, as it helps > > visualize. Google drawing is nice for these. I am happy to share these > > with you all if there is interest :). > > I made these updates, please see: https://i.imgur.com/hoKLvtt.png > > Feel free to use the image for any purpose and thanks ;-) Very good, thank you! Would it be possible to have an arrow marked "X" or "reference to X" from the beginning of the 'Mark "x" for GC' box to the box labeled 'Enter RSCS (access "X")'? Thanx, Paul