From patchwork Tue Sep 19 23:08:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3796735vqi; Tue, 19 Sep 2023 18:16:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6oePXyOaJWWY7AWy7KCRIa/+fSC/8/Omy1rXdoEFv45q5LgB2eaLm5B3zEv2LlpGxobcf X-Received: by 2002:a17:902:e80b:b0:1c2:36a:52aa with SMTP id u11-20020a170902e80b00b001c2036a52aamr1151621plg.30.1695172579720; Tue, 19 Sep 2023 18:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695172579; cv=none; d=google.com; s=arc-20160816; b=pF/0lRCE0WZW+AqzrStRFtey6EWr4x00QJF3/6BLVu4qJZG2YygOn19R3tBa59pFpk 7xbckxNBsY3lrX9kf8gFAoPO1UYY/JzUtAxHuHlBNyjlTWOrmzou+bnt0nZVCDCd2O4t seAbaI5bzTgq3ZV2/Ary8zvDji20fJ2yv2crP5WGiSF73GvUiA2iJmnz5fIOzD8JmMeQ P/shr1e2l1kCwOU/bVVLwFETPVhqqtsUUQpE40ErxKRZTPhCoAZNRia1KJFL4+SijNeW yXE5ekmPB7CU4vnukpQsnEGDiTqt6LDT9chabMKca8gySPQhae54oxtE9HOI4XnXT/ZM lQbg== 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=RTecAisPGy22sD3/lz1Lk9T5rKFv9orfyF0LxD3p8X4=; fh=50vpCM4bvHEw9UCh4Qu+HIAsIf3yT3AMX/s0TvbsiwY=; b=AkF0BxeifpRPqxXV7Pf8qTs+M6mE+1zduyg1phHAJeOgw5g9RE7NvJiw+oFbnZecEb AwA7mu+RsjUUq17AjZjJa/dA67VeV8hBVYoZ3TiaMFtEce1FkjcShfyRET1Su4g8sb17 LOu/h6s+qNCrGIqLt2Nsja85VN6dI55X/LEtAn5rMaBVpnfZqLOcBSkN/sEVfY1o4TBi 8V1g3nQ7Ae+h7d7qg+bKlTYtQSMW9FRB/d+0HCO44yoWgT2B2NfHrY+S/8KO++rATXp4 X58rXjuej5VyeBJ8U9TiCrBYYe5QZ2NJCjcRrINXiLUaeHZMDNgEfTdC3WPlA37fTOxi lXSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=P4Z6YRun; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bNsSiUAr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id x17-20020a170902ec9100b001b9e3a18270si9061223plg.420.2023.09.19.18.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 18:16:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=P4Z6YRun; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bNsSiUAr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id B421180B79CA; Tue, 19 Sep 2023 16:11:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233702AbjISXKH (ORCPT + 26 others); Tue, 19 Sep 2023 19:10:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233500AbjISXJW (ORCPT ); Tue, 19 Sep 2023 19:09:22 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A658D8 for ; Tue, 19 Sep 2023 16:09:17 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164955; 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=RTecAisPGy22sD3/lz1Lk9T5rKFv9orfyF0LxD3p8X4=; b=P4Z6YRunkOPTZKgwIsuWd6MJHC5Jve4xUIDI+d4fkVbHEBJfHvFKY20lKV/ZbQVzzed+bN MfQvRsFkzDdxyBT+IZmKKKUteJ+8J5IBFw0fPuioztjOcPH0Fe+nnJIyu8aykUUn8Ctv8R Ugq8i2XNEq8PUibWlCTC35tFVw1vhjRNRzPnDtPbiCHzbeVy9+CUAhlAdhcdNIei8JnwXy /HE6mWR7bLz2wrXIziuD/LLifTzTCOL3NuTUodQradOkRCPWIM4TSHD3yWuMoHSeTypakZ mSWCGavnEgcD0wtISqPuMfA21Ucw8xbI5ZdrIOruL4WXyc8hMF1PqP1BX4eL6Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164955; 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=RTecAisPGy22sD3/lz1Lk9T5rKFv9orfyF0LxD3p8X4=; b=bNsSiUAr27aTwxXnYRc2P3wJ8k9ud163o0Nv9sPPRSLsA4qNbE2RVUk0ZGHH862/gVt4Ad hKPFyylULklOIbDA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Kees Cook , Luis Chamberlain , Andrew Morton , Peter Zijlstra , Josh Poimboeuf , Andy Shevchenko , "Guilherme G. Piccoli" , Arnd Bergmann Subject: [PATCH printk v2 08/11] panic: Add atomic write enforcement to warn/panic Date: Wed, 20 Sep 2023 01:14:53 +0206 Message-Id: <20230919230856.661435-9-john.ogness@linutronix.de> In-Reply-To: <20230919230856.661435-1-john.ogness@linutronix.de> References: <20230919230856.661435-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:11:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777517283057019209 X-GMAIL-MSGID: 1777517283057019209 From: Thomas Gleixner Invoke the atomic write enforcement functions for warn/panic to ensure that the information gets out to the consoles. For the panic case, add explicit intermediate atomic flush calls to ensure immediate flushing at important points. Otherwise the atomic flushing only occurs when dropping out of the elevated priority, which for panic may never happen. It is important to note that if there are any legacy consoles registered, they will be attempting to directly print from the printk-caller context, which may jeopardize the reliability of the atomic consoles. Optimally there should be no legacy consoles registered. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner (Intel) --- kernel/panic.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kernel/panic.c b/kernel/panic.c index 07239d4ad81e..86ed71ba8c4d 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -275,6 +275,7 @@ static void panic_other_cpus_shutdown(bool crash_kexec) */ void panic(const char *fmt, ...) { + enum nbcon_prio prev_prio; static char buf[1024]; va_list args; long i, i_next = 0, len; @@ -322,6 +323,8 @@ void panic(const char *fmt, ...) if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu) panic_smp_self_stop(); + prev_prio = nbcon_atomic_enter(NBCON_PRIO_PANIC); + console_verbose(); bust_spinlocks(1); va_start(args, fmt); @@ -382,6 +385,8 @@ void panic(const char *fmt, ...) if (_crash_kexec_post_notifiers) __crash_kexec(NULL); + nbcon_atomic_flush_all(); + console_unblank(); /* @@ -406,6 +411,7 @@ void panic(const char *fmt, ...) * We can't use the "normal" timers since we just panicked. */ pr_emerg("Rebooting in %d seconds..\n", panic_timeout); + nbcon_atomic_flush_all(); for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP) { touch_nmi_watchdog(); @@ -424,6 +430,7 @@ void panic(const char *fmt, ...) */ if (panic_reboot_mode != REBOOT_UNDEFINED) reboot_mode = panic_reboot_mode; + nbcon_atomic_flush_all(); emergency_restart(); } #ifdef __sparc__ @@ -436,12 +443,16 @@ void panic(const char *fmt, ...) } #endif #if defined(CONFIG_S390) + nbcon_atomic_flush_all(); disabled_wait(); #endif pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf); /* Do not scroll important messages printed above */ suppress_printk = 1; + + nbcon_atomic_exit(NBCON_PRIO_PANIC, prev_prio); + local_irq_enable(); for (i = 0; ; i += PANIC_TIMER_STEP) { touch_softlockup_watchdog(); @@ -652,6 +663,10 @@ struct warn_args { void __warn(const char *file, int line, void *caller, unsigned taint, struct pt_regs *regs, struct warn_args *args) { + enum nbcon_prio prev_prio; + + prev_prio = nbcon_atomic_enter(NBCON_PRIO_EMERGENCY); + disable_trace_on_warning(); if (file) @@ -682,6 +697,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint, /* Just a warning, don't kill lockdep. */ add_taint(taint, LOCKDEP_STILL_OK); + + nbcon_atomic_exit(NBCON_PRIO_EMERGENCY, prev_prio); } #ifdef CONFIG_BUG