From patchwork Thu Dec 14 21:41:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 178925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8871722dys; Thu, 14 Dec 2023 13:45:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkotrywqPddwRG6dn+zbYq4BjYGLYm7YYOteXEsODd3WSjwCZRB1cbs0tLzpJ6yqEL67V1 X-Received: by 2002:a05:620a:ce5:b0:77e:fba3:a775 with SMTP id c5-20020a05620a0ce500b0077efba3a775mr7613714qkj.83.1702590355282; Thu, 14 Dec 2023 13:45:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590355; cv=none; d=google.com; s=arc-20160816; b=Ie+MuuDhXUH9MXVmvDORRXeVWdJGQIIhreK7lwiB/oAJ+Ru5pu9dsuqGcEXtqRo22p bwxGUXIGJS6f/TbvyUwdUm6PaUr7ieU1B8HJ/CNU3wKLNvE5JZJy3PyhxbGBU0X/UTvo D+yPQpKHoLVRPgcIPRlyMFPfCm8zcZkgkFO0D8eLjY55YmBLDPeIzVO1ljf0+klYBJyK y8YJ4/9+8ZGIipTaqqk4i/jjp6gGfc7KXuLs7eruCxLBGk52Bd1KyUgsr6EftsBj9xYh EiItb3yLnZGbBGEO0DDvEi2i2SFDsFcGbcgsHbVSPT6/CnUHvtlhTFb6Ju6OAya8KedA 2FEg== 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=EjNlI5JonKv0m/kINdXCywSbWYOfTvFxrSFxNOQW5Ko=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=Vqu9Ussix9ubjDbCYbAbQXBzc4ORBqeOF0xoxnO9au9YWgJcSKtE92rNVOyMVDP7wj D1hCt/AMLobx8fvnudTJPYKp7S9CQ+bqlA6evkezrpqOQEj4LJyH+RovhsB0YX4lKIkq SaAFyqmo8MkwlDwCvW+WrBpZGizE21ysx47OQTxk0icmFFvc2Rkk2H2Pas/Nb9kXoFd/ V43+JVS7iSecz5vimdbJReSD3ozo+BYNvb76HBA/xI7LK1GoI+mnt1Q0x2I8V60o0OIp 6FcOD+6lpkeRuQxeYO7hMXqmfDOS0e3BVRv0Doy7DVdSI2IYjgzKVu4eRCiyHcq5olS4 5PrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Fl9EDpri; dkim=neutral (no key) header.i=@linutronix.de header.b="F1l2H1G/"; spf=pass (google.com: domain of linux-kernel+bounces-155-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u15-20020a05620a430f00b0077f76954d7esi10591247qko.102.2023.12.14.13.45.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:45:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155-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=Fl9EDpri; dkim=neutral (no key) header.i=@linutronix.de header.b="F1l2H1G/"; spf=pass (google.com: domain of linux-kernel+bounces-155-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155-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 180F51C21D6D for ; Thu, 14 Dec 2023 21:45:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9240E2C6AB; 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="Fl9EDpri"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="F1l2H1G/" 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 D9F646E2C1 for ; Thu, 14 Dec 2023 21:42:10 +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=1702590126; 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=Fl9EDpriC4isCU/BtgR2fdrIobGrK+hq+Ifz9dlN3/a1ySYUNd1l8M8/WQCtjZso2uBmwY Uz7xWkah907tDY34I+G0Rv68veVCA64rwBs8UMzMFc+M92sG8xPSNeA0g6op0LWfTGnChz ITiH2Li9Zl2EVtitjdzhIS4aK60cshGIyCblZ1/0DdbZdVctvHoWpulv1yRRX2inGcKUBK DuyUZH6NSSFdU35rNVJz8t+vO+yF+rDyB7faIZxTKCYvBPVQTzwqbL6NX9AG3GTBfteHGz idEOWRMKsuB2x0026kUWgjX8jIZ91v8kZ5MXyoYvpq96CtrXV5MahJvvRB6Hug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590126; 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=F1l2H1G/fVUwDSZT60vtw3F6/tqAwdlqkl2Nn/lHaRx4HraBC0vfmiFsvJOZUmAE6vQqJM g6/09CwYWZ8gPIDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v3 07/14] printk: Add this_cpu_in_panic() Date: Thu, 14 Dec 2023 22:47:54 +0106 Message-Id: <20231214214201.499426-8-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: 1785295384092589192 X-GMAIL-MSGID: 1785295384092589192 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 *