From patchwork Tue Jan 9 12:47:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jayachandran C X-Patchwork-Id: 10151977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 974AD601A1 for ; Tue, 9 Jan 2018 12:48:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9051727C0B for ; Tue, 9 Jan 2018 12:48:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8520528434; Tue, 9 Jan 2018 12:48:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0AA3627C0B for ; Tue, 9 Jan 2018 12:48:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SZhjIwCTIc2Oxw/hwcCNJqMnuhf2ADiIALt5E8qbi7I=; b=Rff9ufGhiVpN2J o1qebwBHALqLuLgNDG9AI2x+BgD4XJZZu9gdOYRlgFNxsS0rSccD30ktAjPTMLm+g9x1S2tD6jTwe m967R/99uWF7UTadM28Tpdy895K5h40o2lQ3M2Qvhk0t0U/nqzlRs2/sfNEtdzuzrctGNhH+tAfTV 4OkKaUQlEpEM+1J+K/pePCVRZSHYAHOtkCoIEC/I1HX7kgxjoMNmbqsGQRpn0llzZn3A8/5yzVEhK B48OG/zoDCxW2i/oBVZVMSI7MJLD9WoKVFB+guKuZ8w1q/q2bArZjgFUxHgJcICazbGKnvUjrRlXl //DE7e9bGZ7yZZGy7X3g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eYtJz-0005X9-K7; Tue, 09 Jan 2018 12:48:03 +0000 Received: from mail-bl2nam02on0614.outbound.protection.outlook.com ([2a01:111:f400:fe46::614] helo=NAM02-BL2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eYtJc-0005B3-OI for linux-arm-kernel@lists.infradead.org; Tue, 09 Jan 2018 12:48:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=W6RC1cAE0lgUPfvmIYmuRUCCEDq/CCUPEtAA2gWqOEI=; b=WNw2NNE4FTsIenlUUhvFFCbt0fMjiBqzofwBlz7L0E/WZqa8k2Dpto0oxw1SP907Bew2rgj7nW0jqBxF9iwBsq6DZtORIiNhV3RjABJSzxbtFAPBAxBKs6eDZiQ2FHtAc4gMEiFvtF61kULzbBUfAh1ib7dnNFj510ZK5pfnVSc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jayachandran.Nair@cavium.com; Received: from jc-sabre.caveonetworks.com (50.233.148.156) by SN2PR0701MB1070.namprd07.prod.outlook.com (2a01:111:e400:341f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.366.8; Tue, 9 Jan 2018 12:47:25 +0000 From: Jayachandran C To: Will Deacon Subject: [PATCH v2] arm64: Branch predictor hardening for Cavium ThunderX2 Date: Tue, 9 Jan 2018 04:47:02 -0800 Message-Id: <1515502022-7376-1-git-send-email-jnair@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20180108164651.GQ25869@arm.com> References: <20180108164651.GQ25869@arm.com> MIME-Version: 1.0 X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: YQXPR0101CA0056.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c00:14::33) To SN2PR0701MB1070.namprd07.prod.outlook.com (2a01:111:e400:341f::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e82bca74-ad6a-4f0b-638f-08d5575f23a1 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:SN2PR0701MB1070; X-Microsoft-Exchange-Diagnostics: 1; SN2PR0701MB1070; 3:pDgdgUAcrJKgsPt1w/xGWPjQMxZmPoslg5CP6/1vL04de16McvEFgOcBbQ+GIOwJqwH5nFt726fngUFeskN7g9vghBCeLelWrpXiUGFv2lMrZBBPHjia6cybDj9m/rtCOdWKCo4iIj4aqLG1xfA2kbRr3CzaLGCqgUbsnArGCYKomhNHEtibiYkZ5fy5+tF8dAHXJqMRbxvSPiNt4duywFSkb42pLPFCJkCF/BupfsBPq2LajwDHQjHCixiR7fH8; 25:vNPux/iu2WkQ05zkI/UF8JK5JWf2RT7jaE2NEf2rhbEdcM8ce3G5kgKcCnznyb3CC/8ynCxPn7demnRc0Cas2O2EMutIq0K3jdZuCNl0a+vJPtV0jZ5AbGpI0zlM8jQDTZRwfKGu8QP3QKJMxymi5xqD4YzeF6KT2rwT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coJJSfCgPXzAMhZaFpDA=; 4:3RjMKOHwZ+71O+RRe2z2c2lYS1V7ZWpetOqEFfgePu/JTy2rJlNkTrhAnjFpYqRqjNu3QNAP7Vj6xSAUTfTlfXvZuMDFnTUwkXp49t7/CaYcgwab6HHNcGWqKpRasbm3KnUCFnnDNmI6faA7bqnqfz08uuaJYKsHkTQJ9bym7C32JDRvxHECgQr5aj/K4Qiyy/O5VNNJ4WKjYoz2mivWqk2t/VszMK10CFquyqVgScngnoatpEhXSacQK3MHGJ6AJoDQaFfCdf/gZyXp80lvXQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(10201501046)(3231023)(944501075)(3002001)(93006095)(6041268)(20161123564045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011); SRVR:SN2PR0701MB1070; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:SN2PR0701MB1070; X-Forefront-PRVS: 0547116B72 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(39380400002)(366004)(396003)(376002)(199004)(189003)(478600001)(107886003)(105586002)(16526018)(52116002)(48376002)(316002)(76176011)(16586007)(6486002)(2906002)(72206003)(50226002)(6506007)(8676002)(4326008)(8936002)(81156014)(68736007)(81166006)(106356001)(51416003)(25786009)(386003)(50466002)(6512007)(3846002)(6116002)(5660300001)(53936002)(53416004)(42882006)(6916009)(2950100002)(36756003)(6666003)(66066001)(305945005)(69596002)(97736004)(7736002)(575784001)(47776003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR0701MB1070; H:jc-sabre.caveonetworks.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii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rkM0vuj4rNDpsw64Qyd0ATdFrrM=; 7:8ZtZ4qP3IbNxi9u5stx111wBaMLz9f5m94NhYY3g2E3yF+1RyK0JZC3hI6AW8IJRJm0SS4jgkhQHi0aKlEChP7yfNR+USw2n6RlFTVsq9ns5AlhU1E8tGbNQCQcTTbsOJI/FfyqksvpZqUVLbxzT0g7hGfEjyQMlp1igLTjiDSpJ6rBZ3pLO3Vy71bbrAVltmumvMd7MoU9zz7vDSAN7H8hNsvSYjtzdDi3JqCne4u/QzPsyFzhZS02sPcwQ3fXU SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2018 12:47:25.7363 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e82bca74-ad6a-4f0b-638f-08d5575f23a1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR0701MB1070 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180109_044741_351957_A6F91E53 X-CRM114-Status: GOOD ( 12.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.pieralisi@arm.com, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, catalin.marinas@arm.com, linux-kernel@vger.kernel.org, christoffer.dall@linaro.org, labbott@redhat.com, linux-arm-kernel@lists.infradead.org, Jayachandran C Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Use PSCI based mitigation for speculative execution attacks targeting the branch predictor. The approach is similar to the one used for Cortex-A CPUs, but in case of ThunderX2 we add another SMC call to test if the firmware supports the capability. If the secure firmware has been updated with the mitigation code to invalidate the branch target buffer, we use the PSCI version call to invoke it. Signed-off-by: Jayachandran C --- v2: - rebased on top of the latest kpti branch - use pr_info_once/pr_warn_once to avoid excessive prints - using .desc generated too many prints, dropped plan for using it - fixed up a return arch/arm64/kernel/cpu_errata.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 70e5f18..c626914 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -128,6 +128,7 @@ 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 static int enable_psci_bp_hardening(void *data) @@ -165,6 +166,33 @@ static int qcom_enable_link_stack_sanitization(void *data) return 0; } + +#define CAVIUM_TX2_SIP_SMC_CALL 0xC200FF00 +#define CAVIUM_TX2_BTB_HARDEN_CAP 0xB0A0 + +static int enable_tx2_psci_bp_hardening(void *data) +{ + const struct arm64_cpu_capabilities *entry = data; + struct arm_smccc_res res; + + if (!entry->matches(entry, SCOPE_LOCAL_CPU)) + return 0; + + arm_smccc_smc(CAVIUM_TX2_SIP_SMC_CALL, CAVIUM_TX2_BTB_HARDEN_CAP, 0, 0, 0, 0, 0, 0, &res); + if (res.a0 != 0) { + pr_warn_once("Error: CONFIG_HARDEN_BRANCH_PREDICTOR enabled, but firmware does not support it\n"); + return 0; + } + if (res.a1 == 1 && psci_ops.get_version) { + pr_info_once("Branch predictor hardening: Enabled, using PSCI version call.\n"); + 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) \ @@ -338,6 +366,16 @@ const struct arm64_cpu_capabilities arm64_errata[] = { .capability = ARM64_HARDEN_BP_POST_GUEST_EXIT, MIDR_ALL_VERSIONS(MIDR_QCOM_FALKOR_V1), }, + { + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, + MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), + .enable = enable_tx2_psci_bp_hardening, + }, + { + .capability = ARM64_HARDEN_BRANCH_PREDICTOR, + MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), + .enable = enable_tx2_psci_bp_hardening, + }, #endif { }