Received: by 10.223.185.116 with SMTP id b49csp7396540wrg; Thu, 1 Mar 2018 05:01:52 -0800 (PST) X-Google-Smtp-Source: AG47ELsna6ViHKYi/8J87B8ZCuf5VcWpFe/Qfukqg2QtIuidDdvKvJ8A3F717+PwJEiLmYOe1pJA X-Received: by 2002:a17:902:52ca:: with SMTP id a68-v6mr1857644pli.179.1519909312479; Thu, 01 Mar 2018 05:01:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909312; cv=none; d=google.com; s=arc-20160816; b=Pt+dqq8/L/0WA7elAgQbiHADzyunk+MNUb5vGuA9BEYHHACUOcWa6E2fDZN/Wsnybt UG2HCyZ036EQFV8QJbNcHa9m4UGWk4E5zKaJK5j90aq/XoVkZPFB0fGteR8VBqj6e8BA eDRE0L3+5R+vZ3eRDc1N0sErIcHOIWu4GMto27yzMtOZh/Zea84sRN8G93+nXgfGS0Yf QUsVfcwmg0gH4Xpth7d7stsSL9o/qfln3VC8unlmpXOQUOencU+mUEnfLMphf18JiW+i dzGWrzrnnGWdcKu2S1UtxqoXkyQx62LXJ7bUqQ1tbgQLPygMhlnwGsU7wGGTdilueRN7 pUwQ== 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=vuv71HvEZ9HnAUJTQ52hE3U6SvzV4oqNvK9jHSVsfaA=; b=B1Szvo+hIDNstbCtnUn34jOREsJfQqEH2+uNf+yfK/kfd5JWtWnOUHGcLae+bJAme2 AXAju0n2H6dkVvjEpM9VVOsLsn0zJukqOzhtaSErfCSX9IehyGQGa5U/s7fvGrCr6DEc jJA9xyJ6zgq8T0nDmVpOAZmsNYdOINWf0oi4qOZ1uq/SiEs+DSj+Dsu3UtzZM9JSRLu6 /uQpwvJFuEIbbtgexvBP0gj6MZ4Z/YWqL2HpDYSniB8NHF2j+MRHFTY+vjcSbHK4P4JU kQdPX1YaG6N3SE1gYTmVpl184dNmGWZF23mSdYjrD3rCluXDXk1LllBL+6x74ly/tfww SawQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GqeIjuNj; 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 b89-v6si2986452plb.809.2018.03.01.05.01.36; Thu, 01 Mar 2018 05:01:52 -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=GqeIjuNj; 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 S1031074AbeCANAJ (ORCPT + 99 others); Thu, 1 Mar 2018 08:00:09 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:43014 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030915AbeCANAF (ORCPT ); Thu, 1 Mar 2018 08:00:05 -0500 Received: by mail-pf0-f193.google.com with SMTP id j2so256561pff.10 for ; Thu, 01 Mar 2018 05:00:05 -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=vuv71HvEZ9HnAUJTQ52hE3U6SvzV4oqNvK9jHSVsfaA=; b=GqeIjuNjXZxor3GLsU6Y2KXmuKkjdWSV1yZYtSgDnkbJNcqWzu9QADjLNCLnwyQKcM vniLAn0Wk81/TRsPLSeVLLkci0uT81Ur6XsQKQbFo2lNHC9KqfmSjboosoDS7BkXfHl/ bX3LLQHZcZeoUGQxe08gQJhfvZUxFQHFeR2XU= 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=vuv71HvEZ9HnAUJTQ52hE3U6SvzV4oqNvK9jHSVsfaA=; b=UxSjAhj0EiwefT11j/4zncZGvdkgOsFDYyLls9uYf9RQsVePJ4SqCqK+i0ReXz6NTZ roMhdDC4unytTYB8SCVmHFsBt9E/M1HFrFQPzJuuwrmfxb443gTnykF/huTusLWaunlh 8eP4dLAiUQE+1ipH/tHSbcYO87CjCONTRUDmhUpYFPrXt1uig+EjLBTdc5T7BgQp2kRa rUY+UM28DAfCHWGdwIixnSXk1l2CFEAIG/SpYp4ksM961b1nsTiBoLWG/e9l50e6o29d abWF2OluZ98GWfvzEnW8GT6amvk3lo5MclaQZUjToMvxsDMQJO9Lj1ESl//K1LinbSXq BTMA== X-Gm-Message-State: APf1xPC6WIMVlwoChGS0uJy0+yNVroxA3s89iu7ay9TudjMvbE753zT6 9Kk2quUGn69cNkp+FQaX+/Yo1A== X-Received: by 10.99.109.77 with SMTP id i74mr1449559pgc.73.1519909204541; Thu, 01 Mar 2018 05:00:04 -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.04.59.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 05:00:03 -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 35/45] arm/arm64: KVM: Advertise SMCCC v1.1 Date: Thu, 1 Mar 2018 20:54:12 +0800 Message-Id: <1519908862-11425-36-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 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 | 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