From patchwork Wed Oct 31 13:56:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Long X-Patchwork-Id: 149803 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6826486ljp; Wed, 31 Oct 2018 06:57:28 -0700 (PDT) X-Received: by 2002:ab0:b82:: with SMTP id c2mr1409216uak.121.1540994248784; Wed, 31 Oct 2018 06:57:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540994248; cv=none; d=google.com; s=arc-20160816; b=a9ZwtYJOMAO2fGEP/DivQT5RhPzViWuUiaALlhJHiplHp823GN8zVnVkDQjLp3DBbP XIe+bBPdN2aDiSjihVEaI6NJID5j9MnHVSr4z62sVwKGbHvUSQdbdFv3/wI1yWaFIfQD nIGqquqMQMMxF7WErDe/1E7CcNe5/A97lC5y6mk5y6WqxGCbYbwf1eQkpfWgAuOy3bkr AHcpQwvH2Y/dcYTzLBlcsIbkL5mvsV3HXocxEDwNPK1DCKP8Ax69zcTZTTOn81cH0kTo 0LMjkVYVaFqTNQ5iwSO7RS36hptc3qpdvSoGuRjLdEIZLUw6vd8FbGBsiOxd6AXDXHVH i08g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ia7RGwrKETh+3qMENwxN4H/3Xvo7Bu4DuMH9VrVioPs=; b=f+hdERQ22mcmUmPR8lc9/q8+ElrGDkd8Nwio8RhAmHIh4dYp3v7hBUzuSB2msFLPOE hUut9qn6T7iHJwMCdGA3GyAy0nM8wQSadpLWg6HZKiqY9Kj4wu5DrkT7bIdAJ599I/VJ 8HrbbZQPf/aBSCFz157Cy6drx3PBzbWPPAu2S2XcEVY3DGFLAEEhD8VQz8kK6jNLea3e +E3vIHjciCLZZG8UaOjGfZ0frDmQVe6/01sWWWNl1t+a36n2Y502v2Ppp1dWOTOclVWf NjkEVfKf8jtRpepMOPC/THe2bBbH93VjkmWUt+bF/o3YjQVwQohegfavT66CDjKYGXa0 6ISQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qy+hmwrW; spf=pass (google.com: domain of dave.long@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=dave.long@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h6sor5766426uae.3.2018.10.31.06.57.28 for (Google Transport Security); Wed, 31 Oct 2018 06:57:28 -0700 (PDT) Received-SPF: pass (google.com: domain of dave.long@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qy+hmwrW; spf=pass (google.com: domain of dave.long@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=dave.long@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=Ia7RGwrKETh+3qMENwxN4H/3Xvo7Bu4DuMH9VrVioPs=; b=Qy+hmwrW7m3TTtOwjCWBo761c2FX0vwAhavbzkpvW9REpVdSsnEM5ywL1qeRTNN7b2 tZ7IVKvZz3zml8Ud300Ke3wAw8RQ/36nB5sfTP2fU/nl1TD6ODC8JmnMklgWWgtk+m/Q TQ9JHvq4Zbr5wxG016lHTkBLm//MWfbvSpHYE= 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=Ia7RGwrKETh+3qMENwxN4H/3Xvo7Bu4DuMH9VrVioPs=; b=mrYRx73nFof4wBw+8CZORs5sirzYKWegHG1sRJWQkl6iVLxTC1IuSMm+AlS1k5atpj IdyKXra5xbsBanyXwODQNCzKWqx25KdPVTs6jMy3cW4Kqskv2qIdfnkQlKxU+xK2scyK 0XaM10I3GYihCi4BxPKF+/w4Ojaph9upi/IBbgzA2u/fVrZ1lU092C0Qmr2gM2KfgTdo aFj5P+jakPxK/fsRsId2AIGGuL3DWT5JyYTRZ1JK4Zr4sj293Ip5JlB6P3TevyvlLBJu UGvL+QGGUTDpJAsEzhSgbSkhVLfvYuDqTf6uymUtseIBomXpoQDLj/K/CxeWz47Iv61F wHsA== X-Gm-Message-State: AGRZ1gLfZIJYF7PWm0OaFAGBccI/px8SaFfwamzrnvLV/kvLYNdoBLfs FSRD8aRp3k3jzFCXRURelQlT+Ny6 X-Google-Smtp-Source: AJdET5fFax7/vbitnTZnWPSa1ipwX7Bn/SX4HQzBV1aXl1mjgoPiha+55eKtCoUIKrRq/zBANfVXGw== X-Received: by 2002:ab0:5a2b:: with SMTP id l40mr1341522uad.15.1540994248184; Wed, 31 Oct 2018 06:57:28 -0700 (PDT) Return-Path: Received: from dave-Dell-System-XPS-L502X.hsd1.nh.comcast.net ([2603:3005:3403:7100:2c71:8680:34e1:a6aa]) by smtp.googlemail.com with ESMTPSA id s85-v6sm2275624vse.29.2018.10.31.06.57.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 06:57:27 -0700 (PDT) From: David Long To: stable@vger.kernel.org, Russell King - ARM Linux , Florian Fainelli , Tony Lindgren , Marc Zyngier , Mark Rutland Cc: Greg KH , Mark Brown Subject: [PATCH 4.9 09/24] ARM: spectre-v2: add firmware based hardening Date: Wed, 31 Oct 2018 09:56:58 -0400 Message-Id: <20181031135713.2873-10-dave.long@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031135713.2873-1-dave.long@linaro.org> References: <20181031135713.2873-1-dave.long@linaro.org> From: Russell King Commit 10115105cb3aa17b5da1cb726ae8dd5f6854bd93 upstream. Add firmware based hardening for cores that require more complex handling in firmware. Signed-off-by: Russell King Boot-tested-by: Tony Lindgren Reviewed-by: Tony Lindgren Reviewed-by: Marc Zyngier Signed-off-by: David A. Long --- arch/arm/mm/proc-v7-bugs.c | 60 ++++++++++++++++++++++++++++++++++++++ arch/arm/mm/proc-v7.S | 21 +++++++++++++ 2 files changed, 81 insertions(+) -- 2.17.1 diff --git a/arch/arm/mm/proc-v7-bugs.c b/arch/arm/mm/proc-v7-bugs.c index 85a2e3d6263c..da25a38e1897 100644 --- a/arch/arm/mm/proc-v7-bugs.c +++ b/arch/arm/mm/proc-v7-bugs.c @@ -1,14 +1,20 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include +#include #include #include #include +#include #include #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR DEFINE_PER_CPU(harden_branch_predictor_fn_t, harden_branch_predictor_fn); +extern void cpu_v7_smc_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm); +extern void cpu_v7_hvc_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm); + static void harden_branch_predictor_bpiall(void) { write_sysreg(0, BPIALL); @@ -19,6 +25,16 @@ static void harden_branch_predictor_iciallu(void) write_sysreg(0, ICIALLU); } +static void __maybe_unused call_smc_arch_workaround_1(void) +{ + arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); +} + +static void __maybe_unused call_hvc_arch_workaround_1(void) +{ + arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); +} + static void cpu_v7_spectre_init(void) { const char *spectre_v2_method = NULL; @@ -45,7 +61,51 @@ static void cpu_v7_spectre_init(void) harden_branch_predictor_iciallu; spectre_v2_method = "ICIALLU"; break; + +#ifdef CONFIG_ARM_PSCI + default: + /* Other ARM CPUs require no workaround */ + if (read_cpuid_implementor() == ARM_CPU_IMP_ARM) + break; + /* fallthrough */ + /* Cortex A57/A72 require firmware workaround */ + case ARM_CPU_PART_CORTEX_A57: + case ARM_CPU_PART_CORTEX_A72: { + struct arm_smccc_res res; + + if (psci_ops.smccc_version == SMCCC_VERSION_1_0) + break; + + switch (psci_ops.conduit) { + case PSCI_CONDUIT_HVC: + arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, + ARM_SMCCC_ARCH_WORKAROUND_1, &res); + if ((int)res.a0 != 0) + break; + per_cpu(harden_branch_predictor_fn, cpu) = + call_hvc_arch_workaround_1; + processor.switch_mm = cpu_v7_hvc_switch_mm; + spectre_v2_method = "hypervisor"; + break; + + case PSCI_CONDUIT_SMC: + arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, + ARM_SMCCC_ARCH_WORKAROUND_1, &res); + if ((int)res.a0 != 0) + break; + per_cpu(harden_branch_predictor_fn, cpu) = + call_smc_arch_workaround_1; + processor.switch_mm = cpu_v7_smc_switch_mm; + spectre_v2_method = "firmware"; + break; + + default: + break; + } } +#endif + } + if (spectre_v2_method) pr_info("CPU%u: Spectre v2: using %s workaround\n", smp_processor_id(), spectre_v2_method); diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S index 2d2e5ae85816..8fde9edb4a48 100644 --- a/arch/arm/mm/proc-v7.S +++ b/arch/arm/mm/proc-v7.S @@ -9,6 +9,7 @@ * * This is the "shell" of the ARMv7 processor support. */ +#include #include #include #include @@ -88,6 +89,26 @@ ENTRY(cpu_v7_dcache_clean_area) ret lr ENDPROC(cpu_v7_dcache_clean_area) +#ifdef CONFIG_ARM_PSCI + .arch_extension sec +ENTRY(cpu_v7_smc_switch_mm) + stmfd sp!, {r0 - r3} + movw r0, #:lower16:ARM_SMCCC_ARCH_WORKAROUND_1 + movt r0, #:upper16:ARM_SMCCC_ARCH_WORKAROUND_1 + smc #0 + ldmfd sp!, {r0 - r3} + b cpu_v7_switch_mm +ENDPROC(cpu_v7_smc_switch_mm) + .arch_extension virt +ENTRY(cpu_v7_hvc_switch_mm) + stmfd sp!, {r0 - r3} + movw r0, #:lower16:ARM_SMCCC_ARCH_WORKAROUND_1 + movt r0, #:upper16:ARM_SMCCC_ARCH_WORKAROUND_1 + hvc #0 + ldmfd sp!, {r0 - r3} + b cpu_v7_switch_mm +ENDPROC(cpu_v7_smc_switch_mm) +#endif ENTRY(cpu_v7_iciallu_switch_mm) mov r3, #0 mcr p15, 0, r3, c7, c5, 0 @ ICIALLU