Received: by 10.223.164.202 with SMTP id h10csp2757603wrb; Sun, 12 Nov 2017 17:55:13 -0800 (PST) X-Google-Smtp-Source: AGs4zMZDqkKXTGq1ijIpQs3H7cZe64ArAw4zwXHqKCx5GnqdIZqPMZQOLPsP6HWX4Y+zvgDqAaat X-Received: by 10.84.215.129 with SMTP id l1mr7448863pli.181.1510538113860; Sun, 12 Nov 2017 17:55:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510538113; cv=none; d=google.com; s=arc-20160816; b=h7hr6g2UqsIUJshudPxOZWt0ZKsuPPsxG0AjwzzGQZSG83MSRwMi1aGLQDiH7ZjzhG gn4Firp4RyHqYQ0nSHb3FzSwBm/DHh2z4Yeg8klq9+V3p4j0NZ0/N5UhmK+336W9Nv/o +950DTjjda4Asi5sSCCltpO6JlVlme/j83KS2O590KjS69chhFBI67EuXWYQW2iAD00L mECwFwysMFEmsFFlyEBqGpk46XQnlqOXU1zaSugLDyn6cwOWU3RRWLrnJyBzqLFYT+EQ h9GwPT80TWTqJtb1BgPYHIJ0nqXco+owgMF41rvELVdezn1iVwwUqApDqbRYyc2JAA2h BP4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:reply-to:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=+2HGIQqIvrvLjdXuW6Exyy+1zT09MO8hO4I8s90GXLI=; b=C8DFGGeVyQ3z7Gzx6QjMfcO1UizeWIqA+YztZENVEkfT/uwL5YC7aK34U5E++P6fvO jBmfvWfOMJGW8E+os++JbpD8E6AOp9EOb6Z9RaKdOrjtVGqK971erMohGjrI8XNKgGn5 Utisq3aNReb3U5X/PXZG9kLSqgOASEhbzUyXWjI8Q46mwiunQLo1KuCHkB2YTcQKEbRQ T2OShgBwvCYv8SGHTzqjziZPAN9fNQuiCiYasOB+J8rynyq995YsewMzg8aPUmFYM1Gq ovy8bcBKxVNQKrcrcjP70IAzZZ5ZVAoscl65qzpw7diGiO4FiAMjwrHhr634OW/z+Q+U PCHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=L9OVhXLX; dkim=pass header.i=@codeaurora.org header.s=default header.b=F+rrsOlv; 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 r3si12955706pgq.361.2017.11.12.17.55.01; Sun, 12 Nov 2017 17:55:13 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=L9OVhXLX; dkim=pass header.i=@codeaurora.org header.s=default header.b=F+rrsOlv; 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 S1751578AbdKMByQ (ORCPT + 87 others); Sun, 12 Nov 2017 20:54:16 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:54986 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751043AbdKMByO (ORCPT ); Sun, 12 Nov 2017 20:54:14 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 7441A6080C; Mon, 13 Nov 2017 01:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1510538054; bh=IlK3+LwWbaZ7NePAW4HRzeGsHNo8/DMAK90xc/n2SrA=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=L9OVhXLXQRQLnoZQpxLJA1I8wEhAJnnZB7Ib/10a2BAUke08L4BgMARXkPisG9QWO uPkiLTF1JSBvi3zb2TknT2mm0pqz7MEFEEe7lCgOmaMMwrEXORQXo0PsEZLJRjYWwi FKgoQVV5WgVommw2jbM/i2zZ4cy0rdrvqFXBDgQg= 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 [10.0.2.15] (unknown [70.123.43.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: shankerd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 7CDE26055A; Mon, 13 Nov 2017 01:54:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1510538052; bh=IlK3+LwWbaZ7NePAW4HRzeGsHNo8/DMAK90xc/n2SrA=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=F+rrsOlvwUuZZ9WGHO7PyA7h5mFOzUFznPtKj8gE3L1cdvs7TDDlfEM/1aWrhbrYb gXSz97gVkRtzvusF5MOPxsfa1y/ICc9tD72UoakLQXG2FvYuKfgBQOnXyUp4Va9F3/ 4rwBuBNhcLu2mCViHHz8KYmAgd9Lw33HBQP3UJP4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 7CDE26055A 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 Reply-To: shankerd@codeaurora.org Subject: Re: [PATCH v2 2/2] arm64: Add software workaround for Falkor erratum 1041 To: Will Deacon , Marc Zyngier , linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org, Ard Biesheuvel , Matt Fleming , Catalin Marinas , linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Christoffer Dall References: <1510535802-2799-1-git-send-email-shankerd@codeaurora.org> <1510535802-2799-3-git-send-email-shankerd@codeaurora.org> From: Shanker Donthineni Message-ID: Date: Sun, 12 Nov 2017 19:54:10 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1510535802-2799-3-git-send-email-shankerd@codeaurora.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Sorry, I've posted a wrong patch which causes the compilation errors. Please disregard this patch, I posted v3 patch to fix the build issue. https://patchwork.kernel.org/patch/10055077/ On 11/12/2017 07:16 PM, Shanker Donthineni wrote: > 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 4K and next 4K. > > 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. > > The conditions leading to this erratum will not occur when either of the > following occur: > 1) A higher exception level disables translation of a lower exception level > (e.g. EL2 changing SCTLR_EL1[M] from a value of 1 to 0). > 2) An exception level disabling its stage-1 translation if its stage-2 > translation is enabled (e.g. EL1 changing SCTLR_EL1[M] from a value of 1 > to 0 when HCR_EL2[VM] has a value of 1). > > 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 | 18 ++++++++++++++++++ > arch/arm64/include/asm/cpucaps.h | 3 ++- > arch/arm64/kernel/cpu-reset.S | 1 + > arch/arm64/kernel/cpu_errata.c | 16 ++++++++++++++++ > arch/arm64/kernel/efi-entry.S | 2 ++ > arch/arm64/kernel/head.S | 1 + > arch/arm64/kernel/relocate_kernel.S | 1 + > arch/arm64/kvm/hyp-init.S | 1 + > 10 files changed, 53 insertions(+), 1 deletion(-) > > 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..8f73eac 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_E1041 > + 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 d58a625..eb11cdf 100644 > --- a/arch/arm64/include/asm/assembler.h > +++ b/arch/arm64/include/asm/assembler.h > @@ -499,4 +499,22 @@ > #endif > .endm > > +/** > + * Errata workaround prior to disable MMU. Insert an ISB immediately prior > + * to executing the MSR that will change SCTLR_ELn[M] from a value of 1 to 0. > + */ > + .macro pre_disable_mmu_workaround > +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_E1041 > +alternative_if ARM64_WORKAROUND_QCOM_FALKOR_E1041 > + isb > +alternative_else_nop_endif > +#endif > + .end > + > + .macro pre_disable_mmu_early_workaround > +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_E1041 > + isb > +#endif > + .end > + > #endif /* __ASM_ASSEMBLER_H */ > 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-reset.S b/arch/arm64/kernel/cpu-reset.S > index 65f42d2..2a752cb 100644 > --- a/arch/arm64/kernel/cpu-reset.S > +++ b/arch/arm64/kernel/cpu-reset.S > @@ -37,6 +37,7 @@ ENTRY(__cpu_soft_restart) > mrs x12, sctlr_el1 > ldr x13, =SCTLR_ELx_FLAGS > bic x12, x12, x13 > + pre_disable_mmu_workaround > msr sctlr_el1, x12 > isb > > diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c > index 0e27f86..2fd1938 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_E1041 > + { > + .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 4e6ad35..dc675ba 100644 > --- a/arch/arm64/kernel/efi-entry.S > +++ b/arch/arm64/kernel/efi-entry.S > @@ -96,6 +96,7 @@ ENTRY(entry) > mrs x0, sctlr_el2 > bic x0, x0, #1 << 0 // clear SCTLR.M > bic x0, x0, #1 << 2 // clear SCTLR.C > + pre_disable_mmu_early_workaround > msr sctlr_el2, x0 > isb > b 2f > @@ -103,6 +104,7 @@ ENTRY(entry) > mrs x0, sctlr_el1 > bic x0, x0, #1 << 0 // clear SCTLR.M > bic x0, x0, #1 << 2 // clear SCTLR.C > + pre_disable_mmu_early_workaround > msr sctlr_el1, x0 > isb > 2: > diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S > index 0b243ec..a807fca 100644 > --- a/arch/arm64/kernel/head.S > +++ b/arch/arm64/kernel/head.S > @@ -732,6 +732,7 @@ __primary_switch: > * to take into account by discarding the current kernel mapping and > * creating a new one. > */ > + pre_disable_mmu_early_workaround > msr sctlr_el1, x20 // disable the MMU > isb > bl __create_page_tables // recreate kernel mapping > diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S > index ce704a4..f407e42 100644 > --- a/arch/arm64/kernel/relocate_kernel.S > +++ b/arch/arm64/kernel/relocate_kernel.S > @@ -45,6 +45,7 @@ ENTRY(arm64_relocate_new_kernel) > mrs x0, sctlr_el2 > ldr x1, =SCTLR_ELx_FLAGS > bic x0, x0, x1 > + pre_disable_mmu_workaround > msr sctlr_el2, x0 > isb > 1: > diff --git a/arch/arm64/kvm/hyp-init.S b/arch/arm64/kvm/hyp-init.S > index 3f96155..870828c 100644 > --- a/arch/arm64/kvm/hyp-init.S > +++ b/arch/arm64/kvm/hyp-init.S > @@ -151,6 +151,7 @@ reset: > mrs x5, sctlr_el2 > ldr x6, =SCTLR_ELx_FLAGS > bic x5, x5, x6 // Clear SCTL_M and etc > + pre_disable_mmu_workaround > msr sctlr_el2, x5 > isb > > -- Shanker Donthineni Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. From 1583913363493260845@xxx Mon Nov 13 01:44:54 +0000 2017 X-GM-THRID: 1583013979194485035 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread