Received: by 10.223.176.5 with SMTP id f5csp2642414wra; Thu, 1 Feb 2018 03:51:15 -0800 (PST) X-Google-Smtp-Source: AH8x227RPkiGBS/1NQMXYpYr5sMhbUiQxwfOZsSIo19TRDOPUi+A4XYu5cgjHPNBDYSbnIIEXAf0 X-Received: by 10.98.49.199 with SMTP id x190mr36924105pfx.1.1517485875294; Thu, 01 Feb 2018 03:51:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517485875; cv=none; d=google.com; s=arc-20160816; b=MNVLUXRiYrfqItJk16kbgDQAwV+gw+55xOrdOz9a6QA6rC2lQokYxiNc9CuE3vYvKO iToigOecE0yKFoi/+4E7dBRONTahYmSMd/BM5WZe7zgzS8madXJz1nTGLPANOOi7FyU6 JWtBilIiS1+dqzRGZS/KHN/F1pMhS+lofey6n66Dq2197M0FT+UaZETYCdC51lPz0ZS+ ZzTe6xsK0UN8JpndHRJp2IJpDh1NNvlohmx6mONaVRuMgm9ED+718wptSe8xCq8qtH91 h+TJXQFngzh50dxQ5xiNPXAxdvh1YE9Q1S2FjDhs8wBDj+Uqofg1zH5H3+EMANaP1AnH kpMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Km4L7yruoSldAhWjKilVKAjYdmo10nkuBg9oVPXNZx0=; b=dN6bE9lWnILj+lLQ+hNKtoYLet1/bmU8eN2RyK7WqsaRghP8N0nWtI8PX1q8L0QqYK QNZAFxoLreH07HvI4nrFNfAdfWbBlsaa4m3aWmYczf7AMHddSWfm4CsgeUnGJRxNFrZM bs+zfWstk/98djOSflj/mAilT/J+EOGVnAPFuWZrxSBf5FNUV8XuRKZxRw4ccvNzq97W 1cOaq8jt+PmlLajLwaxfdnjROESOHS9bfY8LTM4EyycVOje+DbGHiBTSdFCYwVB6hSQh 9pH8dElS3no9oshSPZTuTVUVaXfMDdxrQlzatzHCRUYuUdctOVO4rWtbdusykBF1VoVd QUow== 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 n9-v6si1706218plk.311.2018.02.01.03.50.56; Thu, 01 Feb 2018 03:51:15 -0800 (PST) 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 S1752530AbeBALsQ (ORCPT + 99 others); Thu, 1 Feb 2018 06:48:16 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:48502 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752257AbeBALsK (ORCPT ); Thu, 1 Feb 2018 06:48:10 -0500 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 42BEA80D; Thu, 1 Feb 2018 03:48:10 -0800 (PST) Received: from approximate.cambridge.arm.com (approximate.cambridge.arm.com [10.1.207.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7A10F3F25C; Thu, 1 Feb 2018 03:48:07 -0800 (PST) From: Marc Zyngier To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: Catalin Marinas , Will Deacon , Peter Maydell , Christoffer Dall , Lorenzo Pieralisi , Mark Rutland , Robin Murphy , Ard Biesheuvel , Andrew Jones , Hanjun Guo , Jayachandran C , Jon Masters , Russell King - ARM Linux Subject: [PATCH v3 11/18] arm64: KVM: Report SMCCC_ARCH_WORKAROUND_1 BP hardening support Date: Thu, 1 Feb 2018 11:46:50 +0000 Message-Id: <20180201114657.7323-12-marc.zyngier@arm.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180201114657.7323-1-marc.zyngier@arm.com> References: <20180201114657.7323-1-marc.zyngier@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A new feature of SMCCC 1.1 is that it offers firmware-based CPU workarounds. In particular, SMCCC_ARCH_WORKAROUND_1 provides BP hardening for CVE-2017-5715. If the host has some mitigation for this issue, report that we deal with it using SMCCC_ARCH_WORKAROUND_1, as we apply the host workaround on every guest exit. Signed-off-by: Marc Zyngier --- arch/arm/include/asm/kvm_host.h | 7 +++++++ arch/arm64/include/asm/kvm_host.h | 6 ++++++ include/linux/arm-smccc.h | 5 +++++ virt/kvm/arm/psci.c | 9 ++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index e9d57060d88c..6c05e3b13081 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -309,4 +309,11 @@ static inline void kvm_fpsimd_flush_cpu_state(void) {} static inline void kvm_arm_vhe_guest_enter(void) {} static inline void kvm_arm_vhe_guest_exit(void) {} + +static inline bool kvm_arm_harden_branch_predictor(void) +{ + /* No way to detect it yet, pretend it is not there. */ + return false; +} + #endif /* __ARM_KVM_HOST_H__ */ diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 10af386642c6..448d3b9a58cb 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -418,4 +418,10 @@ static inline void kvm_arm_vhe_guest_exit(void) { local_daif_restore(DAIF_PROCCTX_NOIRQ); } + +static inline bool kvm_arm_harden_branch_predictor(void) +{ + return cpus_have_const_cap(ARM64_HARDEN_BRANCH_PREDICTOR); +} + #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index dc68aa5a7261..e1ef944ef1da 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -73,6 +73,11 @@ ARM_SMCCC_SMC_32, \ 0, 1) +#define ARM_SMCCC_ARCH_WORKAROUND_1 \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0x8000) + #ifndef __ASSEMBLY__ #include diff --git a/virt/kvm/arm/psci.c b/virt/kvm/arm/psci.c index 2efacbe7b1a2..22c24561d07d 100644 --- a/virt/kvm/arm/psci.c +++ b/virt/kvm/arm/psci.c @@ -406,13 +406,20 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) { u32 func_id = smccc_get_function(vcpu); u32 val = PSCI_RET_NOT_SUPPORTED; + u32 feature; switch (func_id) { case ARM_SMCCC_VERSION_FUNC_ID: val = ARM_SMCCC_VERSION_1_1; break; case ARM_SMCCC_ARCH_FEATURES_FUNC_ID: - /* Nothing supported yet */ + feature = smccc_get_arg1(vcpu); + switch(feature) { + case ARM_SMCCC_ARCH_WORKAROUND_1: + if (kvm_arm_harden_branch_predictor()) + val = 0; + break; + } break; default: return kvm_psci_call(vcpu); -- 2.14.2