Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2354499pxb; Mon, 20 Sep 2021 19:54:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/FYRh3u6t4dNpraxwzE7ke4Xo6nKe7iMXNBoe/0DddxfH9ymFS8E3aAQZPDnQHS6TvSKL X-Received: by 2002:aa7:c4ce:: with SMTP id p14mr31569958edr.129.1632192843597; Mon, 20 Sep 2021 19:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192843; cv=none; d=google.com; s=arc-20160816; b=b6x0EnWRSMsvDRR19GWGZt+WmJRJXfsWMb39WSw83fasOL7tbUB/ifgvia51mozUEZ MrQO6yHZPzwxv8fDi5/GneEQ8UUcD3Ubr+qbpw6/1WsLJ1htLSYEKx38qrDjNUSwma/k zzcRxQhhPTphVvY4JZ4ue/R7WayhPkoHuwql7dXVe14fCWONKHmk7bsF7oNRRbbTl9Va EjRaY/NwFrs3hQgYHV4zDz0mu3HSszFd2na8E0RqLOhOd9EY24o/jJZvc2L/pjW09+VR jZdiPBjARLRBiWlD5w4+SmvIluItYlXOOjgpiW2w6Det/VLNSdCG0RbFYZ9aaP7rkF4a GV1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HMnFhtwBhVWuci9hen6rQnRTh/hcfFyTGUx0wY1qLRQ=; b=YMbmXDjCFFOrnHPzHNttIzpJ243O+WTBv/smAXmr30Y/yf8SbP/PG+vE+bAVtuc1Ai FesTChLPcCLaeCVnCpTxIOswYtf9CMviyyBkOz5hZMaeBGL1fsBKNvRMOBwKh1eQaiAf VvJTeskjZvSIi8apbcMnye1iaDihPK4aUgeTzFWVsZQlZza/KmDDSLKhGDUoCRmuH8RM wIQyj7Gap534ZBrDihEBt5OZm4hoNgkD+/URGxmCSCt8RPaQbD35DRSOIk/DQjROftv6 F4iE4wX8ELsiYmHLtoyLne1JyKrbww4Exvz8fsTUNByWoGDnAQXtbW1BoKbUw38u3BOG E9VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="U7Y/YCEV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c4si14962891ejc.709.2021.09.20.19.53.40; Mon, 20 Sep 2021 19:54:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="U7Y/YCEV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385007AbhITSt1 (ORCPT + 99 others); Mon, 20 Sep 2021 14:49:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:59876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384101AbhITSqd (ORCPT ); Mon, 20 Sep 2021 14:46:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E4E0A63363; Mon, 20 Sep 2021 17:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159222; bh=BvUepuoep7XTWaVhs83x1LXOtgm9K1UWGy0biRI2gO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U7Y/YCEVjx5wJPuXyAp1x3uzChBur+IZEi1rd9jXymj9IKlbpJen2GdCP6pl4qjLj rb+PwpIEV1/BtUde6E2FR9f9ZEI6jPrlWLchgRdp+00Q3siZ/GzbuByQjtJ+mqFbkA jfKbFl+j9QA54zJmszF5JXM6S1yNQR1BSUHi0MJk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Scull , Quentin Perret , Will Deacon , Marc Zyngier , Sasha Levin Subject: [PATCH 5.14 101/168] KVM: arm64: Make hyp_panic() more robust when protected mode is enabled Date: Mon, 20 Sep 2021 18:43:59 +0200 Message-Id: <20210920163924.960132609@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon [ Upstream commit ccac96977243d7916053550f62e6489760ad0adc ] When protected mode is enabled, the host is unable to access most parts of the EL2 hypervisor image, including 'hyp_physvirt_offset' and the contents of the hypervisor's '.rodata.str' section. Unfortunately, nvhe_hyp_panic_handler() tries to read from both of these locations when handling a BUG() triggered at EL2; the former for converting the ELR to a physical address and the latter for displaying the name of the source file where the BUG() occurred. Hack the EL2 panic asm to pass both physical and virtual ELR values to the host and utilise the newly introduced CONFIG_NVHE_EL2_DEBUG so that we disable stage-2 protection for the host before returning to the EL1 panic handler. If the debug option is not enabled, display the address instead of the source file:line information. Cc: Andrew Scull Cc: Quentin Perret Signed-off-by: Will Deacon Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20210813130336.8139-1-will@kernel.org Signed-off-by: Sasha Levin --- arch/arm64/kvm/handle_exit.c | 23 ++++++++++++++--------- arch/arm64/kvm/hyp/nvhe/host.S | 21 +++++++++++++++++---- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 6f48336b1d86..04ebab299aa4 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -292,11 +292,12 @@ void handle_exit_early(struct kvm_vcpu *vcpu, int exception_index) kvm_handle_guest_serror(vcpu, kvm_vcpu_get_esr(vcpu)); } -void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr, u64 elr, +void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr, + u64 elr_virt, u64 elr_phys, u64 par, uintptr_t vcpu, u64 far, u64 hpfar) { - u64 elr_in_kimg = __phys_to_kimg(__hyp_pa(elr)); - u64 hyp_offset = elr_in_kimg - kaslr_offset() - elr; + u64 elr_in_kimg = __phys_to_kimg(elr_phys); + u64 hyp_offset = elr_in_kimg - kaslr_offset() - elr_virt; u64 mode = spsr & PSR_MODE_MASK; /* @@ -309,20 +310,24 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr, u64 elr, kvm_err("Invalid host exception to nVHE hyp!\n"); } else if (ESR_ELx_EC(esr) == ESR_ELx_EC_BRK64 && (esr & ESR_ELx_BRK64_ISS_COMMENT_MASK) == BUG_BRK_IMM) { - struct bug_entry *bug = find_bug(elr_in_kimg); const char *file = NULL; unsigned int line = 0; /* All hyp bugs, including warnings, are treated as fatal. */ - if (bug) - bug_get_file_line(bug, &file, &line); + if (!is_protected_kvm_enabled() || + IS_ENABLED(CONFIG_NVHE_EL2_DEBUG)) { + struct bug_entry *bug = find_bug(elr_in_kimg); + + if (bug) + bug_get_file_line(bug, &file, &line); + } if (file) kvm_err("nVHE hyp BUG at: %s:%u!\n", file, line); else - kvm_err("nVHE hyp BUG at: %016llx!\n", elr + hyp_offset); + kvm_err("nVHE hyp BUG at: %016llx!\n", elr_virt + hyp_offset); } else { - kvm_err("nVHE hyp panic at: %016llx!\n", elr + hyp_offset); + kvm_err("nVHE hyp panic at: %016llx!\n", elr_virt + hyp_offset); } /* @@ -334,5 +339,5 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr, u64 elr, kvm_err("Hyp Offset: 0x%llx\n", hyp_offset); panic("HYP panic:\nPS:%08llx PC:%016llx ESR:%08llx\nFAR:%016llx HPFAR:%016llx PAR:%016llx\nVCPU:%016lx\n", - spsr, elr, esr, far, hpfar, par, vcpu); + spsr, elr_virt, esr, far, hpfar, par, vcpu); } diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S index 2b23400e0fb3..4b652ffb591d 100644 --- a/arch/arm64/kvm/hyp/nvhe/host.S +++ b/arch/arm64/kvm/hyp/nvhe/host.S @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -85,12 +86,24 @@ SYM_FUNC_START(__hyp_do_panic) mov x29, x0 +#ifdef CONFIG_NVHE_EL2_DEBUG + /* Ensure host stage-2 is disabled */ + mrs x0, hcr_el2 + bic x0, x0, #HCR_VM + msr hcr_el2, x0 + isb + tlbi vmalls12e1 + dsb nsh +#endif + /* Load the panic arguments into x0-7 */ mrs x0, esr_el2 - get_vcpu_ptr x4, x5 - mrs x5, far_el2 - mrs x6, hpfar_el2 - mov x7, xzr // Unused argument + mov x4, x3 + mov x3, x2 + hyp_pa x3, x6 + get_vcpu_ptr x5, x6 + mrs x6, far_el2 + mrs x7, hpfar_el2 /* Enter the host, conditionally restoring the host context. */ cbz x29, __host_enter_without_restoring -- 2.30.2