Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3339694imu; Fri, 18 Jan 2019 08:44:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN7NXGEW5YcbBVdr3FXoQwl/yE5LoCWFJS+tfP1lwtIFmIlK52HUqYvaG9JuA1Lt5KPXUzli X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr20111899plb.107.1547829865736; Fri, 18 Jan 2019 08:44:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547829865; cv=none; d=google.com; s=arc-20160816; b=eeJAlxecOr74B/4YStpd91TTE7wN1ieWk4LO5oeQs04nwTo7LXklzXg+AUCoJ0AuvI yGA+y//6FGbOb/UlTTnTqjFAQsGcewgMRRxzy1rcqHUv7jmnLwd4nT3ZGng07bhyXwGX ZLPWEFZfxm0U4jSXYVSHE71Sjm/n+GyxjDi/Ol/rozN62nT1Q+iv4LcYM4qRDQVwL2bh 3hSscSU/qGag8ckijSFp3uT+XGukZVVVYIWdfunDGMd8bjVzsgUbIjVyKLFkfD0UkdTA WhuB743kpOosrztmkmxJAsTBxJ0RyapIvIfmgVBYUbNnvPG6GhFHKHmQYiThqDOmFPpQ hxMQ== 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; bh=y7RVfHxaGJi+PP3witHygxvO4haR7mpzIinZgy3YIDs=; b=wW9tRc2s/vGnsWz7UPzwZDE4zkw7GCX4LikM1Xn9vnOmczMG7FLza4V/gemhjunsni jzeqh5OV+Jd8VRxPrWL+r86R8dksSfjnsVVjo8CAzBuaKmtQoa+qWmDIDyt0uGd6NsjB tvqktJal3MOBofEF5hNp9UxisrNs5C+dd35bvLcX5sVsOMv7y70bj2joJjkF9e3nY41e FeLsGORdOeDK4TdtStzYT3rs6bHNkOOkanz1DHXs2TIfUzWTI/4cGJgcNw9i/pfV1nJy w6ShXVar9TH6JGxT7rAnfX3I6JqhlyqWedpI0k2UXBWo3VnzcKsJeZD8NXzyf75MNhT6 SgDQ== 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 b63si5060078pfa.250.2019.01.18.08.44.10; Fri, 18 Jan 2019 08:44:25 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728010AbfARQnE (ORCPT + 99 others); Fri, 18 Jan 2019 11:43:04 -0500 Received: from iolanthe.rowland.org ([192.131.102.54]:44434 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1727346AbfARQnE (ORCPT ); Fri, 18 Jan 2019 11:43:04 -0500 Received: (qmail 4164 invoked by uid 2102); 18 Jan 2019 11:43:02 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 18 Jan 2019 11:43:02 -0500 Date: Fri, 18 Jan 2019 11:43:02 -0500 (EST) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Andrea Parri cc: LKMM Maintainers -- Akira Yokosawa , Boqun Feng , Daniel Lustig , David Howells , Jade Alglave , Luc Maranget , Nicholas Piggin , "Paul E. McKenney" , Peter Zijlstra , Will Deacon , Dmitry Vyukov , Nick Desaulniers , Subject: Re: Plain accesses and data races in the Linux Kernel Memory Model In-Reply-To: <20190118155638.GA24442@andrea> 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 Fri, 18 Jan 2019, Andrea Parri wrote: > > A relatively simple solution to this problem would be to say that > > smp_wmb doesn't order plain writes. > > It seems so; I don't have other solutions to suggest ATM. (But, TBH, > I'm still in the process of reviewing/testing these changes... ) > > And yes, this is a pain! : I don't have the exact statistics, but I'm > willing to believe that removing this order will take us back ~99% of > the current (~500!) uses of smp_wmb() ;-/ > > Oh, well, maybe we'll find a better solution one day: after all, that > one doesn't seem worse than what the current LKMM has to say! ;-) > > > > > > I think the rest of the memory model would then be okay. However, I am > > open to arguments that this approach is too complex and we should > > insist on the same kind of strict ordering for race avoidance that the > > C11 standard uses (i.e., conflicting accesses separated by full memory > > barriers or release & acquire barriers or locking). > > Indeed; maybe, we've just found another reason to obsolete smp_wmb()! ;-) Here's another example of how smp_wmb can cause trouble. In this test, I have replaced "*x = 1" in P1 with "r2 = *x; if (r2 != 1) *x = 1", which is a perfectly valid transformation for the compiler to make. But as a result of this transformation, the MP pattern between P1 and P2 is now allowed! This shows that when plain accesses are involved, smp_wmb() in the writing thread is not sufficient to forbid MP. Alan C bad-wmb {} P0(int *x, int *y) { WRITE_ONCE(*x, 1); smp_store_release(y, 1); } P1(int *x, int *y, int *z) { int r1; int r2; r1 = smp_load_acquire(y); if (r1) { /* Instead of *x = 1 ... */ r2 = *x; if (r2 != 1) *x = 1; smp_wmb(); WRITE_ONCE(*z, 1); } } P2(int *x, int *z) { int r3; int r4 = 0; r3 = READ_ONCE(*z); if (r3) { smp_rmb(); r4 = READ_ONCE(*x); } } exists (2:r3=1 /\ 2:r4=0)