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: 10241791 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 5FD3A60208 for ; Mon, 26 Feb 2018 09:44:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DB9029EB9 for ; Mon, 26 Feb 2018 09:44:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4284229EBF; Mon, 26 Feb 2018 09:44:12 +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 ACD1C29EB9 for ; Mon, 26 Feb 2018 09:44:11 +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:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5qcjGRuIa8TA563DoRd2DPK1v4snmYb0DRXRBLD+rao=; b=GT6p62MsnTibXq Gl0wRZ1xwsVKjVDq1h8AnshA/qWLUI6dyc4xa+wgUf+m2xnSXw5j3PR4+i5SYDiAyct0Gp1IwocwK S3WmTXC5lGysLsITDGFYxTjI+gKWhUkLUX5/F1mOMSwioEGGsugGJl7/nfB4cVss0hy4LOSy85DlG xVvfJ7j+HTzT1/2OnrUOSQy5y4yh6MYvnk8WOuNHcuSCP2dYxDsK5ZjBNLqqWm3nIQOUQxWAWRrFB 6tqwfV4WHGYNF0tLPnyTGLEEPDrp80NYf9Aj9v/juv4uwE47Dd0V7WFvwpiaJeETsfYDB/XKHb3VR 1K8i6rzWrd9p4BsZ8Zgw==; 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 1eqFKE-0000hP-7q; Mon, 26 Feb 2018 09:44:02 +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 1eqFI1-0007sG-Ce for linux-arm-kernel@bombadil.infradead.org; Mon, 26 Feb 2018 09:41:45 +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:To:From:Sender:Reply-To:Cc: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=45rSmjFMKcw3BvYABEBt7fYl55v7nB64zwwP7vtw3XM=; b=vKSCdK/tZpMuucsOHOWk2O+gv juf6gIjzVVzqkIUd6Bxah8kUTwl5u/UHWIc2LqiWcXyufqLS2TD+DU+615O0WPJeJMcwx8u2P8BGG /ikHN7E0b3PWQt/+dYDJIGuamriCIFhalaWSk3KHujZKjDlBjiMgCWHf0BLYxDJO1kdFj7t1FwO7j 1XZMdlBF+Dw2pPcN9xB3zIgQSTGczqZfQx+vPRCbrDNzHg4MalMITLxL8TWVUXAlsuzUIqwm1DC47 enr/3JitnIRxcQsHLLBLwB0LHYUsobnbpjE0g9/VZTrOHe/C7MF7XoG8nTmafVLAJhxL6okeWwAXF 1Y93cBpNw==; Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqE6x-0003Zw-Q3 for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2018 08:26:18 +0000 Received: by mail-pl0-x243.google.com with SMTP id s13so8862976plq.6 for ; Mon, 26 Feb 2018 00:26:05 -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=ZuOEPxuMAms2jMwnks62S7WRD6UZku804nzmiDvyhbbLhtVxlTQNO9nX7tEggBCVNE PF/2/pohmg7w8hYSUxHVP2C05DLy/90ClGxsMk30wINbGbH3tuzIcl0+KAltrzOXK7ek JFkopyfZf3v7wSfUMF/tLd0AhOGkO0Wgcm/1ULJbeT24hC534X/ILO2cnf1k8zlofXAQ DM5nL5Shrx28iNOR3tuKiBgpf1Wgtl6UEFLJ9ypFFNcYes8S2NeaXFavEUvlxuDIjijY bnZ0YHOh3VlxLK/2TvQwGP5gcwrahZzus/vkpbMghS9XzZK+eVZ6/BLFZj81wl1JjxsG WlRg== X-Gm-Message-State: APf1xPBagTbeUsy4ApFbd19Fkyqz/LaQXa1MxjjFxyQI1s6euD7bAcHs QSPz+0gsIzkgLgv07ToM4KntTg== X-Google-Smtp-Source: AG47ELseHGqMyD7vV/Vr3UgNtMkuvkh/7NjUzfORNlqdjPG/LMbozRlOC97SSH+kcHOQBbk5IlKK6A== 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?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_032615_876073_389D98D5 X-CRM114-Status: GOOD ( 17.58 ) 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: , 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 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(-) 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