Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2978588imu; Sun, 9 Dec 2018 14:09:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/WkQCY6CGMGptpAKQkpcE7/FvDfOLWGknGalbukWOg0sDsRHXBnz3AngE72QuAB85FRPsgj X-Received: by 2002:a63:6ecf:: with SMTP id j198mr8999909pgc.3.1544393371464; Sun, 09 Dec 2018 14:09:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544393371; cv=none; d=google.com; s=arc-20160816; b=xCKBlY14bUIsQzhiLQB25asoxQ19DPFQD56ANob7V4RyyFyS//TXPKhsDTsWRmBwrq 05MTYI2H3MzsEg5sSg2t8Q+x3SefNqJsy5xIZ7YDFubI/hTNAl0NYTmWGIm677QsvkIi wX4LF3FQjgjAGBLnxdXrO/Tq9qdq0vHV2O0eniOhuv+9ae3LPa6V4snSrixtOONuQGib ucMbd5uApb9dH8Fx8NuCjWhCgrPT5FG9wMzftitmuVZ5MoJg7FfYPCxMOLz9ytZUw77T 5/1ypGSjZLkFQiWQkgCKZcooR6Q7z2qJkAQHJQVFgEcGCU0fHHfb/cYNYoeKgbJDawhd 5m0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=3x6KcisMXb7hzyUGGF3zJPHULtZ7PovRlCbxk8qhKXw=; b=qEX1OqbiQsIQTkhfFjNQXmjKRyVqC3hfNN7lrWv4z+7fdspcJuGC75hj90Kbsh9vAD zifZjclQNaZaxvpqRMo9sbkIgeqZT+bnDtgYXcqZmvDCDHnzLe9iMAqxfyF74DMlMewe 1NtwawCOe9WyHLPOGwOD4dw02a3LKHpcnphUl/8Dmor9zz840OwDhIfln8LEdn3Dx9CA Nwv8KVx1+sNLa3NubhyD+N7kyg0ArBgse+teR4iXYn3tHBmlttRsCH91+3ewBT4bExUF HdUCfRLCj6FnyC1kFNCZnaPjjsHWB0B7BvgkUHsjaKAg8eNFrGqDeDEGVeTIhY1zBwLu ODmw== 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 j20si7342129pgg.162.2018.12.09.14.09.16; Sun, 09 Dec 2018 14:09:31 -0800 (PST) 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 S1727955AbeLIWH4 (ORCPT + 99 others); Sun, 9 Dec 2018 17:07:56 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:37272 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727945AbeLIWHy (ORCPT ); Sun, 9 Dec 2018 17:07:54 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW73O-0002io-HI; Sun, 09 Dec 2018 21:55:58 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72Z-0003G2-Q2; Sun, 09 Dec 2018 21:55:07 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Zhangjin Wu" , "James Hogan" , linux-mips@linux-mips.org, "Huacai Chen" , "Ralf Baechle" , "Fuxin Zhang" , "Paul Burton" , "Huacai Chen" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 049/328] MIPS: Change definition of cpu_relax() for Loongson-3 In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 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 Signed-off-by: Ben Hutchings --- 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 @@ -366,7 +366,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)