Received: by 10.223.164.221 with SMTP id h29csp2881842wrb; Thu, 2 Nov 2017 20:29:34 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SE8G9ZcOgFmN8P6JL9QF+RE/uLXUWk9pAuU0x2UAJJq1hCMlOKh1iDSKRXC5hxGFmtSMdA X-Received: by 10.159.211.67 with SMTP id g3mr5377709plp.381.1509679774751; Thu, 02 Nov 2017 20:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509679774; cv=none; d=google.com; s=arc-20160816; b=v5HhjZ5MORvouK87kuB3X7wUreZBoEjR3M/dMspOXABabtO+uTBXa+cG/B2So3WopS YjKRK1TV6Wfw98CZD7VPsTwiOzLM7rLTSOBaYe4yEqPSDatSF2JhkoSb+O9Tcp0DH0JO 2IF+kmw9XL1t2n7kdMiETc/Ep8zv/KZK3CmP0oD0lUOJ1WktiVyK0yqMy/qBtvF8bR4c c/K/7OQ7gGD9ylRsUEzNW/GRznH6npTTmPZjmsT7Wtvj6PWdSXeb1D5V8cfxIqTIz+m5 zgt3et0cQ3ZklRXhin+1qtRwEfMfp+oKWM5UlLJvrA9MAvIDkEdinef+NwQ4UKTmAoXo OnYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=utHMxgTs+AudRydgVZ7uaSJaFxmNSTJplK6OTayTYMU=; b=OoDb2GexkLrtIV9mgn01EWpzyw4TvPwgyUpGIEKdvpgs8RbP67F5EBIiztMDhH5ZzC 8heuZ/ThoS1pJX6pR/wXwWiaW9R9RKLBQfXP2riTfcfdaI9q0QZXnkfCKAWOrAXCmUfd My5/TC33HjXWR//PJNWTWxBb0KawNC5CQa66vwz4veXtPejfXtfqFK9b2uGqDlqFXRGh uV5+kG8g94WVckObN2qroWVW1vimski1q2M5ijVJU5L2aNitybVLwBesuhN398th+lUh 1vIVx0gcO1QJpN+GcYnTQcjuYcnSgMfLMpxpK9sNWED0yORfkJrEXAkZgj5gLUIYyykP RgOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=hsDWXUTx; dkim=pass header.i=@codeaurora.org header.s=default header.b=Vvt8Jhqs; 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 61si3616355plz.155.2017.11.02.20.29.21; Thu, 02 Nov 2017 20:29:34 -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=pass header.i=@codeaurora.org header.s=default header.b=hsDWXUTx; dkim=pass header.i=@codeaurora.org header.s=default header.b=Vvt8Jhqs; 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 S965034AbdKCD2V (ORCPT + 97 others); Thu, 2 Nov 2017 23:28:21 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:49342 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934779AbdKCD2Q (ORCPT ); Thu, 2 Nov 2017 23:28:16 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9FDC360807; Fri, 3 Nov 2017 03:28:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1509679695; bh=8ZCKF+mA/H/nGeJG44i+xlz/BE0BmJJdIoM3X81o2GQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hsDWXUTxc6r4z/NWvYMmSnOlUz0If3fhURehAGgO7fl3L7uXxqF+jhPjhZLDfsPIj pBinbfVU6BWi3aHrt7T5PlY/rlf/E26me7cvgnBPVNvPKAjxrOQ1yxf+DFtz/eRCCH XZp0syG/Llu8DJOul5vSg1yWCb0h8VQ02xWbj45s= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from shankerd-ubuntu.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: shankerd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id CED6F607E4; Fri, 3 Nov 2017 03:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1509679694; bh=8ZCKF+mA/H/nGeJG44i+xlz/BE0BmJJdIoM3X81o2GQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vvt8JhqsepP1q96O+K6FYXC/mHm6LWYWEQlwWzdc1pW1LzXj1FemqED1j8N0WsOxl HETmWCiabY5gKAS2bHC43qDxj4PfdGGTlKrtgq+zcN1ruGxZSWgRqVJcFJbGAkYY8u lio0laSBJhRWFp5WmlEx3UMdnyRs4AMhNKsy3usw= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org CED6F607E4 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=shankerd@codeaurora.org From: Shanker Donthineni To: Will Deacon , Marc Zyngier , linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Ard Biesheuvel , Matt Fleming , Christoffer Dall , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Shanker Donthineni Subject: [PATCH 3/3] arm64: Add software workaround for Falkor erratum 1041 Date: Thu, 2 Nov 2017 22:27:44 -0500 Message-Id: <1509679664-3749-4-git-send-email-shankerd@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509679664-3749-1-git-send-email-shankerd@codeaurora.org> References: <1509679664-3749-1-git-send-email-shankerd@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ARM architecture defines the memory locations that are permitted to be accessed as the result of a speculative instruction fetch from an exception level for which all stages of translation are disabled. Specifically, the core is permitted to speculatively fetch from the 4KB region containing the current program counter and next 4KB. When translation is changed from enabled to disabled for the running exception level (SCTLR_ELn[M] changed from a value of 1 to 0), the Falkor core may errantly speculatively access memory locations outside of the 4KB region permitted by the architecture. The errant memory access may lead to one of the following unexpected behaviors. 1) A System Error Interrupt (SEI) being raised by the Falkor core due to the errant memory access attempting to access a region of memory that is protected by a slave-side memory protection unit. 2) Unpredictable device behavior due to a speculative read from device memory. This behavior may only occur if the instruction cache is disabled prior to or coincident with translation being changed from enabled to disabled. To avoid the errant behavior, software must execute an ISB immediately prior to executing the MSR that will change SCTLR_ELn[M] from 1 to 0. Signed-off-by: Shanker Donthineni --- Documentation/arm64/silicon-errata.txt | 1 + arch/arm64/Kconfig | 10 ++++++++++ arch/arm64/include/asm/assembler.h | 17 +++++++++++++++++ arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/kernel/cpu_errata.c | 16 ++++++++++++++++ arch/arm64/kernel/efi-entry.S | 4 ++-- arch/arm64/kernel/head.S | 4 ++-- 7 files changed, 50 insertions(+), 5 deletions(-) diff --git a/Documentation/arm64/silicon-errata.txt b/Documentation/arm64/silicon-errata.txt index 66e8ce1..704770c0 100644 --- a/Documentation/arm64/silicon-errata.txt +++ b/Documentation/arm64/silicon-errata.txt @@ -74,3 +74,4 @@ stable kernels. | Qualcomm Tech. | Falkor v1 | E1003 | QCOM_FALKOR_ERRATUM_1003 | | Qualcomm Tech. | Falkor v1 | E1009 | QCOM_FALKOR_ERRATUM_1009 | | Qualcomm Tech. | QDF2400 ITS | E0065 | QCOM_QDF2400_ERRATUM_0065 | +| Qualcomm Tech. | Falkor v{1,2} | E1041 | QCOM_FALKOR_ERRATUM_1041 | diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 0df64a6..7e933fb 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -539,6 +539,16 @@ config QCOM_QDF2400_ERRATUM_0065 If unsure, say Y. +config QCOM_FALKOR_ERRATUM_1041 + bool "Falkor E1041: Speculative instruction fetches might cause errant memory access" + default y + help + Falkor CPU may speculatively fetch instructions from an improper + memory location when MMU translation is changed from SCTLR_ELn[M]=1 + to SCTLR_ELn[M]=0. Prefix an ISB instruction to fix the problem. + + If unsure, say Y. + endmenu diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index b6dfb4f..4c91efb 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -30,6 +30,7 @@ #include #include #include +#include /* * Enable and disable interrupts. @@ -514,6 +515,22 @@ * reg: the value to be written. */ .macro write_sctlr, eln, reg +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1041 +alternative_if ARM64_WORKAROUND_QCOM_FALKOR_E1041 + tbnz \reg, #0, 8000f // enable MMU? + isb +8000: +alternative_else_nop_endif +#endif + msr sctlr_\eln, \reg + .endm + + .macro early_write_sctlr, eln, reg +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1041 + tbnz \reg, #0, 8000f // enable MMU? + isb +8000: +#endif msr sctlr_\eln, \reg .endm diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h index 8da6216..7f7a59d 100644 --- a/arch/arm64/include/asm/cpucaps.h +++ b/arch/arm64/include/asm/cpucaps.h @@ -40,7 +40,8 @@ #define ARM64_WORKAROUND_858921 19 #define ARM64_WORKAROUND_CAVIUM_30115 20 #define ARM64_HAS_DCPOP 21 +#define ARM64_WORKAROUND_QCOM_FALKOR_E1041 22 -#define ARM64_NCAPS 22 +#define ARM64_NCAPS 23 #endif /* __ASM_CPUCAPS_H */ diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 0e27f86..27f9a45 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -179,6 +179,22 @@ static int cpu_enable_trap_ctr_access(void *__unused) MIDR_CPU_VAR_REV(0, 0)), }, #endif +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1041 + { + .desc = "Qualcomm Technologies Falkor erratum 1041", + .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1041, + MIDR_RANGE(MIDR_QCOM_FALKOR_V1, + MIDR_CPU_VAR_REV(0, 0), + MIDR_CPU_VAR_REV(0, 0)), + }, + { + .desc = "Qualcomm Technologies Falkor erratum 1041", + .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1041, + MIDR_RANGE(MIDR_QCOM_FALKOR, + MIDR_CPU_VAR_REV(0, 1), + MIDR_CPU_VAR_REV(0, 2)), + }, +#endif #ifdef CONFIG_ARM64_ERRATUM_858921 { /* Cortex-A73 all versions */ diff --git a/arch/arm64/kernel/efi-entry.S b/arch/arm64/kernel/efi-entry.S index acae627..c31be1b 100644 --- a/arch/arm64/kernel/efi-entry.S +++ b/arch/arm64/kernel/efi-entry.S @@ -96,14 +96,14 @@ ENTRY(entry) read_sctlr el2, x0 bic x0, x0, #1 << 0 // clear SCTLR.M bic x0, x0, #1 << 2 // clear SCTLR.C - write_sctlr el2, x0 + early_write_sctlr el2, x0 isb b 2f 1: read_sctlr el1, x0 bic x0, x0, #1 << 0 // clear SCTLR.M bic x0, x0, #1 << 2 // clear SCTLR.C - write_sctlr el1, x0 + early_write_sctlr el1, x0 isb 2: /* Jump to kernel entry point */ diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index b8d5b73..9512ce7 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -511,7 +511,7 @@ install_el2_stub: mov x0, #0x0800 // Set/clear RES{1,0} bits CPU_BE( movk x0, #0x33d0, lsl #16 ) // Set EE and E0E on BE systems CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems - write_sctlr el1, x0 + early_write_sctlr el1, x0 /* Coprocessor traps. */ mov x0, #0x33ff @@ -732,7 +732,7 @@ __primary_switch: * to take into account by discarding the current kernel mapping and * creating a new one. */ - write_sctlr el1, x20 // disable the MMU + early_write_sctlr el1, x20 // disable the MMU isb bl __create_page_tables // recreate kernel mapping -- Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. From 1584142047695204232@xxx Wed Nov 15 14:19:44 +0000 2017 X-GM-THRID: 1584142047695204232 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread