Received: by 10.223.185.116 with SMTP id b49csp5374138wrg; Tue, 27 Feb 2018 12:10:10 -0800 (PST) X-Google-Smtp-Source: AH8x227SkA/Th6URUf/LDXe4/RytXhKcacrR2c74feyR65bCtnkP1ZwXkc3uHyMkFcnk8rhquz+F X-Received: by 10.99.39.131 with SMTP id n125mr12164553pgn.292.1519762210146; Tue, 27 Feb 2018 12:10:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519762210; cv=none; d=google.com; s=arc-20160816; b=CW5NCPqs2IP2C1QiKmYKpeQ4RvPTt3EX/8HY317Fk435yVMjVYPxrF+rSe4zx7FwO2 +6JrCoAkeNOctC7uitfDQ5v9cpC90vl1tndp0BD1E3LQLt1phxH1Vkd3mkRVJS4+WxNj RgSHGyAC1g44ce3PO8Iv4rYzZ0RP6lMzAgTw1r8zU+woNAXBnEZDG9eoqGaUl9aSCG5T jlnacdRm19s145au6Vq3cyXAhxupwRjxYl2QffXiPZFjhk7lJkvFm1p5ffLMFgF2G8CE OT9Q5sGkuYjt53pGkF5oHV4eQexylfoOYxOngHqZo2EfA7sasH5X7Yh/F7yjAS1qF6nG ysUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=+WTrYJEubfdbZmcWnSF59XvStrPnkxhBbbkALSbgqqA=; b=dhVy3EHKSwnpJD8ElOmhLqHc0ASwO/lXXhJ+9nvLgtFN3zwz01yEp6i+msExVuQIfO Q99sMUYTMsAve4jmkf31HGdhzPJDs2jGIoBF/94dBpXHSbIFSnmAKQgXRKfBY3xk5y+m ICbwUs+TlIbFZ02n5q3NW77rVHMi2OKJKt+ozfouv36a2gMEDrPQ3LGjNGSrxQ3AP2kC RUg9wms4KuKI5Xb43zqTHcQWMEB6+oLImrL1LKdCtojXkXtHQ315wh4VXNO9PQR+4tAE 07/LmnKoms6bat2W254DsAOlrmHWCb+e6cnjiGscd6gfgZJ42QkZqSlWom+Dr+MXRo3W IDkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bM3U5Cxl; 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 s13-v6si9090786plq.793.2018.02.27.12.09.53; Tue, 27 Feb 2018 12:10:10 -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=bM3U5Cxl; 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 S1751930AbeB0UIm (ORCPT + 99 others); Tue, 27 Feb 2018 15:08:42 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:40201 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751716AbeB0UIk (ORCPT ); Tue, 27 Feb 2018 15:08:40 -0500 Received: by mail-wm0-f68.google.com with SMTP id t6so883920wmt.5; Tue, 27 Feb 2018 12:08:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+WTrYJEubfdbZmcWnSF59XvStrPnkxhBbbkALSbgqqA=; b=bM3U5CxlkdBeCOa542EdvvpEmZ919XH4usCcSmjLUUp0czRFgkiJkXO1KFHUK6dFaY rVSSyoKTBe2laCxBnxsnUPguY0Y+3yN19BBZS58kbhDw3koMoFO7JetZconkAPH04oLF Jt73eccN+9egLB8ZPLCoBt4Xut095nr/cSlJ7JLkfj8YQ/mXG2oVENYfTMn+RNt+8nY+ w5dIc2t9ivdJNXwNdfrMWu1HkJ3uYXtwI5GHC6s6rp9HP7Xx2ELzqtCu7hRQKfAP4fA6 6Tty8wH4odX6GwgQNGDH1kiHu8EcbTzjny7o4hyEM9CHRLWti3Xz7oaBvSl2NNHwQXtL GrzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+WTrYJEubfdbZmcWnSF59XvStrPnkxhBbbkALSbgqqA=; b=XfRtzbjhGjBdeaRZRnPzuZQsBirf49RsKS0U7zo5Hael3340+SI7TxTrgFnssvSFtP CwEEtDnoPq66HFwSZV1OX8skjtSOOjGR660H0B4v6rjwjSp6QJZn51zXmdwGoKGRBz4u XOGMfH7fdagD/7Pg0p4A0Mak/1/P7yAS+oQ0WEzJLI4QA2fHb6r2Wjw4uDkgF/GPNDZw qAXr9/6TQ3LxJACXAWTxhInaeVZmW7bk5RGU87hIcnOZrxEVZuRz9m+24ZN4VnogDe8h le1WQ0t+50+BRxIhwflXM9jIjpZrqw0zgunMwaUCzf9gsd7l6Bm6a8g4QW69ht+qV5hK 1t5g== X-Gm-Message-State: APf1xPB6iDkflmKR6JgV3Zr9P/J2LI3SfWdw8blFc3qjUBowFAFTJVAE JEw2fOw6pHOTk+LyJ42lwmB64s9c X-Received: by 10.28.227.66 with SMTP id a63mr11286949wmh.128.1519762118649; Tue, 27 Feb 2018 12:08:38 -0800 (PST) Received: from andrea (dynamic-2a00-1028-8386-da8a-9070-0769-7b5b-6b9a.ipv6.broadband.iol.cz. [2a00:1028:8386:da8a:9070:769:7b5b:6b9a]) by smtp.gmail.com with ESMTPSA id 69sm372440wmw.32.2018.02.27.12.08.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Feb 2018 12:08:37 -0800 (PST) Date: Tue, 27 Feb 2018 21:08:31 +0100 From: Andrea Parri To: Ingo Molnar , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, "Paul E . McKenney" , Alan Stern , Andrew Morton , Ivan Kokshaysky , Linus Torvalds , Matt Turner , Richard Henderson , Thomas Gleixner , linux-alpha@vger.kernel.org, will.deacon@arm.com Subject: Re: [PATCH] locking/xchg/alpha: Remove memory barriers from the _local() variants Message-ID: <20180227200830.GA3164@andrea> References: <1519704058-13430-1-git-send-email-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1519704058-13430-1-git-send-email-parri.andrea@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [+ Will] I'm not sure how this happened; Will, you at least figure as Reported-by: ;-) Andrea On Tue, Feb 27, 2018 at 05:00:58AM +0100, Andrea Parri wrote: > Commits 79d442461df74 ("locking/xchg/alpha: Clean up barrier usage by using > smp_mb() in place of __ASM__MB") and 472e8c55cf662 ("locking/xchg/alpha: > Fix xchg() and cmpxchg() memory ordering bugs") ended up adding unnecessary > barriers to the _local variants, which the previous code took care to avoid. > > Fix them by adding the smp_mb() into the cmpxchg macro rather than into the > ____cmpxchg variants. > > Fixes: 79d442461df74 ("locking/xchg/alpha: Clean up barrier usage by using smp_mb() in place of __ASM__MB") > Fixes: 472e8c55cf662 ("locking/xchg/alpha: Fix xchg() and cmpxchg() memory ordering bugs") > Reported-by: Will Deacon > Signed-off-by: Andrea Parri > Cc: Paul E. McKenney > Cc: Alan Stern > Cc: Andrew Morton > Cc: Ivan Kokshaysky > Cc: Linus Torvalds > Cc: Matt Turner > Cc: Peter Zijlstra > Cc: Richard Henderson > Cc: Thomas Gleixner > Cc: linux-alpha@vger.kernel.org > --- > arch/alpha/include/asm/cmpxchg.h | 20 ++++++++++++++++---- > arch/alpha/include/asm/xchg.h | 27 --------------------------- > 2 files changed, 16 insertions(+), 31 deletions(-) > > diff --git a/arch/alpha/include/asm/cmpxchg.h b/arch/alpha/include/asm/cmpxchg.h > index 8a2b331e43feb..6c7c394524714 100644 > --- a/arch/alpha/include/asm/cmpxchg.h > +++ b/arch/alpha/include/asm/cmpxchg.h > @@ -38,19 +38,31 @@ > #define ____cmpxchg(type, args...) __cmpxchg ##type(args) > #include > > +/* > + * The leading and the trailing memory barriers guarantee that these > + * operations are fully ordered. > + */ > #define xchg(ptr, x) \ > ({ \ > + __typeof__(*(ptr)) __ret; \ > __typeof__(*(ptr)) _x_ = (x); \ > - (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, \ > - sizeof(*(ptr))); \ > + smp_mb(); \ > + __ret = (__typeof__(*(ptr))) \ > + __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \ > + smp_mb(); \ > + __ret; \ > }) > > #define cmpxchg(ptr, o, n) \ > ({ \ > + __typeof__(*(ptr)) __ret; \ > __typeof__(*(ptr)) _o_ = (o); \ > __typeof__(*(ptr)) _n_ = (n); \ > - (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \ > - (unsigned long)_n_, sizeof(*(ptr)));\ > + smp_mb(); \ > + __ret = (__typeof__(*(ptr))) __cmpxchg((ptr), \ > + (unsigned long)_o_, (unsigned long)_n_, sizeof(*(ptr)));\ > + smp_mb(); \ > + __ret; \ > }) > > #define cmpxchg64(ptr, o, n) \ > diff --git a/arch/alpha/include/asm/xchg.h b/arch/alpha/include/asm/xchg.h > index e2b59fac5257d..7adb80c6746ac 100644 > --- a/arch/alpha/include/asm/xchg.h > +++ b/arch/alpha/include/asm/xchg.h > @@ -12,10 +12,6 @@ > * Atomic exchange. > * Since it can be used to implement critical sections > * it must clobber "memory" (also for interrupts in UP). > - * > - * The leading and the trailing memory barriers guarantee that these > - * operations are fully ordered. > - * > */ > > static inline unsigned long > @@ -23,7 +19,6 @@ ____xchg(_u8, volatile char *m, unsigned long val) > { > unsigned long ret, tmp, addr64; > > - smp_mb(); > __asm__ __volatile__( > " andnot %4,7,%3\n" > " insbl %1,%4,%1\n" > @@ -38,7 +33,6 @@ ____xchg(_u8, volatile char *m, unsigned long val) > ".previous" > : "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64) > : "r" ((long)m), "1" (val) : "memory"); > - smp_mb(); > > return ret; > } > @@ -48,7 +42,6 @@ ____xchg(_u16, volatile short *m, unsigned long val) > { > unsigned long ret, tmp, addr64; > > - smp_mb(); > __asm__ __volatile__( > " andnot %4,7,%3\n" > " inswl %1,%4,%1\n" > @@ -63,7 +56,6 @@ ____xchg(_u16, volatile short *m, unsigned long val) > ".previous" > : "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64) > : "r" ((long)m), "1" (val) : "memory"); > - smp_mb(); > > return ret; > } > @@ -73,7 +65,6 @@ ____xchg(_u32, volatile int *m, unsigned long val) > { > unsigned long dummy; > > - smp_mb(); > __asm__ __volatile__( > "1: ldl_l %0,%4\n" > " bis $31,%3,%1\n" > @@ -84,7 +75,6 @@ ____xchg(_u32, volatile int *m, unsigned long val) > ".previous" > : "=&r" (val), "=&r" (dummy), "=m" (*m) > : "rI" (val), "m" (*m) : "memory"); > - smp_mb(); > > return val; > } > @@ -94,7 +84,6 @@ ____xchg(_u64, volatile long *m, unsigned long val) > { > unsigned long dummy; > > - smp_mb(); > __asm__ __volatile__( > "1: ldq_l %0,%4\n" > " bis $31,%3,%1\n" > @@ -105,7 +94,6 @@ ____xchg(_u64, volatile long *m, unsigned long val) > ".previous" > : "=&r" (val), "=&r" (dummy), "=m" (*m) > : "rI" (val), "m" (*m) : "memory"); > - smp_mb(); > > return val; > } > @@ -135,13 +123,6 @@ ____xchg(, volatile void *ptr, unsigned long x, int size) > * Atomic compare and exchange. Compare OLD with MEM, if identical, > * store NEW in MEM. Return the initial value in MEM. Success is > * indicated by comparing RETURN with OLD. > - * > - * The leading and the trailing memory barriers guarantee that these > - * operations are fully ordered. > - * > - * The trailing 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 > @@ -149,7 +130,6 @@ ____cmpxchg(_u8, volatile char *m, unsigned char old, unsigned char new) > { > unsigned long prev, tmp, cmp, addr64; > > - smp_mb(); > __asm__ __volatile__( > " andnot %5,7,%4\n" > " insbl %1,%5,%1\n" > @@ -167,7 +147,6 @@ ____cmpxchg(_u8, volatile char *m, unsigned char old, unsigned char new) > ".previous" > : "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64) > : "r" ((long)m), "Ir" (old), "1" (new) : "memory"); > - smp_mb(); > > return prev; > } > @@ -177,7 +156,6 @@ ____cmpxchg(_u16, volatile short *m, unsigned short old, unsigned short new) > { > unsigned long prev, tmp, cmp, addr64; > > - smp_mb(); > __asm__ __volatile__( > " andnot %5,7,%4\n" > " inswl %1,%5,%1\n" > @@ -195,7 +173,6 @@ ____cmpxchg(_u16, volatile short *m, unsigned short old, unsigned short new) > ".previous" > : "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64) > : "r" ((long)m), "Ir" (old), "1" (new) : "memory"); > - smp_mb(); > > return prev; > } > @@ -205,7 +182,6 @@ ____cmpxchg(_u32, volatile int *m, int old, int new) > { > unsigned long prev, cmp; > > - smp_mb(); > __asm__ __volatile__( > "1: ldl_l %0,%5\n" > " cmpeq %0,%3,%1\n" > @@ -219,7 +195,6 @@ ____cmpxchg(_u32, volatile int *m, int old, int new) > ".previous" > : "=&r"(prev), "=&r"(cmp), "=m"(*m) > : "r"((long) old), "r"(new), "m"(*m) : "memory"); > - smp_mb(); > > return prev; > } > @@ -229,7 +204,6 @@ ____cmpxchg(_u64, volatile long *m, unsigned long old, unsigned long new) > { > unsigned long prev, cmp; > > - smp_mb(); > __asm__ __volatile__( > "1: ldq_l %0,%5\n" > " cmpeq %0,%3,%1\n" > @@ -243,7 +217,6 @@ ____cmpxchg(_u64, volatile long *m, unsigned long old, unsigned long new) > ".previous" > : "=&r"(prev), "=&r"(cmp), "=m"(*m) > : "r"((long) old), "r"(new), "m"(*m) : "memory"); > - smp_mb(); > > return prev; > } > -- > 2.7.4 >