Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2318350imm; Thu, 21 Jun 2018 10:27:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLrf4Ar1ExwecKmudqL2IPbQx0ShjHl9deD0DOVAUiHmH9r2t7gzQWcx+e2YOVGpdS8b1nw X-Received: by 2002:a62:8a0a:: with SMTP id y10-v6mr28511274pfd.237.1529602065548; Thu, 21 Jun 2018 10:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529602065; cv=none; d=google.com; s=arc-20160816; b=NCSqppm2Z/QWXm0z5NXOT+qi/FgPzJ7wICO6TFEQ/rNc6bC4I+WGuTFUdigI+Fq0ar kc2FmhrKf3HKjNVIp3Uwa91TnLjs++1Az4f40jV9eZcNQgFUH+jwDR97IQPVatYBiZ34 cGuaTboZPprQG3EUa9gRtiKJLT1wuS91Ykny3hCQ/DhhnF+icqyymT1xYNqC3rJuDL0/ SWwOUKD8/I4MqK3JZhrTvxTvV+UVX7dZ8dW4pcMYa9tRgdJ0eayklgZnP9UJd7IFMtV2 DHxs+6MnpM01OEyj08yeCpKRN4zOjatqxHwl8wxsPa71dGOmnGoMEUUSeU5TOX8NMiVN z4mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:subject:cc:to :from:date:arc-authentication-results; bh=PI/pxtpoiTJ/B6spsOZ8rDUQZI/hbvYWKfwZc3dpTvI=; b=M1MBdcT7ufcis03W7zX2PwzsByPUgZXFIf9c+SbT6Qtwxg1nC2mdypsy6onOpvilxb 2uu3vBS+AmX+mZhBtoOUItqddfbSoVl/wXfGTHnv2kmZKIubJSZX3fNGvf509Puo6fPa qj/hYb2ul0U+sXTYb+ghAylEsV/i+E5I5U442XOWCpB4z+zUfZVo3bhoMlRFXoTnB38v Re1l3YXN8S08VdRIbIGVI42E7HIeyCOpvSjmBAxXwtPZFBSSDth+yo6KQV9SgB+uT5lK lpdnF0IMK/ApCGZex5IzMEzqPBn4ZxJaYFpAVwXSccJJXYHDZ/iBmLkrJY4DhRKOsGL/ LX/w== ARC-Authentication-Results: i=1; mx.google.com; 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 k12-v6si4385749pgp.561.2018.06.21.10.27.30; Thu, 21 Jun 2018 10:27:45 -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; 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 S932800AbeFUR0v (ORCPT + 99 others); Thu, 21 Jun 2018 13:26:51 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:36776 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S932508AbeFUR0u (ORCPT ); Thu, 21 Jun 2018 13:26:50 -0400 Received: (qmail 4461 invoked by uid 2102); 21 Jun 2018 13:26:49 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 21 Jun 2018 13:26:49 -0400 Date: Thu, 21 Jun 2018 13:26:49 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: LKMM Maintainers -- Akira Yokosawa , Andrea Parri , Boqun Feng , David Howells , Jade Alglave , Luc Maranget , Nicholas Piggin , "Paul E. McKenney" , Peter Zijlstra , Will Deacon cc: Kernel development list Subject: [PATCH 1/2] tools/memory-model: Change rel-rfi-acq ordering to (rel-rf-acq-po & int) Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch changes the LKMM rule which says that an acquire which reads from an earlier release must be executed after that release (in other words, the release cannot be forwarded to the acquire). This is not true on PowerPC, for example. What is true instead is that any instruction following the acquire must be executed after the release. On some architectures this is because a write-release cannot be forwarded to a read-acquire; on others (including PowerPC) it is because the implementation of smp_load_acquire() places a memory barrier immediately after the load. This change to the model does not cause any change to the model's predictions. This is because any link starting from a load must be an instance of either po or fr. In the po case, the new rule will still provide ordering. In the fr case, we also have ordering because there must be a co link to the same destination starting from the write-release. Signed-off-by: Alan Stern --- [as1870] tools/memory-model/Documentation/explanation.txt | 35 ++++++++++++----------- tools/memory-model/linux-kernel.cat | 6 +-- 2 files changed, 22 insertions(+), 19 deletions(-) Index: usb-4.x/tools/memory-model/linux-kernel.cat =================================================================== --- usb-4.x.orig/tools/memory-model/linux-kernel.cat +++ usb-4.x/tools/memory-model/linux-kernel.cat @@ -38,7 +38,7 @@ let strong-fence = mb | gp (* Release Acquire *) let acq-po = [Acquire] ; po ; [M] let po-rel = [M] ; po ; [Release] -let rfi-rel-acq = [Release] ; rfi ; [Acquire] +let rel-rf-acq-po = [Release] ; rf ; [Acquire] ; po (**********************************) (* Fundamental coherence ordering *) @@ -60,9 +60,9 @@ let dep = addr | data let rwdep = (dep | ctrl) ; [W] let overwrite = co | fr let to-w = rwdep | (overwrite & int) -let to-r = addr | (dep ; rfi) | rfi-rel-acq +let to-r = addr | (dep ; rfi) let fence = strong-fence | wmb | po-rel | rmb | acq-po -let ppo = to-r | to-w | fence +let ppo = to-r | to-w | fence | (rel-rf-acq-po & int) (* Propagation: Ordering from release operations and strong fences. *) let A-cumul(r) = rfe? ; r Index: usb-4.x/tools/memory-model/Documentation/explanation.txt =================================================================== --- usb-4.x.orig/tools/memory-model/Documentation/explanation.txt +++ usb-4.x/tools/memory-model/Documentation/explanation.txt @@ -1067,27 +1067,30 @@ allowing out-of-order writes like this t violating the write-write coherence rule by requiring the CPU not to send the W write to the memory subsystem at all!) -There is one last example of preserved program order in the LKMM: when -a load-acquire reads from an earlier store-release. For example: +There is one last example of preserved program order in the LKMM; it +applies to instructions po-after a load-acquire which reads from an +earlier store-release. For example: smp_store_release(&x, 123); r1 = smp_load_acquire(&x); + WRITE_ONCE(&y, 246); If the smp_load_acquire() ends up obtaining the 123 value that was -stored by the smp_store_release(), the LKMM says that the load must be -executed after the store; the store cannot be forwarded to the load. -This requirement does not arise from the operational model, but it -yields correct predictions on all architectures supported by the Linux -kernel, although for differing reasons. - -On some architectures, including x86 and ARMv8, it is true that the -store cannot be forwarded to the load. On others, including PowerPC -and ARMv7, smp_store_release() generates object code that starts with -a fence and smp_load_acquire() generates object code that ends with a -fence. The upshot is that even though the store may be forwarded to -the load, it is still true that any instruction preceding the store -will be executed before the load or any following instructions, and -the store will be executed before any instruction following the load. +written by the smp_store_release(), the LKMM says that the store to y +must be executed after the store to x. In fact, the only way this +could fail would be if the store-release was forwarded to the +load-acquire; the LKMM says it holds even in that case. This +requirement does not arise from the operational model, but it yields +correct predictions on all architectures supported by the Linux +kernel, although for differing reasons: + +On some architectures, including x86 and ARMv8, a store-release cannot +be forwarded to a load-acquire. On others, including PowerPC and +ARMv7, smp_load_acquire() generates object code that ends with a +fence. The result is that even though the store-release may be +forwarded to the load-acquire, it is still true that the store-release +(and all preceding instructions) will be executed before any +instruction following the load-acquire. AND THEN THERE WAS ALPHA