Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1690897rwb; Fri, 23 Sep 2022 17:20:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6dBoEajR9TPYMHw+gUe0tVaXFuQF//5eISFkoEY4jAarlfAE7JavGj/l4nl9zwo30YoZTo X-Received: by 2002:a05:6402:5210:b0:451:d4ff:ab02 with SMTP id s16-20020a056402521000b00451d4ffab02mr11167835edd.345.1663978809842; Fri, 23 Sep 2022 17:20:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663978809; cv=none; d=google.com; s=arc-20160816; b=eNEqjgE9nffWLwE2hZRv2QGxf+3Nzx9LoCKQDmVfZWVB4kRXmQ6X/s2KKaloNLtTUs 00+ahVLzikBAL5paJptKizC7cfsmE8mG/zwuZaNu04F4D2oaUn8Gv16vSYsW4PQO1Ufa bGSfByICYo00oOqWZkqGMhwPBErqKHMvsR/iNp8wSxKhIFKOWHqqDRVR41j5C0PlOmLy MEVo0HvLi3KbZkau8VvCFRHp2JDM/ou3MBv+J0VnqOufOTs870SGoi2MfR2tBN06LKrD ncbkrHtv/UvEKDkUYqbGDp1WTVVwYcTyZ0mrclhMOheh5i3d7l0dQrbzOJCTE49agdAf aLGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=WB3BybeSJAXwy9sZVb/waLS+Dyffg8F8NybWwGa1X/A=; b=fXOOWupt0IhCPOw/7NqIwFrC18MTjhDMYMJBWAg1nfNwXKkztmeWFbf2YDUc1Xe0M6 1P5OnOrfzQCxmbrY8/q2jjLHx1Juaw1tg1S+U1b+PCLbFRlVD+MPlMHvkxAxmAq7+VYi D5NgX8vJ+xSR3adh8zn3F4AQjp8w4p85Wrc+wvkgehUiA4v3tSgcyHPJrtP5b2MLFd/V gslUR3hAfNQQBmW+nqof5yxvwaXV+yAjTFaE14jGRk+2KxlcGu6GfIcbJqeeX6qF9HHR Azmf4PhUH5kP7GFR4Fa+ITkWX/5wRSIxqhGpe0HjMOQ0y/bQIklFp506a6ggbltZDACv OViw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xcriPjgL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=zrUfFUWt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a50cdcb000000b00448ec02447csi8381772edj.144.2022.09.23.17.19.45; Fri, 23 Sep 2022 17:20:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xcriPjgL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=zrUfFUWt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233057AbiIXAFa (ORCPT + 99 others); Fri, 23 Sep 2022 20:05:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbiIXAFK (ORCPT ); Fri, 23 Sep 2022 20:05:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EA8A9AFA8; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977900; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WB3BybeSJAXwy9sZVb/waLS+Dyffg8F8NybWwGa1X/A=; b=xcriPjgLQzRYZ4xUbtrjHhhbSY6X8gfZJ30zvTyo5dN8Exk7uj2MmjaWOSJlNRl7Kx7QgB 9zQMGBTGy3Igy87KJJoiQBMEBq1ZfUyJ3+ONwK3Q2gWgYzXNwtard3Pe2VWpuYp1AjVYud g4vXL5kWEDF7Xo1JpP+wPHuBA6Biyoynv4rES/A0LDxmt5x3U6Khr0Gb1dCj357zAK5TrC 1x5uAsDfEZkZMo21gLUlF5sJX5MVPGjKTRNRPvpHjKdH4vn54Jxdxv93lMZv4COb/J/lqF 2N+8ZBtK8RV+utbDmp1JekmGb65ZIrgEh4rTStW8s+HKiMPBgXfBMmkIZL6g/A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977900; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WB3BybeSJAXwy9sZVb/waLS+Dyffg8F8NybWwGa1X/A=; b=zrUfFUWtkjjZ3Z3lX1frvgxG5HxmxzTiAMVgTfy0X477YaoYnRe+pIKC81HrwV1A1YFwfh Q9yqPZQbhwkJzJCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "James E.J. Bottomley" , Helge Deller , Sven Schnelle , John David Anglin , "Eric W. Biederman" , Julia Lawall , linux-parisc@vger.kernel.org Subject: [PATCH printk 08/18] parisc: Put console abuse into one place Date: Sat, 24 Sep 2022 02:10:44 +0206 Message-Id: <20220924000454.3319186-9-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner PARISC has a hope based mechanism to restore consoles in case of a HPMC (machine check exception) which is scattered over several places. Move it into one place to make further changes simpler and add comments. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky --- arch/parisc/include/asm/pdc.h | 2 +- arch/parisc/kernel/pdc_cons.c | 38 ++++++++++++++++++++++++++++------- arch/parisc/kernel/traps.c | 17 +++++----------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/arch/parisc/include/asm/pdc.h b/arch/parisc/include/asm/pdc.h index b643092d4b98..12bffd8a5d05 100644 --- a/arch/parisc/include/asm/pdc.h +++ b/arch/parisc/include/asm/pdc.h @@ -20,7 +20,7 @@ extern unsigned long parisc_pat_pdc_cap; /* PDC capabilities (PAT) */ #define PDC_TYPE_SNAKE 2 /* Doesn't support SYSTEM_MAP */ void pdc_console_init(void); /* in pdc_console.c */ -void pdc_console_restart(void); +void pdc_console_restart(bool hpmc); void setup_pdc(void); /* in inventory.c */ diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c index 2661cdd256ae..9a0c0932d2f9 100644 --- a/arch/parisc/kernel/pdc_cons.c +++ b/arch/parisc/kernel/pdc_cons.c @@ -237,20 +237,44 @@ void __init pdc_console_init(void) /* - * Used for emergencies. Currently only used if an HPMC occurs. If an - * HPMC occurs, it is possible that the current console may not be - * properly initialised after the PDC IO reset. This routine unregisters - * all of the current consoles, reinitializes the pdc console and - * registers it. + * + * + * Used for emergencies. + * + * - If an HPMC occurs, it is possible that the current console may not be + * properly initialised after the PDC IO reset. This routine unregisters + * all of the current consoles, reinitializes the pdc console and registers + * it. + * + * - Maybe the kernel hasn't booted very far yet and hasn't been able + * to initialize the serial or STI console. In that case we should + * re-enable the pdc console, so that the user will be able to + * identify the problem. + * + * + * + * The above is all wishful thinking: + * + * - Invoking [un]register_console() from exception contexts is obviously + * unsafe. + * + * - If the HPMC left the machine in unpleasant state and the pdc console + * was already initialized, but later removed due to CON_BOOT then this + * will do nothing. + * + * Pretend that any of the below works in the same way as we pretend that + * any of PARISC works. */ - -void pdc_console_restart(void) +void pdc_console_restart(bool hpmc) { struct console *console; if (pdc_console_initialized) return; + if (!hpmc && console_drivers) + return; + /* If we've already seen the output, don't bother to print it again */ if (console_drivers != NULL) pdc_cons.flags &= ~CON_PRINTBUFFER; diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c index b78f1b9d45c1..81e23f589d3d 100644 --- a/arch/parisc/kernel/traps.c +++ b/arch/parisc/kernel/traps.c @@ -235,17 +235,12 @@ void die_if_kernel(char *str, struct pt_regs *regs, long err) " (__)\\ )\\/\\\n" " U ||----w |\n" " || ||\n"); - + /* unlock the pdc lock if necessary */ pdc_emergency_unlock(); - /* maybe the kernel hasn't booted very far yet and hasn't been able - * to initialize the serial or STI console. In that case we should - * re-enable the pdc console, so that the user will be able to - * identify the problem. */ - if (!console_drivers) - pdc_console_restart(); - + pdc_console_restart(false); + if (err) printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n", current->comm, task_pid_nr(current), str, err); @@ -429,9 +424,7 @@ void parisc_terminate(char *msg, struct pt_regs *regs, int code, unsigned long o /* unlock the pdc lock if necessary */ pdc_emergency_unlock(); - /* restart pdc console if necessary */ - if (!console_drivers) - pdc_console_restart(); + pdc_console_restart(false); /* Not all paths will gutter the processor... */ switch(code){ @@ -483,7 +476,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs) int si_code; if (code == 1) - pdc_console_restart(); /* switch back to pdc if HPMC */ + pdc_console_restart(true); /* switch back to pdc if HPMC */ else if (!irqs_disabled_flags(regs->gr[0])) local_irq_enable(); -- 2.30.2