From patchwork Thu Mar 1 12:54:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10251465 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 ADE92605FE for ; Thu, 1 Mar 2018 13:43:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C910201BD for ; Thu, 1 Mar 2018 13:43:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 915BC2018F; Thu, 1 Mar 2018 13:43:24 +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=unavailable 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 AF604209CE for ; Thu, 1 Mar 2018 13:42:39 +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=TwkeI0KwGe5t4hOb0gE97waVlI4w6LkgyUXMd4HZ/Lg=; b=pO01PucRoCriPqihakREGLGNkr K4gILnSCb/haTyCTFH0jKaymOEk+/D0oNXBv8w+Cb9rlaUs5Pjpm9FyqxXRID2Gpe4PJs3ojVfc1D 55ZNo+iDOHxu5bLGtbVY8wXQpO2/Fd/qKLPAy7F1pUr1YAXsq7FZkVM9gI9Y6tGV3W3NNArCY3BBa u01jCkkczc7es/474wb4FjBrOLRaLfhmMWFBrtaTFi/lIiYeDGEUYgEsrKKfJiSUaY2/akB3YC+kh HjSVTmmEoZwBnXQjA/rqlTHSyOtQ61uMGUp+LgPEmg6A6sDVenRPoO/yTdATfwP6DdLx6ekjHxsVe VwbrhI1A==; 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 1erOTi-0004tE-Ey; Thu, 01 Mar 2018 13:42:34 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erO0O-0005gV-Dh for linux-arm-kernel@bombadil.infradead.org; Thu, 01 Mar 2018 13:12:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=vuv71HvEZ9HnAUJTQ52hE3U6SvzV4oqNvK9jHSVsfaA=; b=oqApHA6/rcGVf/+tPWM7zE+KB 7/mmZ2V+FbWNu/3RA/piAvV7uTIICrGY9QdtmHOt3o8qml0Yed3fTiq5O+eod4IOjUdRXGHdS/fNl 7yaEIQQDM95RmbHox6qH99sR1Gn4WgHWGRzkZ78NN0s4Lx3XHuAR4tQQLUNEmGkhBKAnmQuAnvNXA RYKxvIkW4U/B9BX63BFEVKFy7regsTNy1EhtaG+rAoUn3n9sUUwhZCRHWoLRrViQwga7x7bQVUVKF IJzJyrGbzJeV7NpsANr02NIn6iUVnbYE8u3zqJk8MPKO+wYrVvb0m0RpFNh63lfAJpi0GX7ZjaKpM EQdB/oG4w==; Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNom-0005Cg-Ee for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 13:00:19 +0000 Received: by mail-pf0-x241.google.com with SMTP id h11so2011559pfn.4 for ; Thu, 01 Mar 2018 05:00:06 -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=aPSmMLVJuJmaCFBpbqe0zeegGV4y/6f7JvVLi8s4D+3xEb5KS4hlbRa+2jLTBRCxh/ +7ExkeT2eyCMFmMbIl+5/Y3DslJCRfJiymql+Sx7DkKxjjIcbqyE95nd/tNHqCDuQFw+ TjU5NRCqgxfflPz4vjxcN2tZDP+P/zGVQNUxjJeJ6hkBUTMR/Zw4E2oV8bqA6ACIEjD/ b9wMvN0dBzpBPTdIaBUyVbr2bg64RJ0/cv2Tv8b1i2bD+70g44htzcEfLwcclcE6IhRq OBfBKPrl2K9agqs+5+fq4b/8+LpxcFgzce8CfgMnJsi49ydFk1OtaKYiQg/5ANnYQbdS /bTw== X-Gm-Message-State: APf1xPBWpUdCVgsSqla5YycUQTQaNF5vIwe8VQgX9ebOHS9TEEtFUE6h vF5jWKcrVRflTIUUsb/FTvee6A== X-Google-Smtp-Source: AG47ELtgSL1sTSRJuBjBP4LdFCUZmrPYO3mW3EHExX/14b1ZDvOGzGeSzo9GLHApwXH3/j69nhGmWQ== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_130016_548375_BAF4482E X-CRM114-Status: GOOD ( 19.34 ) 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 | 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