Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1795017rwb; Thu, 15 Dec 2022 14:41:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf4S3S6wCVoE7HcPF44/s295vufCAgXp6ioPH/bWs7fu0Q1tyEY63B2ny+tGs0b08gd4c8xK X-Received: by 2002:a17:906:64e:b0:7ad:cf48:c38d with SMTP id t14-20020a170906064e00b007adcf48c38dmr23477700ejb.42.1671144060167; Thu, 15 Dec 2022 14:41:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671144060; cv=none; d=google.com; s=arc-20160816; b=qKwlZ7plqM216lzshQexoXzt99TDDYCawrKhmXsUUvwpq/xXJyZD7lIkRcBI32PudP UjoZAYt2/O/5x3F7RHrM7fM6nHcWn2lvt3bsFg7nink/6vh0qvEvDb+N6HQIKMVM9zs1 jixh7rgRiqqGB1OX1COb3HsyaWRhNIZEXtNDNc5T6AfxwkauECi4D+fx7Zu4yWdA+B6Q HzJC7KRL34V7XEaTkDNPWAS7H/0NJEHouU/09KdPWmYimOib2TMcTrpzGeX+Oz9Q9OQq UAegaI77KYC7BwP+AGSVIzDoh7c0D95Gsx8Wsq1Z03bU2SfKvY2wNGK6Q0o+S+Gau2Br qH8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:in-reply-to:cc:references:message-id:date :subject:mime-version:from:content-transfer-encoding:dkim-signature; bh=I1d3kv2uhlJIGf5YFF6mrLkq+qTAs39pyqPNUHXT0LY=; b=SjrgbQJTDCEewNE2/Bz3OsdUmnuPLq+ut9PxXTwlp15UxWTfCXGOzLQcierDKUEfqs tG4eGYxcLoNLcKj2elOobybEx7o8LFljyN54XuZn8i1OTP/SuOB6Al7oSjcxRcqRhFlJ 6TxB2qnIFGTEl9f2abuT6yKItSZRb/dJg5dm6rQuDcIg9HYpQDJJs50xWXdxh2LrlY+Q 9nD+6NBUx3FIf1iL12PfqwLq5o2srKdpbXhL72wTiHsZPmHR64ahY/hExhbnze3ifMJx ECYVJpXVnbUiOUJzJ0UzZTY/CAwcfvcmBFgzHtxmEa7S84bWWMrDR6MFBm0/j+IWROqH omfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=phD0CuMJ; 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 tb23-20020a1709078b9700b0078e0e866a4dsi470924ejc.682.2022.12.15.14.40.43; Thu, 15 Dec 2022 14:41:00 -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=@joelfernandes.org header.s=google header.b=phD0CuMJ; 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 S229748AbiLOWRA (ORCPT + 68 others); Thu, 15 Dec 2022 17:17:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbiLOWQ6 (ORCPT ); Thu, 15 Dec 2022 17:16:58 -0500 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 412395214F for ; Thu, 15 Dec 2022 14:16:57 -0800 (PST) Received: by mail-qt1-x833.google.com with SMTP id x11so1263804qtv.13 for ; Thu, 15 Dec 2022 14:16:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=I1d3kv2uhlJIGf5YFF6mrLkq+qTAs39pyqPNUHXT0LY=; b=phD0CuMJi0kYgISSYTnXxXhblXeSrwtSERTX/rvh9Sb0unqLt4ztm9nQOor24kYgrY kUs/qmCNrk5f7dW/fkz2QAT47sXsj4dbFvAw5MG6U4ZW2H62Y2uvgMZzsZxDv/QGYZ02 HvkRaIv0lhlW8aouxmECLplEahipSpFJey4RE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I1d3kv2uhlJIGf5YFF6mrLkq+qTAs39pyqPNUHXT0LY=; b=FFFWm7Qd/dfFnA3JrtotAnzAI/ONyaNJXwlQtkXct6x2KUiYSS4Uo2rj1XywTK+kN9 yZEJpaJ2+3dm5BV0FKSg1MdoKZ1PbFs2iO0+pHF67LtSZlML1rvbiaEGxa0kJyHCT7/p Pp7b34lA6fjOX7p3s3+3KvHXu8z/HUDmMiunBWnj2ZTgUWeY+unyCRjJZno2lQWMgsDD QG1LF0E5qvS2eO2SVuyc7/jHsI760q6UCpq4bgS/DApCKT0srk2LC0Iy6p8t7Ed/Q92M ptY7fuRK65PuGL3MYe75599lgoG/zIX13LpmZamNWqg9sYgfyNkQYic3/QpUBuIwx7Er gQdw== X-Gm-Message-State: ANoB5pl0z0XR0H1f8bFUzluPOldCWeCz580GzRgRzCBB01o+rkhrvqI5 vIvPScZi1w7yv9RQdLM2Ex7N6w== X-Received: by 2002:a05:622a:2518:b0:3a8:2e5:5b70 with SMTP id cm24-20020a05622a251800b003a802e55b70mr42123997qtb.34.1671142616308; Thu, 15 Dec 2022 14:16:56 -0800 (PST) Received: from smtpclient.apple (c-98-249-43-138.hsd1.va.comcast.net. [98.249.43.138]) by smtp.gmail.com with ESMTPSA id cq8-20020a05622a424800b003a591194221sm173623qtb.7.2022.12.15.14.16.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Dec 2022 14:16:55 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Joel Fernandes Mime-Version: 1.0 (1.0) Subject: Re: [PATCH RFC] srcu: Yet more detail for srcu_readers_active_idx_check() comments Date: Thu, 15 Dec 2022 17:16:45 -0500 Message-Id: <826527A4-42E6-48AB-80C9-FEC0F330F0BE@joelfernandes.org> References: <20221215221014.GR4001@paulmck-ThinkPad-P17-Gen-1> Cc: Frederic Weisbecker , boqun.feng@gmail.com, neeraj.iitr10@gmail.com, urezki@gmail.com, rcu@vger.kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221215221014.GR4001@paulmck-ThinkPad-P17-Gen-1> To: paulmck@kernel.org X-Mailer: iPhone Mail (20B101) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 Dec 15, 2022, at 5:10 PM, Paul E. McKenney wrote: >=20 > =EF=BB=BFOn Thu, Dec 15, 2022 at 04:42:15PM -0500, Joel Fernandes wrote: >>=20 >>=20 >>>> On Dec 15, 2022, at 4:39 PM, Paul E. McKenney wrot= e: >>>=20 >>> =EF=BB=BFOn Thu, Dec 15, 2022 at 03:33:39PM -0500, Joel Fernandes wrote:= >>>>> On Thu, Dec 15, 2022 at 3:03 PM Joel Fernandes wrote: >>>>>=20 >>>>> Hi Paul, >>>>>=20 >>>>>> 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 b= e >>>>>>> incremented twice. So it depends on how the flip races with >>>>>>> srcu_read_unlock(). >>>>>>=20 >>>>>> I do understand that a number of people like reasoning about >>>>>> memory-barrier ordering, courtesy of the sequentially consistent port= ions >>>>>> of the C and C++ memory models, but thinking in terms of the accesses= >>>>>> surrounding the memory barriers has been far less error-prone. >>>>>=20 >>>>> 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. >>>>>=20 >>>>>>> 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 >>>>>>=20 >>>>>> Nice! >>>>>>=20 >>>>>> I suggest placing a gap between GP 2 and GP 3. That way, you can mak= e it >>>>>> very clear that Reader 1's critical section starts after the end of G= P 2 >>>>>> (thus clearly never blocking GP 2) and before GP 3 (thus possibly hav= ing >>>>>> a reference to some data that is going to be freed at the end of GP 3= ). >>>>>>=20 >>>>>> I also suggest coloring Reader 1 red and Reader 2 green, given that t= he >>>>>> color red generally indicates danger. >>>>>=20 >>>>> 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 :). >>>>=20 >>>> I made these updates, please see: https://i.imgur.com/hoKLvtt.png >>>>=20 >>>> Feel free to use the image for any purpose and thanks ;-) >>>=20 >>> Very good, thank you! >>>=20 >>> 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")'? >>=20 >> I am currently away from desk. I shared the google drawing with you. Coul= d you check and make the change, if that=E2=80=99s ok with you? >>=20 >> Thank you so much, >=20 > I took a cut at it. Thoughts? Yes perfect now :) and handy future reference! Thanks! - Joel >=20 > Thanx, Paul