From patchwork Wed Feb 7 13:40:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 197936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2235423dyb; Wed, 7 Feb 2024 05:43:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEP9kM39eWPFIuQDG04o/mS2r44ZOCVXW0a0ORYLhxfpmnDrYpoLNXiRDXdorG4fhe3tAiC X-Received: by 2002:a05:620a:462a:b0:785:a011:f662 with SMTP id br42-20020a05620a462a00b00785a011f662mr1033544qkb.14.1707313427881; Wed, 07 Feb 2024 05:43:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707313427; cv=pass; d=google.com; s=arc-20160816; b=d8IoOMEXnXpYg8RcaakTLbXLWttEC9wklvn9sypFnBS9tI48naGvUEpxXzu2Blehhh LPRWrwMqHBDLpIc+n/6GdgFqliBRFQI03EOdrFAW+5Lr3wU3Z/HNKO5O8H981546z99X HXP1Sli5eFmrmhJCwPnIxQZASsaxCUAGNtvPwilKbKeALmbkObzopp86Zc0+DonAHe/K QjT+fUZ6LGqZk4Ptw5776ahPOMKkKTHzbDRxIbR2UyHUZYkSfUZ0mztdnRPOIp3iqCJB +dIrv1YHCgy+T8b/63/RhRsyO2OGhOJwyeOYiat7p50tMnRhLulnjY8d1cKCqF2yvNr6 m5sw== 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=EjNlI5JonKv0m/kINdXCywSbWYOfTvFxrSFxNOQW5Ko=; fh=DxVLId4Go2x73hbhB145SHMaKpubSGjggwBmetF6gZg=; b=F0hsAKjrhiQtjplUc8NcK++rSEHlah4Xj5ctieMS+KcoiT2yFvoENt+sOWbhB3vrXH rmVWM06g1fEyhSNPLgpwlFXt4DGrRomqjWa4k/ox8FLI+gVExHiuwNPg6RKR1J7CG6g0 FlMXgVam2k1Rs8IxSaaEdiw3BRbTlQ7P85sYOw18UOw5kMj/YhsElf2X3OX0GOx+obeJ HyEd1smdekjjvzR8DB05Z/55VjfB8aLR1ZM2DO3ZgQB3IEpni8TW1mVh8q7phREqWaSq J2KTEdvWjmlsAf0+y7UeIkB0XPT5SBrLp2NOwj8FTjwI0ohjfEUw7o1Pcxs+Wnu53JMg NewA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="uxq/6dVE"; 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-56567-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56567-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCX4o88KwCWEsMObG1ACrl+R0FPH1KMCv7ayFSwaXJ8hxQOaSpja/tSlkHQn9n+PkrgNgZMVoG4wQgH2mHfAbT+U4AHviQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s18-20020ae9f712000000b00783577b7501si1079356qkg.357.2024.02.07.05.43.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 05:43:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56567-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="uxq/6dVE"; 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-56567-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56567-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9BDA41C22B5C for ; Wed, 7 Feb 2024 13:43:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65B4180025; Wed, 7 Feb 2024 13:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uxq/6dVE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BdlvPSC8" 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 2679B7A720 for ; Wed, 7 Feb 2024 13:41:20 +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=1707313282; cv=none; b=nl9he+8QHHMczTJK5XFTX0oVeGX6LVP/RI7JFB4erDNST3J40BuqcxVGaa7i+3w5cz4V2I6lm1z7e1DrEsePoYqWpgbrWRQJQFH7lEmU4fNlukxn52iyLfH93E2xKCCZ7la5rUmkMHz/C/GqJ/9Mq90Ge2QmU+j1RX8eA5GzICw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707313282; c=relaxed/simple; bh=pLiQvlJlgDBEc8pKrVIe9E9OdNeQXjek3j2d6X2PiC4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K6NiKbN68y6GcYS6weManlqyZ1EAANkMGyyW+RN5nP+Ck8nYBQLxzidHmDyba7sBhkwkZa/+YBVPJqnTaFn+e1JkzxwAnk9SPH6haE2+9nsxz1Y6csaek3TX48ozu8ihgInmvkR/oYWxgaNstqznfKOBk+THdc+jF8KVJcKTeIo= 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=uxq/6dVE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BdlvPSC8; 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=1707313276; 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=EjNlI5JonKv0m/kINdXCywSbWYOfTvFxrSFxNOQW5Ko=; b=uxq/6dVEvZ37HS80Hjl/vLmUowIdMGNG0hnAoQnu3K+bjeH/0sOnBtzakxA0IzW6cVNL3t 7ZfegUL77aQJqqUviE5RemwOyw3m2rcrZ6dXNm7IaY72d7Ve7pmpl7yOcID6pKxSu8RgAv W8g6ZO4SU8TbWUxTHQOiohh+dF7SeZXD6uO2orChx/8vFbglOqNIXahY13nJi/OTyAojoJ ujBzqhCdvuycWQjX4Bmpip+8lxEiskvouWWhyYPSJ9GskpskSsG+9zxwt4nTAScZBjPqB8 4CX492ci8Ap8YtZ7E1bMBObhd+nArjR9MI2Fn2heY1WfK06VFUTLnFosqc+Enw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707313276; 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=EjNlI5JonKv0m/kINdXCywSbWYOfTvFxrSFxNOQW5Ko=; b=BdlvPSC8OAZuBClMDP+9MvJQiYBjLXPNQBmQ2WX/Xsk5C//z4EHRDNcPx20FzIVugyf+WM Mp5PFQTn0R8jD2CQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 07/14] printk: Add this_cpu_in_panic() Date: Wed, 7 Feb 2024 14:46:56 +0106 Message-Id: <20240207134103.1357162-8-john.ogness@linutronix.de> In-Reply-To: <20240207134103.1357162-1-john.ogness@linutronix.de> References: <20240207134103.1357162-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: 1790247884647408341 X-GMAIL-MSGID: 1790247884647408341 There is already panic_in_progress() and other_cpu_in_panic(), but checking if the current CPU is the panic CPU must still be open coded. Add this_cpu_in_panic() to complete the set. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 1 + kernel/printk/printk.c | 43 +++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 6c2afee5ef62..ac2d9750e5f8 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -130,6 +130,7 @@ struct printk_message { }; bool other_cpu_in_panic(void); +bool this_cpu_in_panic(void); bool printk_get_next_message(struct printk_message *pmsg, u64 seq, bool is_extended, bool may_supress); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 22bb45d8f2f2..82dc2c7949b7 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -347,6 +347,29 @@ static bool panic_in_progress(void) return unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID); } +/* Return true if a panic is in progress on the current CPU. */ +bool this_cpu_in_panic(void) +{ + /* + * We can use raw_smp_processor_id() here because it is impossible for + * the task to be migrated to the panic_cpu, or away from it. If + * panic_cpu has already been set, and we're not currently executing on + * that CPU, then we never will be. + */ + return unlikely(atomic_read(&panic_cpu) == raw_smp_processor_id()); +} + +/* + * Return true if a panic is in progress on a remote CPU. + * + * On true, the local CPU should immediately release any printing resources + * that may be needed by the panic CPU. + */ +bool other_cpu_in_panic(void) +{ + return (panic_in_progress() && !this_cpu_in_panic()); +} + /* * This is used for debugging the mess that is the VT code by * keeping track if we have the console semaphore held. It's @@ -2592,26 +2615,6 @@ static int console_cpu_notify(unsigned int cpu) return 0; } -/* - * Return true if a panic is in progress on a remote CPU. - * - * On true, the local CPU should immediately release any printing resources - * that may be needed by the panic CPU. - */ -bool other_cpu_in_panic(void) -{ - if (!panic_in_progress()) - return false; - - /* - * We can use raw_smp_processor_id() here because it is impossible for - * the task to be migrated to the panic_cpu, or away from it. If - * panic_cpu has already been set, and we're not currently executing on - * that CPU, then we never will be. - */ - return atomic_read(&panic_cpu) != raw_smp_processor_id(); -} - /** * console_lock - block the console subsystem from printing *