From patchwork Mon Feb 26 08:20:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 129591 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3358761lja; Mon, 26 Feb 2018 00:26:12 -0800 (PST) X-Google-Smtp-Source: AH8x225KnYEeKAP4IOUHD9s3EyGNSEWXmPEVbHoL+VwDJlwlU1LmAAHBmUDCqIURikHANWcn0GVo X-Received: by 2002:a17:902:9a85:: with SMTP id w5-v6mr9771572plp.417.1519633572190; Mon, 26 Feb 2018 00:26:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633572; cv=none; d=google.com; s=arc-20160816; b=Nj0PUIC89uoPzVI+Db5i91WqfKzzMdDDrOaoGcqQSc/6Cf3p1KCv4BuBkm4NKJuLe6 esIhgX2tiNVdfzWmex+b8S6eXlz8v+oQGqsLsJBrfpTKqmbxvkvAtRk8mkcW21QReyQ6 Qq6xqbxtoLTDw2kWml7NO2wzEBRUpNGdo/nX7L3NJ2P90EJ0s/FKtrA45FYWEvrNvXoS GhzsxqYcX1DE2xK/79HsuEMHW/ny1kiH1XQO5a+g9+Fce4X2SWVMKOfN5DZ0/x8IHm9+ K0SdzYnVmKYsdDW1zLM/mYljXxluqXVhwzOfrrR5JHrTwE/ULauDJUOatsfiGR0IOxIB 5DfA== 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:to:from:dkim-signature:arc-authentication-results; bh=45rSmjFMKcw3BvYABEBt7fYl55v7nB64zwwP7vtw3XM=; b=XCIULhfJET/d3uQxEiJHbPbASoflYSdIwoPopTLMA0lPCgA+Jp5gjUL0kEHFN0j6bl Cuy3MTuGImXYXf6/LVB8i0VBqPZrbtO49KbEj8owJnXDEB4dCkvQBAQs2WhC0R54Wu/0 AKbBF0/mkSFcsAE8uaFBYDBtNYnWKRNimbh+RBTmE4O1+ibIyXCr7MuTgiitP1RbbXa6 o7yevcROcXgl5YzBJfDIIPKGxN4+X3JTF9rXwBMzTtGshGHH5SExCsTwr1BJ3wAbxar7 UX1dz+YF4qOGDhk9otKpWnnSwOmgx4N67w+Ge4cai4fz6J2+6aMSeIs8EWNGfpwsyF6p drfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qy/nBnHn; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j127si5283966pgc.653.2018.02.26.00.26.11; Mon, 26 Feb 2018 00:26:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qy/nBnHn; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752544AbeBZI0K (ORCPT + 10 others); Mon, 26 Feb 2018 03:26:10 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:33450 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752253AbeBZI0E (ORCPT ); Mon, 26 Feb 2018 03:26:04 -0500 Received: by mail-pl0-f68.google.com with SMTP id c11-v6so5450952plo.0 for ; Mon, 26 Feb 2018 00:26:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=45rSmjFMKcw3BvYABEBt7fYl55v7nB64zwwP7vtw3XM=; b=Qy/nBnHn996E+ZwHe6hLkYYQlxHxsnIypZQj6cnYiIwBfmMuM8Pkdma37+9jCVk4Qa SQ9+VuQlIZif6zdMPAC/OGKrw+Whz9J9tv1C8KL5ehDLk+VAcPks1qZ3fc3Vc9WeiSp1 UK4vkuDxwglnmW7qgT0ob5kxf+qGnIE8kc+es= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=45rSmjFMKcw3BvYABEBt7fYl55v7nB64zwwP7vtw3XM=; b=kyXzMTX5m4e3fcC6GK6ZqWvEJK+u+kRP03txjxlJ+lEnVe6Fz7giNHf1f4EefNNFpl LCv3SuD8YHMsl/iykUUFWEkNsdA9nzaPgCe4Z3NJUwVOLAxSzuUsiP3DZklAvFkhP3Mf E6xkbCGbPs4FlFN8L+D12+KuX/E2Wmgg9NPCVCOHFS7IXc3Uy7POTX2dU90Nnd/poY4L 2fH/rCtjB+5Z2f2KSJ12t18sI4och3Z9XiOLDphADUQo9c/o7Vsw8zxLq/zogUWKJdZF 8DCKxYGExHkSC+pvn6R1kVbTXeU5fSq0i/ObHSqGcO7dHkp3MQaZgyWI9G+9R3gTS4VD /hnQ== X-Gm-Message-State: APf1xPABCwGg+Mrng6Jp33odOctn1DXT0NIFfQAfsMXRywsYJ2trcdQV TtxFf7YHk8f9dk9CyqQCIueAXH1Rfgw= X-Received: by 2002:a17:902:3341:: with SMTP id a59-v6mr4859451plc.20.1519633563557; Mon, 26 Feb 2018 00:26:03 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.25.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:26:02 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, Christoffer Dall , Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , Russell King , linux-arm-kernel@lists.infradead.org (moderated list:KERNEL VIRTUAL MACHINE (KVM) FOR ARM), kvmarm@lists.cs.columbia.edu (open list:KERNEL VIRTUAL MACHINE (KVM) FOR ARM), kvm@vger.kernel.org (open list:KERNEL VIRTUAL MACHINE (KVM)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 38/52] arm64: KVM: Report SMCCC_ARCH_WORKAROUND_1 BP hardening support Date: Mon, 26 Feb 2018 16:20:12 +0800 Message-Id: <1519633227-29832-39-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Marc Zyngier commit 6167ec5c9145 upstream. 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 Signed-off-by: Catalin Marinas Signed-off-by: Will Deacon Signed-off-by: Alex Shi Conflicts: no sve support in arch/arm64/include/asm/kvm_host.h mv changes from virt/kvm/arm/psci.c to arch/arm/kvm/psci.c using cpus_have_cap instead of cpus_have_const_cap --- arch/arm/include/asm/kvm_host.h | 6 ++++++ arch/arm/kvm/psci.c | 9 ++++++++- arch/arm64/include/asm/kvm_host.h | 6 ++++++ include/linux/arm-smccc.h | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index d5423ab..9fe1043 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -318,4 +318,10 @@ static inline int kvm_arm_vcpu_arch_has_attr(struct kvm_vcpu *vcpu, return -ENXIO; } +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/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 396eb5d..a825638 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -404,13 +404,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); diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index e505038..7f5244a 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -393,4 +393,10 @@ static inline void __cpu_init_stage2(void) "PARange is %d bits, unsupported configuration!", parange); } + +static inline bool kvm_arm_harden_branch_predictor(void) +{ + return cpus_have_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 dc68aa5..e1ef944 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