Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp1076034lqh; Fri, 29 Mar 2024 06:40:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVRNP4P8IQC8kBs4Qa/yNlk5DzVL+LU2tcVcxOWZgRyeSo/4RUGdCEED9jQfwfmkBe2I9gg+Rd8BGwqQM9eKJZgiQFw6Z9mLjAieCFOxw== X-Google-Smtp-Source: AGHT+IHO88/5fSyLn58EeGpFYG450w+HW2X+PQa2DfVPFBo9uCtBI2G7z2yQMyZkxmeRZsRTp2dY X-Received: by 2002:a05:6e02:1a88:b0:368:a609:8154 with SMTP id k8-20020a056e021a8800b00368a6098154mr2302158ilv.13.1711719612860; Fri, 29 Mar 2024 06:40:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711719612; cv=pass; d=google.com; s=arc-20160816; b=trNClRtkQsz7j4bUspR5wcT38DDWOInMUdzhqnlulGX3Qm4FjIVRamI8w/mFjK9bKp PNWliAm2hJ7vl3cfBWPR+OpKfzmZgCLc/EbxAtPTX6EC3yn4PaVdWs7JQzz1QlWgZrDR 3JoW1OxrylS/jDVmLjJbOufny9FtWqXb6QxL63+m3QKjlbbfwwwr94Crl6T10vwTZvjm UyO/gzDD46dRV2RdPDEwGhQ8r8xzjzpCGw39etwwXBg9JIMe24tMcUJ2sJHBhjHY0xBj uneeOlJMJVm1/Tu7azWcSUTop7PTtrXPN+X4O63ByOe2HIkI2zIwKF4fHM2GIQ15P2qR VP9A== 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:from:dkim-signature; bh=0I63wCg1HufW2Cj1zd2H6ztMEtGlkTlGABH4UTns6Gk=; fh=j+aMbK7eLMI2KMaRmGMOCTxfEkIc4TPOnxEcnsSirNc=; b=qfeiehqqP5MJQIGlUebb8CTfWVO4NvnAuNHUWTiDGQPF4LGY2KIkLpZQvwXSATLell XbCpax9sk7l+5uHaWo06nBf+BrojgL7hDksVHvXqh5dLJxaL6QA4No0ZV6n8o7UE7LUr g5iGxd1gjymTeGHocSOTEYBZfZLXQcGE0B0YyYhfCrlSECsirG1DOZodczaka/u5dUpc sl+WShLJH6Nphfi3yTno/5gVExSq1Su0v1LeCtg1geO9QJ875bcgelsRPbWM+ovsHeqN H+sWKAimpBZRJQQSR82Ly9UCZkF4FvskMcz83mLm82uLn7tR5pquSc1jb4CUcBL5Q1NQ btWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=X6uxYtTl; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124730-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124730-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u2-20020a655c02000000b005e438e96c48si3651955pgr.164.2024.03.29.06.40.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 06:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124730-linux.lists.archive=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=@kernel.org header.s=k20201202 header.b=X6uxYtTl; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124730-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124730-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 811D3288F23 for ; Fri, 29 Mar 2024 13:36:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C971517831C; Fri, 29 Mar 2024 12:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X6uxYtTl" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CEA18178300; Fri, 29 Mar 2024 12:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716023; cv=none; b=SZGPhB1inBIUQp44rGhKHhm08/RHC7Eak+2XRMDDmnqvyX0E5vz9U0fcIoLxjfIfoGLssnev4KG7HicYFsP7zBrDhsWJfQ8O9MEi0/ztDjfeX4frlg7WFx1QA13ycmyqvuycqJ/c+8IbMBtquIDgPCwkPnhSeJMaa6YjaFQuqIQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716023; c=relaxed/simple; bh=qH4wBsJJjj8SlxCCkzXzWl5dgUByJwVQ9Ltc3P2cF8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=krV4tRd0aG6j2xO1VPTo4ld2q3WuETOYQusTSstkKzJIjtYiH5KXfRwJbEKA8s4jN0kXczbAbdmY/x38FK9qyl4Q/gJo7gAqyYu0Bdyr4XTIMLlH/XZAieInagsXpdW4mirm55dCY3q/L4uvIZHfFDE51sIxyXL8U3UxDMeC9Xg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X6uxYtTl; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6CD7C433C7; Fri, 29 Mar 2024 12:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716023; bh=qH4wBsJJjj8SlxCCkzXzWl5dgUByJwVQ9Ltc3P2cF8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X6uxYtTlBGNB6v7JbjTvtcJN80l3nBOUPf/hkg7w2bKl08nAWrSLPlPyqEt16+Eix djNf/kqpPsDHM0RT2X163X2vtcb2NqOUz3YIxQYZG4cka5njRR7qxifvEyJUHMc+of AmePS4ynw6OjPAi1LQp2HytNzT5t1o4BCG74jOi5wIE9CnONEumSMM1CujQ6VaWuMi p/7QtAwVl7W/RBorvdMUxzY+R2NN2IXig2mTneklk2gXzUO5yk+HOISeoSTHRgwQbq G6ltsdaHlyXUKrw+bSkC+fOWROKif77izea08+YpsT8Vs3/R0F3YSnccVt0A+XDU1z Cx4amEDEeqaRw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: John Ogness , Petr Mladek , Sasha Levin Subject: [PATCH AUTOSEL 6.8 21/98] printk: Avoid non-panic CPUs writing to ringbuffer Date: Fri, 29 Mar 2024 08:36:52 -0400 Message-ID: <20240329123919.3087149-21-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329123919.3087149-1-sashal@kernel.org> References: <20240329123919.3087149-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.2 Content-Transfer-Encoding: 8bit From: John Ogness [ Upstream commit 779dbc2e78d746250f07c463e13ac603b349f6f3 ] 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. Another motivation is that non-finalized messages already might be skipped in panic(). In other words, random messages from non-panic CPUs might already get lost. It is better to ignore all to avoid confusion. To avoid losing panic CPU messages, silence non-panic CPUs immediately on panic. Signed-off-by: John Ogness Reviewed-by: Petr Mladek Link: https://lore.kernel.org/r/20240207134103.1357162-13-john.ogness@linutronix.de Signed-off-by: Petr Mladek Signed-off-by: Sasha Levin --- 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 742fb479b1d60..336c092632f4e 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 */ @@ -2293,7 +2287,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) { @@ -2778,8 +2777,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); @@ -2807,17 +2804,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; -- 2.43.0