Received: by 10.223.164.202 with SMTP id h10csp4782697wrb; Wed, 29 Nov 2017 11:45:49 -0800 (PST) X-Google-Smtp-Source: AGs4zMbW35jEctherFPi6nJCIXsjuZL3hbScdowTg7YvNHpPdwzOVrkVYX9Mr2fRrTXjfNM3U55o X-Received: by 10.99.3.195 with SMTP id 186mr3917345pgd.103.1511984749818; Wed, 29 Nov 2017 11:45:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511984749; cv=none; d=google.com; s=arc-20160816; b=gsfoNAI65zaTjkrQi6m9z2lSqtMf1sqMvRrkTh1yJlAMaXVhp+bdZFOd87LmVz/pY5 ECEzWZwp6faS5OFMtAGcge00vEaGkxxT8rW0xYSEsA/8ATu3UHzGj9Jh7u31x740l3sA tuxV2rS3hwNw7pBagpBdDUtp1k8VlcQlAwVZ8i05HQROz678xnVDbb1GMadT8BgZVIjK KvULH2SCdkdH0LQriymm4IkXrWQMVXK+WhFKISFsfP046gAa/NQU1QDiy7YnNnJzDqqn 9R3TE19SDmuLCDRmIgLOQCIcyeUGPm1ho90cKc9H5w08FQnFFWPaYFnhRFqcf47WPks5 YsXg== 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:in-reply-to :subject:cc:to:from:date:arc-authentication-results; bh=SWS15/CvRFTX1c9v6w9IFbhmd/Z/nMHVVru8IxUe67g=; b=ZxIDKIeeZfhhjvAVfTvJdnf1tTZjUc7GgPjiOJMJ4AjO5JeFQpiSBdkAjrh53XgKEh EtOlv/hTlNii9vzM5155bIvDAEG0Rifmr5LCWT2ZxXIIW0MARjcwKR19J1TujCVN5wv2 /8tmAxd80aF7lHLkhP+AK67rmHMlEh/mYcY48JEcvuj0tGKTIA9Dsk4I1p19Yut3GnCr CZvRzTSHOSIstX+JkjMsNx0clrMEGPMT05IjOjdZN1Ln1QuYcziqiFqYNeLrW9QDJ0RH mUbGW+DfUuy6t5uz28j54TiUtzfs6aYBtiaWoDkQWcyGKcOjbs6KYZQOEEB1rQppZ5F6 9J+A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5si1702015plk.250.2017.11.29.11.45.35; Wed, 29 Nov 2017 11:45:49 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752783AbdK2Tok (ORCPT + 99 others); Wed, 29 Nov 2017 14:44:40 -0500 Received: from iolanthe.rowland.org ([192.131.102.54]:40520 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752189AbdK2Toi (ORCPT ); Wed, 29 Nov 2017 14:44:38 -0500 Received: (qmail 7047 invoked by uid 2102); 29 Nov 2017 14:44:37 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 29 Nov 2017 14:44:37 -0500 Date: Wed, 29 Nov 2017 14:44:37 -0500 (EST) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Daniel Lustig cc: "Paul E. McKenney" , Andrea Parri , Luc Maranget , Jade Alglave , Boqun Feng , Nicholas Piggin , Peter Zijlstra , Will Deacon , David Howells , Palmer Dabbelt , Kernel development list Subject: Re: Unlock-lock questions and the Linux Kernel Memory Model In-Reply-To: <17506ed0-1ce8-791d-7cf1-c40426015a99@nvidia.com> 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 On Wed, 29 Nov 2017, Daniel Lustig wrote: > While we're here, let me ask about another test which isn't directly > about unlock/lock but which is still somewhat related to this > discussion: > > "MP+wmb+xchg-acq" (or some such) > > {} > > P0(int *x, int *y) > { > WRITE_ONCE(*x, 1); > smp_wmb(); > WRITE_ONCE(*y, 1); > } > > P1(int *x, int *y) > { > r1 = atomic_xchg_relaxed(y, 2); > r2 = smp_load_acquire(y); > r3 = READ_ONCE(*x); > } > > exists (1:r1=1 /\ 1:r2=2 /\ 1:r3=0) > > C/C++ would call the atomic_xchg_relaxed part of a release sequence > and hence would forbid this outcome. > > x86 and Power would forbid this. ARM forbids this via a special-case > rule in the memory model, ordering atomics with later load-acquires. > > RISC-V, however, wouldn't forbid this by default using RCpc or RCsc > atomics for smp_load_acquire(). It's an "fri; rfi" type of pattern, > because xchg doesn't have an inherent internal data dependency. > > If the Linux memory model is going to forbid this outcome, then > RISC-V would either need to use fences instead, or maybe we'd need to > add a special rule to our memory model similarly. This is one detail > where RISC-V is still actively deciding what to do. > > Have you all thought about this test before? Any idea which way you > are leaning regarding the outcome above? Good questions. Currently the LKMM allows this, and I think it should because xchg doesn't have a dependency from its read to its write. On the other hand, herd isn't careful enough in the way it implements internal dependencies for RMW operations. If we change atomic_xchg_relaxed(y, 2) to atomic_inc(y) and remove r1 from the test: C MP+wmb+inc-acq {} P0(int *x, int *y) { WRITE_ONCE(*x, 1); smp_wmb(); WRITE_ONCE(*y, 1); } P1(int *x, int *y) { atomic_inc(y); r2 = smp_load_acquire(y); r3 = READ_ONCE(*x); } exists (1:r2=2 /\ 1:r3=0) then the test _should_ be forbidden, but it isn't -- herd doesn't realize that all atomic RMW operations other than xchg must have a dependency (either data or control) between their internal read and write. (Although the smp_load_acquire is allowed to execute before the write part of the atomic_inc, it cannot execute before the read part. I think a similar argument applies even on ARM.) Luc, consider this a bug report. :-) Alan From 1585430191349248614@xxx Wed Nov 29 19:34:13 +0000 2017 X-GM-THRID: 1585255508732072548 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread