Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1714513imm; Fri, 6 Jul 2018 05:19:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeGVolIg0QpfUWPxvfVunX+usSW+eXZdNQPfg6FtG4yd6bLk/2EGFRDoPxMER8sJFRLxnuo X-Received: by 2002:a17:902:20ca:: with SMTP id v10-v6mr9964127plg.255.1530879573551; Fri, 06 Jul 2018 05:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530879573; cv=none; d=google.com; s=arc-20160816; b=zfGJ5X7R6Mim68XZjF/bRnQvQ9UdWmuIz62aoBdsaNoHeMpPTaXeRSuFKjGBpH/+57 PysqWdrsDpmznbnYOvCHnSOqoxY5TtIrcbwAs7YSJBKuaQKDN3/mr2/sur10R8LWjphF 9fvQpRR4MtjMXWYg+tqRziLMtWHLrxUQQmx1iacdsd0W9DQyDTeepiz/sPTg4yLdaOKf 8qjeiZYIsENvj+aWB85A96gMyFOj93BYk4e0Re/E8gNq8vd+xt8mz7E3SnR1pC7yPrxd VBBzJhG2nxknugdTL9BkeB+HgzQ8Q4AlOSNkKSGCLM9XXLSV6W6yMFgiHpG6z5GD3B+o b4cg== 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=XRJlrDqObBe2aPw6BTdVXU724T4m8PKuo0iFGPdRo1c=; b=H/RIE4C93JLG71ms+v94RhxPi6cd7cna9croBVgUraO8Qziea+WxpVjNLYp2jdnUyH 71C/K503/iHODNI3oDNblzSAphhx8OE5EgfM+L8XSILMUUG3voUz84y6NsElolNkZwQV GHxeMvN7fUSFy1pc7SEr4mJD3Idl3nZmsUNQz91tAIkAaICov7GwJmf39BV820sVrv0o Vp02aIp+jeiLEjmPLNmp5bSRwSTbsPIHNvPu4zSr+SdrTQkAhwhNsjCdf0EScw/EceKh wDWDJGxJ9+vXVizvsWge/EERgRoFbnkMFdX22bxElnBgUCeorYyhh3cCoyrfe5WmwK6y cdVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=JVlqyxbf; 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 t21-v6si7625605pgb.553.2018.07.06.05.19.17; Fri, 06 Jul 2018 05:19:33 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=JVlqyxbf; 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 S932878AbeGFMRr (ORCPT + 99 others); Fri, 6 Jul 2018 08:17:47 -0400 Received: from merlin.infradead.org ([205.233.59.134]:43948 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932483AbeGFMRp (ORCPT ); Fri, 6 Jul 2018 08:17:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=XRJlrDqObBe2aPw6BTdVXU724T4m8PKuo0iFGPdRo1c=; b=JVlqyxbfHouwOgTC0/q9wndfn UQLBt9Lyey3VY33fDFQQbVGrirVBmdl8VTg/jbqA5dj0utBz2NACojSc37ZdiKPUg1IqsgdKkQ71o MxBhFN1fGysTxqdwL4XlK39yyFl/4krms6uPqsLS/bxKUpNtwhL2u9fa1HydX8FvsX7DZR77Pr1WA K93JHtz+KrOaRePoAw23uL8SjeMEBE466Dr5xQh/K794OqNaj3xylZwHknUctGtJxTzpC3i9hawSQ flBL0KAHz8/OtxJPlZ/EhxBEF3PFYc1+Z5djtqa/l5z41nAfafjF0/ptYq3pTlMT8TAdwXBI40sX/ +kiF3pDSw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fbPfq-0000ns-D8; Fri, 06 Jul 2018 12:17:18 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C464920291063; Fri, 6 Jul 2018 14:17:16 +0200 (CEST) Date: Fri, 6 Jul 2018 14:17:16 +0200 From: Peter Zijlstra To: Guo Ren 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: <20180706121716.GO2512@hirez.programming.kicks-ass.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180706115614.GV2476@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.0 (2018-05-17) 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 01:56:14PM +0200, Peter Zijlstra wrote: > > But I couldn't undertand what's wrong without the 1th smp_mb()? > > 1th smp_mb will make all ld/st finish before ldex.w. Is it necessary? > > Yes. > > 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. 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()).