From patchwork Wed Feb 14 11:36:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10218485 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 19D036055C for ; Wed, 14 Feb 2018 11:39:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEA7228BFA for ; Wed, 14 Feb 2018 11:39:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E351928C33; Wed, 14 Feb 2018 11:39:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 61A8228F5C for ; Wed, 14 Feb 2018 11:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=loTjQBdvcP8LPxIjsOzvh46VMs/Dig/+rYWCjq7mXS0=; b=jKQF3PXkPkZNEaN5xS2n9YfvKF 5PjTXp1+oVSv/FL/v4mhjA0ezfQsfZ79BFTATl3ZhLgeYssnl7CbehbGHm9WP1L5RjCJgl4DsM+M6 U++uHw1weYBfPy2b4jhezlCwBod3odrvE0A0M25tgpxPMBUy/wjmm7QwimahK2zAw3zN4oqAkOGyE fxmbEJc//sH94UrxayeRrzdvdTe0MSYYzqiQUA2tUrgyWdBBS8khnvzNnQQwq75M9ZmMKB2WfwxZe thkzGcrzSJeQljSawWjrGReuEEhZx1aaewUvEbs588xMooAILgQlGYOmvctE4CLSJM6zuvjyJDWkh Q/0KN5QA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1elvPD-000788-Il; Wed, 14 Feb 2018 11:39:19 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1elvNK-0005li-9y for linux-arm-kernel@lists.infradead.org; Wed, 14 Feb 2018 11:37:29 +0000 Received: by mail-wm0-x241.google.com with SMTP id t74so22055341wme.3 for ; Wed, 14 Feb 2018 03:37:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qJAQKN2DsbAHvtlNcU0Xlmoyj0PQKUQTNtZNXfa2C6I=; b=NJS1l4/Qxa0p3kyjUn4JbwjAMsSQ2zasAP9iqztdSapkr5ihD9TICb0XDNSGlTb8/v 8pAZ2b7OQnJ3vYPWNbE3ul8i5oNKeNuRkObJxoG8E6RiRuUVBRLqn+BdAJYRayWC4b6z Sg+AJTVZjmVyDKxYJROKwQxT7LBTd60CSd+RY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qJAQKN2DsbAHvtlNcU0Xlmoyj0PQKUQTNtZNXfa2C6I=; b=ZV86Yw9P4fMCnMT9cA9SDY2/lNz9MSiPOv3pPhjdven2S7eCY9Ar/phDnRAKKT69Lx aqBLtIVTte7grYCJma07zWWn2EJDhUPCSUr0va7ze2+P9MfllM7A/nY+FlD6yDVEgL5g n7q4uFNrSlw1xNV9Af4GFLDobD93we4IWHvFWDkEI8KkQVB3y2TYa4+QU+prgTQyfXvL ZktZfktbIMW5OfdIIgyP1xYFKRE4CR/JzB7QKWo0Nf4Id2xOdhpvUcV2KP6F077eD9Kp JPbP7QB4PbUO9d4ocVx0vV2VSYjFC6+69aBwH8/W9QXvKpGrqVtcV2Mv/LNsYdoft9yk 5CwQ== X-Gm-Message-State: APf1xPAFnUn1C30UAwKjN/CsnaxfvTyiyHbLuHjry+gqefPmADucWQbN 5LqpPaAMW0f53Uc2d0jCJueQ0j+0cbQ= X-Google-Smtp-Source: AH8x227CLXp50lKSMaMcO2zBjGp7vuFLkYjq0Qu3+kUgXI1t7xxeQ4ADrqeyq9VMWdl5RpGL6vuH+g== X-Received: by 10.28.153.20 with SMTP id b20mr4165915wme.6.1518608230337; Wed, 14 Feb 2018 03:37:10 -0800 (PST) Received: from localhost.localdomain ([154.145.114.50]) by smtp.gmail.com with ESMTPSA id o82sm9158905wmo.30.2018.02.14.03.37.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Feb 2018 03:37:09 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, mark.rutland@arm.com Subject: [RFC PATCH v3 3/3] arm64/kernel: enable A53 erratum #8434319 handling at runtime Date: Wed, 14 Feb 2018 11:36:45 +0000 Message-Id: <20180214113645.16793-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180214113645.16793-1-ard.biesheuvel@linaro.org> References: <20180214113645.16793-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180214_033722_580499_28C44DC0 X-CRM114-Status: GOOD ( 15.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marc.zyngier@arm.com, catalin.marinas@arm.com, Ard Biesheuvel , suzuki.poulose@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Omit patching of ADRP instruction at module load time if the current CPUs are not susceptible to the erratum. Signed-off-by: Ard Biesheuvel --- Open question: how should we handle big.LITTLE configurations where affected Cortex-A53s may appear late. arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/kernel/cpu_errata.c | 26 ++++++++++++++++++++ arch/arm64/kernel/module-plts.c | 3 ++- arch/arm64/kernel/module.c | 3 ++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h index bb263820de13..39134c46bb13 100644 --- a/arch/arm64/include/asm/cpucaps.h +++ b/arch/arm64/include/asm/cpucaps.h @@ -45,7 +45,8 @@ #define ARM64_HARDEN_BRANCH_PREDICTOR 24 #define ARM64_HARDEN_BP_POST_GUEST_EXIT 25 #define ARM64_HAS_RAS_EXTN 26 +#define ARM64_WORKAROUND_843419 27 -#define ARM64_NCAPS 27 +#define ARM64_NCAPS 28 #endif /* __ASM_CPUCAPS_H */ diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 07823595b7f0..c065d5649b1b 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -228,6 +228,23 @@ static int qcom_enable_link_stack_sanitization(void *data) } #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ +static bool __maybe_unused +needs_erratum_843419_workaround(const struct arm64_cpu_capabilities *entry, + int scope) +{ + u32 cpuid = read_cpuid_id(); + + WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); + + if ((cpuid & MIDR_CPU_MODEL_MASK) != MIDR_CORTEX_A53) + return false; + else if ((cpuid & (MIDR_REVISION_MASK | MIDR_VARIANT_MASK)) == 0x4) + /* erratum was fixed in some versions of r0p4 */ + return !(read_cpuid(REVIDR_EL1) & BIT(8)); + else + return true; +} + #define MIDR_RANGE(model, min, max) \ .def_scope = SCOPE_LOCAL_CPU, \ .matches = is_affected_midr_range, \ @@ -283,6 +300,15 @@ const struct arm64_cpu_capabilities arm64_errata[] = { MIDR_CPU_VAR_REV(1, 2)), }, #endif +#ifdef CONFIG_ARM64_ERRATUM_843419 + { + /* Cortex-A53 r0p[01234] */ + .desc = "ARM erratum 843419", + .capability = ARM64_WORKAROUND_843419, + .def_scope = SCOPE_LOCAL_CPU, + .matches = needs_erratum_843419_workaround, + }, +#endif #ifdef CONFIG_ARM64_ERRATUM_845719 { /* Cortex-A53 r0p[01234] */ diff --git a/arch/arm64/kernel/module-plts.c b/arch/arm64/kernel/module-plts.c index 93b808056cb4..0a208a49eb70 100644 --- a/arch/arm64/kernel/module-plts.c +++ b/arch/arm64/kernel/module-plts.c @@ -156,7 +156,8 @@ static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int num, break; case R_AARCH64_ADR_PREL_PG_HI21_NC: case R_AARCH64_ADR_PREL_PG_HI21: - if (!IS_ENABLED(CONFIG_ARM64_ERRATUM_843419)) + if (!IS_ENABLED(CONFIG_ARM64_ERRATUM_843419) || + !cpus_have_const_cap(ARM64_WORKAROUND_843419)) break; /* diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index d1bbdffd1e6c..5a05f84d575e 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -201,7 +201,8 @@ static int reloc_insn_imm(enum aarch64_reloc_op op, __le32 *place, u64 val, static bool reloc_adrp_erratum_843419(struct module *mod, __le32 *place, u64 val) { - if (!IS_ENABLED(CONFIG_ARM64_ERRATUM_843419)) + if (!IS_ENABLED(CONFIG_ARM64_ERRATUM_843419) || + !cpus_have_const_cap(ARM64_WORKAROUND_843419)) return false; /* only ADRP instructions at the end of a 4k page are affected */