From patchwork Fri Oct 13 20:43:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 152728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2144156vqb; Fri, 13 Oct 2023 13:44:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRo4dClCV9lAOQp8VzrX1YvpT/Ym7Fy6Xw84L3diZart19WjtoIYiIe6G0TNSFlPBmKMJC X-Received: by 2002:a05:6a00:1d22:b0:693:38c5:4d6d with SMTP id a34-20020a056a001d2200b0069338c54d6dmr30811753pfx.2.1697229843738; Fri, 13 Oct 2023 13:44:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697229843; cv=none; d=google.com; s=arc-20160816; b=GfSW/UaTv5Qe3UBNUMgTuq+lQzkCXPkXtnV2AP20aT1CfvoNPb8GVUgOi1knBQ7APm wxGmW7DW67Gxs+Eduyu2E6a7SHhoJ3dO+Wg8O0Xc0Iuh6oToWil17m6nWm7JVLLRI5Lc LyIyKafhi/NhEmxypRR/ZLAdX5P/u8BmUJVr9px6kETrLWwU5OVlMacpt8PIZKzy9dMq +0mMLVp0yvjt0PaPcvUgZjsezqK/cu9WPQnB2Pcum9Y5EOG45tQJAaBwdDNA4n6MShGi 16mEALl/wlM60hR6Z769nUR6rE8AXtngA/xdXHHXJyEB+5qeEPSGbBvof52hFKRSHcgX hV6Q== 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=mYzxkwxZz9LXzgUZOnKlYZjB7QiQP/AcfRfhCkfffWU=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=wBfjJILRU9rLmwHHMTAxNKwgWaNs3QHrgWrD+2PngMZqgz+z+XAs6wLbaJx2A/a0Ox yEujmZIh5uyL/jgFA2H2cmj0Qr5oqtSn+KCQCosgCw/OVHxAkiWVkcp+7mSox+Zw8Pdj xF+W0jWkpKAXUS/h3lb+e4D0fZrddJLUdqNoWZN2EkDgC2yhx2ODPyGamix87ZDRTvvK RAacMO8VJJsuQIxCSm9aS8VBaoO6EGBst/fij3i6Xwo2WtYZrW/2QwkL3SUuD8/8F6ch E6LRGNjBNIzKBxrro/U+mY+lhMSGZDRaJrpaaBX3jDgxkmnNQsytWCiaYpi2iVgL3la+ hntw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WZF9t0mB; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s6-20020a056a0008c600b00690d4fad431si18613449pfu.260.2023.10.13.13.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 13:44:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WZF9t0mB; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id B57E782B8A9F; Fri, 13 Oct 2023 13:44:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231922AbjJMUnx (ORCPT + 19 others); Fri, 13 Oct 2023 16:43:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbjJMUnt (ORCPT ); Fri, 13 Oct 2023 16:43:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05387BB for ; Fri, 13 Oct 2023 13:43:48 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697229826; 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=mYzxkwxZz9LXzgUZOnKlYZjB7QiQP/AcfRfhCkfffWU=; b=WZF9t0mBANVVYkG73VGE2cN9flCFUsOuRIGSTjLh39C2aw1HMcMzyIPfC/MmiyXrLYaK5g R0bY39rCL7Fzd3cmOUf3Ex4hjJSypZFhxMpCeZ/xxkpTO359ocBukhcahue4qNpr4e/P9Y 6HT4UK6SUSfrwtZVyytH9FPP1EFwpOt0hcFycJWR7Oaeg9ToQj6Apk56GD3nhDGd1XQVb6 k595uNASeRsswgmi1n28OH5L2xnTVM0Ga+UAUvNcHnvW/AfH40GirLApj/OR70xIqxiZFr IAhU2Hx3Avw6LcE9mS0Y5fujZo6T52AUBcYizxwwkL4tFZeY7/SqIdVJIEdbFw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697229826; 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=mYzxkwxZz9LXzgUZOnKlYZjB7QiQP/AcfRfhCkfffWU=; b=6hKBtv1gpM+ovw3KsKEpHuHn+ASfz/FSSRdq218lNqAJ7oTvpZYhdN2xIgzOq3BWX1rVIJ Ob1sJiFebcu1iiAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 2/4] printk: Add this_cpu_in_panic() Date: Fri, 13 Oct 2023 22:49:38 +0206 Message-Id: <20231013204340.1112036-3-john.ogness@linutronix.de> In-Reply-To: <20231013204340.1112036-1-john.ogness@linutronix.de> References: <20231013204340.1112036-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Fri, 13 Oct 2023 13:44:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779674480738490483 X-GMAIL-MSGID: 1779674480738490483 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 7d4979d5c3ce..2397734c0fd2 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -105,3 +105,4 @@ struct printk_message { }; bool other_cpu_in_panic(void); +bool this_cpu_in_panic(void); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index abb6a50ee26f..19b752880879 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -351,6 +351,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 @@ -2610,26 +2633,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 *