From patchwork Tue Sep 19 23:08:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 142261 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3941514vqi; Wed, 20 Sep 2023 00:26:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwvpeGaE7PLTvUx5IpohD8dMk37ToMbCN2BOX7oQURfUgdhUalQNRkFefOHZnCjXv76KTn X-Received: by 2002:a17:90b:4f88:b0:268:557e:1848 with SMTP id qe8-20020a17090b4f8800b00268557e1848mr1845475pjb.2.1695194789360; Wed, 20 Sep 2023 00:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695194789; cv=none; d=google.com; s=arc-20160816; b=LJIFHQ1ZY9pcWvLYGg+fVIYOYqkACSmTuDWPWhXR9BBnmFacy/TpzFelsOpjK0afv1 Upk4J8ReseBR5L2vU9kdBtORTRfkaX4OAbQZHBpWS9cUPMt1k6LU/tKpk6ga6A1U+4sK ZE25GQjI8832SUBNWGaZR8eHTG1agIdEL2SxRuOUWccS3+jezZVvILqDffUhg+UwBiDI uC8LzhDkgU5fVdWkMDfSCkYL32hOlryYTUqdZUbRZEonCR1nMkcO8I4HL4LhXPpj8dsY vSf0NEROYI+vefPQqe1fStaKG3TVWNC+LyiMIKs8d4VESmIl0+btv3u/qlaPe3p3cda1 h2Rg== 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=OzbPeuWkTorGv3d2yuxEAEu0gnIlvdjiqaqtf+AucME=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=r7NJLIPhyXGfPiD+OA06xYYBzMeyPcUhkIhVnrunQtll0IBASfcyiieNiW3y7PS+pz qKQhSprfdcAJOQzOfuuoCE8b4M2D2gEJH5drpOzE/c3lHurLvgZ21M9XkA2YxWAa/Oku lUz7DkhjHv6e8frbukryoPDjAHTnaRRdMz02KWtSTYtQNOX3l6R+cG1JcleWAxxcZ8uJ e7nZe56kT+sqEd46i8y1dWvnlYlwJjYrQn47s3jCGGBqaYU0aqswjIeGX9+KuVrPcZhJ H9LsTQ3sk+KuhnSsLXWaIjcLxVcQ0cAN1N/Wkc8smKxhXeXTXL3E6qeuJ6/OdT/Kh6Aa GiZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AcOxDy26; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id mv16-20020a17090b199000b00262ebe643a2si940349pjb.186.2023.09.20.00.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 00:26:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AcOxDy26; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 3C7D981D7A78; Tue, 19 Sep 2023 16:09:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233660AbjISXJh (ORCPT + 26 others); Tue, 19 Sep 2023 19:09:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233410AbjISXJV (ORCPT ); Tue, 19 Sep 2023 19:09:21 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15213C6 for ; Tue, 19 Sep 2023 16:09:15 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695164952; 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=OzbPeuWkTorGv3d2yuxEAEu0gnIlvdjiqaqtf+AucME=; b=AcOxDy26/wZHBrY1PDymcspuNPgrI1Epe/gZj0sMxSW60NjlAnd6XQ6j36zzzT9zkdYknI SyHklaTdzHgcn9LBQa9GGeaoNOXlRJLOqVyOGnYrx+zkzbIjOj+rGfYaUoKZUHiO1i/fJH oRx2nLs96R3O1IprrRjd2SBLf/ZzZYM+KNEtDNGbqNxLXnoWFeL0oc2AHgyQV9MqCQR7Qi 5z3jbF9q+31Ek8GNWMxr5rL6OX2Euegaz4BAcEFUl5UJQycdekHwYzhpuVHgZpAp3Ui5WR RMvkiMCLnfrW7ohY4ApfANrEpdmBI0//+TmvQRYsEISQxTsj/D2MYWTr6R03sw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695164952; 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=OzbPeuWkTorGv3d2yuxEAEu0gnIlvdjiqaqtf+AucME=; b=gKmdzdskT7Ri+LOcvfojaRdY0IBLQEasZSxD8GXhIC5B7lEqTcovfFCrvzcWfX0+Tniup9 d/UYvefBi8WwQrAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 06/11] printk: nbcon: Wire up nbcon console atomic flushing Date: Wed, 20 Sep 2023 01:14:51 +0206 Message-Id: <20230919230856.661435-7-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=-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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:09:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777540571101023045 X-GMAIL-MSGID: 1777540571101023045 From: Thomas Gleixner Perform nbcon console atomic flushing at key call sites: nbcon_atomic_exit() - When exiting from the outermost atomic printing section. If the priority was NBCON_PRIO_PANIC, attempt a second flush allowing unsafe hostile takeovers. console_flush_on_panic() - Called from several call sites to trigger ringbuffer dumping in an urgent situation. console_flush_on_panic() - Typically the panic() function will take care of atomic flushing the nbcon consoles on panic. However, there are several users of console_flush_on_panic() outside of panic(). printk_trigger_flush() - Used in urgent situations to trigger a dump in an irq_work context. However, the atomic flushing part happens in the calling context since an alternative context is not required. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner (Intel) --- kernel/printk/nbcon.c | 10 ++++++++++ kernel/printk/printk.c | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 2a9ff18fc78c..82e6a1678363 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1092,6 +1092,11 @@ void nbcon_atomic_flush_all(void) * Return: The previous priority that needs to be fed into * the corresponding nbcon_atomic_exit() * Context: Any context. Disables migration. + * + * When within an atomic printing section, no atomic printing occurs. This + * is to allow all emergency messages to be dumped into the ringbuffer before + * flushing the ringbuffer. The actual atomic printing occurs when exiting + * the outermost atomic printing section. */ enum nbcon_prio nbcon_atomic_enter(enum nbcon_prio prio) { @@ -1130,8 +1135,13 @@ void nbcon_atomic_exit(enum nbcon_prio prio, enum nbcon_prio prev_prio) { struct nbcon_cpu_state *cpu_state; + __nbcon_atomic_flush_all(false); + cpu_state = nbcon_get_cpu_state(); + if (cpu_state->prio == NBCON_PRIO_PANIC) + __nbcon_atomic_flush_all(true); + /* * Undo the nesting of nbcon_atomic_enter() at the CPU state * priority. diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 6ef33cefa4d0..419c0fabc481 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3159,6 +3159,8 @@ void console_flush_on_panic(enum con_flush_mode mode) console_srcu_read_unlock(cookie); } + nbcon_atomic_flush_all(); + console_flush_all(false, &next_seq, &handover); } @@ -3903,6 +3905,10 @@ void defer_console_output(void) void printk_trigger_flush(void) { + migrate_disable(); + nbcon_atomic_flush_all(); + migrate_enable(); + defer_console_output(); }