From patchwork Fri Mar 9 09:07:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10270189 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 45094605CE for ; Fri, 9 Mar 2018 09:26:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4142229D76 for ; Fri, 9 Mar 2018 09:26:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35C7B29D9B; Fri, 9 Mar 2018 09:26:46 +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=ham 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 8F59D29D8A for ; Fri, 9 Mar 2018 09:26:45 +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=jD8ztKWofv7nLg97OeKRAmFkNxZ9rMo7n0huJNcUIuA=; b=DaEjyBXGJrT2J/+sbvhg4XwvEB 5CGMGn/RLxsSR0HCcwsXktymRB6fKn+WnTMBe0yLmMggCwDXGWyPNVfT+Yimdtk4C7QckcyE0BSPH Mpk+SHZfaDdckJ98w66ha8VYQ15O5mEzjKu5CQI+7WUdTAOJmk1m95UIGLNqlKDgDWYX3F4J3g/0D G8P3EgEZcIZ6sjxPv+RNld5H4FRbw4y89ryDRtEinqowi7nN8R3bYpuPqYouAilr7/NDy7f4AqA1d 1A1hft1vYT8yacIBlzQH9cyhRWNPZtIPhw97ZFYF4mA2Dw4rPcZh2aHqK29i9RgGAHHfVClkctzaS GTjuLsNQ==; 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 1euEIO-0000EZ-Ly; Fri, 09 Mar 2018 09:26:36 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euEHl-0008EU-Sf for linux-arm-kernel@bombadil.infradead.org; Fri, 09 Mar 2018 09:25:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=LdfrCCdjRKhGEJGEckz8O123XPPSbfZVeCUNgTSwGdo=; b=htuogz7CAhUgP9mrSMnY5i1n7 ZM3joc9I/a+KCT1Kn9FYYHjtgEHA4nfgLLEJG4RU5dQsIR0JEH3N2KPcBO49ez4IwU59bACj4q+at PrHMSuFzIImniHvvFS1eqPZp6U5s6eIVFxwUJTrIDmao1v/Iw6V1dCPIkh0qOpMRluHwgXvBrIVjU hLgBCuSyMzrbzqfSGyAGSzZ5ilBMhXmaapKnUSehMR+slw7ur7sIyR7Trn8ys1xIanWzzcZ85j0oh ltWC1qHPnVzH4cLSymNEE6Iu9lYNdKWmjPVuUTVldT1dWBjv8yycrdwpUPTamdDBcHkVGLptUKhC6 cYNUR8Zkw==; Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euE4P-0001mC-Hw for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 09:12:12 +0000 Received: by mail-pf0-x241.google.com with SMTP id a16so1050047pfn.9 for ; Fri, 09 Mar 2018 01:11:59 -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=LdfrCCdjRKhGEJGEckz8O123XPPSbfZVeCUNgTSwGdo=; b=bIpRzYFXCUuu8g2qQrBw8pKtYWcV/Ng2M4nIStYfeUwr19PXnQGtigBWAsu7xjsfw2 0gyoargvku8aMD2ihIIBGKlkRwckKeZvPmaSx6JMET+l+e48GDRecz0hsobItHmih0KC LgNfa9NOXvA+e/iMZtXQCzzYnB9LvNL+OHBGE= 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=LdfrCCdjRKhGEJGEckz8O123XPPSbfZVeCUNgTSwGdo=; b=V2E8ELAHOzUSYEPrZDRCcQbSQykX3CIL97KFKdr5f3NJ8QZaoSqPbbuCRvBvDBwPdc OpBS2H3rVu7SFByfoAyWvihRb170xUBAGeKb1Ai/uzjroyadvGe3NefhVJ4kK84t+o9T qsEzx6yMsAJHnB0YOW4M+fl5yd6+HR6418ZD9ghIRIN0IUw0ZN8FZMphamvJ7TTeQ3PX pCjaYhavmtaN8bs6chbFgGwnnlvipHUzNxsmOH/OdFGv0G4JfPtoxwL/CutaNB86FPbY cjycdSoH6IIsY2S0wDgwFgfGh6mxRYUCDM02viaLLceUbXGI8s7V8Tu83hxBpkwQrwHs pt5w== X-Gm-Message-State: APf1xPBun3YewhQy/Jpi344vgfdWP7HTd0KVD+6iv4ZQHAut7bFzPk4c 0DuC36sq4F+MACMu520FiMn0jw== X-Google-Smtp-Source: AG47ELugheBVlewo0sMOrLKkcQ9jhRyjqINEmgvjeuZHkOvRVgGQY+7XrvgJPEc3KxTatyLU/c5NDw== X-Received: by 10.98.251.5 with SMTP id x5mr29570329pfm.18.1520586717808; Fri, 09 Mar 2018 01:11:57 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id c7sm1961752pfg.36.2018.03.09.01.11.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 01:11:57 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , broonie@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 33/39] arm64: KVM: Report SMCCC_ARCH_WORKAROUND_1 BP hardening support Date: Fri, 9 Mar 2018 17:07:16 +0800 Message-Id: <20180309090722.26279-34-alex.shi@linaro.org> X-Mailer: git-send-email 2.16.2.440.gc6284da In-Reply-To: <20180309090722.26279-1-alex.shi@linaro.org> References: <20180309090722.26279-1-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180309_091209_583950_BDA31810 X-CRM114-Status: GOOD ( 18.30 ) 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 6692982c9b57..2009894d9a8a 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -237,4 +237,10 @@ static inline void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) {} static inline void kvm_arm_clear_debug(struct kvm_vcpu *vcpu) {} static inline void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu) {} +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 6f691d7b9fdc..d06852e9c189 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 a35ce7266aac..ae0de3a9c759 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -258,4 +258,10 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu); void kvm_arm_clear_debug(struct kvm_vcpu *vcpu); void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu); + +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 80e6a6bb8a20..a5ed4511af47 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -76,6 +76,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) + /** * struct arm_smccc_res - Result from SMC/HVC call * @a0-a3 result values from registers 0 to 3