Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752309AbcDBUN7 (ORCPT ); Sat, 2 Apr 2016 16:13:59 -0400 Received: from mail-ob0-f171.google.com ([209.85.214.171]:34742 "EHLO mail-ob0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751291AbcDBUN5 (ORCPT ); Sat, 2 Apr 2016 16:13:57 -0400 MIME-Version: 1.0 In-Reply-To: <20160402183919.GA2538@pd.tnic> References: <4085070316fc3ab29538d3fcfe282648d1d4ee2e.1459605520.git.luto@kernel.org> <20160402183919.GA2538@pd.tnic> From: Andy Lutomirski Date: Sat, 2 Apr 2016 13:13:37 -0700 Message-ID: Subject: Re: [PATCH v5 3/9] x86/head: Move early exception panic code into early_fixup_exception To: Borislav Petkov Cc: Andy Lutomirski , X86 ML , Paolo Bonzini , Peter Zijlstra , KVM list , Arjan van de Ven , xen-devel , "linux-kernel@vger.kernel.org" , Linus Torvalds , Andrew Morton Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2709 Lines: 80 On Sat, Apr 2, 2016 at 11:39 AM, Borislav Petkov wrote: > On Sat, Apr 02, 2016 at 07:01:34AM -0700, Andy Lutomirski wrote: >> This removes a bunch of assembly and adds some C code instead. It >> changes the actual printouts on both 32-bit and 64-bit kernels, but >> they still seem okay. >> >> Signed-off-by: Andy Lutomirski >> --- >> arch/x86/include/asm/uaccess.h | 2 +- >> arch/x86/kernel/head_32.S | 49 +++++------------------------------------- >> arch/x86/kernel/head_64.S | 45 ++------------------------------------ >> arch/x86/mm/extable.c | 29 ++++++++++++++++++++----- >> 4 files changed, 32 insertions(+), 93 deletions(-) > > ... > >> @@ -99,21 +101,38 @@ int __init early_fixup_exception(struct pt_regs *regs, int trapnr) >> >> /* Ignore early NMIs. */ >> if (trapnr == X86_TRAP_NMI) >> - return 1; >> + return; >> + >> + if (early_recursion_flag > 2) >> + goto halt_loop; >> + >> + if (regs->cs != __KERNEL_CS) >> + goto fail; >> >> e = search_exception_tables(regs->ip); >> if (!e) >> - return 0; >> + goto fail; >> >> new_ip = ex_fixup_addr(e); >> handler = ex_fixup_handler(e); >> >> /* special handling not supported during early boot */ >> if (handler != ex_handler_default) >> - return 0; >> + goto fail; >> >> regs->ip = new_ip; >> - return 1; >> + return; >> + >> +fail: >> + early_printk("PANIC: early exception 0x%02x IP %lx:%lx error %lx cr2 0x%lx\n", >> + (unsigned)trapnr, (unsigned long)regs->cs, regs->ip, >> + regs->orig_ax, read_cr2()); >> + >> + show_regs(regs); > > To make this even better, it could be something called early_show_regs() > or so and be a simplified version of __show_regs() on both bitness but > which calls early_printk(). > > This way you'll be able to get out stuff to the console as early as > possible. > > Btw, you don't need to dump rIP, CR2, etc in the PANIC message above > since you're going to early_show_regs() anyway. Given that I this isn't really a regression with my patches (it probably never worked much better on 32-bit and the regs never would have shown at all on 64-bit), I propose a different approach: make printk work earlier. Something like: if (early) { early_printk(args); } or early_vprintk or whatever. If the cost of a branch mattered, this could be alternative-patched out later on, but that seems silly. I also bet that a more sensible fallback could be created in which printk would try to use an early console if there's no real console. --Andy