Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1015034ybg; Mon, 27 Jul 2020 05:52:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfV7ldSHQuHDuU0IUUPlQhIFPwy+PFD3OR+NUl2luiASwg1jMUOiLJaQcaRPwsRTlUa7oV X-Received: by 2002:a50:ee07:: with SMTP id g7mr21800852eds.320.1595854373912; Mon, 27 Jul 2020 05:52:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595854373; cv=none; d=google.com; s=arc-20160816; b=fH7rLhf5x79E6V+FyiJHdsqI8aBz70GT63X0ZHArD0/giM64g5Qx9/VLaWgg9eZ2Ww oYrAIgQMe73ttzMBDXwbY0zgYNtZgESYNgSsJ2TOM5skN5zN4Fq8qpFJMOP4oUjJGw4h VgAa2e1hWG5j2Lz8NJDeEurgT5zReuXO9W8fhVsZrZGKoZkti0NIo7TqcoUHsL8GAlc8 qzStIZ4wnxWe9OW3Z2go5Ey1VC+SvCPoHschCJpF+W1Fn4vZcBBw5WgX3ooH3Gjju28k bRCfzhYdV59nk06rpu25IzTD6ioyCaTDQqLy6rQYWfUabegC5cNlGVm4gX6JzC5Ohkyh CRfw== 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=DaAYayPt0rjSYJYHQGKl8PlBczwB5P48X+5+SHwawBM=; b=0/kxfPL8Iwbl+6CgE0XJx7E0B5xrFRNmAT3KM0JGoLN75W2wnyKgFvfRlJmVfSqqJS 8pbWrswKyk0GbXfypQQV4vU73ywec1tdrqmrVxaIqmfT1AdgMLEp56u3RdtzD1zLtIR0 +tsuEyvsve5gzL7VCa1/inK5VxP0bvwWCh2xWhHTPdrPs//hL1ypp9n26Atk++OGGhlC YTtepg3F5PBpse1MfUGPt8UYKU5ooptX2Gob+CeU0Y5v2R5DwkoYMSrczp16BMRDx7Ox ZJb9GdCY6/izLUx2zREHRzXZM+VhXbK/7Zz4UFTNQWW82Z7bGZNdg0fzSkbQreNWiguI 3s4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=QHt89R9F; 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 i25si5521943ejy.603.2020.07.27.05.52.31; Mon, 27 Jul 2020 05:52:53 -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=QHt89R9F; 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 S1728559AbgG0Mvn (ORCPT + 99 others); Mon, 27 Jul 2020 08:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728467AbgG0Mvn (ORCPT ); Mon, 27 Jul 2020 08:51:43 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 086CFC061794; Mon, 27 Jul 2020 05:51:43 -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=DaAYayPt0rjSYJYHQGKl8PlBczwB5P48X+5+SHwawBM=; b=QHt89R9FfGq2fppSZ477pANbbQ SoFXylVsYKqCIG+2ofNxlnC1P4aqRHuam6ZdFpV4GDtaVAnwFKqd7ExrrLYGFiPELztpcU+xaA52M CcX4acasJ4IxvlBtG4F/8ZAtFMztyotzBhLNz/OxyXgaQlSFNoFqFktwQo/mzz1izN6+Gc3e6nt5z QuQQ+mVc++qSyWh5FpsqFZOspW52TDKZKoPrEWSxnzOvzu+PbGOlaUiXdV9rC0zbekRXYLMWB8bwL UiR6m4tQQ/5YGlv2zdfZeudZsMjor1GdFeHNd8M6MGIylP4FaO6OmXOYUlyznlq1VZV3UEFzJx3Si wHhMcw3A==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1k02bR-0008Cm-ED; Mon, 27 Jul 2020 12:51:37 +0000 Date: Mon, 27 Jul 2020 13:51:37 +0100 From: Matthew Wilcox To: Eric Biggers Cc: Alan Stern , 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 , "Darrick J . Wong" , 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: <20200727125137.GK23808@casper.infradead.org> References: <20200717044427.68747-1-ebiggers@kernel.org> <20200717174750.GQ12769@casper.infradead.org> <20200717175138.GB1156312@rowland.harvard.edu> <20200718010247.GC2183@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200718010247.GC2183@sol.localdomain> 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 06:02:47PM -0700, Eric Biggers wrote: > On Fri, Jul 17, 2020 at 01:51:38PM -0400, Alan Stern wrote: > > On Fri, Jul 17, 2020 at 06:47:50PM +0100, Matthew Wilcox wrote: > > > On Thu, Jul 16, 2020 at 09:44:27PM -0700, Eric Biggers wrote: > > ... > > > > + /* on success, pairs with smp_load_acquire() above and below */ > > > > + if (cmpxchg_release(&foo, NULL, p) != NULL) { > > > > > > Why do we have cmpxchg_release() anyway? Under what circumstances is > > > cmpxchg() useful _without_ having release semantics? > > > > To answer just the last question: cmpxchg() is useful for lock > > acquisition, in which case it needs to have acquire semantics rather > > than release semantics. > > > > To clarify, there are 4 versions of cmpxchg: > > cmpxchg(): does ACQUIRE and RELEASE (on success) > cmpxchg_acquire(): does ACQUIRE only (on success) > cmpxchg_release(): does RELEASE only (on success) > cmpxchg_relaxed(): no barriers > > The problem here is that here we need RELEASE on success and ACQUIRE on failure. > But no version guarantees any barrier on failure. Why not? Do CPU designers not do load-linked-with-acquire-semantics? Or is it our fault for not using the appropriate instruction? > So as far as I can tell, the best we can do is use cmpxchg_release() (or > cmpxchg() which would be stronger but unnecessary), followed by a separate > ACQUIRE on failure. OK, but that detail needs to be hidden behind a higher level primitive, not exposed to device driver writers.