Received: by 10.223.185.116 with SMTP id b49csp3491130wrg; Mon, 26 Feb 2018 00:28:21 -0800 (PST) X-Google-Smtp-Source: AH8x226fWMwe0Cpto12CDIw6C0w/55Glecq7awIRvud2YZx4TVknaU4C51IHf4VMPlS3rg+uqCKF X-Received: by 10.101.90.10 with SMTP id y10mr7812016pgs.34.1519633701641; Mon, 26 Feb 2018 00:28:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633701; cv=none; d=google.com; s=arc-20160816; b=VgMCZojbVLr0ZJqK1VVjd34AcKQU1jB/k2QNoVj8S/uQoxhdqSPCSzD7zfyQeFIf7Y M2/+/ukNvw+43NMsaKYIOVy5IYf5i0z0Fr70/EDaMFlbGKUedb+bn5Z/QKKFmXqRcXAa ssZqc5Ol90nWBOHIvNJF1SeQHFzkQmmWrGzVTnNmVoCWtxtXliNlL8NaRWdWWF7FctFn SAitEudFRCQXERICGIu9i9rpj/slZptsBUx7NO2TIA6EEt3ySl8pj9YnxEBRZ45v0MIe CuTiq5H/iqZpvxJDZQHRTEBm6h8lAit8Asf8IFPoE5tdyiNU7SI4pIsMyPcUBSel+1kl dO8w== 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:to:from:dkim-signature:arc-authentication-results; bh=IG03JAN328WQoLPMHLwAVvntjAGN6WojvlYcD547iug=; b=LxFjqvGW0gO0W5AbX9s+xYsPFWRD86CQou5awEKgGeIZ36xE+Pl6W23sVqlIvM90VX 3YbtyzOKUBDGOV/VB0KAW0wHPmSSPOmDZdwHR9yo+SR99gzZARrktH6Fe/T6aNX5pm1o XIjRbk7GcdbT9dzyVDU9TFdh+JMKGNMg8LwJm5K63V1AvbJ8GlDDiYU7xFwnX3y7HJWM FVtAT43ITgr4GsfrE9bTUYk/x0YIwJyDknFFuqu41nEkr4NkUA2LRzIjfZB/olCcQ9gi N61wgzMtu8snTe3RJQEc2v8yxHxxtSsVlX6UTqeNpscaFQuN2LsqeS0kDgyDdw/1visj BGnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ivfKy5AL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si1568704pgr.410.2018.02.26.00.28.07; Mon, 26 Feb 2018 00:28:21 -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=@linaro.org header.s=google header.b=ivfKy5AL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752793AbeBZI07 (ORCPT + 99 others); Mon, 26 Feb 2018 03:26:59 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36131 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752773AbeBZI0v (ORCPT ); Mon, 26 Feb 2018 03:26:51 -0500 Received: by mail-pf0-f194.google.com with SMTP id 68so6230508pfx.3 for ; Mon, 26 Feb 2018 00:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=IG03JAN328WQoLPMHLwAVvntjAGN6WojvlYcD547iug=; b=ivfKy5ALTV8W9jS9/aq+RYhNJoCWcBm9h5ZHNs+gFuoEXXjaK5sQOXmlZPe/KpcqX3 BGojPU5Zqnyyt6yEnZWwVnLRzA/2VSg9iW1rmRf0SO0QkG7VEllJZGB5EmJgniiU/ZxX BZo5h8HIxfhBikGXQhU7Y0r0VxrqsutZg5ZhI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=IG03JAN328WQoLPMHLwAVvntjAGN6WojvlYcD547iug=; b=iMW92mh488E3fE6qSOlOlT3HcH70Wjc61y5L4y8LcPZYNDz6Sk6cYpAlirlz8Y5sLA F/pMfXjkha4hJfj2TA42x+xHMXaKz78d+l7g1FKw9z0GDS8nuoJiqf6Jtad4tVCQXLNk Dj8UfvNH/mLtnINGw8cjIjKICp51k5RfdrjcghUvlMT2DohSoVc8JtRIerbLGIx2WVfH JE0h5/qv2ekKF87k81ZZGGBSTKAP4OjMWNL2vZ6qxFalJn9dQaXz8ar3DdvA7CEq4ww+ f8jgZuQADtqY6xcoRiQRWTvGqK9J/Oy2Ar/PnNzuPIvHMioYRzCXTSI8VKSe1pECkX0n HDIw== X-Gm-Message-State: APf1xPA3mTWQyRre7FRjvtUjZ4/sBPP77TI500xPaWL6e8Qw21BHu8sR DrgR/Ow3ykaWCC01aLWXIfXa5w== X-Received: by 10.99.0.207 with SMTP id 198mr6260504pga.364.1519633611030; Mon, 26 Feb 2018 00:26:51 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.26.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:26:50 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org (moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 44/52] arm64: Add ARM_SMCCC_ARCH_WORKAROUND_1 BP hardening support Date: Mon, 26 Feb 2018 16:20:18 +0800 Message-Id: <1519633227-29832-45-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit b092201e0020 upstream. Add the detection and runtime code for ARM_SMCCC_ARCH_WORKAROUND_1. It is lovely. Really. Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Will Deacon Signed-off-by: Alex Shi Conflicts: no qcom hyp functions in arch/arm64/kernel/bpi.S arch/arm64/kernel/cpu_errata.c --- arch/arm64/kernel/bpi.S | 20 ++++++++++++ arch/arm64/kernel/cpu_errata.c | 72 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/bpi.S b/arch/arm64/kernel/bpi.S index dec95bd..c72f261 100644 --- a/arch/arm64/kernel/bpi.S +++ b/arch/arm64/kernel/bpi.S @@ -17,6 +17,7 @@ */ #include +#include .macro ventry target .rept 31 @@ -77,3 +78,22 @@ ENTRY(__psci_hyp_bp_inval_start) ldp x0, x1, [sp, #(16 * 8)] add sp, sp, #(8 * 18) ENTRY(__psci_hyp_bp_inval_end) + +.macro smccc_workaround_1 inst + sub sp, sp, #(8 * 4) + stp x2, x3, [sp, #(8 * 0)] + stp x0, x1, [sp, #(8 * 2)] + mov w0, #ARM_SMCCC_ARCH_WORKAROUND_1 + \inst #0 + ldp x2, x3, [sp, #(8 * 0)] + ldp x0, x1, [sp, #(8 * 2)] + add sp, sp, #(8 * 4) +.endm + +ENTRY(__smccc_workaround_1_smc_start) + smccc_workaround_1 smc +ENTRY(__smccc_workaround_1_smc_end) + +ENTRY(__smccc_workaround_1_hvc_start) + smccc_workaround_1 hvc +ENTRY(__smccc_workaround_1_hvc_end) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index f8810bf..9632319 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -54,6 +54,10 @@ DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); #ifdef CONFIG_KVM extern char __psci_hyp_bp_inval_start[], __psci_hyp_bp_inval_end[]; +extern char __smccc_workaround_1_smc_start[]; +extern char __smccc_workaround_1_smc_end[]; +extern char __smccc_workaround_1_hvc_start[]; +extern char __smccc_workaround_1_hvc_end[]; static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start, const char *hyp_vecs_end) @@ -96,8 +100,12 @@ static void __install_bp_hardening_cb(bp_hardening_cb_t fn, spin_unlock(&bp_lock); } #else -#define __psci_hyp_bp_inval_start NULL -#define __psci_hyp_bp_inval_end NULL +#define __psci_hyp_bp_inval_start NULL +#define __psci_hyp_bp_inval_end NULL +#define __smccc_workaround_1_smc_start NULL +#define __smccc_workaround_1_smc_end NULL +#define __smccc_workaround_1_hvc_start NULL +#define __smccc_workaround_1_hvc_end NULL static void __install_bp_hardening_cb(bp_hardening_cb_t fn, const char *hyp_vecs_start, @@ -124,17 +132,75 @@ static void install_bp_hardening_cb(const struct arm64_cpu_capabilities *entry, __install_bp_hardening_cb(fn, hyp_vecs_start, hyp_vecs_end); } +#include +#include #include +static void call_smc_arch_workaround_1(void) +{ + arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); +} + +static void call_hvc_arch_workaround_1(void) +{ + arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); +} + +static bool check_smccc_arch_workaround_1(const struct arm64_cpu_capabilities *entry) +{ + bp_hardening_cb_t cb; + void *smccc_start, *smccc_end; + struct arm_smccc_res res; + + if (!entry->matches(entry, SCOPE_LOCAL_CPU)) + return false; + + if (psci_ops.smccc_version == SMCCC_VERSION_1_0) + return false; + + 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 (res.a0) + return false; + cb = call_hvc_arch_workaround_1; + smccc_start = __smccc_workaround_1_hvc_start; + smccc_end = __smccc_workaround_1_hvc_end; + break; + + case PSCI_CONDUIT_SMC: + arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, + ARM_SMCCC_ARCH_WORKAROUND_1, &res); + if (res.a0) + return false; + cb = call_smc_arch_workaround_1; + smccc_start = __smccc_workaround_1_smc_start; + smccc_end = __smccc_workaround_1_smc_end; + break; + + default: + return false; + } + + install_bp_hardening_cb(entry, cb, smccc_start, smccc_end); + + return true; +} + static int enable_psci_bp_hardening(void *data) { const struct arm64_cpu_capabilities *entry = data; - if (psci_ops.get_version) + if (psci_ops.get_version) { + if (check_smccc_arch_workaround_1(entry)) + return 0; + install_bp_hardening_cb(entry, (bp_hardening_cb_t)psci_ops.get_version, __psci_hyp_bp_inval_start, __psci_hyp_bp_inval_end); + } return 0; } -- 2.7.4