Received: by 10.223.185.116 with SMTP id b49csp969298wrg; Tue, 20 Feb 2018 10:47:43 -0800 (PST) X-Google-Smtp-Source: AH8x225PYGf2935kU1uUJrq0I5mouaN+nJpSAJbWZXfHHPdnoR1nuCLDdcLBB2FFJ0L7pmoXqSjq X-Received: by 10.98.13.196 with SMTP id 65mr551550pfn.139.1519152463429; Tue, 20 Feb 2018 10:47:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519152463; cv=none; d=google.com; s=arc-20160816; b=fnooZ3gwJZ9efmBfoc9qpyGBQHvAiIr8AnkIy139c7wA48DdORd4lafwJQgKjMS3ia /DnWvXiQ9B+IrTTZsVoL4KtXtJlvWZOq9AsGKlCCfbQSpMfx2DmLTfDq/dh7RAebmGh9 4MnN288QkPe9MvpptRFoYKscuOH/LETcFEyfV+3/lBg38PoxnyokcqaHBF35zLxm6EP8 ApVW8AO06exnDNry9JSBN8LAy7wCu6dL0SepmzXsNfyermUcyumys725qO7XJnzyxXtc scOhkNFeeHIz3SobWldSM4+M7iqS5b5dmLzDC5N2PpY5AimHDcMnOp25+IU8jQaW+I2V qGwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=qE9E/Z1ETg1/MM3T4akacabs069ozlB8PwFQLXd0Axc=; b=TLiwyrvHdes/m4telNppfktWM1/k7Zzrl0Kbr6rytx/C19pd1hL/0/+t0kOrZSTEfz BFbmTYVxWoWJvgiK0HQ/uakG10xCKqWvZzPlasMeovtj7vt/AHYEEOaGaAmSbnKe0hy/ eAB36ERAo/jQZdXS22qfdAYE0AUAdbtC2hrqO3IiVhlTd/SkAnGLpkpU6XFjZ0Yqj0b/ ci4rdY+FzdtiPU2yiGpVPBrPf0q7chLQfxp520NIq1dQSQkZtZI69mRMsBADTc8KNPhh 6uOiLRGEkNyFHt0lxWiRqVKuWSAFjEDmO3MlWRFedCjiTg/MiVXJU9Rp9zh5GEhjfYk7 q3rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dfNJLlDj; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i30si643059pgn.252.2018.02.20.10.47.27; Tue, 20 Feb 2018 10:47:43 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dfNJLlDj; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751571AbeBTSqV (ORCPT + 99 others); Tue, 20 Feb 2018 13:46:21 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:41826 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751158AbeBTSqT (ORCPT ); Tue, 20 Feb 2018 13:46:19 -0500 Received: by mail-wr0-f196.google.com with SMTP id f14so12840573wre.8; Tue, 20 Feb 2018 10:46:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=qE9E/Z1ETg1/MM3T4akacabs069ozlB8PwFQLXd0Axc=; b=dfNJLlDjIh8HDzrLJH698qH/aRtzKwCa25bS68Y3Hhz3FNYRDd3SxFZ1ilZFltx+kx tYaartKDIEQLjc74HJJl0YqT1rWCyAnpNMmoYnI2crv46q1yyjDsTpYa8h3NW5Yi8cjJ T5ZX4TGhXFK3GfXtj7PR60lhRZOLaoKjWsGIXZl0eQLEKTXarThal/2exC6qxBvGqYFw ssJNzEbRCsk+fXzPQRPDQSak0RU7UVBU/sc+WvbmAcyRhEXKpKYw733PrNjOtFbc00/8 jltAOyf5kVevnDyg4hVGpxpIQWKXgGsuWymulelO3u8a6LPu7MIE7Ck+B1mG8uNSqmxN hTag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qE9E/Z1ETg1/MM3T4akacabs069ozlB8PwFQLXd0Axc=; b=dBJO/bTyvP07rvamNrhUmoBq0CknOZdFlc8zctxCUIar2CKJLjTu5WlY8Pm6ymKmnB sADmnGAHKvQldTnP+b/NsW4svmXII2ve5Xm0Cxs63bRtjY8bRgDvmbkyyiRye2a+Rj7O hkKEiQN2Y1QEuPFCxooL+51jMBiAIOV5OH+LnlYfeZ62uQ6BxvFaE8GZ6v7hI8xwAq1D sBDF1hHgvlp6613fe8kyMAHBXHZp4JO29f14AK2Qzowpl35isG4T8ETkQ5a2gJO/Cqeu hynLN53AgtcAYhfjzipKSzknArW8WlgKcBvqds8fkL3hWXwW7YO8lnx6OxGrGU3am53/ Krgg== X-Gm-Message-State: APf1xPB5veZcf7u/sQwXf/c6UcAGrTtHTwtG7rNJiyvOGHQbDYm6RJLj kM/FMh1G30ZsBtpza4pNbsI= X-Received: by 10.80.204.3 with SMTP id m3mr1497662edi.69.1519152378334; Tue, 20 Feb 2018 10:46:18 -0800 (PST) Received: from localhost.localdomain (dynamic-2a00-1028-8386-da8a-4d0b-93bd-d3c6-8b98.ipv6.broadband.iol.cz. [2a00:1028:8386:da8a:4d0b:93bd:d3c6:8b98]) by smtp.gmail.com with ESMTPSA id k9sm7559554edh.34.2018.02.20.10.46.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Feb 2018 10:46:17 -0800 (PST) From: Andrea Parri To: Ingo Molnar Cc: Andrea Parri , Will Deacon , "Paul E. McKenney" , Alan Stern , Richard Henderson , Ivan Kokshaysky , Matt Turner , linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] xchg/alpha: Add unconditional memory barrier to cmpxchg Date: Tue, 20 Feb 2018 19:45:56 +0100 Message-Id: <1519152356-4804-1-git-send-email-parri.andrea@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Will Deacon Cc: "Paul E. McKenney" Cc: Alan Stern Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: linux-alpha@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- 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 68dfb3cb71454..e2660866ce972 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" -- 2.7.4