Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755620AbeAHGcK (ORCPT + 1 other); Mon, 8 Jan 2018 01:32:10 -0500 Received: from mail-by2nam01on0079.outbound.protection.outlook.com ([104.47.34.79]:40608 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755472AbeAHGcI (ORCPT ); Mon, 8 Jan 2018 01:32:08 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jayachandran.Nair@cavium.com; Date: Sun, 7 Jan 2018 22:31:54 -0800 From: Jayachandran C To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, lorenzo.pieralisi@arm.com, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, catalin.marinas@arm.com, linux-kernel@vger.kernel.org, labbott@redhat.com, christoffer.dall@linaro.org Subject: Re: [v2, 11/11] arm64: Implement branch predictor hardening for affected Cortex-A CPUs Message-ID: <20180108063115.GA163286@jc-sabre> References: <1515157961-20963-12-git-send-email-will.deacon@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1515157961-20963-12-git-send-email-will.deacon@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: BN6PR14CA0014.namprd14.prod.outlook.com (2603:10b6:404:79::24) To DM2PR0701MB1068.namprd07.prod.outlook.com (2a01:111:e400:2472::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1e605b4e-f5fc-44d6-2850-08d55661894b X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:DM2PR0701MB1068; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0701MB1068;3:9b3QdMKQCloFKe0JXrg/fYrwbEb/HaV5ZTn2YkD2X3OD2hdb23uf5cImEeXk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h9ppdz3/K3skcsCzC+ZgfApXY6t4sqc9xFauxy2tPeyIBzZ6GkAYuqsU7ej2yuMFr2kJrAvzz5Un2kuTD51gRu3GrvuhM8bWBVWZ4g3qMRn1RgfFp4s+u2ulnLYMbZ8wPj45TswrnVmA6N/biNC+vXz9n8uv2OK8rNfENxieU72MjYOiETeXoX7i2zzE+EqhN624VIylPk+ahWraZ4J2e2uNTWu9CXc8r6J567jZ0ua6ovl4zDxNG2c0M8r5vMsK2vGSElzRfGgqWrB4cs1uAjYwH92WTsZCIKSuqENRZvywmyohQ+usZeP96NTvT+QrjP7nYyg+FLtxjbQwG3AqmOBSn2gXGX4DHB160FBofXuOdBxJHAZVbsmB1roht5hqsJ5lBsuN7qY=;4:caDTiKsX3O6O0qcjxQcJwY+ek0AeJNuIoGQG1+XOVnOkYZYnRZaudCJnjGbqAwflYek05mFXpvgbXqhn21OzTIkSqvah4I7NXmfY7b8ctccvAHVtCIdZfmcBS7zkhwPAJInKeaLUssFOw+tZA664O6cSjzN7QVWCB1ksBnWpmVr0WDO4L3F0D0WGKpHCurDLIlE2dbtPqjugO8Zw8UNtyNFqe7GiPZzawrP+xmw6R3Q8zPHSdBCa7rpBbboV+o0Q3vFYTsh3/G2hqO65lxhDf4rNLXoBL1D+0OOccnKFrbOOPm63qyeHtcvxB3/Zbm3f X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(3231023)(944501075)(3002001)(10201501046)(93006095)(6041268)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM2PR0701MB1068;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:DM2PR0701MB1068; X-Forefront-PRVS: 054642504A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(39380400002)(366004)(396003)(376002)(346002)(39850400004)(24454002)(189003)(199004)(59450400001)(87496004)(52116002)(76176011)(386003)(6496006)(25786009)(33896004)(6116002)(478600001)(3846002)(23726003)(1076002)(72206003)(4326008)(8936002)(2906002)(97736004)(83506002)(316002)(58126008)(16586007)(47776003)(50466002)(575784001)(16526018)(105586002)(7736002)(305945005)(53936002)(106356001)(33656002)(6916009)(42882006)(9686003)(81166006)(8676002)(81156014)(33716001)(2950100002)(68736007)(6666003)(6246003)(66066001)(5660300001)(55016002)(229853002)(18370500001)(107986001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR0701MB1068;H:jc-sabre;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR0701MB1068;23:twjQp4BOV6wCyph2qRSNEjFH4mc7KQPQqaKvSW8?= =?us-ascii?Q?bzR4OScytncXZ0pOYDS5hiNU8UHm3PUaMsKwsi9jvjPsteDz09yxjDNoH95e?= =?us-ascii?Q?jqL6epzEjsyqRqsbgLaR4xN1jI169J+ze584pJr78iQnntky7PvB5XvNxvXR?= =?us-ascii?Q?I3D/x4beptK4qjqSFnsoyyIvKxCLldX83h9y22Cq9pWUknq3j6DYaLJwyoI4?= =?us-ascii?Q?3tpSVNiuOYgCyyhJLeAIl6vjm4YXo3JbNbW80B/x+yDVCy/oarNraoplGGuY?= =?us-ascii?Q?2xYS8fQ4rT4T2MKHK42OIdtKp9kfDfIfzv1SoPJeq90k92+tZdy9VxtC0gKM?= =?us-ascii?Q?Fh2Jx1on5SMvW7KW5Q1NaS3OkzhMsstQIKSW6/Vm29UbA6PcszgiXkq/JU4L?= =?us-ascii?Q?spZJXUuDa/nkdO4tsh9ajowfUjfDwVqE1n3g4NWIsYmjk4QbY1J17O0Y4bf6?= =?us-ascii?Q?+q9XjGUW/U2kBtd+rHlU9Y6dBtTHRmj/PmrJJozwanwsLEjuJ4LdAxRIJb7/?= =?us-ascii?Q?+UGR5zWMg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zYHiFhKgHOXCG9e5kP/4TQofAB73DmhWHr4/QYsektWt+J44tvZVFMY5Uo07QvIc+L/xLbEn3OZVyCXgkO5P4lPbO7HPwIJnRhzgpNy3i7hnh9k2ymDxr9SHrL1+DLhla0A1/bBnnSXPwiQ9zsJkvVM3qOlWmA/zl3zgITwOQzC5YiFoRGAR9zvMt9D7fjvPBPFyb5jKOM3uVY4ErmByQfUlWXk0QkUWaV9+FuhpQSrgfZUml8S59L7mQiuZ75R4Qja5aKdXRUmn3eDGeH7th99brE7CbwweoGsi0UmsqngEDUrNmSwJYr+ymAyLrk4meTG2Dr/VR8fzU=;5:qLQFrPys53YpW1fQG5db86w+ADLhRmtOJo6eaaE0cwgfDijVfN14SLa6s5p0mxXdEHS4qTBXRsjtz2znPGRypvITRyf+bTTTPxWIYMZP68oU0+tvZCbhI3qutAm28xHDDX+BiKN2KfMmB3xGz6StHC4Bf1w1KQpK0JhDDi76Sdw=;24:kKwpbdIU9wJWj3/0ymvGQDtUimA8FysEAok/M3Arf4qjI2BEoo0c7FpzFUMVxGr3R3qjeAJSu/Y6e4cr9d/LUiqqelQXNpuWlkEadcmj+Hk=;7:+yFV9NNub+4ID9EK6mebeEj4rBNo53u6CD911kz+8iMRAmE3cUrFbqcst5IORWIeKuH+8IcvalJ/jAVAjg3O+cZAehQxkkKHPSmiM/shi3yGJiw16IFtP2iUrvKtChGGnGuTjLdVth3Lb8ASGshvpw02NYKUKEd1E65HjQtLgPlybOlR5rEO5/hf5mpFXtDcH3CnqMhpInG6u4WpUQaQ+KbqQvJahQVK4z6c+OCTDQEyS8H9s9G/hHvz1O4VP7Vy SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2018 06:32:04.5826 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1e605b4e-f5fc-44d6-2850-08d55661894b X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0701MB1068 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Fri, Jan 05, 2018 at 01:12:41PM +0000, Will Deacon wrote: > Cortex-A57, A72, A73 and A75 are susceptible to branch predictor aliasing > and can theoretically be attacked by malicious code. > > This patch implements a PSCI-based mitigation for these CPUs when available. > The call into firmware will invalidate the branch predictor state, preventing > any malicious entries from affecting other victim contexts. > > Signed-off-by: Marc Zyngier > Signed-off-by: Will Deacon > --- > arch/arm64/kernel/bpi.S | 24 ++++++++++++++++++++++++ > arch/arm64/kernel/cpu_errata.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 66 insertions(+) > > diff --git a/arch/arm64/kernel/bpi.S b/arch/arm64/kernel/bpi.S > index 06a931eb2673..2e9146534174 100644 > --- a/arch/arm64/kernel/bpi.S > +++ b/arch/arm64/kernel/bpi.S > @@ -53,3 +53,27 @@ ENTRY(__bp_harden_hyp_vecs_start) > vectors __kvm_hyp_vector > .endr > ENTRY(__bp_harden_hyp_vecs_end) > +ENTRY(__psci_hyp_bp_inval_start) > + sub sp, sp, #(8 * 18) > + stp x16, x17, [sp, #(16 * 0)] > + stp x14, x15, [sp, #(16 * 1)] > + stp x12, x13, [sp, #(16 * 2)] > + stp x10, x11, [sp, #(16 * 3)] > + stp x8, x9, [sp, #(16 * 4)] > + stp x6, x7, [sp, #(16 * 5)] > + stp x4, x5, [sp, #(16 * 6)] > + stp x2, x3, [sp, #(16 * 7)] > + stp x0, x1, [sp, #(18 * 8)] > + mov x0, #0x84000000 > + smc #0 > + ldp x16, x17, [sp, #(16 * 0)] > + ldp x14, x15, [sp, #(16 * 1)] > + ldp x12, x13, [sp, #(16 * 2)] > + ldp x10, x11, [sp, #(16 * 3)] > + ldp x8, x9, [sp, #(16 * 4)] > + ldp x6, x7, [sp, #(16 * 5)] > + ldp x4, x5, [sp, #(16 * 6)] > + ldp x2, x3, [sp, #(16 * 7)] > + ldp x0, x1, [sp, #(18 * 8)] > + add sp, sp, #(8 * 18) > +ENTRY(__psci_hyp_bp_inval_end) > diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c > index 16ea5c6f314e..cb0fb3796bb8 100644 > --- a/arch/arm64/kernel/cpu_errata.c > +++ b/arch/arm64/kernel/cpu_errata.c > @@ -53,6 +53,8 @@ static int cpu_enable_trap_ctr_access(void *__unused) > 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[]; > + > static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start, > const char *hyp_vecs_end) > { > @@ -94,6 +96,9 @@ 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 > + > static void __install_bp_hardening_cb(bp_hardening_cb_t fn, > const char *hyp_vecs_start, > const char *hyp_vecs_end) > @@ -118,6 +123,21 @@ static void install_bp_hardening_cb(const struct arm64_cpu_capabilities *entry, > > __install_bp_hardening_cb(fn, hyp_vecs_start, hyp_vecs_end); > } > + > +#include > + > +static int enable_psci_bp_hardening(void *data) > +{ > + const struct arm64_cpu_capabilities *entry = data; > + > + if (psci_ops.get_version) > + 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; > +} > #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ > > #define MIDR_RANGE(model, min, max) \ > @@ -261,6 +281,28 @@ const struct arm64_cpu_capabilities arm64_errata[] = { > MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), > }, > #endif > +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR > + { > + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, > + MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), > + .enable = enable_psci_bp_hardening, > + }, > + { > + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, > + MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), > + .enable = enable_psci_bp_hardening, > + }, > + { > + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, > + MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), > + .enable = enable_psci_bp_hardening, > + }, > + { > + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, > + MIDR_ALL_VERSIONS(MIDR_CORTEX_A75), > + .enable = enable_psci_bp_hardening, > + }, > +#endif > { > } > }; On ThunderX2, we would like to do something similar, but it is important to find out if the current firmware has support for BTB invalidate in the PSCI version call. Otherwise, we will end up doing version calls that do nothing but return version (and waste cycles). I will follow up with ThunderX2 patches, but it would be good to have a standard way of figuring out if the firmware has BTB invalidate support. JC.