From patchwork Fri Oct 23 15:47:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11853759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6421C5517A for ; Fri, 23 Oct 2020 15:49:27 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 42B5D21D47 for ; Fri, 23 Oct 2020 15:49:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="V/In+KKE"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="M/GS969E" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42B5D21D47 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References:List-Owner; bh=6yiW1MTkXo/KNdtIhG5xwoiOEQUUDiWOXe1KBpyCcW0=; b=V/In+KKE2BGQ2we3DWdLUgMDJL KhggXeANnxLh/lmPPyw6KbLiy63NCU3W7hh5qEJRDRdnQ5uKwNlYG599+MgtmmKZcN0h1sPTUHwXj 80jgVLRBVzDYzJzsKTr0Ud//cXNsU95MnloBtEFuw95iXfqzIEDpPvT5O7GUkOxReGVUpG6BDRfCN G6suOAz1EWfhUKXbmRBaXQB3lsa9ssLh4akCPlONkXO2s75d0k+7KYX7/qJ85Ut5s5ba7J5CYehVp YvrT/akMVJrQBT/ZMZnvHQXQXuOcuUxIXQadTiQJ0Umpof4mgzXFmOnUnMu7xoO2KZnni+aafGVaw hgOhfufQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVzIQ-0003Tm-Cw; Fri, 23 Oct 2020 15:48:02 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVzIN-0003SZ-DO for linux-arm-kernel@lists.infradead.org; Fri, 23 Oct 2020 15:48:00 +0000 Received: by mail-pf1-x441.google.com with SMTP id c20so1639297pfr.8 for ; Fri, 23 Oct 2020 08:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Euid2rOIqVxU7BCKc29LGBrOY7GyDm6FtEEpwHglGRU=; b=M/GS969E9V3i09GCuC41mYN/VDUOQUKzlMSMBpISUGxrl8e0AnBOu62xTbAgpXkzbS 5NLXBjzluFLSNZyvQWzcBuXc9alqLSImvHEoFLme/j0k89U1z+qsRc2m0IB+PsXamJf5 k1wezWUJ+yz+ead4BL9mEB0rQpouYI/1056Hk= 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:mime-version :content-transfer-encoding; bh=Euid2rOIqVxU7BCKc29LGBrOY7GyDm6FtEEpwHglGRU=; b=J6CQmXhlCC2HuTpWQAG7xrkImN4KnCrPBuUfFoBFmjCSuHNbrp6Q7yjrhYVYyfplEy wWa4YaC8YTzqKv+HO8NePRSLovWZ48kmLw9lNtHaGy2kD4UMvOARY0m0YRTp/qrG06tX 6/NNAvdDqjSczRCpnMyrFQtsdE1R6Rl5Snod3ff4lxSiHnNzwOB4N4sU2P46cPMWYZ/Q RxR5spOQFLo22K/xTACoS43XNTUmrit3i+w2+voIdYK4vHed6BjyTbosNmn9Imyogkyw J72eW0YnQ3gzy/FzahSuzrVBrf3rc1jOdc6da+qFt3+fiaC9Nf3qi/bqL9XFIZpsf/yz iPnA== X-Gm-Message-State: AOAM532hIuxEwN5GQNv824ZQYVzlW7J2pVhi3kcqtkisANzhE8JJOHGx NiBYrCPGqC9fM0WskWzq40z/ng== X-Google-Smtp-Source: ABdhPJzYLUg/ViEmI70rBqC4Esx7lIduLkcNso4qinU5LfKpUejh1bMzhBnu8IwRnHgAqpvsWGhV+A== X-Received: by 2002:a62:7cd4:0:b029:154:f9ee:320b with SMTP id x203-20020a627cd40000b0290154f9ee320bmr2955753pfc.26.1603468073137; Fri, 23 Oct 2020 08:47:53 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:201:3e52:82ff:fe6c:83ab]) by smtp.gmail.com with ESMTPSA id t6sm2532576pfl.50.2020.10.23.08.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2020 08:47:52 -0700 (PDT) From: Stephen Boyd To: Will Deacon , Catalin Marinas Subject: [PATCH v3] KVM: arm64: ARM_SMCCC_ARCH_WORKAROUND_1 doesn't return SMCCC_RET_NOT_REQUIRED Date: Fri, 23 Oct 2020 08:47:50 -0700 Message-Id: <20201023154751.1973872-1-swboyd@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201023_114759_478935_C8A47AC3 X-CRM114-Status: GOOD ( 17.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andre Przywara , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Steven Price , Marc Zyngier , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org According to the SMCCC spec[1](7.5.2 Discovery) the ARM_SMCCC_ARCH_WORKAROUND_1 function id only returns 0, 1, and SMCCC_RET_NOT_SUPPORTED. 0 is "workaround required and safe to call this function" 1 is "workaround not required but safe to call this function" SMCCC_RET_NOT_SUPPORTED is "might be vulnerable or might not be, who knows, I give up!" SMCCC_RET_NOT_SUPPORTED might as well mean "workaround required, except calling this function may not work because it isn't implemented in some cases". Wonderful. We map this SMC call to 0 is SPECTRE_MITIGATED 1 is SPECTRE_UNAFFECTED SMCCC_RET_NOT_SUPPORTED is SPECTRE_VULNERABLE For KVM hypercalls (hvc), we've implemented this function id to return SMCCC_RET_NOT_SUPPORTED, 0, and SMCCC_RET_NOT_REQUIRED. One of those isn't supposed to be there. Per the code we call arm64_get_spectre_v2_state() to figure out what to return for this feature discovery call. 0 is SPECTRE_MITIGATED SMCCC_RET_NOT_REQUIRED is SPECTRE_UNAFFECTED SMCCC_RET_NOT_SUPPORTED is SPECTRE_VULNERABLE Let's clean this up so that KVM tells the guest this mapping: 0 is SPECTRE_MITIGATED 1 is SPECTRE_UNAFFECTED SMCCC_RET_NOT_SUPPORTED is SPECTRE_VULNERABLE Note: SMCCC_RET_NOT_AFFECTED is 1 but isn't part of the SMCCC spec Cc: Andre Przywara Cc: Steven Price Cc: Marc Zyngier Cc: stable@vger.kernel.org Link: https://developer.arm.com/documentation/den0028/latest [1] Fixes: c118bbb52743 ("arm64: KVM: Propagate full Spectre v2 workaround state to KVM guests") Signed-off-by: Stephen Boyd Acked-by: Will Deacon Acked-by: Marc Zyngier --- I see that before commit c118bbb52743 ("arm64: KVM: Propagate full Spectre v2 workaround state to KVM guests") we had this mapping: 0 is SPECTRE_MITIGATED SMCCC_RET_NOT_SUPPORTED is SPECTRE_VULNERABLE so the return value '1' wasn't there then. Once the commit was merged we introduced the notion of NOT_REQUIRED here when it shouldn't have been introduced. Changes from v2: * Moved define to header file and used it Changes from v1: * Way longer commit text, more background (sorry) * Dropped proton-pack part because it was wrong * Rebased onto other patch accepted upstream arch/arm64/kernel/proton-pack.c | 2 -- arch/arm64/kvm/hypercalls.c | 2 +- include/linux/arm-smccc.h | 2 ++ 3 files changed, 3 insertions(+), 3 deletions(-) base-commit: 66dd3474702aa98d5844367e1577cdad78ef7c65 diff --git a/arch/arm64/kernel/proton-pack.c b/arch/arm64/kernel/proton-pack.c index 25f3c80b5ffe..c18eb7d41274 100644 --- a/arch/arm64/kernel/proton-pack.c +++ b/arch/arm64/kernel/proton-pack.c @@ -135,8 +135,6 @@ static enum mitigation_state spectre_v2_get_cpu_hw_mitigation_state(void) return SPECTRE_VULNERABLE; } -#define SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED (1) - static enum mitigation_state spectre_v2_get_cpu_fw_mitigation_state(void) { int ret; diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index 9824025ccc5c..25ea4ecb6449 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -31,7 +31,7 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) val = SMCCC_RET_SUCCESS; break; case SPECTRE_UNAFFECTED: - val = SMCCC_RET_NOT_REQUIRED; + val = SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED; break; } break; diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 15c706fb0a37..0e50ba3e88d7 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -86,6 +86,8 @@ ARM_SMCCC_SMC_32, \ 0, 0x7fff) +#define SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED 1 + /* Paravirtualised time calls (defined by ARM DEN0057A) */ #define ARM_SMCCC_HV_PV_TIME_FEATURES \ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \