Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1625079imm; Tue, 10 Jul 2018 05:19:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfA9elrzuPjThbXjqQfqKvQW9+7uPgByq7qWit7WburReQ2YMDXnU0V53x5wwQijwFHambd X-Received: by 2002:a63:2d45:: with SMTP id t66-v6mr22097880pgt.381.1531225167512; Tue, 10 Jul 2018 05:19:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531225167; cv=none; d=google.com; s=arc-20160816; b=OMHlGy1Wa9yd9H0V1cWzh0tI6uXtSvT2i1VT/vQ718+8ACl/ZNwLNg13DGwSxB9PxZ wNtzMOiCQqRcKFJJ/pSMoRYegVQw+T0tQowZmcFu6e0gaogEYHyP8di49LyGD0jJfzsm SFgkMnQGPpTt8cIvjDjtKqqmgV0uz5jHfmGveolpkqB7s4tF8xHzdt8jbcv2sz8DXouA xppX+2wRdTjyX9dZxmuM4N4T8+xus6q54hdbazktgSiHxRWHFgPmA8FlMKcJveQCQzMl 9aohA72SDnToOHjwE4KEUkCBAYFAsfEvbyILmf4UAH3ucWa3EAm0aSBIpUOazlECH45+ 7U+Q== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=MZFMTH6VlIXUlqaq37dPcLaeB4xCIapawCih6xTygmM=; b=DTZzxv+djMFfdN9ebI+yJdeCcxiuv0DvYuVfL+xYjylius5OZDG5HA9gyaahJqKbcR 52w5r4JzY7+3Y+e2uG2lPmOLOR0mK73mjtG2mvCHEwT7xWnP/BTsIL9aMZMoP0viKtZl JXxTiS2Yk4+/b3gYUEscee+NXhYll6w8HMyPE75CIzHfVk5VjCLhdJVasMyastl6PaL6 zlo8JsS2WiJXODSasF/iauU+5COcVlhHP7Tt831H1wepMuCgayX5R0sK9D28xVX6nON9 8+FbajoqfbjEcX4BwJlhLGrv5QPKRtorBU1+zhBaKUs1fNDpeTbVGSCS8UevVvALbzen i4TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=C9xZmfaL; 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 e9-v6si15962738pgu.636.2018.07.10.05.19.12; Tue, 10 Jul 2018 05:19:27 -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=C9xZmfaL; 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 S933379AbeGJMSH (ORCPT + 99 others); Tue, 10 Jul 2018 08:18:07 -0400 Received: from merlin.infradead.org ([205.233.59.134]:57760 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933313AbeGJMSE (ORCPT ); Tue, 10 Jul 2018 08:18:04 -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-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To: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=MZFMTH6VlIXUlqaq37dPcLaeB4xCIapawCih6xTygmM=; b=C9xZmfaLAs1iNq7PDUQvpKXI8A lBf7D3KnZC38ML2oaua9ln6txGbw6GeJrawXQ3np5y3DHF/JF8gtVs26nyJJTGm815qRqWy/EjtOi aDzVcJvsmaepDCC/PFRTj4GOxPU/Pgnzndw7YYHGIvNOeIoX+EKv5EgDECdms1LitLhaQtOHg17R6 XhnczB3eQm+m5Ix3kGMW5poANODskX/7EFsj6+ufZm7oTHQ01x891vDfeVgQ7NEtNco8Tq4A7XcEm SO05OR/5ha/QhWCQEWw7LZATQSMs36Aq0k+a0mxHyduN9HN16WNGURBPD63L1HuXwROcNRgVTAdK/ 3g6EtDyQ==; 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 1fcraC-0004N6-SV; Tue, 10 Jul 2018 12:17:29 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 791372016798C; Tue, 10 Jul 2018 14:17:27 +0200 (CEST) Date: Tue, 10 Jul 2018 14:17:27 +0200 From: Peter Zijlstra To: =?utf-8?B?6ZmI5Y2O5omN?= Cc: Paul Burton , Ralf Baechle , James Hogan , linux-mips , Fuxin Zhang , wuzhangjin , stable , Alan Stern , Andrea Parri , Will Deacon , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , LKML Subject: Re: [PATCH V2] MIPS: implement smp_cond_load_acquire() for Loongson-3 Message-ID: <20180710121727.GK2476@hirez.programming.kicks-ass.net> References: <1531103198-16764-1-git-send-email-chenhc@lemote.com> <20180709164939.uhqsvcv4a7jlbhvp@pburton-laptop> <20180710093637.GF2476@hirez.programming.kicks-ass.net> <20180710105437.GT2512@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Please!! Learn to use email. A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail? Also, wrap non-quoted lines to 78 characters. On Tue, Jul 10, 2018 at 07:45:22PM +0800, 陈华才 wrote: > I'm afraid that you have missing something...... > > Firstly, our previous conclusion (READ_ONCE need a barrier to avoid > 'reads prioritised over writes') is totally wrong. So define > cpu_relax() to smp_mb() like ARM11MPCore is incorrect, even if it can > 'solve' Loongson's problem. Secondly, I think the real problem is > like this: > 1, CPU0 set the lock to 0, then do something; > 2, While CPU0 is doing something, CPU1 set the flag to 1 with > WRITE_ONCE(), and then wait the lock become to 1 with a READ_ONCE() > loop; > 3, After CPU0 complete its work, it wait the flag become to 1, and if > so then set the lock to 1; > 4, If the lock becomes to 1, CPU1 will leave the READ_ONCE() loop. > If without SFB, everything is OK. But with SFB in step 2, a > READ_ONCE() loop is right after WRITE_ONCE(), which makes the flag > cached in SFB (so be invisible by other CPUs) for ever, then both CPU0 > and CPU1 wait for ever. Sure.. we all got that far. And no, this isn't the _real_ problem. This is a manifestation of the problem. The problem is that your SFB is broken (per the Linux requirements). We require that stores will become visible. That is, they must not indefinitely (for whatever reason) stay in the store buffer. > I don't think this is a hardware bug, in design, SFB will flushed to > L1 cache in three cases: > 1, data in SFB is full (be a complete cache line); > 2, there is a subsequent read access in the same cache line; > 3, a 'sync' instruction is executed. And I think this _is_ a hardware bug. You just designed the bug instead of it being by accident. > In this case, there is no other memory access (read or write) between > WRITE_ONCE() and READ_ONCE() loop. So Case 1 and Case 2 will not > happen, and the only way to make the flag be visible is wbflush > (wbflush is sync in Loongson's case). > > I think this problem is not only happens on Loongson, but will happen > on other CPUs which have write buffer (unless the write buffer has a > 4th case to be flushed). It doesn't happen an _any_ other architecture except that dodgy ARM11MPCore part. Linux hard relies on stores to become available _eventually_. Still, even with the rules above, the best work-around is still the very same cpu_relax() hack.