From patchwork Fri Mar 9 09:07:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10270397 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 113246016D for ; Fri, 9 Mar 2018 10:26:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E69D029D71 for ; Fri, 9 Mar 2018 10:26:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB60A29D75; Fri, 9 Mar 2018 10:26:27 +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 24BF629D73 for ; Fri, 9 Mar 2018 10:26:27 +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=cxStpZN1z/iEp2MeTAn6ojFRDwEYWdT6Oi2W20C+WXk=; b=KZhSQT7GGC9uy5Y0Qbfj3HKvG+ 5y0a7vPbsQYjOktE+Zj2UcJe28Lhvf9Z7fG7uSYZxYCjSp+paPGs00ePVHnrnAcsqS520qoR5nwk/ YoXfbKE6nCAasF5At65MZB5tH8gPpqr1AypZqNU7U1QJxUNaHhb5iFP64+8eedYjXR9PDTJWx4C92 sY7abKSAgBDwGdlE2FL9Fj5L4wpkSpvPF91NutM1vyk7z1H4HJres6CyInXCf69J3ZrT9nRxYFeun Ew9tGbd5MZZtrexlueQidna/W/rA+ulPaiZltMWSFDOADeV2b0/+/SL1Y8rqY1cMhUvA5Xt/gHR8I tdndYiBw==; 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 1euFEB-0001Hy-DF; Fri, 09 Mar 2018 10:26:19 +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 1euF7Z-0002qN-Hc for linux-arm-kernel@bombadil.infradead.org; Fri, 09 Mar 2018 10:19:29 +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=6IAKFt41L6If/Fx4uGTYFYQK1+0cuc3GMEmhzFr45B8=; b=dVZxYtGmuMDv6cIiMd7zNXXgj sss/a+i6YmHx9uq/wLEwHmAHOYz5RDegj5EBvyVgEFpbpCKNq6XJt+BC9hjae5gsiMo6masbSq4ZW ngcub7xpkXmcNTafdnzzNqymmYUBkJspBAnYjsaoZImaMpqx4NY+7oOGY/uPn4ypxtMY9dn/hOOaD bzV2p4CjEBAbal3TS9Ot1CNuMaxYL1eRP2M/dEqym70GgYcVWTKazXzvtmMWwBS1abmUFAoWlxeeb EzZDwlkZ8vcU1q3afHwdhSUpQVsTJuhlwns2LDdfYa2DPsu/uCumAON77RhKGeHed9Iig2cZoj6m9 da9szqXEA==; 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 1euE4C-0002iR-ER for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 09:11:57 +0000 Received: by mail-pf0-x241.google.com with SMTP id h19so1047484pfd.12 for ; Fri, 09 Mar 2018 01:11:46 -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=6IAKFt41L6If/Fx4uGTYFYQK1+0cuc3GMEmhzFr45B8=; b=kUk4UZPj1Axt5YJNO3Hy90fp/k4EMVw6BOiSFvIgvg08Pf3vgvJc+MwqZZ52S9nSrq bshs8+nz4Lir/44pI0qDGGiY4YFYZtBnsYt8JQAuUJ9hZBclkym+tLw9c8WL689Qq2M8 q77F56x1NPIEmRvJ2JAKpleCqOEKIdKpKnHPE= 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=6IAKFt41L6If/Fx4uGTYFYQK1+0cuc3GMEmhzFr45B8=; b=X6fIdCGAexzUhw1tMS7x4a/QBnWVHE7f/wOZfIU2Xj3E8C7or96X+uifcVoEkV99bh UMuLbSGtWTBqPfbSUbVZLeqG+BSerTvgnQvuuo0uFEF/2zXDZ8avmCuuoaExOTGjNCr7 l+t9ekV4nMHsD/CaTwlPfqXeol69wSEvzVSemaFfHXD2H9oM3hcbQ/CuYX1mWPQsgd8n anq7keVeLsaZzwCmHZznKwf4s86dplSMzvRoR3gO/EkYTh8Q9tNJ+50NkptSQMTNWXG2 0gQc10kk0wcvWd6Taqbw+cQ9DJ/DSjJDCru2+4AdGA56jOzuJEOHbxe+AY8J1GSOV2OC O0ZA== X-Gm-Message-State: APf1xPDu6vfN0ZFSLs6BNWpcbYYp82U1fkCXstJ5p5Kx7dc0eNlaqUfw 0vgdbDKaEfJigvnGU1SdCaeKEA== X-Google-Smtp-Source: AG47ELu6elRtYq0lIOhIcPkSnWVzoIUiIi0mp/9h6DO7b+gJcCK0iMYFqRI3h97s3f6utaOjm4o09Q== X-Received: by 10.99.154.18 with SMTP id o18mr24051664pge.344.1520586704241; Fri, 09 Mar 2018 01:11:44 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 01:11:43 -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 31/39] arm/arm64: KVM: Advertise SMCCC v1.1 Date: Fri, 9 Mar 2018 17:07:14 +0800 Message-Id: <20180309090722.26279-32-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_041156_527122_89BB7196 X-CRM114-Status: GOOD ( 18.07 ) 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 09e6be12effd upstream. The new SMC Calling Convention (v1.1) allows for a reduced overhead when calling into the firmware, and provides a new feature discovery mechanism. Make it visible to KVM guests. 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/kvm/handle_exit.c | 2 +- arch/arm/kvm/psci.c | 24 +++++++++++++++++++++++- arch/arm64/kvm/handle_exit.c | 2 +- include/kvm/arm_psci.h | 2 +- include/linux/arm-smccc.h | 16 ++++++++++++++++ 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c index fc911e349a18..7bce79dcc746 100644 --- a/arch/arm/kvm/handle_exit.c +++ b/arch/arm/kvm/handle_exit.c @@ -43,7 +43,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) trace_kvm_hvc(*vcpu_pc(vcpu), *vcpu_reg(vcpu, 0), kvm_vcpu_hvc_get_imm(vcpu)); - ret = kvm_psci_call(vcpu); + ret = kvm_hvc_call_handler(vcpu); if (ret < 0) { kvm_inject_undefined(vcpu); return 1; diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 84027927986b..a74e3a67ef7a 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -338,6 +339,7 @@ static int kvm_psci_1_0_call(struct kvm_vcpu *vcpu) case PSCI_0_2_FN_SYSTEM_OFF: case PSCI_0_2_FN_SYSTEM_RESET: case PSCI_1_0_FN_PSCI_FEATURES: + case ARM_SMCCC_VERSION_FUNC_ID: val = 0; break; default: @@ -392,7 +394,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) * Errors: * -EINVAL: Unrecognized PSCI function */ -int kvm_psci_call(struct kvm_vcpu *vcpu) +static int kvm_psci_call(struct kvm_vcpu *vcpu) { switch (kvm_psci_version(vcpu)) { case KVM_ARM_PSCI_1_0: @@ -405,3 +407,23 @@ int kvm_psci_call(struct kvm_vcpu *vcpu) return -EINVAL; }; } + +int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) +{ + u32 func_id = smccc_get_function(vcpu); + u32 val = PSCI_RET_NOT_SUPPORTED; + + 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 */ + break; + default: + return kvm_psci_call(vcpu); + } + + smccc_set_retval(vcpu, val, 0, 0, 0); + return 1; +} diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index f1b00be0b829..031691843729 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -41,7 +41,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) trace_kvm_hvc_arm64(*vcpu_pc(vcpu), vcpu_get_reg(vcpu, 0), kvm_vcpu_hvc_get_imm(vcpu)); - ret = kvm_psci_call(vcpu); + ret = kvm_hvc_call_handler(vcpu); if (ret < 0) { vcpu_set_reg(vcpu, 0, ~0UL); return 1; diff --git a/include/kvm/arm_psci.h b/include/kvm/arm_psci.h index 32360432cff5..ed1dd8088f1c 100644 --- a/include/kvm/arm_psci.h +++ b/include/kvm/arm_psci.h @@ -27,6 +27,6 @@ #define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0 int kvm_psci_version(struct kvm_vcpu *vcpu); -int kvm_psci_call(struct kvm_vcpu *vcpu); +int kvm_hvc_call_handler(struct kvm_vcpu *vcpu); #endif /* __KVM_ARM_PSCI_H__ */ diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 632dbb45a110..80e6a6bb8a20 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -60,6 +60,22 @@ #ifndef __ASSEMBLY__ #include #include +#define ARM_SMCCC_QUIRK_NONE 0 +#define ARM_SMCCC_QUIRK_QCOM_A6 1 /* Save/restore register a6 */ + +#define ARM_SMCCC_VERSION_1_0 0x10000 +#define ARM_SMCCC_VERSION_1_1 0x10001 + +#define ARM_SMCCC_VERSION_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0) + +#define ARM_SMCCC_ARCH_FEATURES_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 1) + /** * struct arm_smccc_res - Result from SMC/HVC call * @a0-a3 result values from registers 0 to 3