Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2401853rdf; Mon, 6 Nov 2023 13:07:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZ1Y3O6J3IPkyvKlofQS48wihawhc3RXcxHYN5fjCVFmL/6cTj2vVDOjG7hiqbJeX/N0GA X-Received: by 2002:a05:6a00:158f:b0:690:fe13:1d28 with SMTP id u15-20020a056a00158f00b00690fe131d28mr37245774pfk.33.1699304870870; Mon, 06 Nov 2023 13:07:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699304870; cv=none; d=google.com; s=arc-20160816; b=08MrDOrklDjwwnSiGeX73RmXD95nJkDOeYYO2VafVyhiR8G6JKwP/DaYRMof4r/Nxm e1v8mMpePnyFs6bvPL9FXN3qhV4gYbTC3rMjUNSgSnl7tGQlzpecGxV3PfcU+Ub10axS 8q4S+1IBICcJ+28Y557cZ+7y5B9NSbpf3HnwFodu7JzQQ2f4e/bOhhUpUE+2+IkTBfmr iAX9xPgfQNN/Wxktpq8wRcrUgrjIRbtU82lEXVKsqYOXYXB2zezzfd77YaOqb+UmYLG+ y6xojdYP9oPiXCzoDpSZpgQ0eep101TDMcMG067Ud+h48a7Wd/LLpXaQPAOiBPzsva7M RCFA== 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 Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s35-20020a056a0017a300b006c347df967dsi8774667pfg.155.2023.11.06.13.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 13:07:50 -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 B9348801B425; Mon, 6 Nov 2023 13:07:49 -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 S233116AbjKFVHm (ORCPT + 99 others); Mon, 6 Nov 2023 16:07:42 -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 Content-Transfer-Encoding: 8bit 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:49 -0800 (PST) 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 * -- 2.39.2