Received: by 10.223.176.5 with SMTP id f5csp3170059wra; Mon, 29 Jan 2018 09:48:02 -0800 (PST) X-Google-Smtp-Source: AH8x22460utsFCJI9hQroDUkOsFMBNMP+PyQTZvNABY4JwfkRfKSl55AuW6lZNbKnWfLYXw4extd X-Received: by 10.98.228.5 with SMTP id r5mr28263959pfh.193.1517248082464; Mon, 29 Jan 2018 09:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517248082; cv=none; d=google.com; s=arc-20160816; b=uqn3dOBg2Fj67fTDGyj+0Ev3ndjhlKMJBj0hN5JQNYSlDw86nZsiu8ecE+NOV/rSvT Q0wpndiIsSkDh6s2LItd5Mjsjw+47Cfu9iKpBXm7pMnfuC7dFNjDUBQ/b0LsSjx75nve jmoLRm+NKqR4E62Z29HUF5h4fZ9qU1MYW9VUEmJUNIi/m1mSTAfjFDEFIwP4fKMQCjT3 NHoNO7OU6685zDZ885EqZXs2IQk1CKWOihjORyROLRVjyxubuiGBjaWmmFwpQq7NsKqi BJEEc80tPsvPJoi6bbm6DXsEcIo2R/sZM0oAKGRw2mC5QbcumP2I4Q1Q9TVCOmvU0jee xabQ== 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:arc-authentication-results; bh=Ir97slddoRv/AN6lupZv+LIzNZgWkjdasd0ObkcrnTI=; b=m71xM7xsCLCFSIcEfPSuwYRNzFi3EXJhQ8DUyoRVG0mWvL76A7Q/FpU7o6YI1b7Tze 8iBqbNfEUmC4/DOJ/n+DJZgzznOWi9+7BqU56s0t97wTI4VKC6AyO1oAHDrFbjD4dwjR uFxHX5irDuy4s70DLY2q+1n/770Yo6D3T5nYLFsV3XSmkWO63Lk7karrIoySbFkUeS1E KS2o3xsp1anLPjZHT6EyT5ExpkmVQ/yam5xLspBtalbSuKFD/fwimiw3ZLFzD+O6J+7v baSUulrTCe8UHRLTcDjAJkoT6iYAgt6szKIEr/biTEaTasNWv9O+g4H8yrb5bUFryFmG fuUg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o14si7758857pgr.340.2018.01.29.09.47.47; Mon, 29 Jan 2018 09:48:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751835AbeA2Rq5 (ORCPT + 99 others); Mon, 29 Jan 2018 12:46:57 -0500 Received: from foss.arm.com ([217.140.101.70]:43542 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751663AbeA2Rqd (ORCPT ); Mon, 29 Jan 2018 12:46:33 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AC27D15BE; Mon, 29 Jan 2018 09:46:32 -0800 (PST) Received: from approximate.cambridge.arm.com (approximate.cambridge.arm.com [10.1.207.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 992963F487; Mon, 29 Jan 2018 09:46:30 -0800 (PST) From: Marc Zyngier To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: Catalin Marinas , Will Deacon , Peter Maydell , Christoffer Dall , Lorenzo Pieralisi , Mark Rutland , Robin Murphy , Ard Biesheuvel , Jon Masters Subject: [PATCH v2 08/16] arm/arm64: KVM: Advertise SMCCC v1.1 Date: Mon, 29 Jan 2018 17:45:51 +0000 Message-Id: <20180129174559.1866-9-marc.zyngier@arm.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180129174559.1866-1-marc.zyngier@arm.com> References: <20180129174559.1866-1-marc.zyngier@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Marc Zyngier --- Documentation/virtual/kvm/arm/psci.txt | 12 +++++++----- arch/arm/kvm/handle_exit.c | 2 +- arch/arm64/kvm/handle_exit.c | 2 +- include/kvm/arm_psci.h | 2 +- include/linux/arm-smccc.h | 13 +++++++++++++ virt/kvm/arm/psci.c | 24 +++++++++++++++++++++++- 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/Documentation/virtual/kvm/arm/psci.txt b/Documentation/virtual/kvm/arm/psci.txt index 2e49a4e9f084..aafdab887b04 100644 --- a/Documentation/virtual/kvm/arm/psci.txt +++ b/Documentation/virtual/kvm/arm/psci.txt @@ -13,7 +13,7 @@ a migration causes a different PSCI version to be exposed out of the blue to an unsuspecting guest. In order to remedy this situation, KVM exposes a set of "firmware -pseuodo-registers" that can be manipulated using the GET/SET_ONE_REG +pseudo-registers" that can be manipulated using the GET/SET_ONE_REG interface. These registers can be saved/restored by userspace, and set to a convenient value if required. @@ -21,8 +21,10 @@ The following register is defined: * KVM_REG_ARM_PSCI_VERSION: - - Only valid if the vcpu has KVM_ARM_VCPU_PSCI_0_2 feature set - - Returns the current PSCI version on GET_ONE_REG - - Allows any supported PSCI version compatible with v0.2 to be set - with SET_ONE_REG + - Only valid if the vcpu has the KVM_ARM_VCPU_PSCI_0_2 feature set + (and thus has already been initialized) + - Returns the current PSCI version on GET_ONE_REG (defaulting to the + highest PSCI version implemented by KVM and compatible with v0.2) + - Allows any PSCI version implemented by KVM and compatible with + v0.2 to be set with SET_ONE_REG - Affects the whole VM (even if the register view is per-vcpu) diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c index e020cc82c4b1..a4520c7118d2 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/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 97e8d64a203d..bb6e1518d819 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -52,7 +52,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 f2fa7d752c4e..4876bfac2195 100644 --- a/include/kvm/arm_psci.h +++ b/include/kvm/arm_psci.h @@ -26,7 +26,7 @@ #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); struct kvm_one_reg; diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 4c5bca38c653..dc68aa5a7261 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 diff --git a/virt/kvm/arm/psci.c b/virt/kvm/arm/psci.c index 682f9be6264b..3bb336ac7d7d 100644 --- a/virt/kvm/arm/psci.c +++ b/virt/kvm/arm/psci.c @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -353,6 +354,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: @@ -407,7 +409,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: @@ -421,6 +423,26 @@ int kvm_psci_call(struct kvm_vcpu *vcpu) }; } +int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) +{ + u32 func_id = smccc_get_function(vcpu); + u32 val; + + switch (func_id) { + case ARM_SMCCC_VERSION_FUNC_ID: + val = ARM_SMCCC_VERSION_1_1; + break; + case ARM_SMCCC_ARCH_FEATURES_FUNC_ID: + val = -1; /* Nothing supported yet */ + break; + default: + return kvm_psci_call(vcpu); + } + + smccc_set_retval(vcpu, val, 0, 0, 0); + return 1; +} + int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu) { return 1; /* PSCI version */ -- 2.14.2