Received: by 10.223.185.116 with SMTP id b49csp7396306wrg; Thu, 1 Mar 2018 05:01:45 -0800 (PST) X-Google-Smtp-Source: AG47ELv8iAWurA/Ud90jIvHsGSTUS5xRKWL7ppqhXwAyWLM90WQPGYqhJwJ0v7P683613FLFZ7wv X-Received: by 10.99.125.25 with SMTP id y25mr1497586pgc.227.1519909305244; Thu, 01 Mar 2018 05:01:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909305; cv=none; d=google.com; s=arc-20160816; b=RknDxhdaqJKVaZrjGEyFdnyWRQqfW/N8q5r39mjwcUVUe9/Mg4dMTie3SN4xg9Jm4x ES7vKK+Q1/9O8khPs2y8uEFe5tI2QUFGhikvnwUJ81sTvLJQddVZQq0h7vnBkWpIhyRI q9DpqRO8L/PvqGVNjAYJGcZ7R/yvEgpH5bEReq+e99t8rEV2mSNuskO8tcc9rwE3iR9O BEFQwk/RaTWz8V0tIceHEg+Kp4GYktclY0TpOfE1Hc8OAbE7lGRvmcmrd+OWYpbOn42U zAsH5tgla9Te8/xlWJntX5d6ybflGNMpJlZm3Ng2yMBMx1E1R0LRzFPtajrsrv0iYACA vHQA== 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:dkim-signature:arc-authentication-results; bh=/+g8Mla38uMrMfR6tapxbEKrs5n2o8KvDdig+FWlP0U=; b=GANCJeVg2CRY3nkGJONtjnXMrCb2XvFwtUnJHW7z0VuFVO+hlv00dRoTvtqBCpb9av E3uXDYO+HfJ/HUSeYQ1pNy2KPF8ptn2g7V9fhfT6lvKfXvXXCKdgv7z8iQx3yvrA8ePa VVQr845PifHr00imcU7KggwM7XyHnOLD/Wb5o6p6e3Y6npTjCdIexM9S5t7Yrk1TlO/w 7rUQ58q15nyH6kxUWbTps8hFxMxc1LM9EakOgoJNYhuog0kHLQcMrF7WVSqITjnRfaUa ZOCiZ2QeAbHGuONEVs2n7ue6aI49kvO7Cd4cQFbpEyIXsDQAz1b3uCzLWmuUSux65FsH EQUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DQBYvdGO; 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; 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 v11-v6si1345328plz.386.2018.03.01.05.01.22; Thu, 01 Mar 2018 05:01:45 -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; dkim=pass header.i=@linaro.org header.s=google header.b=DQBYvdGO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031103AbeCANAY (ORCPT + 99 others); Thu, 1 Mar 2018 08:00:24 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:38271 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031094AbeCANAU (ORCPT ); Thu, 1 Mar 2018 08:00:20 -0500 Received: by mail-pl0-f65.google.com with SMTP id m22-v6so75269pls.5 for ; Thu, 01 Mar 2018 05:00:20 -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=SEcsxdmDFhkY7i70Ca2OA5kxllhbgHiaHT8DY9SuH2/CcL2MuLYuLj6BScaWCS2Wjl j/LquTkozISM3Z3cbs/HFfpoGLRZGu9nySTceP9qzCv6NgcIF8sE+iAD8emzH/LNdRdL maTsYlevB77wZ0raKd/Ch/SUlCU9ahLBCEXcn9kkM3cANt0NYrse4TdQa7N8Br/dVzxo cqLMF2Qf5JEcd8lvRCwAqH1EEeSb0I8CdL/Bekp//O5iI+Si0E18DxUMXvixsLm3WRxK Q77qGjqqtMYIfCMaC7vw+Cmm8YTWyC5HFBylrMqcIijUOKafh32xlDY0CEqW2Ysoa8R+ B57Q== X-Gm-Message-State: APf1xPC+K6uY4ge8CdI0uPqEN7XTknjCVzG7ZtIs6TzjEwFGI6TruiIc WCH6PRrSVU7Nn/+V650nAGhdtQ== 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 Cc: Alex Shi 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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__ */ -- 2.7.4