From patchwork Tue Jul 10 19:47:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishanth Menon X-Patchwork-Id: 141651 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4278877ljj; Tue, 10 Jul 2018 12:47:57 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfh6KEME1Jn7GukJKkfLo7f1ifMPeB6790nq0dXwdRbmvx2Dk0D/vv+nG0QFZq6BtdeTRMh X-Received: by 2002:a17:902:301:: with SMTP id 1-v6mr25716960pld.127.1531252077357; Tue, 10 Jul 2018 12:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531252077; cv=none; d=google.com; s=arc-20160816; b=hLPnhdSvdetLy0OAUlmVbfagny6K94aUrvvdDK2eiOdNvOA17U7P5imLiP3a72Ocd1 QWiDRVwfjcxjrPoH6iYJf/1BR8cm3e/T6gIB5hB4rDF3bCJMIrpUUATFq56WPIoPbIVE /+sqI7SSUf5TppDoQuJhO0aN3vJQYe3gFyMqJ0FXGh6Y77GsOywIzF/dEBTHmSIKxeW5 hqSTPcurYKywTK3TbdmgVALR2tVGyGOTGE7xcCyNE11c+UDZMbSKlkNPVzBoLG1tCeJi eN4d7FgvZ27NFLA7yd6NYtaoWHYeTx0+HRuQmFRvmYy9PZvkCgvbpT0qztrT7BEIqRVx rK+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature:arc-authentication-results; bh=wqmMlqToFroJuvROZb2wh3G7iDl4mpplvnCjdNNGLF0=; b=YoNei6aa2orsLTBwcQ0yGuYOcTMATI1vgg/lRrTPVIllQPIJa4iPzAhGrRx3Shxe18 2VV95TzrkYrS/knlu/QM0clK0q8Zx47ACgf0CrSUnda23IX0KBDkZFeiCZZk2+1LRZ+n fE44PgRKBjvzk02+fZpp/tg8lOyHGGt/Akjjh2uHyWc+A9Ub3M5f6p1sTShNJ4c8pgmQ RSiQI70Z3soCHUY9CVr4/UtHN7Df663ASiKXeSY+WV6iChxfkUAxYw5fctLGECODxAu9 86sGvRcG/LBM7UXC+4zBdgGn2mUtxllCer35itUlfNQYuIBPHwsvb9K2t5h7b/gH2eTP wYHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Fudi9L6I; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5-v6si15992336pgr.436.2018.07.10.12.47.57; Tue, 10 Jul 2018 12:47:57 -0700 (PDT) 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=@ti.com header.s=ti-com-17Q1 header.b=Fudi9L6I; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732934AbeGJTs0 (ORCPT + 18 others); Tue, 10 Jul 2018 15:48:26 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:41628 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732205AbeGJTsZ (ORCPT ); Tue, 10 Jul 2018 15:48:25 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id w6AJlS90116828; Tue, 10 Jul 2018 14:47:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1531252048; bh=wqmMlqToFroJuvROZb2wh3G7iDl4mpplvnCjdNNGLF0=; h=From:To:CC:Subject:Date; b=Fudi9L6ID/WdV+XebigcWPmQW/vdAu5tQ99D6b+ZFoyUpciTc2egfjJQZeLQ46xFh 1ta2WHm5Tvq9/O1abzzvpNq8/GAmjZSq+ZBW2TB4h/0ylGeNMFqOGqYhwZWofeE6Lk m+yAIZj4rqboKdaXMRxKouf/C5wmExh1VwcTxE2U= Received: from DFLE102.ent.ti.com (dfle102.ent.ti.com [10.64.6.23]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w6AJlSfD026673; Tue, 10 Jul 2018 14:47:28 -0500 Received: from DFLE113.ent.ti.com (10.64.6.34) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Tue, 10 Jul 2018 14:47:27 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Tue, 10 Jul 2018 14:47:28 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w6AJlRos030440; Tue, 10 Jul 2018 14:47:27 -0500 From: Nishanth Menon To: Russell King , Tony Lindgren CC: , , , Nishanth Menon Subject: [PATCH V2] ARM: DRA7/OMAP5: Enable ACTLR[0] (Enable invalidates of BTB) for secondary cores Date: Tue, 10 Jul 2018 14:47:25 -0500 Message-ID: <20180710194725.20339-1-nm@ti.com> X-Mailer: git-send-email 2.15.1 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Call secure services to enable ACTLR[0] (Enable invalidates of BTB with ICIALLU) when branch hardening is enabled for kernel. On GP devices OMAP5/DRA7, there is no possibility to update secure side since "secure world" is ROM and there are no override mechanisms possible. On HS devices, appropriate PPA should do the workarounds as well. However, the configuration is only done for secondary core, since it is expected that firmware/bootloader will have enabled the required configuration for the primary boot core (note: bootloaders typically will NOT enable secondary processors, since it has no need to do so). Signed-off-by: Nishanth Menon --- NOTE: For U-boot based platforms, please make sure you are on v2018.07 at least. Linux kernel will complain if the workaround are not activated. Changes since V1: * review comments update for commit message, added incode documentation + renamed function to better indicate this is for secondary core. V1: https://patchwork.kernel.org/patch/10461275/ arch/arm/mach-omap2/omap-smp.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) -- 2.15.1 diff --git a/arch/arm/mach-omap2/omap-smp.c b/arch/arm/mach-omap2/omap-smp.c index 69df3620eca5..1c73694c871a 100644 --- a/arch/arm/mach-omap2/omap-smp.c +++ b/arch/arm/mach-omap2/omap-smp.c @@ -109,6 +109,45 @@ void omap5_erratum_workaround_801819(void) static inline void omap5_erratum_workaround_801819(void) { } #endif +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +/* + * Configure ACR and enable ACTLR[0] (Enable invalidates of BTB with + * ICIALLU) to activate the workaround for secondary Core. + * NOTE: it is assumed that the primary core's configuration is done + * by the boot loader (kernel will detect a misconfiguration and complain + * if this is not done). + * + * In General Purpose(GP) devices, ACR bit settings can only be done + * by ROM code in "secure world" using the smc call and there is no + * option to update the "firmware" on such devices. This also works for + * High security(HS) devices, as a backup option in case the + * "update" is not done in the "security firmware". + */ +static void omap5_secondary_harden_predictor(void) +{ + u32 acr, acr_mask; + + asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr)); + + /* + * ACTLR[0] (Enable invalidates of BTB with ICIALLU) + */ + acr_mask = BIT(0); + + /* Do we already have it done.. if yes, skip expensive smc */ + if ((acr & acr_mask) == acr_mask) + return; + + acr |= acr_mask; + omap_smc1(OMAP5_DRA7_MON_SET_ACR_INDEX, acr); + + pr_debug("%s: ARM ACR setup for CVE_2017_5715 applied on CPU%d\n", + __func__, smp_processor_id()); +} +#else +static inline void omap5_secondary_harden_predictor(void) { } +#endif + static void omap4_secondary_init(unsigned int cpu) { /* @@ -131,6 +170,8 @@ static void omap4_secondary_init(unsigned int cpu) set_cntfreq(); /* Configure ACR to disable streaming WA for 801819 */ omap5_erratum_workaround_801819(); + /* Enable ACR to allow for ICUALLU workaround */ + omap5_secondary_harden_predictor(); } /*