Received: by 10.223.185.116 with SMTP id b49csp3490620wrg; Mon, 26 Feb 2018 00:27:35 -0800 (PST) X-Google-Smtp-Source: AG47ELtMd3/QYaQCuPkgcIrXJw5stu8UTg69YZVJBNC2WMfWQ8y2Oy7yj7MebEJgzGoiSBuH5SBi X-Received: by 10.101.69.66 with SMTP id x2mr4279739pgr.438.1519633655234; Mon, 26 Feb 2018 00:27:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633655; cv=none; d=google.com; s=arc-20160816; b=c+I/SIgjXItECulhmpuDL0lJqkHXYaV/BtvNQaNDe9CM4w8xul+Vi/Ggx3JtqZNl8n WqXjzUHEWIyXYMLL4awGBTPqXCGFFu3+Q2xEzJLAlufjiJ5oqItrYWWmGHbky3MpsR5+ 2B/p06bPb0t1FRKeZsv8WHQmZGDodcugYkHX56TSlhB/58VARSlU3tS1yfrH+KIx1HAE qZqe1yRFKMz4Jyh4DQgOAtGOUqVOAR3501kX9xsm16MwjVEEQgRv5NF49+3Iq5TWOMSv 1/o3cBw9O7FTl64QxIHO06ngg12Qd6z1y4k3EiUtgs2vtUZaq0PfwarJx7v82Wj+J5A6 +Iug== 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:to:from:dkim-signature:arc-authentication-results; bh=d7AzDfwawwGLQswEyJ47jtnJY3zEo49brcg9XtRqJ2I=; b=z94Z6wjvTHE6M3rHbps+lc579H4r8oJNHsl8eKTi6/YEJx8m6GnNJ5H6+NJWd70F17 x8u02q2JNpisUw81hRxl3fDNYhptkilnRqJ7nNORv+iA+nM24sw442E/5SnzbNyxtV5x BhCO4jl+aK8i1RntPsZ7gr9kczuV8wuKY42IOG40JtACdSFbJKnFFsrd2y6SID3pDVYW MOq3MQLDUzY3GVKn7J5guzd4Vm+hRWxFHot+YVguNPXCVgInuFjRfJMWdR0usKNPoMTQ ynCFjWdRmZv4sazTLLsNR6NOerUTj5xUFypmSQ44lBhCXxMN2KQNwMVuj1Glvw4RVEs5 a5tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F9bW8+dZ; 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 x32-v6si6349355pld.595.2018.02.26.00.27.21; Mon, 26 Feb 2018 00:27:35 -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=F9bW8+dZ; 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 S1752610AbeBZIZn (ORCPT + 99 others); Mon, 26 Feb 2018 03:25:43 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:38663 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752076AbeBZIZe (ORCPT ); Mon, 26 Feb 2018 03:25:34 -0500 Received: by mail-pg0-f65.google.com with SMTP id l24so5916588pgc.5 for ; Mon, 26 Feb 2018 00:25:34 -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=d7AzDfwawwGLQswEyJ47jtnJY3zEo49brcg9XtRqJ2I=; b=F9bW8+dZecvQMzbS8ejkFcwARWuvthBO3T9ZVb3U9hfhI0DCluBnRTP4W551EuhtPF y92fNzqCp2XcjpKm8YMsJQT+7e/gSXhD5rY+h0dspPhxWgTCCfYC2Q+vJAuwgnGN3Pcz Kg2Yhdpl4DDxphCk1jzyLY+poRQ7wROCQuMio= 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=d7AzDfwawwGLQswEyJ47jtnJY3zEo49brcg9XtRqJ2I=; b=pKXfK2PK3fayT8bCsTO3vc5XIw6Y0aZd038jVKotNC2TgOUVsGdCtxpr3nfSzmhXk+ /XnDUwHP5d/zJ/ONitzOIZ/lOC0xeNJxZo7qP4zCTy8sb4MdmqPVHLPqwVhHAgS3G1kr EZ97LfkuEASvu6YwQBZl7fEK5ocbfx/mlAo2B89Qxf9TwD+90dtD0Z4NqI2Pbdaj8XDM UnjbHq5pI3B6If3XTIfvVSiCY0Eznv+i/y71DBmlgjQflJsdmYwqThqGRWPkGr6HJWbX r/UJrC31ETFQKWqq3TV5xOF0y2he6rhL2xjZpVgOehDNsNFgQapN8c7ejc1WIrOrh9TX TeJA== X-Gm-Message-State: APf1xPB0GxD3IvdkxwOLjAjHZfpPMR/ctz0Qy6iP1jjLoplclkL6LxlX 1H6NlsX47wWYPrUlO6ulWTtV9Q== X-Received: by 10.101.97.72 with SMTP id o8mr7934493pgv.119.1519633533597; Mon, 26 Feb 2018 00:25:33 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:25:33 -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 35/52] arm/arm64: KVM: Advertise SMCCC v1.1 Date: Mon, 26 Feb 2018 16:20:09 +0800 Message-Id: <1519633227-29832-36-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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Conflicts: mv change from virt/kvm/arm/psci.c to arch/arm/kvm/psci.c --- 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 | 13 +++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c index 0a2b758..de1aedc 100644 --- a/arch/arm/kvm/handle_exit.c +++ b/arch/arm/kvm/handle_exit.c @@ -36,7 +36,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) kvm_vcpu_hvc_get_imm(vcpu)); vcpu->stat.hvc_exit_stat++; - 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/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 097632c..7b44253 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 0231ebc..d4047fc 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -43,7 +43,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) kvm_vcpu_hvc_get_imm(vcpu)); vcpu->stat.hvc_exit_stat++; - 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 3236043..ed1dd80 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 4c5bca38..dc68aa5 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -60,6 +60,19 @@ #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) + #ifndef __ASSEMBLY__ #include -- 2.7.4