From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51180 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729716AbeGQSeo (ORCPT ); Tue, 17 Jul 2018 14:34:44 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6HHxFkm078453 for ; Tue, 17 Jul 2018 14:00:57 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2k9ms49ctk-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 17 Jul 2018 14:00:56 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Jul 2018 14:00:56 -0400 Date: Tue, 17 Jul 2018 11:03:12 -0700 From: "Paul E. McKenney" To: Paul Burton Cc: Huacai Chen , Ralf Baechle , James Hogan , linux-mips@linux-mips.org, Fuxin Zhang , Zhangjin Wu , Huacai Chen , stable@vger.kernel.org, Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , linux-kernel@vger.kernel.org Subject: Re: [PATCH] MIPS: Change definition of cpu_relax() for Loongson-3 Reply-To: paulmck@linux.vnet.ibm.com References: <1531467477-9952-1-git-send-email-chenhc@lemote.com> <20180717175232.ea7pi2bqswnzmznc@pburton-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180717175232.ea7pi2bqswnzmznc@pburton-laptop> Message-Id: <20180717180312.GP12945@linux.vnet.ibm.com> Sender: stable-owner@vger.kernel.org List-ID: On Tue, Jul 17, 2018 at 10:52:32AM -0700, Paul Burton wrote: > Hi Huacai, > > On Fri, Jul 13, 2018 at 03:37:57PM +0800, Huacai Chen wrote: > > Linux expects that if a CPU modifies a memory location, then that > > modification will eventually become visible to other CPUs in the system. > > > > On Loongson-3 processor with SFB (Store Fill Buffer), loads may be > > prioritised over stores so it is possible for a store operation to be > > postponed if a polling loop immediately follows it. If the variable > > being polled indirectly depends on the outstanding store [for example, > > another CPU may be polling the variable that is pending modification] > > then there is the potential for deadlock if interrupts are disabled. > > This deadlock occurs in qspinlock code. > > > > This patch changes the definition of cpu_relax() to smp_mb() for > > Loongson-3, forcing a flushing of the SFB on SMP systems before the > > next load takes place. If the Kernel is not compiled for SMP support, > > this will expand to a barrier() as before. > > > > References: 534be1d5a2da940 (ARM: 6194/1: change definition of cpu_relax() for ARM11MPCore) > > Cc: stable@vger.kernel.org > > Signed-off-by: Huacai Chen > > --- > > arch/mips/include/asm/processor.h | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/arch/mips/include/asm/processor.h b/arch/mips/include/asm/processor.h > > index af34afb..a8c4a3a 100644 > > --- a/arch/mips/include/asm/processor.h > > +++ b/arch/mips/include/asm/processor.h > > @@ -386,7 +386,17 @@ unsigned long get_wchan(struct task_struct *p); > > #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29]) > > #define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status) > > > > +#ifdef CONFIG_CPU_LOONGSON3 > > +/* > > + * Loongson-3's SFB (Store-Fill-Buffer) may get starved when stuck in a read > > + * loop. Since spin loops of any kind should have a cpu_relax() in them, force > > + * a Store-Fill-Buffer flush from cpu_relax() such that any pending writes will > > + * become available as expected. > > + */ > > I think "may starve writes" or "may queue writes indefinitely" would be > clearer than "may get starved". > > > +#define cpu_relax() smp_mb() > > +#else > > #define cpu_relax() barrier() > > +#endif > > > > /* > > * Return_address is a replacement for __builtin_return_address(count) > > -- > > 2.7.0 > > Apart from the comment above though this looks better to me. > > Re-copying the LKMM maintainers - are you happy(ish) with this? This looks much better to me. Thanx, Paul