Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp471372imm; Sat, 7 Jul 2018 01:10:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeDBfzoviIBKgj9E7XL6xsDd30qQ9ukYgRwPxJGtOE/2c/sQ2Mo7sRnyw6EVHthWnqmB5Br X-Received: by 2002:a17:902:6b0b:: with SMTP id o11-v6mr13372530plk.101.1530951000942; Sat, 07 Jul 2018 01:10:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530951000; cv=none; d=google.com; s=arc-20160816; b=C987YSSkDdF3N+Rxh7QMRqQ7muIt82yAdB0d7M3COIzJGCVB4Y7cVmcKq6tZTYxt7i gGlQZiX/Vl9DisDPUUlogNXJ9yJ9MQPVE/zLvkYms5ulFP/zRkwL3/ROfzfZRp9fxIYo a6rttIAWY+1n8V7aw3TGjD1JLLMPP2MpwPXhR90UY3F0ftJyWmjtJtYm/5Ttnqxm4HM9 ozqlDjnjGljmBp4Jzpd1PkqELNEH1v8BmH2pjuz6zOHREmjrLIs/pG7cpGJp+9IP3lTR C3B3VsI4nwAmjKjIU0sJubEUpPBqmhLLS6/95FSv1aFVst0n6E5gT9exM1PtBIUaUWDv eI9g== 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:arc-authentication-results; bh=OSVgjLtCnPDsJDaWJN+6tRrKXdOvfy4KKEkd4EhRj4U=; b=upB2aVYbsODRyGsavhWeAoiYM4IqWXUUf0rCzioyWrof7YoV7QPo0usEvZokdxORHx z43O/QtsIctWPKSeWs0ytycBmV+iDzDvIVOAp0R2uIiZxOYibl/RlRyxFT1/fh/2GEbE nC1zwY04kfwFJs2gqixDDbNIW3GYhrHtWSlKrVPl7eoWLP7S3SZ34kB60bst9jX84mvT 89OMN9HB1Mwv5n3DJjpXdPNNu6kc9lSxGcxO+UZxho33+UWm8hhewhclKwrLkB0+ZPis FNBfDjuPTn1cOnBgoPvAnssovelbRKvh/x6LywWywlH12sQrscu7gZC2uMxJtb+9E8Z1 tE5Q== 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 x2-v6si9126739pgr.33.2018.07.07.01.09.44; Sat, 07 Jul 2018 01:10:00 -0700 (PDT) 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 S1752809AbeGGIJC (ORCPT + 99 others); Sat, 7 Jul 2018 04:09:02 -0400 Received: from smtp2200-217.mail.aliyun.com ([121.197.200.217]:38648 "EHLO smtp2200-217.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751693AbeGGII7 (ORCPT ); Sat, 7 Jul 2018 04:08:59 -0400 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.09957097|-1;CH=green;FP=0|0|0|0|0|-1|-1|-1;HT=e02c03298;MF=ren_guo@c-sky.com;NM=1;PH=DS;RN=13;RT=13;SR=0;TI=SMTPD_---.CNO7aKH_1530950927; Received: from localhost(mailfrom:ren_guo@c-sky.com fp:SMTPD_---.CNO7aKH_1530950927) by smtp.aliyun-inc.com(10.147.43.230); Sat, 07 Jul 2018 16:08:47 +0800 Date: Sat, 7 Jul 2018 16:08:47 +0800 From: Guo Ren To: Peter Zijlstra Cc: 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 Subject: Re: [PATCH V2 11/19] csky: Atomic operations Message-ID: <20180707080845.GA346@guoren> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180706121716.GO2512@hirez.programming.kicks-ass.net> 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 On Fri, Jul 06, 2018 at 02:17:16PM +0200, Peter Zijlstra wrote: > > > > CPU0 CPU1 > > > > r1 = READ_ONCE(x); WRITE_ONCE(y, 1); > > r2 = xchg(&y, 2); smp_store_release(&x, 1); > > > > must not allow: r1==1 && r2==0 > > Also, since you said "SYNC.IS" is a pipeline flush, those > instruction-sync primitives normally do not imply a store-buffer flush, > does yours? If not it is not a valid smp_mb() implementation. Sync.is will flush pipeline and store-buffer. "sync" means completion memory barrier. "i" means flush cpu pipeline. "s" means sharable to other cpus. > > Notably: > > CPU0 CPU1 > > WRITE_ONCE(x, 1); WRITE_ONCE(y, 1); > smp_mb(); smp_mb(); > r0 = READ_ONCE(y); r1 = READ_ONCE(x); > > must not allow: r0==0 && r1==0 > > Which would be possible with a regular instruction-sync barrier, but > must absolutely not be true with a full memory barrier. > > (and you can replace the smp_mb(); r = READ_ONCE(); with r = xchg() to > again see why you need that first smp_mb()). 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? Guo Ren