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: 10241691 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 E469060208 for ; Mon, 26 Feb 2018 08:55:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBE762945A for ; Mon, 26 Feb 2018 08:55:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D082729D6C; Mon, 26 Feb 2018 08:55:14 +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 5F0412945A for ; Mon, 26 Feb 2018 08:55:14 +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:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sEIZPmlBFKBmwQuUfwGKOIYPNzyczEc0KiMjhE7PD78=; b=VgirebJkGDSI5X ZHlDUUets7PnlJNt7l+j2kVNrDWc1We5s6JzrxJjWtqh7xbAH2A1FffU7ygswidjobuajwL8ihKaJ LIV5meocJYd8TM/GWw/fDQZ4sWIkSSlv56kfrW+8395rOphYpuz/L+QC+8W5o/mWfNEaGHLJ16H0K 0XzISEJIhuRzsZCJSFVEPgPz1vpnMiXvJdvjHlQgmDwNMS6MOwwdKz1tD7UKYkro8xRofJSpDmfUU gy9eXLNnOcWOe7OpuysBhCv/6WYG0rRBM7xy79u+zOQwQDi7uTiV8LNh1qqnrK9Tyk2olWmOPjbA+ oOR7U/FeI6wWOxaqOxkw==; 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 1eqEYw-00015X-7m; Mon, 26 Feb 2018 08:55:10 +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 1eqEJr-0005la-TX for linux-arm-kernel@bombadil.infradead.org; Mon, 26 Feb 2018 08:39:36 +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:To:From:Sender:Reply-To:Cc: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=1RaPKZO6eEZg+WHRSpnHizT0jS04yyLzTCiVvYJ2E2U=; b=RUlyWVIZuT5fUKwHZS/wlxJsK EDvDR9pAK/NIxbHDPZ3s8bmS1SrchGuQ09c+N0oJS/eT9WvT8XGsXnOEU469xNNxeLWIM2Y0ZxVv3 0lK9HS0asGv8Mh5/cV2neXyuLcWAx1takbDDzXYQ85N6yLM+yt93FTOPBRYGH6eiCc3A0OCv8mO7e wenrwaugRbGio1wUtSsGZfQ84eCnJhB1/JyZF44NFfty3majMfgRYQ1UC4cMG4L5L6fVZz87FkZBq 9DLijbqtYFMxQzi7TJp4KdegfHIvNtq74tjVVKkUa/L8AU9udw0VKAL+4FOpFSQ5YXB/njz+Ckl/z t4K22LAmg==; Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqE6n-0006IG-59 for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2018 08:26:07 +0000 Received: by mail-pf0-x243.google.com with SMTP id y186so5539462pfb.2 for ; Mon, 26 Feb 2018 00:25:55 -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=sq4e/d//huZG0uaBWvVP6M57WS/MgGn1Pteonhrr/+ezNat1/l2E2NbQZ8ljYnjniM FR9oRLfcU5LGK1PAuxp7xlW9HXJqO3fTLU1EUCfNLhf02vr/sWyB45k1p2fOZAJr2l9e vnk577WILR3N7Ln2Agq2f4wUrzJfQ7UtSK1aSTaPBa10/ztNK3FrWBex/dJKP3w76rqS iVqJoJa9echLShWimDoKqk1rDJGOvsrnw9ACyj8hRV5P9TQidD2H/R2aJ0N0NhMGKLR7 6qsw2/6JmIQZBlG1cFmoWybJlLhMDD4NGXCS6BXdH15uZsMPTnneWvQhivYRoLICZM0B NyBQ== X-Gm-Message-State: APf1xPBpRsG9NtNSs8pZjPM7Kvz+usC7wHilFgXIZXGH+AyeRAmfnetW V3CqS0he4IK2ff+IyUgsHsl+ig== X-Google-Smtp-Source: AH8x2261ip32ESoaUUJMgG2qXq37FfCK0Frp+J0W6ow2faItx/vDYgVb4W74DrqCiqMh/Z0I2NowYw== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_082605_187498_A27ADD21 X-CRM114-Status: GOOD ( 21.59 ) 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: , 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 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__ */