From patchwork Mon Nov 6 21:07:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 162189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2927976vqu; Mon, 6 Nov 2023 13:07:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBoGBhdIe4DM2Z9d/Lfe3p8CuxIJrrcplWt8n0TYBweVlTLnk6jxskqjgYNLTEbHBn3f1g X-Received: by 2002:a17:902:d401:b0:1cc:2f90:6291 with SMTP id b1-20020a170902d40100b001cc2f906291mr23801857ple.54.1699304873361; Mon, 06 Nov 2023 13:07:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699304873; cv=none; d=google.com; s=arc-20160816; b=L2UgCKDSmts1oQc9qpdjuS9iTk5rxGmjcp1auBNkIpsLYFDrwOHF8u2V9v2HMq8/G+ 2NPf94sGKu0gWsIVCzY5YXCq4GzKclIi6F8CzlLOMWRiyYuvtLEAeZ4c+FORoKO8q7Xx fnzycz0kEQjT1oFb9YnNYVaaRGVnPRIFL/Nf6MVHM7PY6K/d96LFP7lu4iRHxi5f9zRS dT2caLvtCDPoz/P3ktbWKwMgLR4qaj6HaGmEwQl8sn1tN5BVmeR8fyVOJjwon+xUeFZJ eBQdv5LndkBjpf5pUJXSmJro/yCbdf9MaZZs05nseBtgdfL4RUa71GjXZMApNiMrPLSB wLsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=EjNlI5JonKv0m/kINdXCywSbWYOfTvFxrSFxNOQW5Ko=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=G8NCYCzgvZjVOH2i8y/38vw6sSNYRKCEj8PwnvzTkCZ0Q5Sfti+isnT5ZJNEujY0aS LLvN50S2gz1IlcCYaGRuGwSnQAA3Mc76qXebsgGQ0y4GY4ceWrSc+lSiRLJZbTmfwLR9 BtUjlftwsVp/irFdxCS2QkaLGzVM81tj4zX0duxFCswaUQSq/9yK0xT8xaSwLPhU5Ks5 wACje9eG0Lzfs+Q2kWMoPsPL8pUuXMk+vqsvNrIOwTpx+9RnK9x1fdQi2rVADCrJ3cjh 5QtfylzxcLFHbfV9F/T8aUXZUyI11rZ8aAph3lid/ex1p6j37hycBHlH3tNOmTeDbfdV orug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MJVAR+sg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id jb9-20020a170903258900b001c7345bc01csi8376514plb.450.2023.11.06.13.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 13:07:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MJVAR+sg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 61D56801B3D2; Mon, 6 Nov 2023 13:07:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233128AbjKFVHn (ORCPT + 34 others); Mon, 6 Nov 2023 16:07:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233093AbjKFVHi (ORCPT ); Mon, 6 Nov 2023 16:07:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6F4C103 for ; Mon, 6 Nov 2023 13:07:35 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1699304854; 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=MJVAR+sgDJZ8TL8ljWTnvRYcn0y6yHtJzqUbEQ1e08Ii5zXYVTcFfCo+HM+F2/58vSrvt8 EROu+OomB2vxIDFyqIF2UTt13/UFWVxvHcwBgtziEhu4iXKMvgFDdEgFc77rLT8H+sO9ty 3U6iH2DrYM/PwKtpj508qEy+IUrJug5tljmMnPg/N4zQWNiSoxyk6pEDgjCYL/m1iXd/sB KfsNmQVvxP+S+XbGcI+HrkLUQn2BTjvNDWOSesTg2KVF2HrtTRtzQKIeDXn6CpErnA3WBD 6lV/LSeGIK0g3Hvm7yE9wr20Vmx93ZNrfmVWVFvMByZgIub8HG2pQFLQnSb51A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1699304854; 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=RyhUWvptryHr7Sz4ofjXpuWKZwkpDAcmLBQ1/uuyrbLijg192A/cny+0wnHW0xwQ/7zmoj PfrSVwuLOHUZAOCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 4/9] printk: Add this_cpu_in_panic() Date: Mon, 6 Nov 2023 22:13:25 +0106 Message-Id: <20231106210730.115192-5-john.ogness@linutronix.de> In-Reply-To: <20231106210730.115192-1-john.ogness@linutronix.de> References: <20231106210730.115192-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 13:07:52 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781850306793176801 X-GMAIL-MSGID: 1781850306793176801 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 *