Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1197545rdb; Wed, 20 Sep 2023 02:24:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+VaVfIXs1+MAuRX0keTEWCMCa32/+Ah10fkTidOcsh3ZL30A+PLr6ul6Rr7MlrbE/OhpI X-Received: by 2002:a67:b304:0:b0:452:6465:4a35 with SMTP id a4-20020a67b304000000b0045264654a35mr1672870vsm.11.1695201845671; Wed, 20 Sep 2023 02:24:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695201845; cv=none; d=google.com; s=arc-20160816; b=YIUUakM8pMJGgkfix0YGdI9TH9urcToxrcnIQHHu4Sc62Kxm2hdphUVFYCbHcCxcIn iOErWbQsz5c97SDhO2KZKqjzAMGHfD1vaca44hJXUFyxkdl/PopcDTYj+RyqqQh0UN5q wgEoK8gLMa3n7pg+O8ZmTq1YZBvoxQEbK4MMqzt090UAt+pTlQh8PM5qcAiRPKmyBLHh 00CPxUWfCEIOMqulUOKm03Pc5Hev4xtDJfDIdLuDod7hLeMqxyNKKJn7H73B6/qBC7Dc HWx2IZzf3lE+EGLAMaxLmQwHg8JgnPAweXWeB+c0vesx1+nvsQ9NcfUja28geUsDbcQI JnaA== 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 header.b=gKmdzdsk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a21-20020a63e855000000b0056a9b0297cesi562167pgk.150.2023.09.20.02.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 02:24:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; 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 header.b=gKmdzdsk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id A7DDA828F4F9; Tue, 19 Sep 2023 16:10:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233679AbjISXJh (ORCPT + 99 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 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 19 Sep 2023 16:10:14 -0700 (PDT) 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(); } -- 2.39.2