From patchwork Mon Jan 9 06:24:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9503827 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 D70C56075F for ; Mon, 9 Jan 2017 06:27:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7C19280D0 for ; Mon, 9 Jan 2017 06:27:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC06B2823E; Mon, 9 Jan 2017 06:27:46 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B83C2815E for ; Mon, 9 Jan 2017 06:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760692AbdAIG1Q (ORCPT ); Mon, 9 Jan 2017 01:27:16 -0500 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]:38261 "EHLO outprodmail01.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939371AbdAIG0H (ORCPT ); Mon, 9 Jan 2017 01:26:07 -0500 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096P4eS017232 for ; Mon, 9 Jan 2017 01:26:04 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 8A52086 for ; Mon, 9 Jan 2017 01:26:04 -0500 (EST) Received: from sendprodmail01.cc.columbia.edu (sendprodmail01.cc.columbia.edu [128.59.72.13]) by hazelnut (Postfix) with ESMTP id AD0928A for ; Mon, 9 Jan 2017 01:26:02 -0500 (EST) Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by sendprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096Q2Ms041023 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:26:02 -0500 Received: by mail-qt0-f198.google.com with SMTP id a29so74188551qtb.6 for ; Sun, 08 Jan 2017 22:26:02 -0800 (PST) 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=U5HC7ruizG/OI6UbmUN50LCxpsRmvtR53XHpI3gTmzU=; b=HAse2GdDN0abygVsuk2AszCt0ZH3Ay2n1QeKQ0icnTxNKEsg26+KIkqrF1JwCK40ci kFHjbGP6wXnBJeUpr/o9Q9arlqmxF6Oo5gZqguw9xZ2uH/k6w9rN0qKhVFAPsXWyUxxt gDkLiCWEMDqX5QKFwCIpb6E+wglOqT3kCcUZ4CjnhAOmIiSpP7YhEEmRfivnB+N4Mb/D oGtbBNu3KojdNsnXZGaqHxQCpTTWiDtf4uMY8ydSygzZT6ZOAItnoZoSg93gUzMyQ9wU aR/RmpssnoxcvtGtUoY7B5AiLLVSYYeCsyT6efhiFvssXxTxX429W2GAfU9ixXzcGSNC P/Gw== X-Gm-Message-State: AIkVDXKHf7sz0mMm7SCfZFtJoeVAnbvDbPBWuFJTZIl/JPMgSQfIT59UuNISKzlYSX9dPhsu5cHJQjzW6qeQZUFr/mC46mEW3InDanH/sGSmyNntDgSyNK0ENRqF8y7vEDwLgYdA5/oDIfU= X-Received: by 10.237.59.150 with SMTP id r22mr80937458qte.162.1483943162306; Sun, 08 Jan 2017 22:26:02 -0800 (PST) X-Received: by 10.237.59.150 with SMTP id r22mr80937427qte.162.1483943162146; Sun, 08 Jan 2017 22:26:02 -0800 (PST) Received: from jintack.cs.columbia.edu ([2001:18d8:ffff:16:21a:4aff:feaa:f900]) by smtp.gmail.com with ESMTPSA id h3sm8623257qtc.6.2017.01.08.22.26.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:26:01 -0800 (PST) From: Jintack Lim To: christoffer.dall@linaro.org, marc.zyngier@arm.com, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, vladimir.murzin@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, james.morse@arm.com, lorenzo.pieralisi@arm.com, kevin.brodsky@arm.com, wcohen@redhat.com, shankerd@codeaurora.org, geoff@infradead.org, andre.przywara@arm.com, eric.auger@redhat.com, anna-maria@linutronix.de, shihwei@cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jintack@cs.columbia.edu Subject: [RFC 23/55] KVM: arm64: Forward WFX to the guest hypervisor Date: Mon, 9 Jan 2017 01:24:19 -0500 Message-Id: <1483943091-1364-24-git-send-email-jintack@cs.columbia.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> References: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.78 on 128.59.72.13 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Forward exceptions due to WFI or WFE to the guest hypervisor if the guest hypervisor has set corresponding virtual HCR_EL2.TWX bits. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_nested.h | 1 + arch/arm64/kvm/handle_exit.c | 11 ++++++++++- arch/arm64/kvm/handle_exit_nested.c | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h index 620b4d3..8d36935 100644 --- a/arch/arm64/include/asm/kvm_nested.h +++ b/arch/arm64/include/asm/kvm_nested.h @@ -2,4 +2,5 @@ #define __ARM64_KVM_NESTED_H__ int handle_hvc_nested(struct kvm_vcpu *vcpu); +int handle_wfx_nested(struct kvm_vcpu *vcpu, bool is_wfe); #endif diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index ce6d2ef..046fdf8 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -101,7 +101,16 @@ static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run) */ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run) { - if (kvm_vcpu_get_hsr(vcpu) & ESR_ELx_WFx_ISS_WFE) { + bool is_wfe = !!(kvm_vcpu_get_hsr(vcpu) & ESR_ELx_WFx_ISS_WFE); +#ifdef CONFIG_KVM_ARM_NESTED_HYP + int ret = handle_wfx_nested(vcpu, is_wfe); + + if (ret < 0 && ret != -EINVAL) + return ret; + else if (ret >= 0) + return ret; +#endif + if (is_wfe) { trace_kvm_wfx_arm64(*vcpu_pc(vcpu), true); vcpu->stat.wfe_exit_stat++; kvm_vcpu_on_spin(vcpu); diff --git a/arch/arm64/kvm/handle_exit_nested.c b/arch/arm64/kvm/handle_exit_nested.c index a6ce23b..871ecfc 100644 --- a/arch/arm64/kvm/handle_exit_nested.c +++ b/arch/arm64/kvm/handle_exit_nested.c @@ -25,3 +25,21 @@ int handle_hvc_nested(struct kvm_vcpu *vcpu) { return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); } + +/* + * Inject wfx to the nested hypervisor if this is from the nested VM and + * the virtual HCR_EL2.TWX is set. Otherwise, let the host hypervisor + * handle this. + */ +int handle_wfx_nested(struct kvm_vcpu *vcpu, bool is_wfe) +{ + u64 hcr_el2 = vcpu_el2_reg(vcpu, HCR_EL2); + + if (vcpu_mode_el2(vcpu)) + return -EINVAL; + + if ((is_wfe && (hcr_el2 & HCR_TWE)) || (!is_wfe && (hcr_el2 & HCR_TWI))) + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); + + return -EINVAL; +}