From patchwork Mon Feb 26 08:20:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 129590 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3358585lja; Mon, 26 Feb 2018 00:26:00 -0800 (PST) X-Google-Smtp-Source: AH8x226l3CnCG+ANOAgRPgKwDHKHZ7BnBTych7hwifmVN4sROlIZvvGE4mw2/ZZtaY9Lzyvzxp8s X-Received: by 10.99.159.10 with SMTP id g10mr7683183pge.407.1519633559869; Mon, 26 Feb 2018 00:25:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633559; cv=none; d=google.com; s=arc-20160816; b=oL+gl9nm9TQTEWzRomLcYE3BIfGzoGCTZAgdwidgQg7JYK9H4ZFqomyCCseoAUc6U6 RETL4Q3Q/PY3X9dX19C6hQyiRqDbUfgcilqOaL1uhExwkjn0hGrPNkDzrdeyGZAaeHQF yjrO8Zbj9TZb0AYBLof1ke13hdU8xg0FTDV+Wkcy8Mb7dpcssrZGf68+iTO4v3JSfS6C OiqjOujYTQGEZYptcdD61Qdd+Tc7FlygJRSGdOZcVCOFpTdc1eFSwL1h+nemHYJVLAsW 6SUtClWe/txk2mJCqHGztsuJXYTJPYmzuPh95WiCekC+wEP2wPbmxQLfh7tjdOwWkrHz 5ZZw== 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=GYLVfy2NhMPaJh0XS3VYzUtPfRg41TeJvTd7q9Pr5/myzKLa45ICaIfmKFMrJAnBr0 uc5RVRvrkW4pbe1p+vAi5McVb9Sg/RDy2rV90ockgI3oHYkyUnR555JKWR1tDjkadLSV G9RuelkkQ+2GsbbxTc/PkRsUTI3mCzdYhoe7v9d/yJCPFM3Z5Vh5SocF0ZXacN1OQIxc CAI5v85FpJGfrF8e5WmNgw92jwd3M6kVdo8jdp+ADYBZgtz1WdE/HpsUw0H4YWFwikqm kLaSvYHZ9hDYR+syu9BQl3waeYe7FJ1PWQ4nBTXj40Dy7MJ7onwrCUJ2VE398susP7d/ 9/DA== 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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 u62si5274966pgd.579.2018.02.26.00.25.59; Mon, 26 Feb 2018 00:25:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S1752576AbeBZIZ6 (ORCPT + 10 others); Mon, 26 Feb 2018 03:25:58 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:40131 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752255AbeBZIZy (ORCPT ); Mon, 26 Feb 2018 03:25:54 -0500 Received: by mail-pf0-f193.google.com with SMTP id m5so6218492pff.7 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=rw3wt6LJruCuJe0qLNbuCOIViull+YzTUMufwM0QYK3A02Xu+AmEFipqJgY4z2i+Yn 2LQmJitUQFE2RsGhrzy8FTAID0UezbgVxr2Ilq58CnALX+VNsS5IP23fc9v4+b2Jgr2u uu4edPQLC5D65Wtk9deNWrOdx+8/fHxrDerOlb/ZJqZQ/aP29zLs2PCk0JgDkLEiMVAD 9P0PZApw3PhuVjtiEZ39185Tjd3KfpM7ro6BuDU5nkYFApb6PGf5t1OAxop6EpCROR04 rm5JxWTAr4o/Lm3HK8v0GovM/xGUTM49vAnRSmic6kg5tSOGrh2crVVFlvrQFC4iAdLs XX2Q== X-Gm-Message-State: APf1xPCin3G0GIIiEX4i7Pbt5VAMeDCmU0ppgWP0XqLA4264WtYYIzpr AkXZOx2F+DkEvqXWISt52yUiog== 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?b?UmFkaW0gS3LEjW3DocWZ?= , 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: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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(-) -- 2.7.4 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__ */