From patchwork Fri Mar 9 09:07:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10270191 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 8BD6560236 for ; Fri, 9 Mar 2018 09:27:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8698529D8A for ; Fri, 9 Mar 2018 09:27:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AE8429D76; Fri, 9 Mar 2018 09:27:18 +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=ham 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 0321429D76 for ; Fri, 9 Mar 2018 09:27:17 +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=iQlxZRLMAWDQVwQFjzHQIYhayhMa3EXbSTRuBX4Kgbs=; b=R5veP53RotjAjMWC7nu1ziK2dZ Sq1VPuU9DCwyLGbE7udIrf5pNG+yzUUMdUjTGgmWHe6HHVgtrnkBTMg0tIXsA0tjNzr4iuPTyxviM gAWuo+akXdchbuh7rPiV3vYdcFOxpIvcE0j13HKlFyOYb4uCSfiPHAe+9xDi7YU2mcNQnolTeQN0x hdq18bgINseHYF2819mkAeu87OwxC3TkTwN2Qzo/Cg9ETh3bj4r1rhL9M1ShoQ79sfmAf3Ce3qjKq lgi9bxz8L1Qc6NmkgZOtSMnwii0C9Uoil+S+0EYi9oBHHayEYn8DBlb0ky2MOT0TGRM5hdUWYqIpT drF5HOMg==; 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 1euEIu-0000a1-P4; Fri, 09 Mar 2018 09:27:08 +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 1euEHn-0008EU-09 for linux-arm-kernel@bombadil.infradead.org; Fri, 09 Mar 2018 09:25:59 +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=K+O5ciLHiOVzbK32mHCZssy0JHHf8sOn790hKrJElvA=; b=Kk4h1Zp1P3OnTnGPhUfOGt9ke 49Ilpbomt6mENwvwxKCvU1Pn2yXhRjG3rM59hwqq0DIiFa5NSHCAR6eWCoiW+p6iomSdj5Z5lKrut qQjM1LsI1LRO6ukYQJItzEJseoQMTDBm2U2dQfW4/IolGE78e3LrY9kRTxrsAfgs2E/P1VT23b8ca VLJr/gaNAHM8C8qd8SSOU1HoRiRDdK2FpkWwbia/ln94cykDU+xdaqvgqWuozsDnf8hnYNG9Yk02A oew+A7LgEVJoHw/QQ/Y8/gLjAlc1eC73C/MobDyYiRM8H+5PF0LljGM1LL7OnC+DqcpEyw/MCkPdL KUkbr5wGw==; Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euE4I-0001lr-Nf for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 09:12:05 +0000 Received: by mail-pl0-x241.google.com with SMTP id y8-v6so4914778pll.13 for ; Fri, 09 Mar 2018 01:11:52 -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=K+O5ciLHiOVzbK32mHCZssy0JHHf8sOn790hKrJElvA=; b=BmjPtu5Y22DWrGow43PsAjKddrgduU8aPVhKiUmBcM8siQupfCy3yBP3DSFBunmYGi niePcik8toeY15WIJ+z9VDVtyLsJ7GIq1sHzXk9Xl0/6gSDbmL+XkaNu4fsBbDQbzuwL K+foeGi0BrvIvRfFX0gAA1DckHhdqLCreJb4o= 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=K+O5ciLHiOVzbK32mHCZssy0JHHf8sOn790hKrJElvA=; b=FWbqfIG+0wEhkET66ONTpFfb50UH3PFJeakGGdt0z5+C7Ma/0rpM46/rBO2l9Mn0y+ 7kLnG4VWdyw9IrZv+svZiNpglQndYhGIU1Ic75TwpbFZSV0DwyDjnppFMDs3UO7e+1/z PV9ksNRW+DedKAf5ucpA3eLxwvte3MJHJosclimFCVvChl91NY7nvPpjL2JlP0rn1VwI WzOBPqN1q5UtUA0nAfbl33+59OCnHKaOBPQrd+g1ZGvISgbUERZQgC+cyHqWvdfIrMvY 7w+9lHJVkN42rBa6aFokWXJ2mG8D+mmTpcX+0T5w3I9eD7cZtRp3NWACpKf2IH2Q3Y+p OOjg== X-Gm-Message-State: APf1xPAuwjjqLPyOFfHPOb6wwTwmWA+H2fo/RIpByal3m5oNMuUr1bof VioSrMnqRopOi8ToSOPnF39AIw== X-Google-Smtp-Source: AG47ELsK8yzBz2EeyJ+gWsnrczZpt0nrHxp1mG3c2bsGC6bHI3N19ZM3fMzQAi8xdic0BpcBbVFKhg== X-Received: by 2002:a17:902:684:: with SMTP id 4-v6mr26372414plh.262.1520586711162; Fri, 09 Mar 2018 01:11:51 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id c7sm1961752pfg.36.2018.03.09.01.11.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 01:11:50 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , broonie@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 32/39] arm/arm64: KVM: Turn kvm_psci_version into a static inline Date: Fri, 9 Mar 2018 17:07:15 +0800 Message-Id: <20180309090722.26279-33-alex.shi@linaro.org> X-Mailer: git-send-email 2.16.2.440.gc6284da In-Reply-To: <20180309090722.26279-1-alex.shi@linaro.org> References: <20180309090722.26279-1-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180309_091202_764482_674118C0 X-CRM114-Status: GOOD ( 20.20 ) 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 ++---------- include/kvm/arm_psci.h | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index a74e3a67ef7a..6f691d7b9fdc 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/include/kvm/arm_psci.h b/include/kvm/arm_psci.h index ed1dd8088f1c..e518e4e3dfb5 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__ */