Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1478138rwb; Thu, 15 Dec 2022 10:30:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf7nGgypz15K48NZrKa8mvaTFUfUi60XZbDPBDoLzjRum91HtrMg++kkJs719KEaT57oclrO X-Received: by 2002:a17:902:7e88:b0:189:ced9:c9e5 with SMTP id z8-20020a1709027e8800b00189ced9c9e5mr28929253pla.13.1671129055455; Thu, 15 Dec 2022 10:30:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671129055; cv=none; d=google.com; s=arc-20160816; b=Oc5h2Ecj9+3mi0ySfXWGUq/PmwCmkAiYRuAZDXaJ8Y5uBDDaPiVRq7qVXJ70AfT8I0 PhDCilL9nE7Ocn2//PPR5/DRmVWqQYfUAO1NSWwG1dNl2EkjA1i9bJOarb7LgeUf81UN tzd22m95r8iQjj1RVBClJYlZjPo+ZmKpgZfgl6mkryUx1q7mgrOoVTWN7FUohFOVfNvu m+c3Qj1MyZVrq/u2xgi4KD0iiEzmKESpYd55BKFDpIPoH7qcRDUTPCfSUaeasKKJY1d6 nxk2ylniVioWeStG3g/3vPSlb6RzAPTFUXtxzUYDteculmvaflfQO+bGJ6xD6LDmdNFZ R93w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=cjIQxwghSX8UYWFnSTuWJDMMlMgaiz3CsovlV0p8Z9c=; b=Pb0UjRhnqc6oMhmb9GyU+YWZ1I7Ulebb6UhNxbv3ZD8F2GsyENQLGipHLQPKEb4lyl gGfv/pVarExOELJ2A8i8QDqoo5tzaPmZfZN5z94LOoGq3Vi08Cv96f50QuGLiGzIphiC EKNVhjEidczRH+Pt+rKezDdgIRFMouTi1wopvWjzayxcrJgWqPhjpV70vW2QvOHiD1oL bpru2F0zkbn6OocjtN2cknJQMgnHh1op5DilmSLUwwEzZMgLaXAoeKgmav8XgfZlqrjd c2ok7T01eoWYZPDE3ZD5lRZkRKcm7fl3eV5GzOp4lUeYnAN1ZTp89Xkj87hD77yfc1UG dcNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="yXTN/7+3"; 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 f15-20020a170902ce8f00b00189b6d0d70dsi7050490plg.516.2022.12.15.10.30.45; Thu, 15 Dec 2022 10:30:55 -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="yXTN/7+3"; 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 S230013AbiLORtD (ORCPT + 68 others); Thu, 15 Dec 2022 12:49:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbiLORtA (ORCPT ); Thu, 15 Dec 2022 12:49:00 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F57827DFC for ; Thu, 15 Dec 2022 09:48:59 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id q6so16799902lfm.10 for ; Thu, 15 Dec 2022 09:48:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=cjIQxwghSX8UYWFnSTuWJDMMlMgaiz3CsovlV0p8Z9c=; b=yXTN/7+3cSAVFqup8NKvO4wwdLWZxKsw2oi/mRzXdSj44pOVStpEmq6kMm6rPvNhFW 2MHOygN6xDMfFWLDdT5/JsX04/WCp/LIV2ktFR5vDCAb5IgWqNdFohkNS869FJtwpabS 3HdmbPCH/GqldfcSylZT9MgEd+f55rhloNQQw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cjIQxwghSX8UYWFnSTuWJDMMlMgaiz3CsovlV0p8Z9c=; b=mxDvfrOD1PU7FdQWGCJHDZ8+Kaxnf7PW139s9/06RbExzkgK6iuBAq1zWPjIsimD8+ of/rFs+IUTjU3Cq0BWpL29+oS0VCfM+82qFPtmBzBcNy37wZkRscZQ5fYdtF4PZQifKz s0Jm8cMwO5PXHQw9Dw3mzKdhNSzH9m7wbGR7AlZ1qaoSO0Hr8W8DJ/jciubZTJ1BYa0J 2y2FX3nBGFZ6lWbEy2WuZHdFZKfzKamWqNYuFbj9OitEh5fWYEwHQ7bBBMEGAdB8vYOz wqvNTbypDC+l7rPa+48YjTPXAnguFPGeV910Pnbdgdvaz7k58ZhoNbsXI55/EBzoktP9 CMAw== X-Gm-Message-State: ANoB5pkq7XtiWlsi1Fy4I5skgAKtsGmn1/Fpfr/p2PkIVxyz6G8dEvZL JdgMaY0WLRfVIba/GFtVDzxnL6QbOHGWK32eGx6A1iakISBheiBd X-Received: by 2002:a05:6512:224c:b0:4b5:ad89:8174 with SMTP id i12-20020a056512224c00b004b5ad898174mr2261149lfu.84.1671126537736; Thu, 15 Dec 2022 09:48:57 -0800 (PST) MIME-Version: 1.0 References: <20221214191355.GA2596199@paulmck-ThinkPad-P17-Gen-1> <20221215165452.GA1957735@lothringen> <20221215170834.GH4001@paulmck-ThinkPad-P17-Gen-1> In-Reply-To: <20221215170834.GH4001@paulmck-ThinkPad-P17-Gen-1> From: Joel Fernandes Date: Thu, 15 Dec 2022 17:48:46 +0000 Message-ID: Subject: Re: [PATCH RFC] srcu: Yet more detail for srcu_readers_active_idx_check() comments To: paulmck@kernel.org Cc: Frederic Weisbecker , boqun.feng@gmail.com, neeraj.iitr10@gmail.com, urezki@gmail.com, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 Thu, Dec 15, 2022 at 5:08 PM Paul E. McKenney wrote: > > Scenario for the reader to increment the old idx once: > > > > _ Assume ssp->srcu_idx is initially 0. > > _ The READER reads idx that is 0 > > _ The updater runs and flips the idx that is now 1 > > _ The reader resumes with 0 as an index but on the next srcu_read_lock() > > it will see the new idx which is 1 > > > > What could be the scenario for it to increment the old idx twice? > > Unless I am missing something, the reader must reference the > srcu_unlock_count[old_idx] and then do smp_mb() before it will be > absolutely guaranteed of seeing the new value of ->srcu_idx. I think both of you are right depending on how the flip raced with the first reader's unlock in that specific task. 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(). 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 thanks, - Joel