From patchwork Thu Oct 12 10:41:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10001541 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 7CA71602BF for ; Thu, 12 Oct 2017 10:42:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E5B128BEC for ; Thu, 12 Oct 2017 10:42:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 630E528D4E; Thu, 12 Oct 2017 10:42:32 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 02CFC28D6E for ; Thu, 12 Oct 2017 10:42:32 +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:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=p5FYSWh9T9jW8rqxd7PnNprg5//980S2pAv6tcyK3Ns=; b=mBPaw8T+BVqcITmxQOqyp658w2 IdXRUPsyHqa0+edaropkAb/Aw9fSA9DdO2IS7Dkdz75uB8g4s/iaT+S9d4YFe73IvoyPXvNheh4EH j7sVrn4RsLTi7uT/GTOVODbLng+T6ISXfjrNHcMlAhJnJ7e6m2rXPtGvgYMeRYbMrsUQc+wiDUdkn DpQm9fJGus06DMH5Iw4Kij2ttbQwXPAiifMVrFv7kG6OohStdO0ehREW9HtfHaV7BPosfFmLWS53m r7hhX7Sw4S6Vh6ZI5sd1YQuxkBEWF7+jsLZDfZRuSxlfc3tpYgEpv82VG2xG8MtC0LOkwPf0wupie K+APrf4g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e2awK-0007ZT-SJ; Thu, 12 Oct 2017 10:42:08 +0000 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2awG-0007Tn-3I for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2017 10:42:06 +0000 Received: by mail-wm0-x22f.google.com with SMTP id u138so12156667wmu.4 for ; Thu, 12 Oct 2017 03:41:45 -0700 (PDT) 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=CqnRUOK0+XIZmtfJV282JdQ+HFjCIh6SO7/OcZ0F3ng=; b=fkVohn/IfOwnJvhok1a9BQuW/GMfbue5SuD+ed8R3jjoaHhtR6sF18QAEJWp3Rmegn AWasAMuCR83TtAy4NzLQIzgYLddwLDfCd+a45E2Q8lHw37DN9atUE7Uybm6+IQ92Rwsa OOjJrvBYVqbT9DhL0Jz7N8rPT9jypvwfmCPwg= 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=CqnRUOK0+XIZmtfJV282JdQ+HFjCIh6SO7/OcZ0F3ng=; b=jQFSVP3Sgqs8E3ZvShTnv6nbuZLcB9cBAGteVXSCpruS9kACvAjP4VJ77g3kVqK5Hg PvsBOVX7dJtASjItUdL4PPzZ1CFjBb9D99N+iUqbU/zm0pbgAisipgYnUT9/eA3u31qd r3J63aO9YHZ+cLkwSRCKzVrFNOLTzaWHBwcgx9mq3ySBmRKCiY2dWV2l8PSfPvja2EM2 3hw1vPwlkAu59e1cwtu/BCchFITFU5u5Gkq/wmFfcIYqg2N/c10HiQHYXIeYTTq0QHbx PRASQ0FaJm+OE5/HAtKyWtReTSpcC+xp4Cmk4AnqiPHxNTtDQ3fPxZXQdOzYscAWkUNa DcVg== X-Gm-Message-State: AMCzsaVrI6CN8FGomUSowvk86NF46U3M/2ltxfzU8wr40efJAEWKPpco a3XCd4+vnqH1VuLBG45ii6T0sw== X-Google-Smtp-Source: AOwi7QCJ3GuhVXwCIq7wC+XW60PXPvno4JY3wTYDOQogQ60HY6myVFPTA9LG4r5hmhGTuwGUro6d/w== X-Received: by 10.80.161.134 with SMTP id 6mr2364412edk.197.1507804904000; Thu, 12 Oct 2017 03:41:44 -0700 (PDT) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id g49sm4798603edc.31.2017.10.12.03.41.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Oct 2017 03:41:43 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 02/37] KVM: arm64: Rework hyp_panic for VHE and non-VHE Date: Thu, 12 Oct 2017 12:41:06 +0200 Message-Id: <20171012104141.26902-3-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171012104141.26902-1-christoffer.dall@linaro.org> References: <20171012104141.26902-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171012_034204_489146_1195A8C3 X-CRM114-Status: GOOD ( 17.85 ) 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: , Cc: Marc Zyngier , Christoffer Dall , Shih-Wei Li , kvm@vger.kernel.org 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 VHE actually doesn't rely on clearing the VTTBR when returning to the hsot kernel, and that is the current key mechanism of hyp_panic to figure out how to attempt to return to a state good enough to print a panic statement. Therefore, we split the hyp_panic function into two functions, a VHE and a non-VHE, keeping the non-VHE version intact, but changing the VHE behavior. The vttbr_el2 check on VHE doesn't really make that much sense, because the only situation where we can get here on VHE is when the hypervisor assembly code actually caleld into hyp_panic, which only happens when VBAR_EL2 has been set to the KVM exception vectors. On VHE, we can always safely disable the traps and restore the host registers at this point, so we simply do that unconditionally and call into the panic function directly. Signed-off-by: Christoffer Dall --- arch/arm64/kvm/hyp/switch.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index a0123ad..a50ddf3 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -394,10 +394,20 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) static const char __hyp_panic_string[] = "HYP panic:\nPS:%08llx PC:%016llx ESR:%08llx\nFAR:%016llx HPFAR:%016llx PAR:%016llx\nVCPU:%p\n"; static void __hyp_text __hyp_call_panic_nvhe(u64 spsr, u64 elr, u64 par, - struct kvm_vcpu *vcpu) + struct kvm_cpu_context *__host_ctxt) { + struct kvm_vcpu *vcpu; unsigned long str_va; + vcpu = __host_ctxt->__hyp_running_vcpu; + + if (read_sysreg(vttbr_el2)) { + __timer_disable_traps(vcpu); + __deactivate_traps(vcpu); + __deactivate_vm(vcpu); + __sysreg_restore_host_state(__host_ctxt); + } + /* * Force the panic string to be loaded from the literal pool, * making sure it is a kernel address and not a PC-relative @@ -411,40 +421,31 @@ static void __hyp_text __hyp_call_panic_nvhe(u64 spsr, u64 elr, u64 par, read_sysreg(hpfar_el2), par, vcpu); } -static void __hyp_text __hyp_call_panic_vhe(u64 spsr, u64 elr, u64 par, - struct kvm_vcpu *vcpu) +static void __hyp_call_panic_vhe(u64 spsr, u64 elr, u64 par, + struct kvm_cpu_context *host_ctxt) { + struct kvm_vcpu *vcpu; + vcpu = host_ctxt->__hyp_running_vcpu; + + __deactivate_traps_vhe(); + __sysreg_restore_host_state(host_ctxt); + panic(__hyp_panic_string, spsr, elr, read_sysreg_el2(esr), read_sysreg_el2(far), read_sysreg(hpfar_el2), par, vcpu); } -static hyp_alternate_select(__hyp_call_panic, - __hyp_call_panic_nvhe, __hyp_call_panic_vhe, - ARM64_HAS_VIRT_HOST_EXTN); - void __hyp_text __noreturn hyp_panic(struct kvm_cpu_context *__host_ctxt) { - struct kvm_vcpu *vcpu = NULL; - u64 spsr = read_sysreg_el2(spsr); u64 elr = read_sysreg_el2(elr); u64 par = read_sysreg(par_el1); - if (read_sysreg(vttbr_el2)) { - struct kvm_cpu_context *host_ctxt; - - host_ctxt = __host_ctxt; - vcpu = host_ctxt->__hyp_running_vcpu; - __timer_disable_traps(vcpu); - __deactivate_traps(vcpu); - __deactivate_vm(vcpu); - __sysreg_restore_host_state(host_ctxt); - } - - /* Call panic for real */ - __hyp_call_panic()(spsr, elr, par, vcpu); + if (!has_vhe()) + __hyp_call_panic_nvhe(spsr, elr, par, __host_ctxt); + else + __hyp_call_panic_vhe(spsr, elr, par, __host_ctxt); unreachable(); }