From nobody Wed Feb 5 16:45:49 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