From patchwork Thu Mar 1 12:54:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10251391 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 457F3602B5 for ; Thu, 1 Mar 2018 13:28:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 335432015F for ; Thu, 1 Mar 2018 13:28:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2824420182; Thu, 1 Mar 2018 13:28:11 +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 B57C52015F for ; Thu, 1 Mar 2018 13:28:10 +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=wengVHqRwpOS7r/Z/1mj+TJgyPTL85+AplQQyvODLtQ=; b=kxNza9HbVNChN5jgC6m8BUWVGy cKJUb+chP0kHncxFokXw54gzM7Uvp/utlteSLrdeYea04x8hyIO5SHzKATGrDcSGWP25fc1F/+DCj DQiQ/RlM7b+TMPpFIfWsEJDo9GP5KOAFH9ponYencWmsJoH9dXr+8qhQgvhq6xvywdwlWRB9cRbcB czyWkvf6KqfosJogt+Rhg+i6vY5N8CKgelbhOaeyySNCht3p9tLo8xnjn/si+KLbC0L35V93qAYq1 H7Xj0PlX18vX1OXWSOFw5fcaq5Y93OB6rLgfFi9y9NuQ1aQF9LOeHREJ4AjAc6vLQrKYPqgh22t1x kUZg6gUQ==; 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 1erOFd-0000vQ-VG; Thu, 01 Mar 2018 13:28:02 +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 1erO0K-0005NC-DL for linux-arm-kernel@bombadil.infradead.org; Thu, 01 Mar 2018 13:12:12 +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=/+g8Mla38uMrMfR6tapxbEKrs5n2o8KvDdig+FWlP0U=; b=gO37Fgcl5+b4OB8Ipo7VswKL4 n/frud+0Q0JyzGQnYIObbp//HQxoGG1YRZ8BU/uQHtZxqTdK3Pxu1eYWIFkOGQRr1RWuWg1Mk2zuW MfAlR5GLVgcuMsA36jArCfMZ+obquWhvCFJaVK7JmS1YY01hYq5F/YobcSQ+VNe8ulEH5ZovqyifV UfkWHtVV3xDDEw7mecqKL+R06QxYxFAajac7XzJ3BKmEwbXTmoJfClFtSluy5hx6h9bxKvplWRkyS J9odgHjgLeqZCG4ccUuIevfoXeQOJvNubOu0dsIIoz/MZ+NMAcxJOvXpZfCfBCqNJx0ZMPPP95s6P dIri9o4vA==; Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNp1-0005FS-Tl for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 13:00:35 +0000 Received: by mail-pl0-x244.google.com with SMTP id bb3-v6so3600578plb.2 for ; Thu, 01 Mar 2018 05:00:21 -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=/+g8Mla38uMrMfR6tapxbEKrs5n2o8KvDdig+FWlP0U=; b=DQBYvdGOnOaO7HF/5ssmRJUALIhN7DYHPWq7nj+87TgOt3gdCCDAxhYD5ljJmPXktW o2AeKIRGxN5gALi3mVK7npTIcZlDtdD1Xm5c9IPmUznpPSF/GkerHM6fkKa/aRNlgH7p eZN+KWeZOwh44hgnNH7lRYaY20Qi/KLrqS9dw= 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=/+g8Mla38uMrMfR6tapxbEKrs5n2o8KvDdig+FWlP0U=; b=p5HG8GD3pjW3Q2NoLqEOXBOH0Q/aIyT6FBvbqYgX4DttqBXIRwCzHk1mmTOc2vNO1d L47RE1LoDA+dMK0qEj8+ZrXzr/AqbqgClUXZVS/q5QIZiQ6JjIe8oRxRnJSn8BL525ye lDNtYkycf+gpsSuZyymWq/q/2yZeMv8gacbzz0QmjHsgRDUr3WJJ2o5MhRW53H7MT/G0 tLU7d/px8LIT5fbh2ydwzDgkoGkgvWtvbK9zXynFazO2wbAeJc1h9LUxDI0vUEiZbiWg Tuu+MSHBQv4kXyKE7jJmrSlwf67g89NrP8AIMIELe1qW4bCxtjsNGATTpNFl8wHaSDow YlwA== X-Gm-Message-State: APf1xPAjIiQm70sL2cWuLjUzc3PanVFxgjqAp7+ByqnlNw6voB4jgjq2 ifW5LTUzpDGk5OYv0cIRtEPeig== X-Google-Smtp-Source: AG47ELvpbtXJMZWpASzK7r51f75rqRBVXl9U1Krdva+VcDgbDztkGJFq/KM5Wsce1LnU3orbmlYe7w== X-Received: by 2002:a17:902:968d:: with SMTP id n13-v6mr1912241plp.33.1519909220204; Thu, 01 Mar 2018 05:00:20 -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.05.00.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 05:00:19 -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 37/45] arm/arm64: KVM: Turn kvm_psci_version into a static inline Date: Thu, 1 Mar 2018 20:54:14 +0800 Message-Id: <1519908862-11425-38-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_130032_210981_8E9BD205 X-CRM114-Status: GOOD ( 22.29 ) 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 a4097b351118 upstream. We're about to need kvm_psci_version in HYP too. So let's turn it into a static inline, and pass the kvm structure as a second parameter (so that HYP can do a kern_hyp_va on it). 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/psci.c | 12 ++---------- arch/arm64/kvm/hyp/switch.c | 20 ++++++++++++-------- include/kvm/arm_psci.h | 21 ++++++++++++++++++++- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 7b44253..396eb5d 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -121,7 +121,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) if (!vcpu) return PSCI_RET_INVALID_PARAMS; if (!vcpu->arch.power_off) { - if (kvm_psci_version(source_vcpu) != KVM_ARM_PSCI_0_1) + if (kvm_psci_version(source_vcpu, kvm) != KVM_ARM_PSCI_0_1) return PSCI_RET_ALREADY_ON; else return PSCI_RET_INVALID_PARAMS; @@ -231,14 +231,6 @@ static void kvm_psci_system_reset(struct kvm_vcpu *vcpu) kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_RESET); } -int kvm_psci_version(struct kvm_vcpu *vcpu) -{ - if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features)) - return KVM_ARM_PSCI_LATEST; - - return KVM_ARM_PSCI_0_1; -} - static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) { struct kvm *kvm = vcpu->kvm; @@ -396,7 +388,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) */ static int kvm_psci_call(struct kvm_vcpu *vcpu) { - switch (kvm_psci_version(vcpu)) { + switch (kvm_psci_version(vcpu, vcpu->kvm)) { case KVM_ARM_PSCI_1_0: return kvm_psci_1_0_call(vcpu); case KVM_ARM_PSCI_0_2: diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 3eab6ac..996328e 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -19,6 +19,8 @@ #include #include +#include + #include #include #include @@ -311,14 +313,16 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) if (exit_code == ARM_EXCEPTION_TRAP && (kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_HVC64 || - kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_HVC32) && - vcpu_get_reg(vcpu, 0) == PSCI_0_2_FN_PSCI_VERSION) { - u64 val = PSCI_RET_NOT_SUPPORTED; - if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features)) - val = 2; - - vcpu_set_reg(vcpu, 0, val); - goto again; + kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_HVC32)) { + u32 val = vcpu_get_reg(vcpu, 0); + + if (val == PSCI_0_2_FN_PSCI_VERSION) { + val = kvm_psci_version(vcpu, kern_hyp_va(vcpu->kvm)); + if (unlikely(val == KVM_ARM_PSCI_0_1)) + val = PSCI_RET_NOT_SUPPORTED; + vcpu_set_reg(vcpu, 0, val); + goto again; + } } if (static_branch_unlikely(&vgic_v2_cpuif_trap) && diff --git a/include/kvm/arm_psci.h b/include/kvm/arm_psci.h index ed1dd80..e518e4e 100644 --- a/include/kvm/arm_psci.h +++ b/include/kvm/arm_psci.h @@ -18,6 +18,7 @@ #ifndef __KVM_ARM_PSCI_H__ #define __KVM_ARM_PSCI_H__ +#include #include #define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1) @@ -26,7 +27,25 @@ #define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0 -int kvm_psci_version(struct kvm_vcpu *vcpu); +/* + * We need the KVM pointer independently from the vcpu as we can call + * this from HYP, and need to apply kern_hyp_va on it... + */ +static inline int kvm_psci_version(struct kvm_vcpu *vcpu, struct kvm *kvm) +{ + /* + * Our PSCI implementation stays the same across versions from + * v0.2 onward, only adding the few mandatory functions (such + * as FEATURES with 1.0) that are required by newer + * revisions. It is thus safe to return the latest. + */ + if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features)) + return KVM_ARM_PSCI_LATEST; + + return KVM_ARM_PSCI_0_1; +} + + int kvm_hvc_call_handler(struct kvm_vcpu *vcpu); #endif /* __KVM_ARM_PSCI_H__ */