From nobody Wed Feb 5 16:44:32 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