Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4925943imm; Wed, 30 May 2018 15:03:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJWSmzWWOd5yR7vnd1INHs5+KX1/++sUjw1MF4UrEZuydLa0wjaCAhCcOaS9ny+CY+1u7/Q X-Received: by 2002:a65:4cc3:: with SMTP id n3-v6mr3479094pgt.98.1527717798943; Wed, 30 May 2018 15:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527717798; cv=none; d=google.com; s=arc-20160816; b=AjD1xegQbG9OHB+DYw0solrKYX8i88IN6fwNhNqbwCDqacI6xMoGP2gOJpVt5QqUyq lqfXJBbg8iNjj/TFSbPytVFu987jIbmN3/h1AsRGc6NFehKLY7Dp6Mbl118HktkHEddI /f3EKOufEpzcCMiW/FcT9vFTg0o79gcVEa6fFbjUXD4UgBcqHFYaaMNFG6Jvp9jPqS7c ZXlsk/Qjs70dIeEOszTKBMioCJrQmvhcXZ5ItCwdUMFbKXvTnFBKEq/jAqpuhM7kKFQG sUpfDkeZjdPa4e+tOvKLuuTMKRdUq+VbI/UZrib7r7Ohl21O9VJRmTmX9M359+jwp0hI zDGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=OUQMo3YGUP+hqbNvCkI6XaUveQyXEM+63f5eG0MAcKQ=; b=tZBxKpHOdO84meeSFBiElfIdEXPytOPzKqBCIDJrpaUSDN6IM48eCb2xOuVirnaJOC bp6NmJo6nBKPKLPam3zGWRdd48QPeuwwLr3bVgONvzqrXPIwc6BVQwlv6+Xv1hpTfF2m 3JCbtCBu36gtNJX3wla43+edCvfY/Gth/w1r3ik0t3Ddu4/sEpOQm4w1mlGxEKvZphn2 4cw3GfeA8psM+5Fn/NJDAqca0ne7g8XW8GDz6RtdBx15wi0ORhYbRNlbUQEl6GW0adwT EHetQYJ+p39vRRIWsnc9a40klrsftmlNavRdbs4EgPElJbdf+X7ktptBNOzNykTIVcFR xxPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=WVUSCmPN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g65-v6si8373345pfa.304.2018.05.30.15.03.04; Wed, 30 May 2018 15:03:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=WVUSCmPN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932549AbeE3WBR (ORCPT + 99 others); Wed, 30 May 2018 18:01:17 -0400 Received: from mail-io0-f178.google.com ([209.85.223.178]:34490 "EHLO mail-io0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932222AbeE3WBO (ORCPT ); Wed, 30 May 2018 18:01:14 -0400 Received: by mail-io0-f178.google.com with SMTP id e15-v6so15081928iog.1; Wed, 30 May 2018 15:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OUQMo3YGUP+hqbNvCkI6XaUveQyXEM+63f5eG0MAcKQ=; b=WVUSCmPNQlZfK2hoie1oS1pxLtB5ZNxF23lKchyK69Jl7GxhSABeMaZlKMf3y4mIkp iINbRnyedJVwQDYs2c0R7E3ygUPrH67yodhZNgXhjbt1oOmGYyk2S5yP4PzIpdvkWVdF sxTBhfJxuIlNQe7Xex0Mk7HkwkAwyGopH3MRA= 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=OUQMo3YGUP+hqbNvCkI6XaUveQyXEM+63f5eG0MAcKQ=; b=ZnHgVoE9ic93vukOR641s8dxr+JpD7uHsKTnDavEF839Iv7RGtDJtP5ALynAKgal1x Mc1XkiY50rxT5M9tut8RAfUw0k400D3lVlAkwMKowFoYnoOSb2eSEjbzBhK6ur40Zsc1 RxAt7YyTjYjOojcyVj8NjZymLAf+t7iHWV0osID91ArS/MXwGkZz0H8ms71NJYOcbq46 ZQJiiYQkkpLUe7dRNvkOYxB2HZRq0kxeirPY9R2FNoe9poXbM4eBFfRkntwGTCDYbsjq qHUOA7f3XxWA32SOSnJGhK9432kNTGVXiAqejpEp6tl0F9A3AbxdNSJYkgQ15UJjJuCm fdqA== X-Gm-Message-State: APt69E28yO2Xm/TJV2fByDlr+jH4ywXLYaewUWeu5FG5WsnIdWsFeD5o 4Sd/d6Eamg+yIGkMBoq7i+hzJ2gsEpkb8Gh22lE= X-Received: by 2002:a6b:ce15:: with SMTP id p21-v6mr791712iob.257.1527717673498; Wed, 30 May 2018 15:01:13 -0700 (PDT) MIME-Version: 1.0 References: <20180530183826.GI7063@linux.vnet.ibm.com> In-Reply-To: From: Linus Torvalds Date: Wed, 30 May 2018 17:01:01 -0500 Message-ID: Subject: Re: LKMM litmus test for Roman Penyaev's rcu-rr To: Alan Stern Cc: Paul McKenney , Linux Kernel Mailing List , linux-arch , andrea.parri@amarulasolutions.com, Will Deacon , Peter Zijlstra , Boqun Feng , Nick Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Ingo Molnar , Roman Pen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 30, 2018 at 2:08 PM Alan Stern wrote: > > Indeed. The very first line Linus quoted in his first reply to me > (elided above) was: > > Putting this into herd would be extremely difficult, if not impossible, > because it involves analyzing code that was not executed. > > It should be clear from this that I was talking about herd. Not gcc or > real hardware. So what does herd actually work on? The source code or the executable, or a trace? I found the herd paper, but I'm on the road helping my daughter in college move, and I don't have the background to skim the paper quickly and come up with the obvious answer, so I'l just ask. Because I really think that from our memory model standpoint, we really do have the rule that load -> cond -> store is ordered - even if the store address and store data is in no way dependent on the load. The only thing that matters is that there's a conditional that is dependent on the load in between the load and the store. Note that this is *independent* of how you get to the store. It doesn't matter if it's a fallthrough conditional jump or a taken conditional jump, or whether there is a joining. The only thing that *does* matter is whether the conditional can be turned into a "select" statement. If the conditional can be turned into a data dependency, then the ordering goes away. That is why it was relevant whether "C" contained a barrier or not (it doesn't even have to be a *memory* barrier, it just has to be a barrier for code generation). Note that the "C doesn't even have to have a memory barrier" is important, because the orderin from load->cond->store doesn't actually have anything to do with any memory ordering imposed by C, it's much more fundamental than that. > Preserving the order of volatile accesses isn't sufficient. The > compiler is still allowed to translate > > r1 = READ_ONCE(x); > if (r1) { > ... > } > WRITE_ONCE(y, r2); > > into something resembling > > r1 = READ_ONCE(x); > WRITE_ONCE(y, r2); > if (r1) { > ... > } Correct. What matter is that the code in C (now called "..." above ;^) has a build-time barrier that means that the compiler cannot do that. That barrier can be pretty much anything. The important part is literally that there's a guarantee that the write cannot be migrated below the conditional. But I don't know what level 'herd' works on. If it doesn't see compiler barriers (eg our own "barrier()" macro that literally is just that), only sees the generated code, then it really has no other information than what he compiler _happened_ to do - it doesn't know if the compiler did the store after the conditional because it *had* to do so, or whether it was just a random instruction scheduling decision. Linus