From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrea Parri Subject: Re: [PATCH V2 11/19] csky: Atomic operations Date: Sat, 7 Jul 2018 22:10:24 +0200 Message-ID: <20180707201024.GB3225@andrea> References: <860b8db036b33d7b3648cb1f4ec827a53dc1a01b.1530465326.git.ren_guo@c-sky.com> <20180705175059.GE2530@hirez.programming.kicks-ass.net> <20180706110129.GC8707@guoren> <20180706115614.GV2476@hirez.programming.kicks-ass.net> <20180706121716.GO2512@hirez.programming.kicks-ass.net> <20180707080845.GA346@guoren> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20180707080845.GA346@guoren> Sender: linux-kernel-owner@vger.kernel.org To: Guo Ren Cc: Peter Zijlstra , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, daniel.lezcano@linaro.org, jason@lakedaemon.net, arnd@arndb.de, c-sky_gcc_upstream@c-sky.com, gnu-csky@mentor.com, thomas.petazzoni@bootlin.com, wbx@uclibc-ng.org, green.hu@gmail.com, Will Deacon List-Id: linux-arch.vger.kernel.org On Sat, Jul 07, 2018 at 04:08:47PM +0800, Guo Ren wrote: > On Fri, Jul 06, 2018 at 02:17:16PM +0200, Peter Zijlstra wrote: > CPU0 CPU1 > > WRITE_ONCE(x, 1) WRITE_ONCE(y, 1) > r0 = xchg(&y, 2) r1 = xchg(&x, 2) > > must not allow: r0==0 && r1==0 > So we must add a smp_mb between WRITE_ONCE() and xchg(), right? The state (r0==0 && r1==0) _must_ not be allowed in the above snippet (so, even without the additional smp_mb() between WRITE_ONCE() and xchg()). In informal terms, xchg() provides the smp_mb(). Compare implementations of xchg() and xchg_relaxed(). The following could also be helpful (in addition to the references pointed out earlier): Documentation/atomic_t.txt Andrea > > Guo Ren > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f66.google.com ([74.125.82.66]:55638 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754259AbeGGUK2 (ORCPT ); Sat, 7 Jul 2018 16:10:28 -0400 Received: by mail-wm0-f66.google.com with SMTP id v128-v6so86929wme.5 for ; Sat, 07 Jul 2018 13:10:27 -0700 (PDT) Date: Sat, 7 Jul 2018 22:10:24 +0200 From: Andrea Parri Subject: Re: [PATCH V2 11/19] csky: Atomic operations Message-ID: <20180707201024.GB3225@andrea> References: <860b8db036b33d7b3648cb1f4ec827a53dc1a01b.1530465326.git.ren_guo@c-sky.com> <20180705175059.GE2530@hirez.programming.kicks-ass.net> <20180706110129.GC8707@guoren> <20180706115614.GV2476@hirez.programming.kicks-ass.net> <20180706121716.GO2512@hirez.programming.kicks-ass.net> <20180707080845.GA346@guoren> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180707080845.GA346@guoren> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Guo Ren Cc: Peter Zijlstra , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, daniel.lezcano@linaro.org, jason@lakedaemon.net, arnd@arndb.de, c-sky_gcc_upstream@c-sky.com, gnu-csky@mentor.com, thomas.petazzoni@bootlin.com, wbx@uclibc-ng.org, green.hu@gmail.com, Will Deacon Message-ID: <20180707201024.zAi9nIt3-aQPAxNU7-qYouLf74H889phclBygCD3-as@z> On Sat, Jul 07, 2018 at 04:08:47PM +0800, Guo Ren wrote: > On Fri, Jul 06, 2018 at 02:17:16PM +0200, Peter Zijlstra wrote: > CPU0 CPU1 > > WRITE_ONCE(x, 1) WRITE_ONCE(y, 1) > r0 = xchg(&y, 2) r1 = xchg(&x, 2) > > must not allow: r0==0 && r1==0 > So we must add a smp_mb between WRITE_ONCE() and xchg(), right? The state (r0==0 && r1==0) _must_ not be allowed in the above snippet (so, even without the additional smp_mb() between WRITE_ONCE() and xchg()). In informal terms, xchg() provides the smp_mb(). Compare implementations of xchg() and xchg_relaxed(). The following could also be helpful (in addition to the references pointed out earlier): Documentation/atomic_t.txt Andrea > > Guo Ren >