From patchwork Wed Nov 7 16:43:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Long X-Patchwork-Id: 150424 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5387283ljp; Wed, 7 Nov 2018 08:44:16 -0800 (PST) X-Received: by 2002:a0c:9aca:: with SMTP id k10mr974974qvf.185.1541609056362; Wed, 07 Nov 2018 08:44:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541609056; cv=none; d=google.com; s=arc-20160816; b=TjVa1scljZAIDfocQN2NmaRJO/7+FKdFThKpoe0dnQJ644xMv/HkG+bsnhx+s3cZDk vgkp1RLtGuQZgGuKt7DiINEmwdPg2hMPr35Zz+wVQuQErcsU1G+yUCWF5C8wP3SAlz9p 5InfUhjnL7IH3ifZLT2JgM/DZYNpiRNn+Povq1QsIvOM0Eaa69Ob42yeswI9iq+geNr2 ni3hBdPqLEiYtlIujc9uesL2G3mA/dPy7QgHTAOJlDJ1Fdoo4BkIAUfD6kMZTy5a8HR9 Kj7yndC0Ha3cpU98prpaDaAr+t6y4f/EqvQeKFOq2WSbODxcUwgBWWB9FA/i9GgZhyuY 0K3Q== 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=RE5wi9MCZt8dci0j9GEqkEEMzvZET3+/Prb5cN1cv3I=; b=CpyhWRbzunfRMWh+bHFnPOj6TjUv6IH71rE8wL5QGVksZvzZ0rIlgEGFCfId9aMDSq HsZRbqtLUwKQ6B13kwPfj5gEw4AiBxYdgF7hCqfJFmF1hhpisiFQvxKm/8cQoPxrpzvE T6aR5g3ZXy/SMz3ZpkEH6MSn+VkkX1d+cSpDIdmYch3KcpxyodjFYshTZChnIz7qPAmP F5V0qsJphwTxvsGR8RUqNUwMvoaZUzD6WO4JVl09hmZCwGvyobRBlH0ygAfu4QuR8/cJ ZV11NVZZKT868i0TK5bHHszv4KC72/dgpoQgeBHxV9adFfCYjKyfNP01EcXCNggWlMl7 SnGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P6tLkQP3; 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 u3sor1198450qvi.55.2018.11.07.08.44.16 for (Google Transport Security); Wed, 07 Nov 2018 08:44:16 -0800 (PST) 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=P6tLkQP3; 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=RE5wi9MCZt8dci0j9GEqkEEMzvZET3+/Prb5cN1cv3I=; b=P6tLkQP3YP58z0z3aZ1ZcG1t7heaDhGlS6SLhejHHJCOgpQvo7vntVfjWDbXxrxjoV aHP+FbpIPMY9dMuEShhvdY5cTw3YMgyFSsNj/q6cqv9L7dHaoG/G3QEYtHZeZSRkuHsB UYfy07HaEUjBVHkSDpWkLKNyeO1I9qTbZOGjo= 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=RE5wi9MCZt8dci0j9GEqkEEMzvZET3+/Prb5cN1cv3I=; b=Dhm6y5ARPEvrDV69BOfaD2B+GM9VfFZmh7EyJoOD49Kv2S1NJA+Huzb1Z1YlhXNPGu paNaUFIA5eyubN0PeGPrXG+pUyzJWrAhSqkhNjdFiwXn7ZNEeM/OKmx/lfoJFkh0lxci nWC9Kxv1pIxTplQTboesD/Wsua+T4g4wQqmdAbEP/71IrBGUmaV31MdF2sRGao7lqude iMOfEBlNaNJKTTYNVIYVd0RAJs+EP1FWXQrZiPc7ZhZuEfNX7HwJBq/Mozni4sis7/aN Yz1hpVJJ84xrWOgcZkrIuW0aDuKHx+S/9ZLKafNVXklta2Fih/w4LZ974/iwb1wH588E RgNg== X-Gm-Message-State: AGRZ1gKmlpN4kLUnoHsIZN/qxg7ajmRqpPz+gwZYTweJvG8WIzH2SgLv vO2hwwddnUmHAm3+X8hNJZwVgb0G X-Google-Smtp-Source: AJdET5cojUTv5wmP97rQIGACvA4XHAkQFryoxg1CvI6KTJc40XqqOdyu9hJTssvrud7lr00w3L2TRw== X-Received: by 2002:a0c:be8d:: with SMTP id n13mr955161qvi.143.1541609055845; Wed, 07 Nov 2018 08:44:15 -0800 (PST) Return-Path: Received: from localhost.localdomain (pool-72-71-243-63.cncdnh.fast00.myfairpoint.net. [72.71.243.63]) by smtp.googlemail.com with ESMTPSA id 96-v6sm681817qtc.56.2018.11.07.08.44.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 08:44:15 -0800 (PST) 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 V2 09/24] ARM: spectre-v2: add firmware based hardening Date: Wed, 7 Nov 2018 11:43:47 -0500 Message-Id: <20181107164402.9380-10-dave.long@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181107164402.9380-1-dave.long@linaro.org> References: <20181107164402.9380-1-dave.long@linaro.org> From: Russell King Commit 10115105cb3aa17b5da1cb726ae8dd5f6854bd93 upstream. Commit 6282e916f774e37845c65d1eae9f8c649004f033 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 Acked-by: Marc Zyngier 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..850c22bca19c 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_hvc_switch_mm) +#endif ENTRY(cpu_v7_iciallu_switch_mm) mov r3, #0 mcr p15, 0, r3, c7, c5, 0 @ ICIALLU