From patchwork Tue Feb 27 11:33:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10245003 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 551C860362 for ; Tue, 27 Feb 2018 12:07:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4381828884 for ; Tue, 27 Feb 2018 12:07:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 378AE28886; Tue, 27 Feb 2018 12:07:25 +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 974CB28884 for ; Tue, 27 Feb 2018 12:07:24 +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=NGHXBRzsX8IuSYXHBsSegnc9GHYPAW4WJVLR/kyi18Y=; b=Z9DL4oUMjlzHnH5IYD0h18gBFm 8diTX9G7ao7xpnRp+q3V+6R+GCGL56f2mk6veLYmbJq0dp7qTr/KK9Zx4jVFOBPrUqUmMuMK84mdu NItOoS517rOutvpoXWhI0SF4PJb3C9oJnrl/f0dBEBuIZeJp/2OStIbaJlyo4jepSEnSi8iaExl6U snqo2pHdpH3lKKw88Lwj8GJu68QobcaQXuDzC4ANuyHg6YPXYNfYdVEv4vWD/QlVFqGhSDFh2sUMn LCTl/qWbs9FYhuUoODdpN9pijzHgMWE5lvkz7Rc0dhJ3IhMe4CcV2pQQNGFQyslhoO+afSVkXGR+n pDHcEWzw==; 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 1eqe2Q-0002zs-Jv; Tue, 27 Feb 2018 12:07:18 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqdWv-0006W3-Jq for linux-arm-kernel@lists.infradead.org; Tue, 27 Feb 2018 11:34:52 +0000 Received: by mail-wm0-x243.google.com with SMTP id z81so23371117wmb.4 for ; Tue, 27 Feb 2018 03:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=0chYf7swLLXaZjJg5A9YAgsAgsmf3+AwiqYW/mWEK9s=; b=0jaUsSX/J64eXkzr6zanxSEMyRSOPTvSXKwTY8VmxQ48TJpz5Un1Ab0W2ZNbQBlxRi Dc4tws28RV4FQcRbKSvQ8314yH5llgVSgiZtFfWPTzig4DUZJoqKZ7HSXam5MuxreLgc q5pxxika9XOAarE8NjJ/IsLXqmcZ32BgtzBp814rCQAXRsLqP2kyW0Uxwzy0V+LYHGHy bBZR4BFzcURP0sYavv4o8LqzG5s9U+AhU7RfNfIFn6QI7MYdLkhJTiSMRAE3WiUuk/Rj H6cJwibBoR4PrvN/eIRZI2eZT7pgWdkrKGiAGZmls2qXKgTaLJ+trCTrVuka2SOtqA28 EKww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=0chYf7swLLXaZjJg5A9YAgsAgsmf3+AwiqYW/mWEK9s=; b=jIlx1DTDlDOEylBxYxPCGxvhTSlhUyhvktK8NUGHd6DyTfxBvdA2IvbbZ9Z7VxhH97 obEGiRYMo4yATL7BvUzDAbpTUQrld3jgIAZTChuntQ8bLqY+mcZ/13TnESsecBCBNu47 mzZhWmpC+AYkvzloHkPO6QVyfrs/8MWtOz/q8Tg1IazWmG/n+bKjFG06xvljch6uNKZc Yzt9OtqK5RmpX0IYX/9CrbsUG1JWjQ62Up4Clime4JMNouG7uZJardgy2H0dpPuC4Ay0 2BgD0WYsHYnSIYNUNy4TVRQNp1KTSGaaQaSOlDHi/pTEHR/Lr0G6Q0RSXeuljG+nDKT8 naZA== X-Gm-Message-State: APf1xPBkxhdH9uR+s8ErudHe4YoVk8w501Qe1HuWXicBJFaN4r0Vu7vW J8shaUE3VnPUNLLbQufHrlzzJQ== X-Google-Smtp-Source: AH8x226/ivbcwf65XKvhna03Au73HzHog42IiSy0RjacNwQtqnoIXxYloGhzsQ/E+//CtGNewCyeHw== X-Received: by 10.80.240.213 with SMTP id a21mr18070831edm.77.1519731277928; Tue, 27 Feb 2018 03:34:37 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id m1sm9176786ede.39.2018.02.27.03.34.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 03:34:36 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 04/40] KVM: arm64: Rework hyp_panic for VHE and non-VHE Date: Tue, 27 Feb 2018 12:33:53 +0100 Message-Id: <20180227113429.637-5-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180227113429.637-1-cdall@kernel.org> References: <20180227113429.637-1-cdall@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180227_033445_898471_1BCC3DA8 X-CRM114-Status: GOOD ( 20.16 ) 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: Andrew Jones , kvm@vger.kernel.org, Marc Zyngier , Tomasz Nowicki , Julien Grall , Yury Norov , Dave Martin , Shih-Wei Li 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: Christoffer Dall VHE actually doesn't rely on clearing the VTTBR when returning to the host 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 called 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. Acked-by: Marc Zyngier Reviewed-by: Andrew Jones Signed-off-by: Christoffer Dall --- Notes: Changes since v1: - Fixed typos in the commit message - Still use the generic __deactivte_traps() function in the hyp panic code until we rework that logic later. arch/arm64/kvm/hyp/switch.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 46717da75643..579d9a263853 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -439,10 +439,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 @@ -456,37 +466,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(vcpu); + __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)) { - 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(); }