Received: by 10.223.176.5 with SMTP id f5csp950532wra; Tue, 6 Feb 2018 10:00:06 -0800 (PST) X-Google-Smtp-Source: AH8x224z+jav2k+D/AXKT0dlHBxYfprL92W/40ofl6wJthkaTK5QjU3eacZFL6xMycSynplt0hkQ X-Received: by 10.99.135.67 with SMTP id i64mr1956211pge.331.1517940006119; Tue, 06 Feb 2018 10:00:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517940006; cv=none; d=google.com; s=arc-20160816; b=WdKdNirYJ+xpa40zSRg+EA50d2Sl7y51vgQFm2lQ3UcIKR+/mo3kjW1LFv9h9ZnFYK YhAXKIIVUIDJmMsc5HAG2JrGgbOF0Y5JhGXlTbu846ACMl14oSE7zSMU+ncpukaZT0CP jphYzu7Qp5sCfjH9RdmZyHOvbB+rr+kF7j8atHZ2c7IgaAFFd4rs+a55HFWuIp4lx0vE JCGM6PCT5PkrYKoWzFSRojxI25D2qrpr3kiF6/kReQIT7WNykrYz/69D63zVooQJVJWo JpZk3PqLkK44RLA1lIZnNABg9jnp5pqMvsUB0bkQcnz5ifBXobfS5oRmQbu0ZXu4l8NI we5A== 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=3xFaJTYAhUpMNLEiXafRZOcOykKEflHknI4FLcN+fPc=; b=D+eu7mKuRAnWjdh+mPwwRvAOhxo34jUq9Hd0/2dro1xus8AA+/mqJ7KcYmI7niKYFg Lln2RVCBNWiDlVthHJhG4ErVggVEqmGeZN0GNygSYMJlHLzDPd38v/OUWurCi2HVie8p tL1bbkC4xIcq93Av/b5RGXa3IKqXQQiC8EnNkmZFX8rl75HaxW+gUeucIQQi0prmv2vX 4Bp4WVebCs1AFefNBy0VSME3r+76gHVqYDglTOj4swGDuSZ9iQyCSL0AADXHumNFoYuV wEklC0BIgSxjmbDDpp6O7CySgLLGlOWnShgprL0xTAjVVt2ouQ3QvHW2OjEjcWkHGNKi uMtg== 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 h6si133594pfk.293.2018.02.06.09.59.51; Tue, 06 Feb 2018 10:00:06 -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 S1753080AbeBFR6l (ORCPT + 99 others); Tue, 6 Feb 2018 12:58:41 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:41116 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752817AbeBFR5T (ORCPT ); Tue, 6 Feb 2018 12:57:19 -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 D56EE1596; Tue, 6 Feb 2018 09:57:15 -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 3454E3F25C; Tue, 6 Feb 2018 09:57:13 -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 v4 10/17] arm64: KVM: Report SMCCC_ARCH_WORKAROUND_1 BP hardening support Date: Tue, 6 Feb 2018 17:56:14 +0000 Message-Id: <20180206175621.929-11-marc.zyngier@arm.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180206175621.929-1-marc.zyngier@arm.com> References: <20180206175621.929-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. Tested-by: Ard Biesheuvel Reviewed-by: Christoffer Dall 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 acbf9ec7b396..ef54013b5b9f 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -306,4 +306,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 4485ae8e98de..a73f63aca68e 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -415,4 +415,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 e105c1153794..6919352cbf15 100644 --- a/virt/kvm/arm/psci.c +++ b/virt/kvm/arm/psci.c @@ -405,13 +405,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