From patchwork Thu Dec 14 21:42:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178924 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8871691dys; Thu, 14 Dec 2023 13:45:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkIa1stHThds3F2d+6mG3mCUHxzM1wVk3maizaKzypDvmtyQdETRXYqGzIY0ekH//roRk0 X-Received: by 2002:a17:902:8a88:b0:1d0:6ffd:9e27 with SMTP id p8-20020a1709028a8800b001d06ffd9e27mr9423765plo.121.1702590351187; Thu, 14 Dec 2023 13:45:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590351; cv=none; d=google.com; s=arc-20160816; b=qShvnkR1GQSflb1nrLLcY9E8gPSg/3kt4R9QaMECyPsnt+KSuDI97aIahveCLc4U/X pXAYQ7U2Qr3lZLr0rVZqwGHpmXWN0InMCt0rQEgf3Our6os0jUrtegPb8tLcF7Ujpo6l ShePfvqLzn7XmKV8m41X4651ez+oph62UKmQsFzBmhfRsOu+AfncipfzN2u9LY/7VQ4f 6PSfEwJ65x8Og/O+ltkQpkaN4nbLiBsca+USAizPyazN3RoqviHW/Dacsd4xojQtTu5u W6/0HMg2p+Ak/T5Hj9L3a/O0lK3yGAvAUYBxTx5n11FUGzb43YMfDAwi7INZ4NGjNw9f mcYg== ARC-Message-Signature: i=1; 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=X4rvWoxnqgzEuAgNoYI/eGkAegsSWbGumqPznFMqF+U=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=D2fr60MrTFzdd47J4/RKhKB/PqLojFjSQ0q1Je+xyzbEWIrkmLbFIJER/XoKFHoCg0 7keGERDwOuSYA5VqVv7V0+oI8HMNt1GbrNoRp3xr4edvpCoNNim5hFZUfFCz1oRU9FdL /IulQnnnl9Mq/E15GV+BT+ZaYNVFGMpJgj+dM9Kf4VlwWD2WnboX/5maJ4esu/xeabIV xZjB2bE36GGDPdVlmW9UlWTebeoJ9xNfJJZxEciVGlsTZtBS18PzqVJz5RLQ4LUI+eP1 WwsuK8SGNclW+vUL/VRMyQAc9qhJhEzsbAHvUiChJ6dq/2huYzQXPgTQuYCfc8t6LC2k uHsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IczEGKqF; dkim=neutral (no key) header.i=@linutronix.de header.b="EZ/nLN6F"; spf=pass (google.com: domain of linux-kernel+bounces-156-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f18-20020a170902ce9200b001d36b1705f0si1565065plg.54.2023.12.14.13.45.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:45:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IczEGKqF; dkim=neutral (no key) header.i=@linutronix.de header.b="EZ/nLN6F"; spf=pass (google.com: domain of linux-kernel+bounces-156-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E392328371B for ; Thu, 14 Dec 2023 21:45:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6ADDA2C6A2; Thu, 14 Dec 2023 21:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IczEGKqF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EZ/nLN6F" X-Original-To: linux-kernel@vger.kernel.org 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 DF1496E58E for ; Thu, 14 Dec 2023 21:42:11 +0000 (UTC) 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=1702590128; 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=X4rvWoxnqgzEuAgNoYI/eGkAegsSWbGumqPznFMqF+U=; b=IczEGKqFD1oy+Qg8z9W3ASm1EtJPsy0YWe3mtabbGGlNNi+1YViu93FrmJd/s0YY/mjwVv IbjcDUoXwTMgDkjFvNEIMdAs3d2wRqq22t6BgChFhGJ/ipARopaROpvgZbQQiFta1P8oJ3 86G1akAsb0XQkl/xgOrcdboEkLI2tqDe+uIrsXsYhlxxKS+ThW6/LpoDksG4VC/MqlZeMW lUvFe1M6o66t4WVMSlikkgtaooz6ztl0xuVce+klfEvFeuvHqjDK68JtT5J63BuDEKsDO1 KeC3A2M09eVmkhhXjlCuT9ICK97N/q7lGJ4YzNcUFyHFIQPCKx9EIv1XvRbakA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590128; 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=X4rvWoxnqgzEuAgNoYI/eGkAegsSWbGumqPznFMqF+U=; b=EZ/nLN6FZnFW+QHK6HtPkCdu30khYWm1kLAFdRJgMDfIsfceHUVNIecPc9cscZ9BaccODt phCyLhtqdyFnt1Ag== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 13/14] printk: Avoid non-panic CPUs writing to ringbuffer Date: Thu, 14 Dec 2023 22:48:00 +0106 Message-Id: <20231214214201.499426-14-john.ogness@linutronix.de> In-Reply-To: <20231214214201.499426-1-john.ogness@linutronix.de> References: <20231214214201.499426-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785295379974452857 X-GMAIL-MSGID: 1785295379974452857 Commit 13fb0f74d702 ("printk: Avoid livelock with heavy printk during panic") introduced a mechanism to silence non-panic CPUs if too many messages are being dropped. Aside from trying to workaround the livelock bugs of legacy consoles, it was also intended to avoid losing panic messages. However, if non-panic CPUs are writing to the ringbuffer, then reacting to dropped messages is too late. To avoid losing panic CPU messages, silence non-panic CPUs immediately on panic. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index cb99c854a648..1685a71f3f71 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -462,12 +462,6 @@ static int console_msg_format = MSG_FORMAT_DEFAULT; static DEFINE_MUTEX(syslog_lock); #ifdef CONFIG_PRINTK -/* - * During panic, heavy printk by other CPUs can delay the - * panic and risk deadlock on console resources. - */ -static int __read_mostly suppress_panic_printk; - DECLARE_WAIT_QUEUE_HEAD(log_wait); /* All 3 protected by @syslog_lock. */ /* the next printk record to read by syslog(READ) or /proc/kmsg */ @@ -2322,7 +2316,12 @@ asmlinkage int vprintk_emit(int facility, int level, if (unlikely(suppress_printk)) return 0; - if (unlikely(suppress_panic_printk) && other_cpu_in_panic()) + /* + * The messages on the panic CPU are the most important. If + * non-panic CPUs are generating any messages, they will be + * silently dropped. + */ + if (other_cpu_in_panic()) return 0; if (level == LOGLEVEL_SCHED) { @@ -2799,8 +2798,6 @@ void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) bool printk_get_next_message(struct printk_message *pmsg, u64 seq, bool is_extended, bool may_suppress) { - static int panic_console_dropped; - struct printk_buffers *pbufs = pmsg->pbufs; const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); const size_t outbuf_sz = sizeof(pbufs->outbuf); @@ -2828,17 +2825,6 @@ bool printk_get_next_message(struct printk_message *pmsg, u64 seq, pmsg->seq = r.info->seq; pmsg->dropped = r.info->seq - seq; - /* - * Check for dropped messages in panic here so that printk - * suppression can occur as early as possible if necessary. - */ - if (pmsg->dropped && - panic_in_progress() && - panic_console_dropped++ > 10) { - suppress_panic_printk = 1; - pr_warn_once("Too many dropped messages. Suppress messages on non-panic CPUs to prevent livelock.\n"); - } - /* Skip record that has level above the console loglevel. */ if (may_suppress && suppress_message_printing(r.info->level)) goto out;