From patchwork Thu Mar 1 12:54:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10251421 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 087DD60211 for ; Thu, 1 Mar 2018 13:35:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E93101FE82 for ; Thu, 1 Mar 2018 13:35:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB9E8201B1; Thu, 1 Mar 2018 13:35:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 64A501FE82 for ; Thu, 1 Mar 2018 13:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ruxMaJj0KYwAMnjcBbdFKZyOI5Nuo9z863UWuLUdKDI=; b=AAdppzW0TkfP7SY5Dl1HfOedNM GFydIoOj2VFtA4FEg8tN7ISL/YwpRR1Gsm//yIJ7wGxv/bvHckGrCgEhJsHpsyBLSVRyqVXmf2+ft wTIGkQUBtKJ5+0qMHthHTi+jmK2qU4TcNaf4hA/r2/aUaC6OerMfyKezvcyiufGDZleCP3aVgMD4G B7pgjR0Y65DlvECkcd4RNQETXB7b6qYzZJN2cRuZhBjoHK/7KuVGs0jA+Ufp00uub0A98ggRekX42 J3nzH8xq6XHQ4FVqsXtUf7flrGRjFcaFQYSxHJ3DDHXN1r1Gf89mIaiNwlUVjpqUmeTCVxl2TcYK3 OIz3aXdg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1erOMU-0006Ec-V9; Thu, 01 Mar 2018 13:35:06 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erOHC-0001sV-NU for linux-arm-kernel@bombadil.infradead.org; Thu, 01 Mar 2018 13:29:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZmjCFMUWnpLHU7w3vwDJv0/nQVwyUfFzmKW+/5xa0BE=; b=h355mhFBWxIRs+IhfvfiVUKzM G3du5KXBS5I6WAMj/052HblZEgK1j+FmzJgkwldTpw2nrskG5l3Dl4nsqOBItTGhbbUpIPUSf+ax0 Fh8zOrTEDGRb/xRztkM5EYOEOFsmdoZ5g9pe71LJjS5RhZIlJYl3Wqn2BuVNE1yPNkMhLqit78/CT IK7/+L6INLwLhLqMyihtpzXPaz4K3mBu200vNtQkyaVoh/olRtf5u2LU6dQ+m1/klIFQ/A8IaBfkH xdH2LXWHE9os4JipPT5bT+4HWu8SRGvqd8rKJ2j1zS1sZUJjrRtQWrsI0tWDD/NPRKTj/MjU66Yvz stFsK41Tw==; Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNp9-0002N5-LO for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 13:00:44 +0000 Received: by mail-pf0-x241.google.com with SMTP id d26so2410047pfn.5 for ; Thu, 01 Mar 2018 05:00:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZmjCFMUWnpLHU7w3vwDJv0/nQVwyUfFzmKW+/5xa0BE=; b=gHsG8ThOKmqnIMDNZ2JSmqQeEg7xqG9RdQOFCsJp1Q6Ef9LDvMrlzIvDp8AJUOXAr6 M0u2HfsWBjU9SLvNemokIG+YT3IVY54EOPgs/v69t6ABAzXgjmGrCzBOXQ1Y1/wJTCQg GOCRZa3om6G4IQdTsIMNLJRB1XNypZZ7RIJWE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZmjCFMUWnpLHU7w3vwDJv0/nQVwyUfFzmKW+/5xa0BE=; b=pN7ACiIiqEqbc/ZaOalKeA72BGzAoVwS4IoSK/6Dbhy3glhzppTQ0IpNQDifxKtZUR 4f1TUxA3VOLvs8vmxz8RANbd3oSq6Vu/DaaOYAVgEiKdM2jcdFtqR9tNw5Ubjg6ioN6V rPbgzXkFAz7KjMNRbzvwdnq0yqiI4hFho2p+vfgHJtot/1INKaUz8N3fu8K71RAtPITu RUwccpjMl2g4H8OXjSSDsAWvmghFhFBIf4NyM1oUAocAosAjqMsrd4ZQ2e6Bv2kFQ8q6 3VofNFZXsMvbXPi9jzcAWSYxzBn/dgWjyqZb/CexS5HSZBcRtPrIBVpy9+6W3H/9ESRg Ou5g== X-Gm-Message-State: APf1xPCwaSp3C2dHxKRfbxJk6YLyTfQQl4x4aBEx6o/uw62n321PyCov SA3Ftv+r/UhDZJON+e4UcHzjnw== X-Google-Smtp-Source: AG47ELt57rydrQt9CFOYvCAHRENdupyxOCHIG0gVBLR7BLbGg3BjbfP24p1a2y6W8OAR0Fyt6eiWHw== X-Received: by 10.99.175.87 with SMTP id s23mr1497684pgo.328.1519909227314; Thu, 01 Mar 2018 05:00:27 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.05.00.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 05:00:26 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 38/45] arm64: KVM: Report SMCCC_ARCH_WORKAROUND_1 BP hardening support Date: Thu, 1 Mar 2018 20:54:15 +0800 Message-Id: <1519908862-11425-39-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_080039_726450_D8B1FCD6 X-CRM114-Status: GOOD ( 17.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Shi MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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(-) 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