Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1277088lqj; Mon, 3 Jun 2024 16:33:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVLDnC7wiFrSfgZvZGZ/6nm6Mq37L9wUnXE8QO0xRWLwN5X3RTHBz3cIzibXPUkjLxYozuLZESoTyPcoJfNEiRHBVyUQgyhvhmZ7r1H3w== X-Google-Smtp-Source: AGHT+IHORqWijLMXp2K79o733Qi2VX64CTWS+YjL+umBmDBfKvmgx/EIYnGmvLRgIbW4aXeNzX0a X-Received: by 2002:a17:906:7857:b0:a5a:1562:518c with SMTP id a640c23a62f3a-a6821982253mr671368966b.48.1717457618339; Mon, 03 Jun 2024 16:33:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717457618; cv=pass; d=google.com; s=arc-20160816; b=hBhAUqpCb1+qRwYA1kLWoBmk5QnFmWFOrtMELUCh7ezNOLm9Vnpcai3vot6VrRzAJy S7N1Ifmk5d8lXcDLv7SLQ/46EZbzRiiCnMTSv2JCloP9SjjRLDCljac4cVGLiw3MsKXW Vr98CGdx0+BQ2edKPk2tv9wokfAhbCawhYMMxAyqUBKAcmLeWqL2IagDHbHWRRCNX7+e XbRnLVnlaLB9zg2zxGcPBBRaT58epCfHpws0CNg8/wQWI+9iS0GB8NXVYeItRPu4G8+v 1uEfwhfl3UQUrCl59w55OgQgDxjODP7gi+w/HjG+uhLjipdqHy+CBUmaCNp4xPFAHREv Zf5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=Dj4gOrMYbFMlZqhfQ1sjWqCRmrh47Yb6HFMI47V4kYM=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=FFb4j8MVzznYz86LgvvQpXyEEP+FG3LmrGsjkI4JcocAFTlSedBaOj68FYcRYTcVXC +V7T3AGmDu3yBXO3rdc7/qlQzF+FL2+s92So/oJlRPC0R1skJVNp93Twbl1HioUPYDXb ya3YmZGvjWghvgx8VJB5hs+LKHuCBMwg7PO/qYqqBGwqu/3Z0fYNWTrePTkUw5sOIKtK 5bAgw/6p6c3S2G3sVd6AFZGAWzRImluFEjGasVY38WMkoQRUIEyW1IXB2CLXusKmgdAY CGcSQiHQsPKwpjUvory/+7M4ATKsyuPZ7pg4hLYCugqI/A7UJd4/HkL+6SalwpoYB3KP 0Z5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qV+sNGum; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-199826-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199826-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a68a814290fsi326156566b.802.2024.06.03.16.33.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 16:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199826-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qV+sNGum; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-199826-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199826-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6F7801F26EAF for ; Mon, 3 Jun 2024 23:26:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4049813DDCB; Mon, 3 Jun 2024 23:25:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qV+sNGum"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Odj4u7ry" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F2CC13D2B6 for ; Mon, 3 Jun 2024 23:24:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717457101; cv=none; b=ctYBUu8ZCn1ukvgVt7Ni7jgguVvbphu7GSvqv+wivIC62r1CLmYtKsI9xVrQvS/KGgf72EOgQXDule8c5FQVLsoBf+B8TR/DANru7GvSZCSy9QqPAa/6kz6z4+h2ALw5Gx413sbHcssaMJqHKTOr1KGq9LsvnxNF0SjQaOPL0yg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717457101; c=relaxed/simple; bh=nJLUOO0kFbQq0mpsWpx/7kA8MXGjckBsDAJO8NTpM6E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=imtgu7wmBanP3AWaxQE586I36OTGsMNELklUYS+u6GmFDqr2ISclFRi/V8cAPBrT2HHqa5WZuFW2I0eBMCy8Aq1zGwunHWkmbDWIPNWEyWbkesEF0cfaOAMqPrc9t2OskqCtw3aP0GBwFTLrNxTFhMqodduJ1o1di7Fs2/Sq3tM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qV+sNGum; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Odj4u7ry; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1717457096; 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=Dj4gOrMYbFMlZqhfQ1sjWqCRmrh47Yb6HFMI47V4kYM=; b=qV+sNGumgD9wkX7Nv8ydFkhKqx9YqMjfbJ8zEq9ngIMylq4Ev76annalIm9kksCu5+HfFe 0bcAvNygHFrlh7zvE6jGtoYi4KYzHR6sp2GJqMGu4+lF98mLP5nURHdvjCePu++MhXEeQR SLGZyZwKYcgvKGBF+HG6MkWwVeoJJ2e4LTiABIe2yitQ6PUE8unOk6yizO38mtQowL4qcU 9PsiFmgPDTouoagtWYmpOL4GKX04VPKBBCzyeD243BnH7Ige0D9N2YZjYxPZob2j3psozW 9Ps1+Vvpi5MKDkaLpT92WQmSiwqeCRTqDALqIpGCWPsv5WIYC/IHDsBkHhK1nw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717457096; 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=Dj4gOrMYbFMlZqhfQ1sjWqCRmrh47Yb6HFMI47V4kYM=; b=Odj4u7ryDDsbcjDhjQhN0ZkCrkfM7T/t16qNZj1P56qCxrpCFxqIIbSVXKctpwrhWkRXmg t4hFUzIaZ+YnuQDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 05/18] printk: Atomic print in printk context on shutdown Date: Tue, 4 Jun 2024 01:30:40 +0206 Message-Id: <20240603232453.33992-6-john.ogness@linutronix.de> In-Reply-To: <20240603232453.33992-1-john.ogness@linutronix.de> References: <20240603232453.33992-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit For nbcon consoles, normally the printing is handled by the dedicated console printing threads. However, on shutdown the printing threads may not get a chance to print the final messages. When shutting down or rebooting (system_state > SYSTEM_RUNNING), perform atomic printing from the printk() caller context. Signed-off-by: John Ogness --- kernel/printk/nbcon.c | 5 +++-- kernel/printk/printk.c | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 89b340ca303c..19f0db6945e4 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1297,7 +1297,8 @@ static void nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq, * context must flush those remaining records if the printer thread * is not available do it. */ - if (!con->kthread && prb_read_valid(prb, nbcon_seq_read(con), NULL)) { + if ((!con->kthread || (system_state > SYSTEM_RUNNING)) && + prb_read_valid(prb, nbcon_seq_read(con), NULL)) { stop_seq = prb_next_reserve_seq(prb); goto again; } @@ -1639,7 +1640,7 @@ void nbcon_device_release(struct console *con) */ cookie = console_srcu_read_lock(); if (console_is_usable(con, console_srcu_read_flags(con)) && - !con->kthread && + (!con->kthread || (system_state > SYSTEM_RUNNING)) && prb_read_valid(prb, nbcon_seq_read(con), NULL)) { __nbcon_atomic_flush_pending_con(con, prb_next_reserve_seq(prb), false); } diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 137bd9a721c4..b58db15d2033 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2389,12 +2389,17 @@ asmlinkage int vprintk_emit(int facility, int level, * * - When this CPU is in panic. * + * - During shutdown, since the printing threads may not get + * a chance to print the final messages. + * * Note that if boot consoles are registered, the console * lock/unlock dance must be relied upon instead because nbcon * consoles cannot print simultaneously with boot consoles. */ - if (is_panic_context) + if (is_panic_context || + (system_state > SYSTEM_RUNNING)) { nbcon_atomic_flush_pending(); + } } if (do_trylock_unlock) { -- 2.39.2