Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp59996ybh; Fri, 17 Jul 2020 18:41:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa9XD+D2RK4+mm3ghJlAvZWytmdAUcWdrR5ByAPHlBzo0igDOv0nA7M+FXwnqF54YfL+Jp X-Received: by 2002:a50:9b5d:: with SMTP id a29mr11844246edj.68.1595036485754; Fri, 17 Jul 2020 18:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595036485; cv=none; d=google.com; s=arc-20160816; b=b2T9ocAehYY+92qIGQHJI1wlXVUxkbtOD8++oti6Yvb2JmS5isCJUy/JOKSf2T89Kd PcwOoz09jqLqEIIBDR00/Ln+BdRX+p3rub9RHRJcaaekyT1Dxb55Bxs4bJ5S4LejZzS1 96iRIB8HJ+Vf8amPEUBU1WY1kniFjh06p7QyxX2yLFEmxpQTQVUljvAEVWCY/mq65pd0 VR1xmk1TdH04yR/SPQ+OfZoLvsoFub5pCd3CRWPoMiPm0KI/pT8OVeNglFGp/inLKJ2v +eOZvEctwCalySxNQoeejlq4uyQlz59s3pKvNhLlBpg3JpgDzVH8dr0WPqSVOQ1w+tpx kOEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=z/LXzyQQvIbTaBiNEA7lgQw3JPPFGRlWt4h9R1rYhrg=; b=vuA0ZQmswK89gBXwBs101P4jc3YYtqfX83n19tATL7SXta3ZSwogDQbqZMRBtHbynm d32sPmjPdQnT1yGikKSP3FYz3fdeW2KA4bNAq5mzK/FDWFKKIYQKRUP8cHXWh9AGDI2z Grcm1+v7V7gOGKkSLZkF3yZi4LHI5T/ulb5lKkNBSRdhCozSANW0v6EM5OCuOdbAr41I DiR36Pc/VCKvKnNbHZvknmJJudCzGdkuVDYJJMXjRjChfycTm1Vj0AyNI5QZCbqe2Lyo KsZ1aJTxt9dhCf3Qusosk4oKHi+3sIBB+W5ruXbeyMN1DF81EaKOLx08NDrK4oq2e7uZ fu2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b="TW/I1cKu"; 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 t22si6107250edy.39.2020.07.17.18.41.02; Fri, 17 Jul 2020 18:41:25 -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; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b="TW/I1cKu"; 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 S1728316AbgGRBkw (ORCPT + 99 others); Fri, 17 Jul 2020 21:40:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726710AbgGRBkw (ORCPT ); Fri, 17 Jul 2020 21:40:52 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 418E6C0619D2; Fri, 17 Jul 2020 18:40:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=z/LXzyQQvIbTaBiNEA7lgQw3JPPFGRlWt4h9R1rYhrg=; b=TW/I1cKuOLoHLOvAY6NeiZQoKd Zz2vamGQF53yhMt6PyvGcRSJc2NCJiD8AoqZotSvdc5IfQQi3RarSXe0+gx/TrcCItHtOmrWo9qVD hSWDbi8PLUGIcVHTKBVSin6QPQ0TmYJ9L83ixHQ/dnfUYOUhI0C6jF+x3q+ftwoA78tmPw0utlJYo AXikpTIu3x3a7vkZWPeGKiaitOu9+2+GwAdXj493Fppw/gsg7RJpflX2FbkSZZ+4vfDkCPGYLps85 X1+TZzzOwYMb+6L0J8qB0DvdAZ9754djv/z+wkZUqFKfdF+SMT2frO01tVaf7p4UI/uCgjUwFFJfA 68q3E16A==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwbqH-00016U-IO; Sat, 18 Jul 2020 01:40:45 +0000 Date: Sat, 18 Jul 2020 02:40:45 +0100 From: Matthew Wilcox To: Alan Stern Cc: Eric Biggers , "Darrick J. Wong" , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, "Paul E . McKenney" , linux-fsdevel@vger.kernel.org, Akira Yokosawa , Andrea Parri , Boqun Feng , Daniel Lustig , Dave Chinner , David Howells , Jade Alglave , Luc Maranget , Nicholas Piggin , Peter Zijlstra , Will Deacon Subject: Re: [PATCH] tools/memory-model: document the "one-time init" pattern Message-ID: <20200718014045.GR12769@casper.infradead.org> References: <20200717044427.68747-1-ebiggers@kernel.org> <20200717205340.GR7625@magnolia> <20200718005857.GB2183@sol.localdomain> <20200718012555.GA1168834@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200718012555.GA1168834@rowland.harvard.edu> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 17, 2020 at 09:25:55PM -0400, Alan Stern wrote: > On Fri, Jul 17, 2020 at 05:58:57PM -0700, Eric Biggers wrote: > > On Fri, Jul 17, 2020 at 01:53:40PM -0700, Darrick J. Wong wrote: > > > > +There are also cases in which the smp_load_acquire() can be replaced by > > > > +the more lightweight READ_ONCE(). (smp_store_release() is still > > > > +required.) Specifically, if all initialized memory is transitively > > > > +reachable from the pointer itself, then there is no control dependency > > > > > > I don't quite understand what "transitively reachable from the pointer > > > itself" means? Does that describe the situation where all the objects > > > reachable through the object that the global struct foo pointer points > > > at are /only/ reachable via that global pointer? > > > > > > > The intent is that "transitively reachable" means that all initialized memory > > can be reached by dereferencing the pointer in some way, e.g. p->a->b[5]->c. > > > > It could also be the case that allocating the object initializes some global or > > static data, which isn't reachable in that way. Access to that data would then > > be a control dependency, which a data dependency barrier wouldn't work for. > > > > It's possible I misunderstood something. (Note the next paragraph does say that > > using READ_ONCE() is discouraged, exactly for this reason -- it can be hard to > > tell whether it's correct.) Suggestions of what to write here are appreciated. > > Perhaps something like this: > > Specifically, if the only way to reach the initialized memory > involves dereferencing the pointer itself then READ_ONCE() is > sufficient. This is because there will be an address dependency > between reading the pointer and accessing the memory, which will > ensure proper ordering. But if some of the initialized memory > is reachable some other way (for example, if it is global or > static data) then there need not be an address dependency, > merely a control dependency (checking whether the pointer is > non-NULL). Control dependencies do not always ensure ordering > -- certainly not for reads, and depending on the compiler, > possibly not for some writes -- and therefore a load-acquire is > necessary. > > Perhaps this is more wordy than you want, but it does get the important > ideas across. I don't think we should worry about wordsmithing this. We should just say "Use the init_pointer_once API" and then people who want to worry about optimising the implementation of that API never have to talk to the people who want to use that API.