From patchwork Fri Dec 11 12:04:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 58273 Delivered-To: patch@linaro.org Received: by 10.112.157.166 with SMTP id wn6csp85164lbb; Fri, 11 Dec 2015 04:04:19 -0800 (PST) X-Received: by 10.66.63.33 with SMTP id d1mr24336518pas.120.1449835459047; Fri, 11 Dec 2015 04:04:19 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ud10si911663pab.54.2015.12.11.04.04.18; Fri, 11 Dec 2015 04:04:19 -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 S1754908AbbLKMER (ORCPT + 28 others); Fri, 11 Dec 2015 07:04:17 -0500 Received: from foss.arm.com ([217.140.101.70]:32857 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753675AbbLKMEP (ORCPT ); Fri, 11 Dec 2015 07:04:15 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AFD7E3A8; Fri, 11 Dec 2015 04:03:52 -0800 (PST) Received: from arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EE70F3F21A; Fri, 11 Dec 2015 04:04:13 -0800 (PST) Date: Fri, 11 Dec 2015 12:04:19 +0000 From: Will Deacon To: Peter Zijlstra Cc: Andrew Pinski , Davidlohr Bueso , Thomas Gleixner , "Paul E. McKenney" , Ingo Molnar , Linux Kernel Mailing List , "linux-arm-kernel@lists.infradead.org" Subject: Re: FW: Commit 81a43adae3b9 (locking/mutex: Use acquire/release semantics) causing failures on arm64 (ThunderX) Message-ID: <20151211120419.GD18828@arm.com> References: <5669D5F2.5050004@caviumnetworks.com> <20151211084133.GE6356@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20151211084133.GE6356@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, On Fri, Dec 11, 2015 at 09:41:33AM +0100, Peter Zijlstra wrote: > On Thu, Dec 10, 2015 at 08:51:34PM -0800, Andrew Pinski wrote: > > > So looking further I think I understand what is going wrong and why > > c55a6ffa6285e29f874ed403979472631ec70bff is incorrect. > > The osq_wait_next() call in osq_lock() is when we fail the lock. This is > effectively trylock() semantics and like for cmpxchg a failed trylock > has no implied barrier semantics. So from that POV osq_wait_next() does > not need to provide ACQUIRE semantics. > > In osq_unlock() there's an xchg() in front, which implies full barriers > and thereby provides RELEASE semantics for that part of osq_unlock(), so > again, from this POV osq_wait_next() does not need to provide RELEASE > semantics. > > > The compare and swap inside osq_lock needs to be both release and > > acquire semantics memory barriers because the stores (to node) need to > > be visible to the other cores before the setting of lock->tail > > happens. > > I'm a wee bit confused on what exactly you mean. Both stores to @node: > > 1) osq_wait_next(): next = xchg(&node->next, NULL) > 2) osq_unlock(): next = xchg(&node->next, NULL) > > are xchg() calls which imply full ordering (sequential consistency). I think Andrew meant the atomic_xchg_acquire at the start of osq_lock, as opposed to "compare and swap". In which case, it does look like there's a bug here because there is nothing to order the initialisation of the node fields with publishing of the node, whether that's indirectly as a result of setting the tail to the current CPU or directly as a result of the WRITE_ONCE. Andrew, David: does making that atomic_xchg_acquire and atomic_xchg fix things for you? I don't fully grok what 81a43adae3b9 has to do with any of this, so maybe there's another bug too. Will --->8 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c index d092a0c9c2d4..05a37857ab55 100644 --- a/kernel/locking/osq_lock.c +++ b/kernel/locking/osq_lock.c @@ -93,10 +93,12 @@ bool osq_lock(struct optimistic_spin_queue *lock) node->cpu = curr; /* - * ACQUIRE semantics, pairs with corresponding RELEASE - * in unlock() uncontended, or fastpath. + * We need both ACQUIRE (pairs with corresponding RELEASE in + * unlock() uncontended, or fastpath) and RELEASE (to publish + * the node fields we just initialised) semantics when updating + * the lock tail. */ - old = atomic_xchg_acquire(&lock->tail, curr); + old = atomic_xchg(&lock->tail, curr); if (old == OSQ_UNLOCKED_VAL) return true;