From nobody Wed Feb 5 14:05:16 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 B1ACE1D7998 for ; Wed, 15 Jan 2025 19:14:46 +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=1736968488; cv=none; b=W9dBd8Gt1n5PjbDvJDugDvX/OtCxJZXmegEtBx0ph5qzI99+qrMRXV5SGotmNWnIYJTTLpgYI4tliJRbNHhI5kGbQl3IIWdRPmJWrM/ZKtT2XvlTEy0awhIXRkTRnqaQLgdi5IVsy+swoTGaoz+5W52gBvGteTnnELlySc6f7X8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968488; c=relaxed/simple; bh=9vjtNHx0FqqLcci+rcMEj/5acJBVr9rbniH1U2Dz44w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FN0hKQ87/7bzaoMHWzGfLTyaRHXtjGIHfb0qHpL9X2RsdYv1MaOJLuh4QlQE7youpqPZVsl0xBgStuaJWoeAlrb2TpDARnmzYVwhYYqCNaI2NLjVhbnD+HO8zw6mGXklKnhibjsIbFBgf5GfQXO8rpL9dy5ky2cSRbBbY6rtx0E= 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=Ohvp7AhO; 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="Ohvp7AhO" 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=zf2GiuF4uGIVUxzkVkUG6Og3XO9L1Q3ObwgFc7LbRWg=; b=Ohvp7AhOn/kgth3HVKcG15a/dZ cqzMDWli/JuSB28oYTi7TAsW3FrXa6yS/U39APw5GlB/nrs/OYi7N+tjsI2crhcYH49jTRf+DLy1o 4fhAosBHkgSXBy1XQSOK6UUvwsCvnv72q2MJHeXM9EMdIatABO3xQFU4fPUY9OnHybF2zZSJkMb0V q7K7u4skgXzHI9bxsHfmLdd9p/EYpaqMQhLyk8z5tk1TWT+JELpC28dRAlgEiCO3PpSSWqUouzl0K WoZaiOnxeYr/yhbb3HhWTXb2veD2vKC6TEqVMQMiALbMMQW6eJUUs/POiDVSeH/2bLiRvH2lSfea1 EL5Bc8sw==; 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 1tY8qQ-00000000X7x-3IZr; Wed, 15 Jan 2025 19:14:26 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qO-00000002Uvr-3g2F; Wed, 15 Jan 2025 19:14:24 +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 v6 1/7] x86/kexec: Add CONFIG_KEXEC_DEBUG option Date: Wed, 15 Jan 2025 19:09:30 +0000 Message-ID: <20250115191423.587774-2-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250115191423.587774-1-dwmw2@infradead.org> References: <20250115191423.587774-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 This does nothing yet. Support for x86_64 will follow in subsequent commits, and an Arm64 version is also being worked on. Signed-off-by: David Woodhouse --- arch/x86/Kconfig.debug | 1 + kernel/Kconfig.kexec | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug index 74777a97e394..c54cbd36c710 100644 --- a/arch/x86/Kconfig.debug +++ b/arch/x86/Kconfig.debug @@ -13,6 +13,7 @@ config X86_VERBOSE_BOOTUP =20 config EARLY_PRINTK bool "Early printk" if EXPERT + select HAVE_KEXEC_DEBUG if X86_64 default y help Write kernel log output directly into the VGA buffer or to a serial diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec index 4d111f871951..a65b49c083c9 100644 --- a/kernel/Kconfig.kexec +++ b/kernel/Kconfig.kexec @@ -17,6 +17,9 @@ config KEXEC_ELF config HAVE_IMA_KEXEC bool =20 +config HAVE_KEXEC_DEBUG + bool + config KEXEC bool "Enable kexec system call" depends on ARCH_SUPPORTS_KEXEC @@ -95,6 +98,14 @@ config KEXEC_JUMP Jump between original kernel and kexeced kernel and invoke code in physical address mode via KEXEC =20 +config KEXEC_DEBUG + bool "Debug kexec transition" + depends on HAVE_KEXEC_DEBUG + help + Faults during kexec can be difficult to debug. This installs exception + handlers and attempts to report faults. On x86_64 this would use the + serial port configured for earlyprintk. + config CRASH_DUMP bool "kernel crash dumps" default ARCH_DEFAULT_CRASH_DUMP --=20 2.47.0 From nobody Wed Feb 5 14:05:16 2025 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 06A7A1D6DD4 for ; Wed, 15 Jan 2025 19:14:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968487; cv=none; b=KCy8c9HPJSFMBC8HrmlQPDayFeRvI1Rz1CQJLVFFEEa9VOUnO9vR2057H25NL01kdw0/xzI8wpEj57NEPRWClitmSdnJrv8xUlq0EJuXp6J6nmpJx10gftR9TpJIaI6yrrtY8CXbxdOOlzCE24RI/0P3tKKFLNqwPv3foeQub9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968487; c=relaxed/simple; bh=3gv0x7Zem4Zmes+1DaHZKUreg4e5P9Bw/NMYo6CRLis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WTTHpq3Sio2UyJbTmUAn7/ZHyHmemK1YSEDobRpQ82FKSQPPe865Qqoh1MF3AIy9ffYuJ0wUwOwfyZIDiCVtcpYNOcTtGS/S/4c0YgtjZCiDdEl1ZMAu0J0un9DaV0O1s2w/NwxrSE7StGqB/lc7PK+FgEl6N8MYA9YP22J/I38= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=desiato.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=CmJydDU/; arc=none smtp.client-ip=90.155.92.199 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=desiato.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CmJydDU/" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=gSlCkcjgZBWAkesEhGWssA+8sh3qmIYNjsyEtgrDo9o=; b=CmJydDU/dAvjj4CnxjPLH6YzMp xL7tbn0ps9im7A6cSChwUu7TxpcKV0+MpI4IDFG868u6Mp00Ci1pPnFj5E4xWxaRnzp9Vy6kTJykI KWDB0XphijgmIpsYjCOZnA7j75hLVXzWlP37SefhuHRFM2hdEa7z8EFjVjYpQUQP3CgjIhYQo8ieP 00mwG9JQJyLXAp5LFTESxbaMo21zpkMi5O5hVivkOy9QwQIO6m2z1RlJfJgIiXV6vsVvVdfy39AGQ Hx3kIsIk2X40EJzhRF96dxqQCBDrAODLkAIe1Tc0wXNVeinWMWTR/uQkq0l0YVpW33Ghst0qneIqJ 0QrbJaUQ==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qS-0000000AvMc-07ML; Wed, 15 Jan 2025 19:14:29 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qO-00000002Uvx-3ogr; Wed, 15 Jan 2025 19:14:24 +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 v6 2/7] x86/kexec: Debugging support: load a GDT Date: Wed, 15 Jan 2025 19:09:31 +0000 Message-ID: <20250115191423.587774-3-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250115191423.587774-1-dwmw2@infradead.org> References: <20250115191423.587774-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 desiato.infradead.org. See http://www.infradead.org/rpr.html Content-Type: text/plain; charset="utf-8" From: David Woodhouse There are some failure modes which lead to triple-faults in the relocate_kernel function, which is fairly much undebuggable for normal mortals. Adding a GDT in the relocate_kernel environment is step 1 towards being able to catch faults and do something more useful. Signed-off-by: David Woodhouse --- arch/x86/kernel/relocate_kernel_64.S | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index af2cd06ff318..c62f03808f18 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -39,6 +39,18 @@ SYM_DATA(kexec_pa_table_page, .quad 0) SYM_DATA(kexec_pa_swap_page, .quad 0) SYM_DATA_LOCAL(pa_backup_pages_map, .quad 0) =20 +#ifdef CONFIG_KEXEC_DEBUG + .balign 16 +SYM_DATA_START_LOCAL(kexec_debug_gdt) + .word kexec_debug_gdt_end - kexec_debug_gdt - 1 + .long 0 + .word 0 + .quad 0x00cf9a000000ffff /* __KERNEL32_CS */ + .quad 0x00af9a000000ffff /* __KERNEL_CS */ + .quad 0x00cf92000000ffff /* __KERNEL_DS */ +SYM_DATA_END_LABEL(kexec_debug_gdt, SYM_L_LOCAL, kexec_debug_gdt_end) +#endif /* CONFIG_KEXEC_DEBUG */ + .section .text..relocate_kernel,"ax"; .code64 SYM_CODE_START_NOALIGN(relocate_kernel) @@ -115,6 +127,21 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) /* store the start address on the stack */ pushq %rdx =20 +#ifdef CONFIG_KEXEC_DEBUG + /* Create a GDTR (16 bits limit, 64 bits addr) on stack */ + leaq kexec_debug_gdt(%rip), %rax + pushq %rax + pushw (%rax) + + /* Load the GDT, put the stack back */ + lgdt (%rsp) + addq $10, %rsp + + /* Test that we can load segments */ + movq %ds, %rax + movq %rax, %ds +#endif /* CONFIG_KEXEC_DEBUG */ + /* * Clear X86_CR4_CET (if it was set) such that we can clear CR0_WP * below. --=20 2.47.0 From nobody Wed Feb 5 14:05:16 2025 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 3F6C9482EF for ; Wed, 15 Jan 2025 19:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968484; cv=none; b=IF6qPbssUgcbmBDzN3PeNg3tb9W58fhPlLpkhj+rY1SG//OLFhHJDvUGWuV0TiKUP9gopiJRCujyb9fVo9sTZ5TLC6kg3Kwecna+ZJ4TjL6gz3HGuM16d4u4Pli6acYN6neh7f30e7vNfrdskSRbnExpMdF1OIURyCDc1iS/hIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968484; c=relaxed/simple; bh=KX2zDbp6BlEvBsyiSKnIFwdDwhiybqszDV6WGNqoUjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZNkbrZmRqpO7ndvjE9gLUWFCL8zpp4nAU1DbMxCJlXZ1i872P+awTwhBq5/trpQOMyPVHbEEquGHUN2Q+BdadUB+3kBCU+JrhYFJVPVeY2ixOKahCS9GYmYRyOPuogJGLXkxjGkdrMIckVCnhG6W3/VYe41Nd7PL+plhSFGd3SM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=desiato.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=O1G029fJ; arc=none smtp.client-ip=90.155.92.199 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=desiato.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="O1G029fJ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=0Lfnf5OQV/O8wFKeVcDBQagu82mNw6Nx1vxvLmuyV88=; b=O1G029fJGrVbz1TpuH8Q5lS7O/ xX029hUh7UlzrN6qDj3NkLOtdGsiP1CFat0uSvH7Kxo8pwEdTUTJ5VAK+lODrDNlz+BhWehmSIlAu Zo4652XtGwzYXLIFDFAPDJ34jlAbkMjnoHulVXDPLkuqtxQkO3WPRLRPy7ltk9aDBVjbTWYViivqw 3K+nlFN75OCUcK2Dj/w9oJhz+CZVO1e7vS7XfyRAtBB9RQD1h2OiAbb/DFwRUmBkX1nh11py0xiAr X3M/sm9gslMQ/SfDsr+wEhY9rNlVFE4bVBxk9o3QFNRWyEIH5KPDFu1JsCmpZIB9l4oinbodCb/aJ n5juTMOQ==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qS-0000000AvMb-07Gl; Wed, 15 Jan 2025 19:14:29 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qO-00000002Uw1-3wfb; Wed, 15 Jan 2025 19:14:24 +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 v6 3/7] x86/kexec: Debugging support: Load an IDT and basic exception entry points Date: Wed, 15 Jan 2025 19:09:32 +0000 Message-ID: <20250115191423.587774-4-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250115191423.587774-1-dwmw2@infradead.org> References: <20250115191423.587774-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 desiato.infradead.org. See http://www.infradead.org/rpr.html Content-Type: text/plain; charset="utf-8" From: David Woodhouse Signed-off-by: David Woodhouse --- arch/x86/include/asm/kexec.h | 5 ++ arch/x86/kernel/machine_kexec_64.c | 23 ++++++++ arch/x86/kernel/relocate_kernel_64.S | 82 ++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index 8ad187462b68..ec7636f4f86a 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -8,6 +8,9 @@ # define PA_PGD 2 # define PA_SWAP_PAGE 3 # define PAGES_NR 4 +#else +/* Size of each exception handler referenced by the IDT */ +# define KEXEC_DEBUG_EXC_HANDLER_SIZE 6 /* pushi, pushi, 2-byte jmp */ #endif =20 # define KEXEC_CONTROL_PAGE_SIZE 4096 @@ -58,6 +61,8 @@ struct kimage; extern unsigned long kexec_va_control_page; extern unsigned long kexec_pa_table_page; extern unsigned long kexec_pa_swap_page; +extern gate_desc kexec_debug_idt[]; +extern unsigned char kexec_debug_exc_vectors[]; #endif =20 /* diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_k= exec_64.c index a68f5a0a9f37..535438375568 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -304,6 +304,26 @@ static void load_segments(void) ); } =20 +static void prepare_debug_idt(unsigned long control_page, unsigned long ve= c_ofs) +{ +#ifdef CONFIG_KEXEC_DEBUG + gate_desc idtentry =3D { 0 }; + int i; + + idtentry.bits.p =3D 1; + idtentry.bits.type =3D GATE_TRAP; + idtentry.segment =3D __KERNEL_CS; + idtentry.offset_low =3D (control_page & 0xFFFF) + vec_ofs; + idtentry.offset_middle =3D (control_page >> 16) & 0xFFFF; + idtentry.offset_high =3D control_page >> 32; + + for (i =3D 0; i < 16; i++) { + kexec_debug_idt[i] =3D idtentry; + idtentry.offset_low +=3D KEXEC_DEBUG_EXC_HANDLER_SIZE; + } +#endif +} + int machine_kexec_prepare(struct kimage *image) { void *control_page =3D page_address(image->control_code_page); @@ -321,6 +341,9 @@ int machine_kexec_prepare(struct kimage *image) if (image->type =3D=3D KEXEC_TYPE_DEFAULT) kexec_pa_swap_page =3D page_to_pfn(image->swap_page) << PAGE_SHIFT; =20 + prepare_debug_idt((unsigned long)__pa(control_page), + (unsigned long)kexec_debug_exc_vectors - reloc_start); + __memcpy(control_page, __relocate_kernel_start, reloc_end - reloc_start); =20 set_memory_rox((unsigned long)control_page, 1); diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index c62f03808f18..f5b134a81827 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -49,6 +49,12 @@ SYM_DATA_START_LOCAL(kexec_debug_gdt) .quad 0x00af9a000000ffff /* __KERNEL_CS */ .quad 0x00cf92000000ffff /* __KERNEL_DS */ SYM_DATA_END_LABEL(kexec_debug_gdt, SYM_L_LOCAL, kexec_debug_gdt_end) + + .balign 8 +SYM_DATA_START(kexec_debug_idt) + .skip 0x100, 0x00 +SYM_DATA_END(kexec_debug_idt) + #endif /* CONFIG_KEXEC_DEBUG */ =20 .section .text..relocate_kernel,"ax"; @@ -113,6 +119,11 @@ SYM_CODE_START_NOALIGN(relocate_kernel) jmp *%rsi 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 /* @@ -140,6 +151,15 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) /* Test that we can load segments */ movq %ds, %rax movq %rax, %ds + + /* Now an IDTR on the stack to load the IDT the kernel created */ + leaq kexec_debug_idt(%rip), %rsi + pushq %rsi + pushw $0xff + lidt (%rsp) + addq $10, %rsp + + //int3 #endif /* CONFIG_KEXEC_DEBUG */ =20 /* @@ -367,3 +387,65 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) ret int3 SYM_CODE_END(swap_pages) + +#ifdef CONFIG_KEXEC_DEBUG +SYM_CODE_START_NOALIGN(kexec_debug_exc_vectors) + /* Each of these is 6 bytes. */ +.macro vec_err exc + UNWIND_HINT_ENTRY + . =3D kexec_debug_exc_vectors + (\exc * KEXEC_DEBUG_EXC_HANDLER_SIZE) + nop + nop + pushq $\exc + jmp exc_handler +.endm + +.macro vec_noerr exc + UNWIND_HINT_ENTRY + . =3D kexec_debug_exc_vectors + (\exc * KEXEC_DEBUG_EXC_HANDLER_SIZE) + pushq $0 + pushq $\exc + jmp exc_handler +.endm + + ANNOTATE_NOENDBR + vec_noerr 0 // #DE + vec_noerr 1 // #DB + vec_noerr 2 // #NMI + vec_noerr 3 // #BP + vec_noerr 4 // #OF + vec_noerr 5 // #BR + vec_noerr 6 // #UD + vec_noerr 7 // #NM + vec_err 8 // #DF + vec_noerr 9 + vec_err 10 // #TS + vec_err 11 // #NP + vec_err 12 // #SS + vec_err 13 // #GP + vec_err 14 // #PF + vec_noerr 15 +SYM_CODE_END(kexec_debug_exc_vectors) + +SYM_CODE_START_LOCAL_NOALIGN(exc_handler) + pushq %rax + pushq %rdx + movw $0x3f8, %dx + movb $'A', %al + outb %al, %dx + popq %rdx + popq %rax + + /* Only return from int3 */ + cmpq $3, (%rsp) + jne .Ldie + + addq $16, %rsp + iretq + +.Ldie: + hlt + jmp .Ldie + +SYM_CODE_END(exc_handler) +#endif /* CONFIG_KEXEC_DEBUG */ --=20 2.47.0 From nobody Wed Feb 5 14:05:16 2025 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 4127C1D63FD for ; Wed, 15 Jan 2025 19:14:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968486; cv=none; b=npd1KGEZJhR90QBVlB64llTwKFMlwnjoJsD/SCVLbVttS0wip7VO/r33w438aj+sdQIV5obF/tPxysZFBfkLaqZFtZDVBcPtQoC6BGLGJAR+18NRKTy5Vevgxa3icts5tN7+WH977wyRjojNEdaouaMy4vJvZ0xejCjUsKM/Xjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968486; c=relaxed/simple; bh=Oi6SW6jVaOG+3GRiLQLmC0w3ufiMhi/qukAnrc5l5Xg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SEzitCswCx9DYMbjlmTn0eWp/UgqRlOSW8ZVLFUXFawXKxsMCSETyj1eUSFejVuZ75E50QdKG0ZUJJ9zUboH5NsII7RXtF94tH8+TFEX1/4UcReQtZkvTYTAIyy3ow+1Ci6DOtKwiiDWqTTrEsTK2FhWILqFqon1K+pu7pM5B8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=desiato.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=nrdkr+Tq; arc=none smtp.client-ip=90.155.92.199 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=desiato.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="nrdkr+Tq" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=O03Tc2q45eY1dgZWv0tL053b8rPNbzwQjWQWfzAB6PA=; b=nrdkr+Tq+pjs/xef8ARok0TTNm us2M71UipT8QCVTEp7EN9WdiMQM0yDRMtFg5mMMyuB5o5BNv+MDzvUkANFWVhxJ5oNa0LFpLp/twd /ju1xD3XH4F6np2GQLlxTGitTWFFSnLdZ6AuINFAf868vd17O6X8kMjWIdBSXZhX2wjMOyf3zpPnT r+Vx2J33WYVC8hNMd+MtwarJlDm0KglMWUBQFYA2yQeMG0+nKjkYl9k6r/MbCt4PMsXeeXvpPVpBY +Da+mpBnugY67vcoG2mBNtJJdYkmLA3OqGOWk2m/IcF+pJxm1cwux9MnHFNAfEiBYk/EPYQNfKbeI 8svrmF8A==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qS-0000000AvMd-034B; Wed, 15 Jan 2025 19:14:29 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qO-00000002Uw4-46fA; Wed, 15 Jan 2025 19:14:25 +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 v6 4/7] x86/kexec: Debugging support: Dump registers on exception Date: Wed, 15 Jan 2025 19:09:33 +0000 Message-ID: <20250115191423.587774-5-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250115191423.587774-1-dwmw2@infradead.org> References: <20250115191423.587774-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 desiato.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 | 106 +++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index f5b134a81827..020f0f6e3e2e 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -119,11 +119,6 @@ SYM_CODE_START_NOALIGN(relocate_kernel) jmp *%rsi 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 /* @@ -389,6 +384,69 @@ 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_NOENDBR + 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 @@ -429,11 +487,43 @@ 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', ':', 0x28(%rsp) + print_reg 'E', 'r', 'r', ':', 0x30(%rsp) + print_reg 'r', 'i', 'p', ':', 0x38(%rsp) + print_reg 'r', 's', 'p', ':', 0x50(%rsp) + + /* We spilled these to the stack */ + print_reg 'r', 'a', 'x', ':', 0x20(%rsp) + print_reg 'r', 'b', 'x', ':', 0x18(%rsp) + print_reg 'r', 'c', 'x', ':', 0x10(%rsp) + print_reg 'r', 'd', 'x', ':', 0x08(%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 From nobody Wed Feb 5 14:05:16 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 B1A7A1D7995 for ; Wed, 15 Jan 2025 19:14:46 +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=1736968488; cv=none; b=h9DHeM4BNmb2qnbEPy7U0ZfuvDBk8aN78dXPH6RqjDhxvMm2riyUgJlIDxFhw1SPwK5257gREMJZFIWRjzhNYkLhZykxxcEi1pbi4gO7PF6w9wB3kPX2AoqiFcjyHPp1p5rr1b4QWwtmC3p5NDuqq/dYv2h8iNZ6d9Ngs4sANyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968488; c=relaxed/simple; bh=XUGXiUSwkFqm4I2j09szyZ9PLINXVF6ndyMdIdQbupY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B4vkY/Wj9G55MFM4GoWV+5qaSUWj7HlY32fkKhBZX/tUt2lLMFDQhP1+hWFONh9kwNWYKEQIFRQu1h1bA3vh++aZqkIpsckci1OCGTE+pALKEGnOdFpHgHCYL/g2JNPgpESo7kfwtUlTCxdWQP4iJoLuibClLpsQwq0hbIvFX1c= 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=GVEK6peO; 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="GVEK6peO" 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=M2ULUlwEkdHYrsSmSk7PiK/umziQJgolf5VoS3q1tC0=; b=GVEK6peO8jRhOXCs7jGpwKqf7u PaJy7OjYYycihbMipVyhnyQbCyLcZO1gYAaO7ayjP8i5xHvYkT7x5pZFBJcdpqJ+HTaMtacb34LgQ 2ttw7EDSTGYt+GUJ515dbSz5S9s/+lEwx8WPTWlZFlTEDO9bdvCVuQupEr54KJCmJaUizDvnU0Ylu c2z5LZZ0qU9deft0cSbDRIPoWcEBM22oNu3xFpVY14qeKMii7h8h5rBmOfg48iousg/J5SqD2HIfh /Yu1a/s/MDfNzG2Oo1nP/WquHmstzSVZBYUGgt6wTv3hUiTYHSnAvtcONCxnMBgVxyFwnaAR/NHBx NYY9RhyA==; 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 1tY8qQ-00000000X81-3KTu; Wed, 15 Jan 2025 19:14:26 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qP-00000002UwB-09lZ; Wed, 15 Jan 2025 19:14:25 +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 v6 5/7] x86/kexec: Add 8250 serial port output Date: Wed, 15 Jan 2025 19:09:34 +0000 Message-ID: <20250115191423.587774-6-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250115191423.587774-1-dwmw2@infradead.org> References: <20250115191423.587774-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 If a serial port was configured for early_printk, use it for debug output from the relocate_kernel exception handler too. Signed-off-by: David Woodhouse --- arch/x86/include/asm/kexec.h | 1 + arch/x86/kernel/early_printk.c | 6 +++++ arch/x86/kernel/relocate_kernel_64.S | 39 +++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index ec7636f4f86a..8cbdb6fd10c2 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -63,6 +63,7 @@ extern unsigned long kexec_pa_table_page; extern unsigned long kexec_pa_swap_page; extern gate_desc kexec_debug_idt[]; extern unsigned char kexec_debug_exc_vectors[]; +extern uint16_t kexec_debug_8250_port; #endif =20 /* diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c index 44f937015e1e..bf06866ee90a 100644 --- a/arch/x86/kernel/early_printk.c +++ b/arch/x86/kernel/early_printk.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include #include @@ -141,6 +142,11 @@ static __init void early_serial_hw_init(unsigned divis= or) serial_out(early_serial_base, DLL, divisor & 0xff); serial_out(early_serial_base, DLH, (divisor >> 8) & 0xff); serial_out(early_serial_base, LCR, c & ~DLAB); + +#ifdef CONFIG_KEXEC_DEBUG + if (serial_in =3D=3D io_serial_in) + kexec_debug_8250_port =3D early_serial_base; +#endif } =20 #define DEFAULT_BAUD 9600 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index 020f0f6e3e2e..9781a28c246a 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -38,6 +38,7 @@ SYM_DATA(kexec_va_control_page, .quad 0) SYM_DATA(kexec_pa_table_page, .quad 0) SYM_DATA(kexec_pa_swap_page, .quad 0) SYM_DATA_LOCAL(pa_backup_pages_map, .quad 0) +SYM_DATA(kexec_debug_8250_port, .word 0) =20 #ifdef CONFIG_KEXEC_DEBUG .balign 16 @@ -385,24 +386,50 @@ SYM_CODE_END(swap_pages) =20 #ifdef CONFIG_KEXEC_DEBUG /* - * Generic 'print character' routine (as yet unimplemented) + * Generic 'print character' routine * - %al: Character to be printed (may clobber %rax) * - %rdx: MMIO address or port. */ -SYM_CODE_START_LOCAL_NOALIGN(pr_char) +#define XMTRDY 0x20 + +#define TXR 0 /* Transmit register (WRITE) */ +#define LSR 5 /* Line Status */ + +SYM_CODE_START_LOCAL_NOALIGN(pr_char_8250) UNWIND_HINT_FUNC ANNOTATE_NOENDBR + addw $LSR, %dx + xchg %al, %ah +.Lxmtrdy_loop: + inb %dx, %al + testb $XMTRDY, %al + jnz .Lready + rep nop + jmp .Lxmtrdy_loop + +.Lready: + subw $LSR, %dx + xchg %al, %ah + outb %al, %dx +pr_char_null: + ANNOTATE_NOENDBR + ANNOTATE_UNRET_SAFE ret -SYM_CODE_END(pr_char) +SYM_CODE_END(pr_char_8250) =20 /* * 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 +.macro pr_setup + leaq pr_char_8250(%rip), %rsi + movw kexec_debug_8250_port(%rip), %dx + testw %dx, %dx + jnz 1f + + leaq pr_char_null(%rip), %rsi +1: .endm =20 /* Print the nybble in %bl, clobber %rax */ --=20 2.47.0 From nobody Wed Feb 5 14:05:16 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 3E4F11D7984 for ; Wed, 15 Jan 2025 19:14:46 +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=1736968487; cv=none; b=LqFiRkIWGSRXylQb16dx1b9/xaJVcNmPUEeyKUUti52Eq5zhXKPQJF+k6IP/lV1sXHVSuEjTwjAzmsicFUSJE6Hfr+sK4NDSUzumNQt9PnV13rZP8zOrKf0rKES0m57CAIOX6K+L3tDalK6hQLe5Fux9evmhqznMkbUXM7CiqPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968487; c=relaxed/simple; bh=omxxyZXV5KXMMTzZ5hv6U5m274O34R73kJ/dA/jWpZ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NwYdYl89p4iSlZWsvjXwbOJ/zADebR3wADn3d+1lUbmg028UXiVDK60GyPfqWJoNKEemDm8P/kAJfAlZg9R5Pl0NLnRWlvKfNUrz+WqzncDGO9jWd1raYcttH9cWBJNyA6q6hQ4NDFd+KbaCw2PnRX5dCBMazEVsQ9jpY7QsPv0= 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=LpRXIP8c; 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="LpRXIP8c" 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=E8eKbt9gEj9x3/N+C3q8Wshr1zJkbweN4e5zR2wlGA0=; b=LpRXIP8c28PZvESqVHpWbpi9zF wL5LZl+O7O2Pya3sLX5VwOj6kw/KLnS4cUkPElarW2Q0ROkTsRL8xXd3Phkrb40FvoHHvyBDn+9Qv Esd6eYuhkh/AqbjTgGIk1pkEryvOmPOyaTl8vu1h8ICFfAHPImkpvKh6iHUAOuSfxDV6lcJ9lKuD4 DsSzH3at0vU7fE39swPNb5ClW3eHIyeCCfCEOXPFFaxB3FOfVa0Rviq6Ze1QdiaXcMSqhNEORH39f byOHtsqs3tC1o5xDU8v7q7zqoTYfJUGTTjKfO8jU+FXXDkpR4DVL47qTIgOShCaPdzfiFbXOeUD1U IY5lHKtQ==; 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 1tY8qQ-00000000X7z-3L0i; Wed, 15 Jan 2025 19:14:26 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qP-00000002UwG-0NeT; Wed, 15 Jan 2025 19:14:25 +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 v6 6/7] x86/kexec: Add 8250 MMIO serial port output Date: Wed, 15 Jan 2025 19:09:35 +0000 Message-ID: <20250115191423.587774-7-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250115191423.587774-1-dwmw2@infradead.org> References: <20250115191423.587774-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 This supports the same 32-bit MMIO-mapped 8250 as the early_printk code. It's not clear why the early_printk code supports this form and only this form; the actual runtime 8250_pci doesn't seem to support it. But having hacked up QEMU to expose such a device, early_printk does work with it, and now so does the kexec debug code. Signed-off-by: David Woodhouse --- arch/x86/include/asm/kexec.h | 1 + arch/x86/kernel/early_printk.c | 3 +++ arch/x86/kernel/machine_kexec_64.c | 22 ++++++++++++++++++++++ arch/x86/kernel/relocate_kernel_64.S | 22 ++++++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index 8cbdb6fd10c2..5081d0b9e290 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -64,6 +64,7 @@ extern unsigned long kexec_pa_swap_page; extern gate_desc kexec_debug_idt[]; extern unsigned char kexec_debug_exc_vectors[]; extern uint16_t kexec_debug_8250_port; +extern unsigned long kexec_debug_8250_mmio32; #endif =20 /* diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c index bf06866ee90a..14f548e095c9 100644 --- a/arch/x86/kernel/early_printk.c +++ b/arch/x86/kernel/early_printk.c @@ -296,6 +296,9 @@ static __init void early_pci_serial_init(char *s) /* WARNING! assuming the address is always in the first 4G */ early_serial_base =3D (unsigned long)early_ioremap(bar0 & PCI_BASE_ADDRESS_MEM_MASK, 0x10); +#ifdef CONFIG_KEXEC_DEBUG + kexec_debug_8250_mmio32 =3D bar0 & PCI_BASE_ADDRESS_MEM_MASK; +#endif write_pci_config(bus, slot, func, PCI_COMMAND, cmdreg|PCI_COMMAND_MEMORY); } diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_k= exec_64.c index 535438375568..d47ca1a06a4d 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -76,6 +76,24 @@ map_acpi_tables(struct x86_mapping_info *info, pgd_t *le= vel4p) static int map_acpi_tables(struct x86_mapping_info *info, pgd_t *level4p) = { return 0; } #endif =20 +#ifdef CONFIG_KEXEC_DEBUG +static int map_mmio_serial(struct x86_mapping_info *info, pgd_t *level4p) +{ + unsigned long mstart, mend; + + if (!kexec_debug_8250_mmio32) + return 0; + + mstart =3D kexec_debug_8250_mmio32 & PAGE_MASK; + mend =3D (kexec_debug_8250_mmio32 + PAGE_SIZE + 23) & PAGE_MASK; + pr_info("Map PCI serial at %lx - %lx\n", mstart, mend); + return kernel_ident_mapping_init(info, level4p, mstart, mend); +} +#else +static int map_mmio_serial(struct x86_mapping_info *info, pgd_t *level4p) = { return 0; } +#endif + + #ifdef CONFIG_KEXEC_FILE const struct kexec_file_ops * const kexec_file_loaders[] =3D { &kexec_bzImage64_ops, @@ -285,6 +303,10 @@ static int init_pgtable(struct kimage *image, unsigned= long control_page) if (result) return result; =20 + result =3D map_mmio_serial(&info, image->arch.pgd); + if (result) + return result; + /* * This must be last because the intermediate page table pages it * allocates will not be control pages and may overlap the image. diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index 9781a28c246a..493b378713e5 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -38,6 +38,7 @@ SYM_DATA(kexec_va_control_page, .quad 0) SYM_DATA(kexec_pa_table_page, .quad 0) SYM_DATA(kexec_pa_swap_page, .quad 0) SYM_DATA_LOCAL(pa_backup_pages_map, .quad 0) +SYM_DATA(kexec_debug_8250_mmio32, .quad 0) SYM_DATA(kexec_debug_8250_port, .word 0) =20 #ifdef CONFIG_KEXEC_DEBUG @@ -418,6 +419,22 @@ pr_char_null: ret SYM_CODE_END(pr_char_8250) =20 +SYM_CODE_START_LOCAL_NOALIGN(pr_char_8250_mmio32) + UNWIND_HINT_FUNC + ANNOTATE_NOENDBR +.Lxmtrdy_loop_mmio: + movb (LSR*4)(%rdx), %ah + testb $XMTRDY, %ah + jnz .Lready_mmio + rep nop + jmp .Lxmtrdy_loop_mmio + +.Lready_mmio: + movb %al, (%rdx) + ANNOTATE_UNRET_SAFE + ret +SYM_CODE_END(pr_char_8250_mmio32) + /* * Load pr_char function pointer into %rsi and load %rdx with whatever * that function wants to see there (typically port/MMIO address). @@ -428,6 +445,11 @@ SYM_CODE_END(pr_char_8250) testw %dx, %dx jnz 1f =20 + leaq pr_char_8250_mmio32(%rip), %rsi + movq kexec_debug_8250_mmio32(%rip), %rdx + testq %rdx, %rdx + jnz 1f + leaq pr_char_null(%rip), %rsi 1: .endm --=20 2.47.0 From nobody Wed Feb 5 14:05:16 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 7B3DC1D798E for ; Wed, 15 Jan 2025 19:14:46 +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=1736968487; cv=none; b=pkNsYIDac6QjyNTtQL1HLcn/lXHWmwM8JiKJQYPZC9cpAQPdtGuS9z4ElAUUK1I79lnz3jsrsRDD9YOF+7qjTh9/u+/SZnuYVcNcIvqzl6IYMxOOwFpZnkwz6ydItiPONkY23ws+pwbmrlcqhBr++Sb315djqJlpAPIvy62MUDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736968487; c=relaxed/simple; bh=LDXE4n9+ImIv24KK6ht3PkcNm15LaAs/7YVJO/C+Hlc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=glHin6N7L4yxq6qZ79iEcghvZk2FfbFQjFfqSseBmG7//mWNlpbRMne75N+IgY/wfAvf3wQfbAIcZjT76If+gZLE3N5arbzrdHICsc0MmB+yRk0jJY+XVLsVOdvz54wT/qPlVyIY6Jtolu7YEnlUe2/sRnab5XXVgZSzZxjvTgU= 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=b7EvDy3l; 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="b7EvDy3l" 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=pca4Fxgeu9wcwmYhifyF3EzUvdR40CutdVjYdl24F4w=; b=b7EvDy3lCmeeR/24rdaI88vQTk 20hUAIupH5oYaod9Id99C6cGPmaYEQHN9cGo17x3iKUmZAHOZKnTELa6pPslYsBpjuMfuxOd6Tl3f NL80JohNxvSktbTS6tK9O1QNsveiI+KIvxcmremEAcEm7mo71OrVkU03r5Ax+R4G4XSXPzk1Uv+pn r0Yf+YcFKePS7cw141kREgAuarBYvUbXYyDx4bJILddWOSGZghOiSQc4a3Q26S8EfWTyGi1QbCqNH 1jWq2DVvsrh+KxYiExgjv5AIxPyk6BmFOzaPdmIl7+9vXqrSdLUkZ4sRPVkkpZntcxFtJecQe4Vff zwOCkDMA==; 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 1tY8qQ-00000000X7y-3IOh; Wed, 15 Jan 2025 19:14:26 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tY8qP-00000002UwM-0cha; Wed, 15 Jan 2025 19:14:25 +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 v6 7/7] [DO NOT MERGE] x86/kexec: Add int3 in kexec path for testing Date: Wed, 15 Jan 2025 19:09:36 +0000 Message-ID: <20250115191423.587774-8-dwmw2@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250115191423.587774-1-dwmw2@infradead.org> References: <20250115191423.587774-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 Signed-off-by: David Woodhouse --- arch/x86/kernel/relocate_kernel_64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index 493b378713e5..e4253102b234 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -156,7 +156,7 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) lidt (%rsp) addq $10, %rsp =20 - //int3 + int3 #endif /* CONFIG_KEXEC_DEBUG */ =20 /* --=20 2.47.0