Received: by 10.223.185.116 with SMTP id b49csp7398429wrg; Thu, 1 Mar 2018 05:03:12 -0800 (PST) X-Google-Smtp-Source: AG47ELvgtG0BKl4xmqjytepjiFcme48CjF6k1O1UgwSO8K/gYcUltJjmMK/gUSZ7uSf+LXrGervz X-Received: by 2002:a17:902:6805:: with SMTP id h5-v6mr1903684plk.46.1519909392030; Thu, 01 Mar 2018 05:03:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909391; cv=none; d=google.com; s=arc-20160816; b=LK9AAORYIm01Vz9VHPZa7R+PNIBgbWqBDtalHNpiMRw0VzHD/VvfQFBWrohseH9oef hVEddOx5TLS9LAjJrsTymeKaiFeGBGyuMjOl86Pr162WcJBTIl7TEgBN6jjKnDWcMBsO ltelNZWzksVH2xK+GQOBrl64ggwzeTFKP2gw5gCBP2d4vFG2CrSUF4bA4i0X7i7T9V+s a9r0PAiJTwnNBuQ0BgnKnwl5R2+/gaQTXch+KbrNn9MIec/a0PoFXisu098zj62HFh0m BjVvI3jIAAlKcbX3HMUAYMq3/70HApkWePtp0PM366a5eINjaKhky/rCU9o6tDuRhW6x uAnw== 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:dkim-signature:arc-authentication-results; bh=ZmjCFMUWnpLHU7w3vwDJv0/nQVwyUfFzmKW+/5xa0BE=; b=mvwFwcWOJJzQexpN/Nq6QwuliDePXDfW3EzXL4IzOmx0IlO/c+ouqcwb9nokuv9Qtq peOwgdQInJ8K9m1UHXvt/dUYolbfQ2J8Hwz+lNM2lvysVFWDQgNYSHHOnw1a7MnaLxtl 6U9QGmBl79qXUbLDTmtOmaRaLNkmBpRAm892C2CS6sLgj380jL7RAbpn5ep3m0XDSLmr bZ65YNd4lFRLZ0yh8k9zCVwtd4VSwTd/LK+l0R26J400DD6ywNKwSdvPVssx+p75sVR8 +QVA0/E5iWInvM1Bpw0z7eHY6l7+BvskYPa7IyE1KZExMUX4DWxuDdyEqsgEkUSTZgOE UOtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gHsG8ThO; 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; 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 d8-v6si3028915plo.17.2018.03.01.05.02.50; Thu, 01 Mar 2018 05:03:11 -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; dkim=pass header.i=@linaro.org header.s=google header.b=gHsG8ThO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031118AbeCANAb (ORCPT + 99 others); Thu, 1 Mar 2018 08:00:31 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:41879 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031094AbeCANA1 (ORCPT ); Thu, 1 Mar 2018 08:00:27 -0500 Received: by mail-pf0-f194.google.com with SMTP id f80so2402415pfa.8 for ; Thu, 01 Mar 2018 05:00:27 -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=gcaRxQf3PMvLj2muSQzMu7eOh5Gy4jXW7X7JmS152jkAAviEXIyeWo8S/gS0xThYSW 1ZzaqIHlv97aF/9EIXRPYs20RQV+pGv6KqhTg8doTwskDJaJ4z31VoHRYapJQV9pyiNj Zv6brNPI9Hms+7YBW8BVTshCL4mcBNvhm3IU3NPOqKriWIvAOPYPkew64uRlYmstz9HQ b7CvFHXRuKLk6Uc4519ZfWton3Jvg4SmL7jsUxGiZvaRiwSWcKuWk/4C8JlqGmPYpsvy oEGd+cPym7vhr0x6egq8tHWHdFRvWCpFQjXkXiUT3HJbYy84BNUXTnWLdCHoVR79CKwJ 6r1w== X-Gm-Message-State: APf1xPAlIz36JOfZIazh0jNwePwKu+ambiE5EWx4D7IhBl/aLoE/MU2P PnfA/f52qgWCjSIsYBX7WF9FrQ== 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 Cc: Alex Shi 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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 -- 2.7.4