Received: by 10.223.185.116 with SMTP id b49csp543310wrg; Wed, 21 Feb 2018 02:52:34 -0800 (PST) X-Google-Smtp-Source: AH8x22563lim63Oy8L3FKcDWTCsvwJOpT+Y42iCAYgbw1TUWM42x3QdWYL/vcvk4c3NZmjOZEFHL X-Received: by 10.99.191.78 with SMTP id i14mr2436443pgo.9.1519210354316; Wed, 21 Feb 2018 02:52:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519210354; cv=none; d=google.com; s=arc-20160816; b=UEmeV+jtSIz+jWqeJ/JN84eR8hkmsOpPJxKeZDzgHHPJjudCU2V/tYdfEU5UlMTEtU ucHdYTKCfhcrH19xJtfc7r1daW1O5jZPn1eh+SfOunByRTKn/XWVLhfk1GydkPtH2BTZ Xk9SUmXiAYiuECLXX+787tSeMEex0Ax2++GeOpM+fwREvW3zHseWf4PljgyZilSrE69t IHVkWA5vlk6kQjclI74a254FKPux89zAXdAB+PPd1uk0vBhu/vLFK1V/jn+ZJZNmMBGk BBq70nxzE8ARUBP1hGF5oP8lQHhx43ehCp7bMF9JdRhWikTTsi5Tsn566oVA4OD4T+h0 /YIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=KnMmuxKxq4h/uRxgA3rHtLM3VicXIONDKH/oqD6qY/I=; b=KQwVS+ukOK4dBFj0mVk+p/sQG+IZ443IeZfOqkjWgUy11HGSFf3V7fWOc19n2Ospv9 6xQnIqjZPMgb0s4MmyIkk7jUhhumTEVyVV+t6+whrghSKP55uJnIOv6djd8LwTLqQ08V /gPr/KV2xjnGjUXgzgQ8tT9aZ+iOZkrYPH6Tx0HawUsUMJw3d3X2L0mVTD3pr0ilGWro giCEL2FToOIrZhQ1VvpobNGktChsvykodDIWGFFvPnmQ1b0UQ8RYz1i2J1AdIQavl+Pi JoU2YVR8FVsa/pU3bGFZ9+tqzRfwSUknErdzMvWNDX+CGnxsdQzSVcl8i9y1tYae6aPl ICbQ== 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 h10si1078174pgr.94.2018.02.21.02.52.19; Wed, 21 Feb 2018 02:52:34 -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 S1753751AbeBUKve (ORCPT + 99 others); Wed, 21 Feb 2018 05:51:34 -0500 Received: from terminus.zytor.com ([198.137.202.136]:43175 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751699AbeBUKvc (ORCPT ); Wed, 21 Feb 2018 05:51:32 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1LAnx8l006196; Wed, 21 Feb 2018 02:49:59 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1LAnvGw006189; Wed, 21 Feb 2018 02:49:57 -0800 Date: Wed, 21 Feb 2018 02:49:57 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Andrea Parri Message-ID: Cc: mingo@kernel.org, tglx@linutronix.de, stern@rowland.harvard.edu, torvalds@linux-foundation.org, parri.andrea@gmail.com, rth@twiddle.net, hpa@zytor.com, mattst88@gmail.com, linux-kernel@vger.kernel.org, peterz@infradead.org, ink@jurassic.park.msu.ru, will.deacon@arm.com, paulmck@linux.vnet.ibm.com Reply-To: rth@twiddle.net, parri.andrea@gmail.com, hpa@zytor.com, mingo@kernel.org, tglx@linutronix.de, stern@rowland.harvard.edu, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, peterz@infradead.org, ink@jurassic.park.msu.ru, will.deacon@arm.com, paulmck@linux.vnet.ibm.com, mattst88@gmail.com In-Reply-To: <1519152356-4804-1-git-send-email-parri.andrea@gmail.com> References: <1519152356-4804-1-git-send-email-parri.andrea@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/urgent] locking/xchg/alpha: Add unconditional memory barrier to cmpxchg() Git-Commit-ID: cb13b424e986aed68d74cbaec3449ea23c50e167 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: cb13b424e986aed68d74cbaec3449ea23c50e167 Gitweb: https://git.kernel.org/tip/cb13b424e986aed68d74cbaec3449ea23c50e167 Author: Andrea Parri AuthorDate: Tue, 20 Feb 2018 19:45:56 +0100 Committer: Ingo Molnar CommitDate: Wed, 21 Feb 2018 10:12:29 +0100 locking/xchg/alpha: Add unconditional memory barrier to cmpxchg() Continuing along with the fight against smp_read_barrier_depends() [1] (or rather, against its improper use), add an unconditional barrier to cmpxchg. This guarantees that dependency ordering is preserved when a dependency is headed by an unsuccessful cmpxchg. As it turns out, the change could enable further simplification of LKMM as proposed in [2]. [1] https://marc.info/?l=linux-kernel&m=150884953419377&w=2 https://marc.info/?l=linux-kernel&m=150884946319353&w=2 https://marc.info/?l=linux-kernel&m=151215810824468&w=2 https://marc.info/?l=linux-kernel&m=151215816324484&w=2 [2] https://marc.info/?l=linux-kernel&m=151881978314872&w=2 Signed-off-by: Andrea Parri Acked-by: Peter Zijlstra Acked-by: Paul E. McKenney Cc: Alan Stern Cc: Ivan Kokshaysky Cc: Linus Torvalds Cc: Matt Turner Cc: Richard Henderson Cc: Thomas Gleixner Cc: Will Deacon Cc: linux-alpha@vger.kernel.org Link: http://lkml.kernel.org/r/1519152356-4804-1-git-send-email-parri.andrea@gmail.com Signed-off-by: Ingo Molnar --- arch/alpha/include/asm/xchg.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/alpha/include/asm/xchg.h b/arch/alpha/include/asm/xchg.h index 68dfb3c..e266086 100644 --- a/arch/alpha/include/asm/xchg.h +++ b/arch/alpha/include/asm/xchg.h @@ -128,10 +128,9 @@ ____xchg(, volatile void *ptr, unsigned long x, int size) * store NEW in MEM. Return the initial value in MEM. Success is * indicated by comparing RETURN with OLD. * - * The memory barrier should be placed in SMP only when we actually - * make the change. If we don't change anything (so if the returned - * prev is equal to old) then we aren't acquiring anything new and - * we don't need any memory barrier as far I can tell. + * The memory barrier is placed in SMP unconditionally, in order to + * guarantee that dependency ordering is preserved when a dependency + * is headed by an unsuccessful operation. */ static inline unsigned long @@ -150,8 +149,8 @@ ____cmpxchg(_u8, volatile char *m, unsigned char old, unsigned char new) " or %1,%2,%2\n" " stq_c %2,0(%4)\n" " beq %2,3f\n" - __ASM__MB "2:\n" + __ASM__MB ".subsection 2\n" "3: br 1b\n" ".previous" @@ -177,8 +176,8 @@ ____cmpxchg(_u16, volatile short *m, unsigned short old, unsigned short new) " or %1,%2,%2\n" " stq_c %2,0(%4)\n" " beq %2,3f\n" - __ASM__MB "2:\n" + __ASM__MB ".subsection 2\n" "3: br 1b\n" ".previous" @@ -200,8 +199,8 @@ ____cmpxchg(_u32, volatile int *m, int old, int new) " mov %4,%1\n" " stl_c %1,%2\n" " beq %1,3f\n" - __ASM__MB "2:\n" + __ASM__MB ".subsection 2\n" "3: br 1b\n" ".previous" @@ -223,8 +222,8 @@ ____cmpxchg(_u64, volatile long *m, unsigned long old, unsigned long new) " mov %4,%1\n" " stq_c %1,%2\n" " beq %1,3f\n" - __ASM__MB "2:\n" + __ASM__MB ".subsection 2\n" "3: br 1b\n" ".previous"