Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756261AbeAIMrb (ORCPT + 1 other); Tue, 9 Jan 2018 07:47:31 -0500 Received: from mail-by2nam03on0055.outbound.protection.outlook.com ([104.47.42.55]:49395 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754010AbeAIMr3 (ORCPT ); Tue, 9 Jan 2018 07:47:29 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jayachandran.Nair@cavium.com; From: Jayachandran C To: Will Deacon Cc: marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, lorenzo.pieralisi@arm.com, ard.biesheuvel@linaro.org, catalin.marinas@arm.com, linux-kernel@vger.kernel.org, labbott@redhat.com, christoffer.dall@linaro.org, Jayachandran C 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 Content-Type: text/plain 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+GIOwJqwH5nFt726fngUFeskN7g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5f5FkKJKvTxFIanlJUDoSnsW889GxuRuhDueQBRiJcMPREt5npLkaWXDy1AkYIyVHwFXNK0ubgpUzKql6XCdq9NMQn/7Q9HM5FC4CYII5ppmQCRXoeoPCfzivicZ8Yas3WNRokEnG5Nvq2ax9WESGzgW+kwsQj1UPuh4Se7tF8wZQWB2mt6Q4yQczVBgM7H+7V+0qoO4W7Q8Q2LicQgzBWqJZjH8GDwui/ROo7BZPUcnInJNv5fYUfeGcHmRLxTXYbppjMqbnIozAT9E4iUJgLiWy00aVQa4OiCTE1B/WkT5ZdvmqX34ms1RZBACYPoVyyjM1xHGlHnrUcoJJSfCgPXzAMhZaFpDA=;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; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR0701MB1070;23:/gGEwfhJVHFWZWtMgRW60ZK0eugssrYF/6hoxbp?= =?us-ascii?Q?3PwHQLqJljBZm295Q5zoiXL5DIogDDK9DD000urXRh58N/5qJjlnd4pxtjzM?= =?us-ascii?Q?Cmm68dJeGw/b0vfS1RDtTnvvAEDDMJtCJLASHXTB8uLozS8uQ+1hj/n1z83/?= =?us-ascii?Q?/SV3YKXcSilr7BktgS39JuNgIEvOfyGjda7BFZyWaje+pq302Z4kAL63CH+y?= =?us-ascii?Q?+xb49AW9E/uLApoZbZqA9z/p52afSjzL7VMLPmUHLOGVav5eJrW0j76gpS6l?= =?us-ascii?Q?5vlOvYsZ9H5770XzRSXQ2dra24OKuFlWdlVL6BvRFtrs37A8ON0+yTYTBHWa?= =?us-ascii?Q?coy//dYyaID+5dBztDP5bw8Z8vpITxrQGXSOwMrRjnSxoal2i0B6dszCeVk7?= =?us-ascii?Q?vpo4+6+1BuZlIhJ9AwZKKVNdQj9IyLTUOuO+WGVDjNJEl54M+8taOlML1aAq?= =?us-ascii?Q?8bHORQBXCWeDfl4dJFhDY0FYzM1mrCBGnUUp/olS8z/NHtz6ZQzK1lnNL7Ls?= =?us-ascii?Q?CaW/MJAomCARJg813MKeI7RoCqxRmXbpPfczvlvo1+RCEWJtC/tKDNzY5DHR?= =?us-ascii?Q?ZrYGwRUcBjgNKppy5eBgWdChRK41zByp3JECicKAhseA8zDMGzGPBSiQTTC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roM/1AMLgYuTms2dzomh0H282lCxlutQqE00uCA=;5:gDRnHuR/idq/c3e1d26b3JsiLlFAMpj2dELVL6W/lBkVjSsRBmX5k/Vm/z6meh1G8skpJMgSksGKgPKQZtMzSXaKYD4BUcc7kasbM9RRkBuP89qCD9MVEEkrEzc5zSNKJgdfKanXqZXT/gIDs+Hg/SL289WLhWebOvTqiZxskNg=;24:wwtcb3aieySavBGXU9bwgu9fvkC2PaDHTWUiZd48sEDfNOeRAmvJ+Ntgi9UyCv+JGG37HaQqI6KBQ9DtrkM0vuj4rNDpsw64Qyd0ATdFrrM=;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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: 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 { } -- 2.7.4