From patchwork Thu Mar 1 12:54:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 130222 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp2766687edc; Thu, 1 Mar 2018 05:01:32 -0800 (PST) X-Google-Smtp-Source: AG47ELsEeuIVqfmWP0aG2GwqrmHtLCrGxTJ6pWCrnoMTI5IU1V+DT/0zG8cSekoqGPeb9GKJ/F9j X-Received: by 10.99.95.142 with SMTP id t136mr1473890pgb.94.1519909292066; Thu, 01 Mar 2018 05:01:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909292; cv=none; d=google.com; s=arc-20160816; b=sXPf59rkKtzfzo6e1h9pMmHHiZ5ZQt2/9JKmHp4yZxEWI0kH8FZbUwgrgiztorfYzT OIB5VhpaVLyh861p6DJNYEKPqWjBeTfWWcZ0bQlYhuE4n1LAHM0obhY18iGRu+tLPyc9 OGoga871qC7ugkxFwf/N3QK3DUXKDJOKdwhOoZRF2S/WH7P4Un7krlLWCtrgPp+gk5SM ZgzR7yjzlsWH3Dz4ruFQRYQTKVZ1SRkNTBfGvj8S4rgw2Ut0Y7A8jSsq7hWwgxgT619S CG9y1UyrUOSenGRqFbF3Qu7j9TBiiR3vQpfinC05V04h7paXXqVRqqVo6jUzvBc0zmqr 1w5Q== 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:cc:to:from:dkim-signature:arc-authentication-results; bh=3nJ4z4z9UJLDq0U9q5iOSITdh7PqyHF254/P1MMmfts=; b=yZbKrlDxRiN00DwyEjy1OJxOPYVTqNvxld2DXnOjGOlgRouR7BjQ63jcPL4FNOs+Hn bGYkqXuATttSPvCPQT/0jIM9NSz4M71Zi5fhahhbDP1GMdELSBzNgtUlwWGYV4H7Hf3g FN4Ri4jOxrgKyQwdOgHEbes+c6tnvWUYc1mg5eX6v5i1xfR7tdTIlECw5HlixEZ4PPW5 M9jNIjuenO11wzes4bc47rQkRz8pOqMOyBbwh3O18DUVp0M8yeJqPNOHvQVHV5DBhhJN 2s5ziMKlAyAEAU3HeTsOzIYX+LAjxyYCUA6pKwgMedtjWAmkLYvuUrwJdnarINAhKOk7 e3Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wg1LOuBR; 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 d21si2998591pfk.328.2018.03.01.05.01.20; Thu, 01 Mar 2018 05:01:32 -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=Wg1LOuBR; 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 S1031027AbeCANBQ (ORCPT + 28 others); Thu, 1 Mar 2018 08:01:16 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:43296 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030370AbeCANBN (ORCPT ); Thu, 1 Mar 2018 08:01:13 -0500 Received: by mail-pg0-f67.google.com with SMTP id e9so2268205pgs.10 for ; Thu, 01 Mar 2018 05:01:13 -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=3nJ4z4z9UJLDq0U9q5iOSITdh7PqyHF254/P1MMmfts=; b=Wg1LOuBRMS668yOimNSYIM1saUZk4iDPb3GMf3tokkdrYk8o4bY5Cv01NVVNAinfvj Jv5EeeRoJTplN1p1Nuipz4/QAgvgcrew3/XGu1ka4ESSvztONt35QyLSLXOe6jGnz8UW YQC/+PGUI0A8YLIAHyGWcyRhQqXFEUj2yyO0Q= 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=3nJ4z4z9UJLDq0U9q5iOSITdh7PqyHF254/P1MMmfts=; b=K+QSOSmlGt9joAW5hlZ9VbzhnMBK/RLcBnCvMEX0E+EHLk2djZh0NuBZK4EALiiiXm f0hC0hx+7nm1PnfSYbVeXF4o2iUWQdwlsSWETCu/8Wz14l0aEZdcdN9yiJUTU9pLDH9D 6DqcN+4GVG79Tk+t0EpxU99mhFxT9Gw7nM4klkwfj1LnFrhmDaCSc8UkDDgHTNNXUyUp CtsvbUhpL1dPOSGfreYS01nhpz2/caGjuWEMv3fMmzG2kvzPWwWNV7SfhP3/OdlbofeQ zByD1ODnLMKSd2JnQlGUtvxKUJR+LgzlqeyMdCR7D8nXzKGKw2sn0fg6T8g/A4vbEwKm B9VA== X-Gm-Message-State: APf1xPBgP4Z3VBOxYOFt4LrjnkOiO0mpPo/qKXIjtrudk9G4+SyXnv9R Ug+ZpbO2re2dm/eis1hcXKsW9Q== X-Received: by 10.99.178.6 with SMTP id x6mr1536804pge.98.1519909272669; Thu, 01 Mar 2018 05:01:12 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.05.01.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 05:01:12 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alex Shi Subject: [PATCH 44/45] arm64: Add ARM_SMCCC_ARCH_WORKAROUND_1 BP hardening support Date: Thu, 1 Mar 2018 20:54:21 +0800 Message-Id: <1519908862-11425-45-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-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 --- arch/arm64/kernel/bpi.S | 20 ++++++++++++ arch/arm64/kernel/cpu_errata.c | 72 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 89 insertions(+), 3 deletions(-) -- 2.7.4 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; }