Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1836192imm; Mon, 3 Sep 2018 10:41:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbbgGozrsBFDmxbTy8Fb38Y7tVDf8vdh1wxgSOKWeCKAKwahbWXy4WeV0tJeU/gdH3pkII8 X-Received: by 2002:a62:3ac8:: with SMTP id v69-v6mr30373796pfj.164.1535996473748; Mon, 03 Sep 2018 10:41:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535996473; cv=none; d=google.com; s=arc-20160816; b=hx/zqeyP1NmOteXiAjMludR6alkfBFttHiwbGXACSggzNBeUPOIysbW3yz0oVA3awZ rb7/UJ4wIaGmNY+2u1JsuxXetTp548gCHONNzvjOMhyvTZ688wSaoMGct+lMcizGsxcJ sNujxviNLjLySX083l7PHKi0mNYJBRcLYYHsjCkFn0iFMsHvgY4JxhhQXEDi9X/lWCRI EUeSeHB52BddusrGJ7VqYMLze+H7QIVJX3iNdvExjJOPIYHoBuMcIEEF/EuyhOQyOhZD 6hy/xHnfl86JAikICPsB7YJG1W2YyGCmFMvv7YkhA2vuV3kaCwT8BiUwqfkYhRdX1iV3 U0bQ== 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=3NvVOtZ9DcBhT1Bq7sj+Jml5/2wSQBCSLUxRw8uODVU=; b=Jef6APSrvePEvgr/ZeaZ4C9xgJ9cYfCCIQ7vyQiG2DyctoVDyhqAJIqZgzMMY/mDqp R4LClR2Mq0p8vvGzjCIcNNE/0+JA/ursW0XdOqZLFt7E8dvLJvRyrksMZCHVBeXdLiHi knMwkeuzxjUZ8sImwJ8z8nbHytMXEz8fQNeXefNGsu0OEW7cNeolSp4Gm3mTwJmSlb6v fpRy0MNzLKvlDgo2wf7D9fhy0HROWi54NGBZ0UwbJ3NJeh7YGoDTnTBRXbDo9W2rsy3r zbO3IPBgn5tm0LumIvcWA6krn9CMeLmrx3L8AcPRFjFDc0gM10dPthFr4Ggb7G1NKI5Y Sfzw== 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 i186-v6si17737068pge.414.2018.09.03.10.40.58; Mon, 03 Sep 2018 10:41:13 -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 S1731849AbeICV7s (ORCPT + 99 others); Mon, 3 Sep 2018 17:59:48 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48982 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726384AbeICV7r (ORCPT ); Mon, 3 Sep 2018 17:59:47 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C5505A95; Mon, 3 Sep 2018 17:38:35 +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.18 102/123] MIPS: Change definition of cpu_relax() for Loongson-3 Date: Mon, 3 Sep 2018 18:57:26 +0200 Message-Id: <20180903165723.838149229@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165719.499675257@linuxfoundation.org> References: <20180903165719.499675257@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.18-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 @@ -386,7 +386,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)