Received: by 10.223.185.116 with SMTP id b49csp3490504wrg; Mon, 26 Feb 2018 00:27:23 -0800 (PST) X-Google-Smtp-Source: AH8x226/9mDrnekk3e8lum1JdQIiEslGOi9KDEOGU8Uq4uuZNCjjEm7kaMbfj8wfKOQ90gpwmobq X-Received: by 10.98.245.131 with SMTP id b3mr9853210pfm.20.1519633643806; Mon, 26 Feb 2018 00:27:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633643; cv=none; d=google.com; s=arc-20160816; b=LlSRIxBp7CXyR6mVAkE+cdT4++C65deG1v4RzhYHFc9nxQpLCzwS9BwB5Yb/C5QH2C aCBj5hHZcV9VABcn9v6P6mnaGqbntY/zdTdWQMrvsz1ccDeFyNGnms5ajZzOpm3FrD8s Rpt+x4wS7o/3kyZA0H9uDcit2EV3l6TuLLNbAU0MlCKtTDwBOROrGfo5jiGDIyuznnIO d4CPzyUuEDsAnCirSG2K1Jte6FVXydX/2WsgDF2ptOd8tuh2/QuEKeZrsm2QMBd5mWRk X3/nG7O51ZKv429hLZX/s8pPQtcGW3tBCo8ARnwN/3sbH8p0znj1MBr6yWAzZgA7plit yNDA== 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=1RaPKZO6eEZg+WHRSpnHizT0jS04yyLzTCiVvYJ2E2U=; b=YTGYwHOmhCg4zGt2t45vsrRE8Syx8VZHL+Jkz3rbsDyCUvlWrNSsTJh3MQK45izGB/ GDRqAXaX85+O6E4i5nbVoNSpA5dZ+EkTnnHKE/VnankXg0T5P5iVSJhPtfT6fwYUhNFH MfJKEbxFNOQ0GFnU+JyAKWXpERTE3V70eUkpUHS7LiDOdM+WB21rBmhuc6bPK31QyTMW NxalfrljSS0iLjLSA5Bi8O69rZ+pMU2M+DAPO29S+6/nyxHvvWQ1GC1Pkykvw6OL2LTu 5o/ewJ1ixFOT1Oh/4/JZr8uACntNQpzNRc2qaujG3BAJIoxmerlCzPJ3PAKHj2Dpciah i/Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=enGsPUns; 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 20si6342239pfp.312.2018.02.26.00.27.09; Mon, 26 Feb 2018 00:27:23 -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=enGsPUns; 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 S1752703AbeBZI0B (ORCPT + 99 others); Mon, 26 Feb 2018 03:26:01 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:39760 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752253AbeBZIZy (ORCPT ); Mon, 26 Feb 2018 03:25:54 -0500 Received: by mail-pf0-f196.google.com with SMTP id c143so6225471pfb.6 for ; Mon, 26 Feb 2018 00:25:53 -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=1RaPKZO6eEZg+WHRSpnHizT0jS04yyLzTCiVvYJ2E2U=; b=enGsPUnsm+rGZ3967eUBFmebBMV609UJ2zknLGBLShaV2vJ9LWGdLzFp9gqOiJ5xWh eqAWUacYx6U+Rek47L07Sr9PTS5zy84MhA5M4TkcSlD2NJDlYk0DqJUU0qoWKrFo0wXS oskIb/aQo82DYH127fazCPKXOwx34TNBQ5f6s= 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=1RaPKZO6eEZg+WHRSpnHizT0jS04yyLzTCiVvYJ2E2U=; b=kg54ylXhJjkUBgnish5xZzExBVUoMz+8gf7BGW0tOsZFuGiMLCMJuN8pm2Cvf/lsdv apQozdrPt7C/0nWjhjMoIfjcmzXx73kIhUIwe0pp8U/v6LntsNgvun3i2TcvQm2bMwyn 130pP3EORGycu8w1L1AwPh7Cf1vucRo30ef+1G3yyU72LTMVD2IquNPXPdA4Furs8mMc 3g8KXxrkr0xHZKgF2lKS3ICtWUj78pYuKpy4wytm6hGkzi+mE4Hg/KE6t/W42sGFHJnn eBRlf9RJS062P0XEtommJW5wjtgyanXLUpGicH3Rl2fs0+KX6b6XPREw6tAZkNyhh51O rKnQ== X-Gm-Message-State: APf1xPC180DHae7IVgHnAnQrhpoS1aHnPNyQME4p8vGkZamN4nVwphMK xb4fdqHrDRUbp/mZifFgq1WVIQ== X-Received: by 10.98.74.67 with SMTP id x64mr9824654pfa.135.1519633553460; Mon, 26 Feb 2018 00:25:53 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:25:52 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, Christoffer Dall , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , 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 37/52] arm/arm64: KVM: Turn kvm_psci_version into a static inline Date: Mon, 26 Feb 2018 16:20:11 +0800 Message-Id: <1519633227-29832-38-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: 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 Conflicts: mv changes from virt/kvm/arm/psci.c to arch/arm/kvm/psci.c --- 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