Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1828360imm; Mon, 3 Sep 2018 10:29:04 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZynnXEkNUqsvnbpUlTIxEpyqoQV1iSOQZFEv/ei9nWd4V4sAVmtrgo7hphB52LQGtI7oUR X-Received: by 2002:a62:e11:: with SMTP id w17-v6mr30839227pfi.242.1535995744784; Mon, 03 Sep 2018 10:29:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995744; cv=none; d=google.com; s=arc-20160816; b=u23jD4morzERbhlrWi7kN2KzTktB4LdQ7tRX38hrUP5ea+J5FbDLEv4rdGds2+PK1S LcFIZzD5XOxlQfMiqnyv+fG9e9eAALD50QLieYDBsGcqsneS+Uw7jPkJ0cCNcOBVd8MN y1cDd3zYCc8OROkPdNYfiT/xDcZDZ0QUjqmyt1T44pJ6qmfDhjfqAlDhz0JPEx+TGb7I nilRIZ34aDPDFtBQc0XnAPxOmQFeJQz5dNRicABBRPHaTQGCguFvP5g32Oik+H1gsE8f Th/RCL7mUN95XWOuJziVtKh27sqOhm4IYw6eDlONX8G2jSb3MrUw037tsrVfAj/SlnBc heeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=WzRfvtfO86bEss4h8dGzpvI1R0Cj788XirvdyrtD6Pc=; b=Ly8Oo0tRw08V8cbryzYcUz1b1+BAJBLYBSiOlZ6nk0fOPCTujqH25j6R/gPz1ZXQla 4pTumCoVvFmjjXT2mAknHurLAKzQKEbkZtZmMXztK2s/mXtVNKLVa4fNFdaInGxcXioN QLj3kU5yP4+OYtMhjqIiCyWlJXKhNAHYdkGwgPk7pEn8Vwh/ess6szCPy7qxoxUG8R+w r2r+lM30iqGi8cmsy7KDY561IfPKG7jFNhsOsfTP3txiONt2KbZee+e46HWw3ttkvzPi j8S+PXs4lwP1W1Ly87LCqrZrdCaDTjOwvgWc1u7VZIOxjaJ4fmNbUL0CXS4M3qukPlQy GLdQ== 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 w7-v6si19055355plq.198.2018.09.03.10.28.49; Mon, 03 Sep 2018 10:29:04 -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 S1731036AbeICVsi (ORCPT + 99 others); Mon, 3 Sep 2018 17:48:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46272 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728175AbeICVsh (ORCPT ); Mon, 3 Sep 2018 17:48:37 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id EEE68CF4; Mon, 3 Sep 2018 17:27:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Huacai Chen , Paul Burton , Ralf Baechle , James Hogan , linux-mips@linux-mips.org, Fuxin Zhang , Zhangjin Wu , Huacai Chen Subject: [PATCH 4.14 151/165] MIPS: Change definition of cpu_relax() for Loongson-3 Date: Mon, 3 Sep 2018 18:57:17 +0200 Message-Id: <20180903165704.649556175@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Huacai Chen commit a30718868915fbb991a9ae9e45594b059f28e9ae upstream. Linux expects that if a CPU modifies a memory location, then that modification will eventually become visible to other CPUs in the system. Loongson 3 CPUs include a Store Fill Buffer (SFB) which sits between a core & its L1 data cache, queueing memory accesses & allowing for faster forwarding of data from pending stores to younger loads from the core. Unfortunately the SFB prioritizes loads such that a continuous stream of loads may cause a pending write to be buffered indefinitely. This is problematic if we end up with 2 CPUs which each perform a store that the other polls for - one or both CPUs may end up with their stores buffered in the SFB, never reaching cache due to the continuous reads from the poll loop. Such a deadlock condition has been observed whilst running qspinlock code. This patch changes the definition of cpu_relax() to smp_mb() for Loongson-3, forcing a flush of the SFB on SMP systems which will cause any pending writes to make it as far as the L1 caches where they will become visible to other CPUs. If the kernel is not compiled for SMP support, this will expand to a barrier() as before. This workaround matches that currently implemented for ARM when CONFIG_ARM_ERRATA_754327=y, which was introduced by commit 534be1d5a2da ("ARM: 6194/1: change definition of cpu_relax() for ARM11MPCore"). Although the workaround is only required when the Loongson 3 SFB functionality is enabled, and we only began explicitly enabling that functionality in v4.7 with commit 1e820da3c9af ("MIPS: Loongson-3: Introduce CONFIG_LOONGSON3_ENHANCEMENT"), existing or future firmware may enable the SFB which means we may need the workaround backported to earlier kernels too. [paul.burton@mips.com: - Reword commit message & comment. - Limit stable backport to v3.15+ where we support Loongson 3 CPUs.] Signed-off-by: Huacai Chen Signed-off-by: Paul Burton References: 534be1d5a2da ("ARM: 6194/1: change definition of cpu_relax() for ARM11MPCore") References: 1e820da3c9af ("MIPS: Loongson-3: Introduce CONFIG_LOONGSON3_ENHANCEMENT") Patchwork: https://patchwork.linux-mips.org/patch/19830/ Cc: Ralf Baechle Cc: James Hogan Cc: linux-mips@linux-mips.org Cc: Fuxin Zhang Cc: Zhangjin Wu Cc: Huacai Chen Cc: stable@vger.kernel.org # v3.15+ Signed-off-by: Greg Kroah-Hartman --- arch/mips/include/asm/processor.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/arch/mips/include/asm/processor.h +++ b/arch/mips/include/asm/processor.h @@ -388,7 +388,20 @@ unsigned long get_wchan(struct task_stru #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 buffer writes indefinitely when a + * tight read loop is executed, because reads take priority over writes & the + * hardware (incorrectly) doesn't ensure that writes will eventually occur. + * + * Since spin loops of any kind should have a cpu_relax() in them, force an SFB + * flush from cpu_relax() such that any pending writes will become visible as + * expected. + */ +#define cpu_relax() smp_mb() +#else #define cpu_relax() barrier() +#endif /* * Return_address is a replacement for __builtin_return_address(count)