From patchwork Mon Feb 26 08:20:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 129588 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3358349lja; Mon, 26 Feb 2018 00:25:43 -0800 (PST) X-Google-Smtp-Source: AH8x225lQnscGMdxEkOd2eGyvL8cl0qK1E7i/ypIhsQhk364qSu08m0jPK5f4R0FLobnIw0f7Yjd X-Received: by 10.98.242.65 with SMTP id y1mr9603598pfl.232.1519633543192; Mon, 26 Feb 2018 00:25:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633543; cv=none; d=google.com; s=arc-20160816; b=kt1lGKSoJ4zZFEs01sPfpnVOAPrk/OUX9VmRasjYfp6w86H1eQAqdf1et6J+Jbrx7l YqTs2fEjo2vn17gBpumbSq+1brAuFmRPF58L+dKr6NWCuh2Ys2bQtb83/KysPtROV6CH upcKsEmOAiRdLBbEc0K/NEBAg7CsV1GKFkExrBpxcFA1KeTUk6QKJ/8gzGvxztmEKFaY 3yFOaar18VYW6H/RWd8QeXK67nc8hbahqmWs30jxZq1s85solRf7BSLsujTxGF84jOA2 3XNps8cYDG31AI+N4MD4+xaGv/B0bd8lDbZxdE2XgBk41XzKZtd7PPqyTiIcMX3YC4BT CzHg== 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=H7tfl5kZ5mY5Kp8PNNwAbTxKGdVCixLkrRsHCaFV5nCh0TRb4KDEl4kgXUcBdqdKaZ wc9xE5MaCTCH1BTuMr182zN0Wg0dYu66HYN94H6jGUNtBa1P6xT9rI9iSfQ5BHDA0x4d HpG4TjhfAjn+Rbg+XTxhqJQVUBmlPb9e/jJTcUjNC9aax2OocXwZjQ9p1WAEa0IW8vIE BtXD687YsuDmKO44A8eaJZbVrs89vAL321rSUMXoT9WnNeUG6CSF340O2mwQO2jCjgtF WjnicMcyPCKT6D1jYBTCzKTlxtoEQMirpPc979ASWyVU7pUDJFp9AeuxRahYGaKXLDGV HBUA== 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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 73-v6si3704201ple.829.2018.02.26.00.25.42; Mon, 26 Feb 2018 00:25:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S1752034AbeBZIZk (ORCPT + 10 others); Mon, 26 Feb 2018 03:25:40 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:46681 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752420AbeBZIZe (ORCPT ); Mon, 26 Feb 2018 03:25:34 -0500 Received: by mail-pg0-f68.google.com with SMTP id r26so678095pgv.13 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=tpt9hNwe07hS9iSafWe7sixVY0yW/hTVld0klBOQ+t5zkr4aqze5jixstL2veX4tdr 245T4LpT8+3zzlINnsmRlHE4kbi/2Or+HtfJuM1ZaskjVMs3QbpVXjae5JQxjg6KOQJB H+n2Y/HRlNbo7MqV/bSxGH013HlT6NXrc25qc7L5mRzVt0Mfr0+XgAeqoQ1ZmhaHDyTh MGnw+EbyJhAoJ0dSkFDmmfLyLHV7czsf4K/3JEPzM3TDL8XbfnWRAj9ArHOYtRJWZw6u FYH5yGvqmzaNdgCEgBfOxBBKeav5c6DcQQroZTn+VgfUn+uZBBOTM8BRp1C1xEp/8yYK PkIw== X-Gm-Message-State: APf1xPD83Lysmu89diJnQhs5rblyMKEzAbqPdji4LMIAY0m/HoVUTBfR /uuqx9b+QtVki90vZHAXw6FFOg== 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?b?UmFkaW0gS3LEjW3DocWZ?= , 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: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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(-) -- 2.7.4 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