From nobody Thu Dec 18 09:44:03 2025 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81CC0221471 for ; Thu, 5 Dec 2024 15:34:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733412846; cv=none; b=DyJOA3UpKQadjM+hm8UD1RDAv6U7JAgvKaEF2L8U6D+zYhL1KPQt+4fO5+eRmnaE/JVAOeyFeGwyrvPh8RTBtFEcsp/41B7zfCY8bJdbC8L6GMNvy6/Oin3u9qXzJZI9sSqa+9MGO0Y2c2kq6jjlSfRWeexVbJW2e7Sw0DgKZkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733412846; c=relaxed/simple; bh=Uw3Y4djbQj+oGnM4V8NZ8aD+cLeBaycYn3PSbrmSV2I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OGWX4oPJJTW0+30aM8UF32CbqWB5avc32bgBJhQnD60PeuYHHv/VQSs6eFPK5YJ7lGKleGuImM3RCJqXOqDpBPh+kd4zW0DztgKfkcVSRce8WccVcA4Jc30qppgLmL0MKUDJfp4cs2zCE3TH0eKNxGkWLhNnizQKhswuKi1LhcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=casper.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=eqJcj79h; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=casper.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="eqJcj79h" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=HZSTsH9jPmSjfGOA2jGMGLovn1Q55JGddszKWUZDjoo=; b=eqJcj79hI4wSs88fcoLxxtYL3A lvR/yVNGENcaYUKH66N+Kj8xcULZyLm6TyUbXAEqsJfbMUCAyQzCNONI4guU78uev0o6PYRNUlCbe fyWoIRo1OhSinvFjE74/h08uX8SOu9UtBgsyFlIOAd3Zr7k3WR2g4Hmb6DrtwwEHumHxopnbVXQrC OcXpcP431mrWWQOg539E9zbSoBBB3aJUpGxgOWKSEPufprZd8CxXVO0WRNZHfKjvJ2jqCf4BqxjMs sNge34CK5FExdTjObRDkDfL+p1MWdl+1oBJHG9IDJmzfmBQaCC/yUJ+zJaQ52udgIaPEMUtGhFJ5/ IkdPykLg==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tJDrM-0000000DDpD-3erO; Thu, 05 Dec 2024 15:33:46 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tJDrN-0000000DyMR-3ip1; Thu, 05 Dec 2024 15:33:45 +0000 From: David Woodhouse To: kexec@lists.infradead.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , David Woodhouse , "Kirill A. Shutemov" , Kai Huang , Nikolay Borisov , linux-kernel@vger.kernel.org, Simon Horman , Dave Young , Peter Zijlstra , jpoimboe@kernel.org, bsz@amazon.de Subject: [PATCH v5 17/20] x86/kexec: Debugging support: Dump registers on exception Date: Thu, 5 Dec 2024 15:05:23 +0000 Message-ID: <20241205153343.3275139-18-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241205153343.3275139-1-dwmw2@infradead.org> References: <20241205153343.3275139-1-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Content-Type: text/plain; charset="utf-8" From: David Woodhouse The actual serial output function is a no-op for now. Signed-off-by: David Woodhouse --- arch/x86/kernel/relocate_kernel_64.S | 104 ++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index 2179f691a45b..cd349b6d34a7 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -114,11 +114,6 @@ SYM_CODE_START_NOALIGN(relocate_kernel) int3 SYM_CODE_END(relocate_kernel) =20 -#ifdef DEBUG - UNWIND_HINT_UNDEFINED - .balign 0x100 /* relocate_kernel will be overwritten with an IDT */ -#endif - SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) UNWIND_HINT_END_OF_STACK /* @@ -368,6 +363,68 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) SYM_CODE_END(swap_pages) =20 #ifdef CONFIG_KEXEC_DEBUG +/* + * Generic 'print character' routine (as yet unimplemented) + * - %al: Character to be printed (may clobber %rax) + * - %rdx: MMIO address or port. + */ +SYM_CODE_START_LOCAL_NOALIGN(pr_char) + UNWIND_HINT_FUNC + ANNOTATE_UNRET_SAFE + ret +SYM_CODE_END(pr_char) + +/* + * Load pr_char function pointer into %rsi and load %rdx with whatever + * that function wants to see there (typically port/MMIO address). + */ +.macro pr_setup + /* No output; pr_char just returns */ + leaq pr_char(%rip), %rsi +.endm + +/* Print the nybble in %bl, clobber %rax */ +SYM_CODE_START_LOCAL_NOALIGN(pr_nybble) + UNWIND_HINT_FUNC + movb %bl, %al + nop + andb $0x0f, %al + addb $0x30, %al + cmpb $0x3a, %al + jb 1f + addb $('a' - '0' - 10), %al + ANNOTATE_RETPOLINE_SAFE +1: jmp *%rsi +SYM_CODE_END(pr_nybble) + +SYM_CODE_START_LOCAL_NOALIGN(pr_qword) + UNWIND_HINT_FUNC + movq $16, %rcx +1: rolq $4, %rbx + call pr_nybble + loop 1b + movb $'\n', %al + ANNOTATE_RETPOLINE_SAFE + jmp *%rsi +SYM_CODE_END(pr_qword) + +.macro print_reg a, b, c, d, r + movb $\a, %al + ANNOTATE_RETPOLINE_SAFE + call *%rsi + movb $\b, %al + ANNOTATE_RETPOLINE_SAFE + call *%rsi + movb $\c, %al + ANNOTATE_RETPOLINE_SAFE + call *%rsi + movb $\d, %al + ANNOTATE_RETPOLINE_SAFE + call *%rsi + movq \r, %rbx + call pr_qword +.endm + SYM_CODE_START_NOALIGN(kexec_debug_exc_vectors) /* Each of these is 6 bytes. */ .macro vec_err exc @@ -408,11 +465,42 @@ SYM_CODE_END(kexec_debug_exc_vectors) =20 SYM_CODE_START_LOCAL_NOALIGN(exc_handler) pushq %rax + pushq %rbx + pushq %rcx pushq %rdx - movw $0x3f8, %dx - movb $'A', %al - outb %al, %dx + pushq %rsi + + /* Set up %rdx/%rsi for debug output */ + pr_setup + + /* rip and exception info */ + print_reg 'E', 'x', 'c', ':', 40(%rsp) + print_reg 'E', 'r', 'r', ':', 48(%rsp) + print_reg 'r', 'i', 'p', ':', 54(%rsp) + + /* We spilled these to the stack */ + print_reg 'r', 'a', 'x', ':', 32(%rsp) + print_reg 'r', 'b', 'x', ':', 24(%rsp) + print_reg 'r', 'c', 'x', ':', 16(%rsp) + print_reg 'r', 'd', 'x', ':', 8(%rsp) + + /* Other registers */ + print_reg 'r', 's', 'i', ':', (%rsp) + print_reg 'r', 'd', 'i', ':', %rdi + print_reg 'r', '8', ' ', ':', %r8 + print_reg 'r', '9', ' ', ':', %r9 + print_reg 'r', '1', '0', ':', %r10 + print_reg 'r', '1', '1', ':', %r11 + print_reg 'r', '1', '2', ':', %r12 + print_reg 'r', '1', '3', ':', %r13 + print_reg 'r', '1', '4', ':', %r14 + print_reg 'r', '1', '5', ':', %r15 + print_reg 'c', 'r', '2', ':', %cr2 + + popq %rsi popq %rdx + popq %rcx + popq %rbx popq %rax =20 /* Only return from int3 */ --=20 2.47.0