Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp860256yba; Thu, 18 Apr 2019 10:45:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkg6GBqornFWXZFv4xuosNPDF+SInyDFrXvw3HmBm6WdML0u3OMMYXa1TbGSPXV968FuT6 X-Received: by 2002:a63:d1f:: with SMTP id c31mr88404826pgl.353.1555609547730; Thu, 18 Apr 2019 10:45:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555609547; cv=none; d=google.com; s=arc-20160816; b=txJJf2+X4kDdW6cjZymgZJM3kyym2ZJqiI1ypk7FdlbIsW0n7g5Rw1BJq94NZsdsHd vSN+ua5CRqBRcOkfLWkyXboIgzICKZllWf1uy9EQ0kWEvEANmgoVhP4rrKoSJ3uaYwKe COdk/usRjPP49ND0NB/YR4CthWyITFT/tUgpBoguYg/Mge4Zt1ivc3rHumIh6gZUYgcx hGQllXhU8L4xrY6aUqUM+ZZLAiJepvSdVgVAq4IxM8J+7k997mFiYkU7LdLzV0RWCr6y 8pfWfR97282a6f6bvmhavBitHBV3La2l01qnx8/eoCgri7kqkiUrbNXvWI6967ZIrUeT LMsQ== 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=+xvAFQAYRTmo9CmjspU9/Gc40QxRrRpAcQk3GnLyYYE=; b=NIIJtyQvP6IiVQahsu1BEMnBcT06SwHxCEX2ZxZP4Uol25zj1qZiin83qnrPiA3/AE 5GpW55B+2/Ybu6e9ul9JjbvCReVtu7NDDEIwdVxkf2PRiC5w4JS4YSPLqzauV2n3Bte0 JPbsLLUCcnvRgGOo61Jm+tVKgid69n3BQ5AIjw0SiGI4nTVDoCcR2erHAm+Pk5foXKxB QNZ66nSF4LFbaX4hNYwcpF1KIVwFjX44JWNdLQI632bCldLJt+PMyqvQDiqqkABxhi2J VVdgPt8/VEj7pK7xPInSOxk8L0ylvpWbImmSc0nwMjVVT+jqRFl0R8Vo3/8H73YZDKfY TeiA== 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 i64si2393886pge.179.2019.04.18.10.45.32; Thu, 18 Apr 2019 10:45:47 -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 S2389779AbfDRRoh (ORCPT + 99 others); Thu, 18 Apr 2019 13:44:37 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:48642 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1733067AbfDRRoh (ORCPT ); Thu, 18 Apr 2019 13:44:37 -0400 Received: (qmail 2544 invoked by uid 2102); 18 Apr 2019 13:44:36 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 18 Apr 2019 13:44:36 -0400 Date: Thu, 18 Apr 2019 13:44:36 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Andrea Parri cc: "Paul E. McKenney" , LKMM Maintainers -- Akira Yokosawa , Boqun Feng , Daniel Lustig , David Howells , Jade Alglave , Luc Maranget , Nicholas Piggin , Peter Zijlstra , Will Deacon , Daniel Kroening , Kernel development list Subject: Re: Adding plain accesses and detecting data races in the LKMM In-Reply-To: <20190418125412.GA10817@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 Thu, 18 Apr 2019, Andrea Parri wrote: > > Another question is "should the kernel permit smp_mb__{before,after}*() > > anywhere other than immediately before or after the primitive being > > strengthened?" > > Mmh, I do think that keeping these barriers "immediately before or after > the primitive being strengthened" is a good practice (readability, and > all that), if this is what you're suggesting. > > However, a first auditing of the callsites showed that this practice is > in fact not always applied, notably... ;-) > > kernel/rcu/tree_exp.h:sync_exp_work_done > kernel/sched/cpupri.c:cpupri_set > > So there appear, at least, to be some exceptions/reasons for not always > following it? Thoughts? > > BTW, while auditing these callsites, I've stumbled across the following > snippet (from kernel/futex.c): > > *futex = newval; > sys_futex(WAKE, futex); > futex_wake(futex); > smp_mb(); (B) > if (waiters) > ... > > where B is actually (c.f., futex_get_mm()): > > atomic_inc(...->mm_count); > smp_mb__after_atomic(); > > It seems worth mentioning the fact that, AFAICT, this sequence does not > necessarily provide ordering when plain accesses are involved: consider, > e.g., the following variant of the snippet: > > A:*x = 1; > /* > * I've "ignored" the syscall, which should provide > * (at least) a compiler barrier... > */ > atomic_inc(u); > smp_mb__after_atomic(); > B:r0 = *y; > > On x86, AFAICT, the compiler can do this: > > atomic_inc(u); > A:*x = 1; > smp_mb__after_atomic(); > B:r0 = *y; > > (the implementation of atomic_inc() contains no compiler barrier), then > the CPU can "reorder" A and B (smp_mb__after_atomic() being #defined to > a compiler barrier). Are you saying that on x86, atomic_inc() acts as a full memory barrier but not as a compiler barrier, and vice versa for smp_mb__after_atomic()? Or that neither atomic_inc() nor smp_mb__after_atomic() implements a full memory barrier? Either one seems like a very dangerous situation indeed. Alan > The mips implementation seems also affected by such "reorderings": I am > not familiar with this implementation but, AFAICT, it does not enforce > ordering from A to B in the following snippet: > > A:*x = 1; > atomic_inc(u); > smp_mb__after_atomic(); > B:WRITE_ONCE(*y, 1); > > when CONFIG_WEAK_ORDERING=y, CONFIG_WEAK_REORDERING_BEYOND_LLSC=n. > > Do these observations make sense to you? Thoughts? > > Andrea