Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1659735pxv; Fri, 23 Jul 2021 14:05:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSRdR1BOU2Lq99U8pKart7lQpWzYIgAcpAnYkKBDZ3g90qc5MG8HZQ3IEOzgLZYcRg0cjH X-Received: by 2002:a05:6e02:b24:: with SMTP id e4mr4577903ilu.41.1627074359585; Fri, 23 Jul 2021 14:05:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627074359; cv=none; d=google.com; s=arc-20160816; b=T5Z7hLzfmN0b6SyfRs4iVs4wthxPhPRP1v/i4yAciI8pxQcrfLqeH8yoZiRPoSk9u8 65Ynn8kwnb79nu4OoyXquNOxmiqWcWoMNDy56V2TYU5ZzzjR/PwVOKu4yuHsUqvT/pKJ Kuci0FfLGe69BuTVZkwFMRvgs5N322viV23xPdb24ZARU741CF5CGyX07shvst3u1JNl 6krk1XwDEKOlFdIjCAqxoj6d5KnjYDZP6eh1/SIlWD4KTxhy0H3iDUujK2mv6yvisWO9 naXgyduJVadz3ednsNEjon4ZX4YGd49a6nHRBnSCzQuOoWGN5SikQVYDAjGHJ78f8V0j FmGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=6yJvp7pXULevluu0EvsWC3XmuFUlejO784PmpesHdC8=; b=mvUfEeDTD7gr3QYWbytisqKZmVVnR3eVSc/HzUI8b9Qznt0SGt8G8LMlRH7xju/3tF +2oqMLy9Ccc1FUpsuXPRTKJO9MctlRx5utx3eg6LrOeGmDScNZ+OBqLUG5Vx052df5T6 an9kZoKVotcY8GzWkNSrikevQDFr7st3BczJ1NZ2fxYKh8M1LtUIymiI24cCS/V/v/9d L79sEJOmolPrIeESoICWN3n/Z921ZbaCJio+Y0efOYecRkAP0h+C6O6rcO8LvWrtnimN f3MCWWdZhMeFFhWJKDPnDxs6Aw/nVTXQa8ZOmlCYSujlz5ztzkKz+snyAr6ewuvA90Xh 1O5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w33si24898743jal.65.2021.07.23.14.05.48; Fri, 23 Jul 2021 14:05:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231601AbhGWUXR (ORCPT + 99 others); Fri, 23 Jul 2021 16:23:17 -0400 Received: from netrider.rowland.org ([192.131.102.5]:43335 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S231551AbhGWUXP (ORCPT ); Fri, 23 Jul 2021 16:23:15 -0400 Received: (qmail 53715 invoked by uid 1000); 23 Jul 2021 17:03:47 -0400 Date: Fri, 23 Jul 2021 17:03:47 -0400 From: Alan Stern To: "Paul E. McKenney" Cc: Manfred Spraul , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@fb.com, mingo@kernel.org, parri.andrea@gmail.com, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com Subject: Re: [PATCH memory-model 2/4] tools/memory-model: Add example for heuristic lockless reads Message-ID: <20210723210347.GA53526@rowland.harvard.edu> References: <20210721210726.GA828672@paulmck-ThinkPad-P17-Gen-1> <20210721211003.869892-2-paulmck@kernel.org> <20210723020846.GA26397@rowland.harvard.edu> <20210723130554.GA38923@rowland.harvard.edu> <20210723163008.GG4397@paulmck-ThinkPad-P17-Gen-1> <20210723170820.GB46562@rowland.harvard.edu> <20210723203248.GL4397@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210723203248.GL4397@paulmck-ThinkPad-P17-Gen-1> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 23, 2021 at 01:28:11PM -0700, Paul E. McKenney wrote: > On Fri, Jul 23, 2021 at 02:11:38PM -0400, Alan Stern wrote: > > In other words, if the second read races with the WRITE_ONCE, it needs to > > get either the value before the write or the value after the write; > > nothing else will do because it isn't a heuristic here. Fair point. > > > > > (If the value changes immediately after being read, the fact that > > > ->f_lock is held prevents begin_global() from completing.) > > > > This seems like something worth explaining in the document. That > > "IMPORTANT" comment doesn't really get the full point across. > > How about this comment instead? > > /* This works even if data_race() returns nonsense. */ That's somewhat better. On Fri, Jul 23, 2021 at 01:32:48PM -0700, Paul E. McKenney wrote: > On Fri, Jul 23, 2021 at 01:08:20PM -0400, Alan Stern wrote: > > This doesn't mention the reason for the acquire-release > > synchronization of global_flag. It's needed because work done between > > begin_global() and end_global() can affect a foo structure without > > holding its private f_lock member, and we want all such work to be > > visible to other threads when they call do_something_locked() later. > > Like this added paragraph at the end? > > The smp_load_acquire() and smp_store_release() are required > because changes to a foo structure between calls to begin_global() > and end_global() are carried out without holding that structure's > ->f_lock. The smp_load_acquire() and smp_store_release() > ensure that the next invocation of do_something() from the call > to do_something_locked() that acquires that ->f_lock will see > those changes. I'd shorten the last sentence: The smp_load_acquire() and smp_store_release() ensure that the next invocation of do_something() from do_something_locked() will see those changes. Alan