From patchwork Mon Apr 15 21:21:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 162279 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3418636jan; Mon, 15 Apr 2019 14:22:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUxL8T2/kenXyJnKYw6aOtU9qa+m2iz6X6Di3Zsuizpwg7buiN2ULGBrihewHKbmQfoCcW X-Received: by 2002:a65:608a:: with SMTP id t10mr60614832pgu.125.1555363339274; Mon, 15 Apr 2019 14:22:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555363339; cv=none; d=google.com; s=arc-20160816; b=WfPuPkLDMVZQRdW82mDeZwjwqsk/Tb/NUz++85ohs+TIV0RA25PhWDyqgNgf0Gpfcd Er28QdnPQ8zXeBUATc+9Hvc4eIXTUxxLhQBGyXh0XgaoRCgnO5vdyQjR0zGLbDo+0SRD Lycko9DN8jFQybuZh7xzHV3o9cTGGKICZdX1eADO40SHivPH6jScjEU++2zqDuwJmkvg xg1zlc+ZKL6wiUI5IAgpkaS79EFTHrA15zXvo5no70tLjfO47Zc2eaDJt787aJms1XB+ MEY6gj6FATkanMRhV/3WrX9t1p4iDxDv+pC/anvmg0htUN04PbDGMLCKiN+q7oMa8O6M hVNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=IdW32AdxoA9VbkjcaG360AzZjbEGPKAgmSzvLha/H38=; b=lpu2vhOJhoIw4+zdKfg1rgpCNCZGZiA1KeACDkRFif1ucu5aO+20TYHXJu86RpJ7AD oNQtf4lWcCfjzpoUCi91tie39KVfgY30no5t/DnwVMoGVYZLVG4AnNke6wlwrpfzAY8+ 0sJaAhssVD/GSg3cpJ5neGSKuJBa+2J79aoikFgR4/aaJ3cGlcALqaBpbSA/+TUGLtrV 6sqAuMVoqnteTZigrhFvHtsP0ND1p6NjhG/iACTsDK87+G7xsXz/gfQE9fYJ2hKag7Ia 3YLAtZr84jUSwz+pchPwF1pFYprjke4DUhut7tMdASHxeY7JfpiFpKxP1q3scOxpukHC Sb6g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si26534362plb.168.2019.04.15.14.22.19; Mon, 15 Apr 2019 14:22:19 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728174AbfDOVWN (ORCPT + 30 others); Mon, 15 Apr 2019 17:22:13 -0400 Received: from foss.arm.com ([217.140.101.70]:42926 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727760AbfDOVVm (ORCPT ); Mon, 15 Apr 2019 17:21:42 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3E41FA78; Mon, 15 Apr 2019 14:21:42 -0700 (PDT) Received: from mammon-tx2.austin.arm.com (mammon-tx2.austin.arm.com [10.118.29.246]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 96AD13F68F; Mon, 15 Apr 2019 14:21:41 -0700 (PDT) From: Jeremy Linton To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, marc.zyngier@arm.com, suzuki.poulose@arm.com, Dave.Martin@arm.com, shankerd@codeaurora.org, julien.thierry@arm.com, mlangsdo@redhat.com, stefan.wahren@i2se.com, Andre.Przywara@arm.com, linux-kernel@vger.kernel.org, Jeremy Linton , Andre Przywara Subject: [v8 05/10] arm64: Use firmware to detect CPUs that are not affected by Spectre-v2 Date: Mon, 15 Apr 2019 16:21:24 -0500 Message-Id: <20190415212129.1112-6-jeremy.linton@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190415212129.1112-1-jeremy.linton@arm.com> References: <20190415212129.1112-1-jeremy.linton@arm.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier The SMCCC ARCH_WORKAROUND_1 service can indicate that although the firmware knows about the Spectre-v2 mitigation, this particular CPU is not vulnerable, and it is thus not necessary to call the firmware on this CPU. Let's use this information to our benefit. Signed-off-by: Marc Zyngier Signed-off-by: Jeremy Linton Reviewed-by: Andre Przywara Reviewed-by: Catalin Marinas Tested-by: Stefan Wahren --- arch/arm64/kernel/cpu_errata.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) -- 2.20.1 diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 032f1a4dbea2..60cf87c4deb7 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -230,22 +230,36 @@ static int detect_harden_bp_fw(void) case PSCI_CONDUIT_HVC: arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, ARM_SMCCC_ARCH_WORKAROUND_1, &res); - if ((int)res.a0 < 0) + switch ((int)res.a0) { + case 1: + /* Firmware says we're just fine */ + return 0; + case 0: + cb = call_hvc_arch_workaround_1; + /* This is a guest, no need to patch KVM vectors */ + smccc_start = NULL; + smccc_end = NULL; + break; + default: return -1; - cb = call_hvc_arch_workaround_1; - /* This is a guest, no need to patch KVM vectors */ - smccc_start = NULL; - smccc_end = NULL; + } break; case PSCI_CONDUIT_SMC: arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, ARM_SMCCC_ARCH_WORKAROUND_1, &res); - if ((int)res.a0 < 0) + switch ((int)res.a0) { + case 1: + /* Firmware says we're just fine */ + return 0; + case 0: + cb = call_smc_arch_workaround_1; + smccc_start = __smccc_workaround_1_smc_start; + smccc_end = __smccc_workaround_1_smc_end; + break; + default: return -1; - cb = call_smc_arch_workaround_1; - smccc_start = __smccc_workaround_1_smc_start; - smccc_end = __smccc_workaround_1_smc_end; + } break; default: