Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp5055167rwj; Tue, 20 Dec 2022 19:48:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXuryA1oP/1a+KNnK2oxMZwYKRBNwsiVBmzAbEioS9Q5FpyWnbDeuqesWgvGLI3Qul7W/Zjg X-Received: by 2002:a17:902:7488:b0:189:f708:9b67 with SMTP id h8-20020a170902748800b00189f7089b67mr587011pll.46.1671594480551; Tue, 20 Dec 2022 19:48:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671594480; cv=none; d=google.com; s=arc-20160816; b=cLnU3/ZZnzwWOiDAzxH+nB6C6txk0tYXO+5chOTZgIS/wImFII6riY1AKm8sti7nuo BeIWQfiGkhgT1n5eYhNLa38JqSEYjoO8r5q0+a9YFSxvzusFwANKdQlpVoRw/hWmaRvo KPU7C7CESvC/DtPiVmIGlqg8yWEyjwekKX23XTOjVjpk78w9+PwB1V9ruLhF2O08GxJN CE0BcdN+LjKZLrTpz+/hPvj+3k/JSIng/F7tz7ofoYwLtli28Lf73lg34F1ykM9KUjBL WhnVRULptJB13shKBn/tjSlnYOXXrMpGFF5H7IAfc8lGCwIYaHUxUx0KpDGE2Z3HjeLm 7hPw== 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; bh=RYowydDEKCtIX3TrR3NJZ2ScJXHsQkF4nSpEEExWr44=; b=Xqai1sII+MzYoxDXZEa88Vk0OSTzXpSKnRp1EiPO4UkPD2voTfVaAchIIA2BZ09rSZ 2mV7gjfocwxPyuQ9NO5+VpGLio0t9ikP/lcvORyVbHKVEKo2d6GPswUT6kaPYQCYaJ0m 4xxhVMCxXPnb3AiqrLZ4ZaAdo+p4eETlKDV4e++Gy2zzSYiFzgtr2uyBjCye659cZWE8 bBHqu+QTYQ8lvwjYxnZ+DAsB6kAG88k3UIu9RqSffIgpQ6ckpiqbReD1INQk2BPWNbiY PbtUlugfVvD4gVduNdsLtN0LGEo8mLthBtWwqHm5Q1aBydyU8zuj0gAr8J+gBk1yI1x4 UUhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=g5Egj5va; 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=efficios.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020a63fc49000000b00475abba079bsi14902768pgk.405.2022.12.20.19.47.51; Tue, 20 Dec 2022 19:48: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=@efficios.com header.s=smtpout1 header.b=g5Egj5va; 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=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234387AbiLUDnK (ORCPT + 69 others); Tue, 20 Dec 2022 22:43:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbiLUDnI (ORCPT ); Tue, 20 Dec 2022 22:43:08 -0500 Received: from smtpout.efficios.com (unknown [IPv6:2607:5300:203:b2ee::31e5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC5A21EAD6; Tue, 20 Dec 2022 19:43:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1671594180; bh=AwTHZsJE1OHmZw07jiGlqjcJAYhW0GUTvOa719wrfcw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=g5Egj5vaNGMMyKDGyVK12hdPytUVLvpAYJlg5fhmDr2lN1H0B2+29ItSjzJA5gQL/ 3zF6gYuGrb6EJrrcOwre55oGT4vYz0Nwp2P3nzh49RLBim0oOTnWJl2CxwovVpu246 SzK9ScSOWWln1fhaZulfuvND4o4PIEWv61jZRAgouqK0YOYwurQ3dvXLUuKx5TWk8q MQhX4hxvIp5kL0WQw702zFsQoL2f+067xBRGvt6xhctB+hRRHOCbgLuq9rFd2L5Dmu nk7beGL+LYfF7uy65mU2ZbmQm7QUfbIRpp8GZ3c5TiDIr/N52N7c+qiiovTivU20KM w64WGCwJw99zw== Received: from [10.1.0.30] (192-222-188-97.qc.cable.ebox.net [192.222.188.97]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4NcK5w5GFlzbvj; Tue, 20 Dec 2022 22:43:00 -0500 (EST) Message-ID: Date: Tue, 20 Dec 2022 22:43:25 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [RFC 0/2] srcu: Remove pre-flip memory barrier Content-Language: en-US To: Frederic Weisbecker , Joel Fernandes Cc: linux-kernel@vger.kernel.org, Josh Triplett , Lai Jiangshan , "Paul E. McKenney" , rcu@vger.kernel.org, Steven Rostedt References: <20221220140714.GB22763@lothringen> <20221220224459.GA25175@lothringen> <20221221004957.GA29021@lothringen> <20221221005858.GA29316@lothringen> From: Mathieu Desnoyers In-Reply-To: <20221221005858.GA29316@lothringen> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RDNS_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 2022-12-20 19:58, Frederic Weisbecker wrote: > On Wed, Dec 21, 2022 at 01:49:57AM +0100, Frederic Weisbecker wrote: >> On Tue, Dec 20, 2022 at 07:15:00PM -0500, Joel Fernandes wrote: >>> On Tue, Dec 20, 2022 at 5:45 PM Frederic Weisbecker wrote: >>> Agreed about (1). >>> >>>> _ In (2), E pairs with the address-dependency between idx and lock_count. >>> >>> But that is not the only reason. If that was the only reason for (2), >>> then there is an smp_mb() just before the next-scan post-flip before >>> the lock counts are read. >> >> The post-flip barrier makes sure the new idx is visible on the next READER's >> turn, but it doesn't protect against the fact that "READ idx then WRITE lock[idx]" >> may appear unordered from the update side POV if there is no barrier between the >> scan and the flip. >> >> If you remove the smp_mb() from the litmus test I sent, things explode. > > Or rather, look at it the other way, if there is no barrier between the lock > scan and the index flip (E), then the index flip can appear to be written before the > lock is read. Which means you may start activating the index before you finish > reading it (at least it appears that way from the readers pont of view). Considering that you can have pre-existing readers from arbitrary index appearing anywhere in the grace period (because a reader can fetch the index and be preempted for an arbitrary amount of time before incrementing the lock count), the grace period algorithm needs to deal with the fact that a newcoming reader can appear in a given index either before or after the flip. I don't see how flipping the index before or after loading the unlock/lock values would break anything (except for unlikely counter overflow situations as previously discussed). Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com