Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3080709pxj; Mon, 7 Jun 2021 01:32:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3reGHoZ7o3+ckBO34Gnwzq8dSDypXkAOSj757kgBghEqIP0v6FeJqrm9Q3zEXHKCXAJNL X-Received: by 2002:aa7:dd0b:: with SMTP id i11mr18412050edv.51.1623054777352; Mon, 07 Jun 2021 01:32:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623054777; cv=none; d=google.com; s=arc-20160816; b=iDHa+JIxGWmnkagsqH5397ZfDqQWE0QgvbUeRXU+VAHSkhR49/6wygl4OvyB8kkJe7 YTKfSTVn0+f1FdzMccz7/vfACGXlagdQE08jShMXcdrEvOOBBxIByJmGOnTj/IlGlKHq fosCbdDhVmhHgx5yUxnmaLq6QhUcPjjMoIWIlmsJpj8NKskJUrqq9JcMKP90xixlNK7n MAxs8qIYoh+Q0pleZZHgXpCmjJ/7CSvKNjtCF6OtQQkBHyE5Bg+YNyCjEy7Up/Srfz7k /rzR5MdPYpm+u6wlXiT0Z9921JaQNpIpnN0u3R42NbFUdC6ZMwMM1EXGbslTSdGDTjJM ganA== 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=+hJoek+dH6lRvIIEvtmpn8nrUNfH1I0O0qNY3ghdb8Q=; b=XkSrIwpe2YHyPYeCq9gipzGgr4JdhA6yh1WfmawRJ8K8BEKBg0ohVF3p570jBSjENN w4gn3uRYVmbduy/s+gguTvvV7ZkXk2qm0CfXuy+vf7cnCWDcYH28y6HNlQIhyTqxv+eI 8eRe79dn4SRmEEMl//uiwIWpXhGt0hklaG/pjXOMfyidIYUw2WyOhOdeasMjTJf54nhr jT4Gey9jiRNXjQWCFHDL/7OhMG+r9aw2ZKIu4j6zmGEI7SMlvxlYdOHlUFcEOZlc9KD8 wbzKfGhE6kGjG18R74wYumKo+mYDiOZXZbYuVM6Q/gBOovcErq76okkM37E//uu5QbzO KGVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LOIHafCI; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g7si11218191ejh.141.2021.06.07.01.32.34; Mon, 07 Jun 2021 01:32:57 -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=pass header.i=@google.com header.s=20161025 header.b=LOIHafCI; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231501AbhFGI36 (ORCPT + 99 others); Mon, 7 Jun 2021 04:29:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230403AbhFGI3c (ORCPT ); Mon, 7 Jun 2021 04:29:32 -0400 Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D27B0C061787 for ; Mon, 7 Jun 2021 01:27:25 -0700 (PDT) Received: by mail-oo1-xc2b.google.com with SMTP id q20-20020a4a6c140000b029024915d1bd7cso2285338ooc.12 for ; Mon, 07 Jun 2021 01:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+hJoek+dH6lRvIIEvtmpn8nrUNfH1I0O0qNY3ghdb8Q=; b=LOIHafCIFA0IyhxDKrZXKOLD3XN7IJWm1jCQ89b3C8PBWRM0EWPXMpK+bU8j8FHAmx zBCy3YmZZUZ0fh1b2Z5aX0OYihxljb5HWbZlX4ssC1etg2xnuwIyBZFo3x6KPeep+/Wd SnRHtQ8wY7o3OjrI1m0igZ3dC/oE0Br9IevO15JvfcPCWzzX3kqULNHoI1FkxVckZK32 rLYr0klqfNunFl8K/I0SpyWocYXGUjbHb+0pc86I3lso8POqgvokDcwgGd59MRXOw6I5 vZ0BOFL85Empou7cWfk/hbPTnfuWqAQrZu4pefLvNpgya2FMLrMQrywZNbG33VKJY1cE bQYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+hJoek+dH6lRvIIEvtmpn8nrUNfH1I0O0qNY3ghdb8Q=; b=aW1ghJrNYnG2wIdgeVqWSlqOfqypGg5eoUsI9juVg8FIDWWwzr+HFGk/kQfiEq6sRf pB9Eq/+PZyQZRlj9+4dL4bqQM1AnXeZ5LIw9ehXFiirol1jcchj/Pa50Ve//uOHhiaSw WeCTa9utvROMFAZ3A2LSWB28AUwZv39VjNIUYkVqYU6hDidlCUpUHbYeLHhe3iQatL4K kbSsN4w52X7RPuP1MWyaRunzBwHlIc0C9HojnijkLOSm8N4MJHy1GGrL2M6VwqlUx9JD xEa02Fnwe6CY73iPK0g9yvv49xA/gu/dWI2CJlTeSfr38dtY4/qZ19z14xy1PTQtR/Gp 1tJA== X-Gm-Message-State: AOAM532dKhFrp/1Df+3uuUnMpWsL5nEBSSx0OSH1h6HFMQhQvx2xDhwR mvNnDP3Bdkm5MaPMYqpWDm6b8xaUvv5rETbPh2Isag== X-Received: by 2002:a4a:1145:: with SMTP id 66mr12558163ooc.14.1623054443861; Mon, 07 Jun 2021 01:27:23 -0700 (PDT) MIME-Version: 1.0 References: <20210604205600.GB4397@paulmck-ThinkPad-P17-Gen-1> <20210604214010.GD4397@paulmck-ThinkPad-P17-Gen-1> <20210605145739.GB1712909@rowland.harvard.edu> <20210606001418.GH4397@paulmck-ThinkPad-P17-Gen-1> <20210606012903.GA1723421@rowland.harvard.edu> <20210606185922.GF7746@tucnak> In-Reply-To: From: Marco Elver Date: Mon, 7 Jun 2021 10:27:10 +0200 Message-ID: Subject: Re: [RFC] LKMM: Add volatile_if() To: Alexander Monakov Cc: Linus Torvalds , Jakub Jelinek , Alan Stern , Segher Boessenkool , "Paul E. McKenney" , Peter Zijlstra , Will Deacon , Andrea Parri , Boqun Feng , Nick Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Linux Kernel Mailing List , linux-toolchains@vger.kernel.org, linux-arch Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 7 Jun 2021 at 10:02, Alexander Monakov wrote: > On Sun, 6 Jun 2021, Linus Torvalds wrote: [...] > > On Sun, Jun 6, 2021 at 2:19 PM Alexander Monakov wrote: [...] > > Btw, since we have compiler people on line, the suggested 'barrier()' > > isn't actually perfect for this particular use: > > > > #define barrier() __asm__ __volatile__("" : : "i" (__COUNTER__) : "memory") > > > > in the general barrier case, we very much want to have that "memory" > > clobber, because the whole point of the general barrier case is that > > we want to make sure that the compiler doesn't cache memory state > > across it (ie the traditional use was basically what we now use > > "cpu_relax()" for, and you would use it for busy-looping on some > > condition). > > > > In the case of "volatile_if()", we actually would like to have not a > > memory clobber, but a "memory read". IOW, it would be a barrier for > > any writes taking place, but reads can move around it. > > > > I don't know of any way to express that to the compiler. We've used > > hacks for it before (in gcc, BLKmode reads turn into that kind of > > barrier in practice, so you can do something like make the memory > > input to the asm be a big array). But that turned out to be fairly > > unreliable, so now we use memory clobbers even if we just mean "reads > > random memory". > > So the barrier which is a compiler barrier but not a machine barrier is > __atomic_signal_fence(model), but internally GCC will not treat it smarter > than an asm-with-memory-clobber today. FWIW, Clang seems to be cleverer about it, and seems to do the optimal thing if I use a __atomic_signal_fence(__ATOMIC_RELEASE): https://godbolt.org/z/4v5xojqaY Thanks, -- Marco