From patchwork Fri Oct 13 20:43:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 152730 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2144304vqb; Fri, 13 Oct 2023 13:44:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFI1Pvcj+MIfQVV35CMxANh1eoAz+4pFGrdPp4djY/YB6aY+KoS6grA3hMDzduMHTkgnp8+ X-Received: by 2002:a05:6a20:5484:b0:171:737:dfaf with SMTP id i4-20020a056a20548400b001710737dfafmr14963492pzk.5.1697229863899; Fri, 13 Oct 2023 13:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697229863; cv=none; d=google.com; s=arc-20160816; b=WCBfqCDz4bBdXC93B02TlQAD0xjsijThu2hmrJzE3koMFoTIdLn7yYTL6DfEEl/HvP +rdzfU+nv+0p/JNTtKiPaljXrz5OiOolbTiz4enZ+l2P5f+U8JZB6P+RluVIxGHOyAEw tVM9bC4O7vnX82UDX1ScSEkUpX20lVZ7FXy2sCaT/bchzCCbqtvlBBwr08vAXlDaY4zc Zt+pG/m/RvuwZzSGEP4GvXINiGRICMxP9ze1Ow+LXp0ghZH4mJvRMYn0eqVyLsqtOtX8 Bwv9/z9QR2En9ahlaJQQZwv82yrC3ue36M3YH6nnZR79enkoUz5Y8u+j1OdVOy3Udckh HEsA== 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=wWIIv+mLjlrT3V2Ul9kxF8dv9mzOp3dRSypIrr6l33g=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=Oj90WTE+9cP5EKf1O8EGI4TuQJLlIvh5TRHTghbtFfDmS47xSIUSZLqohM7znlRmH1 MeKx4rlcVZN35k9kVGog8e5kmBVtK9EN6GdPwtS3hSlFTZyKJ0qhvdLheQKG9li0a97f JmqNbf3xU5AP/UG2jNvdEwUqk8UdCenfLm/QzoDTYtPeQymLiX1JPJJrt48NT8azMY94 kx2mL102D4l/FQnQnmLCJIsGSybL+ogHFc9BPu+T9RoHeazJbtg2OUaFnEESHGbr+83U yBUxsTdCH6PaY/fDgAcpBNrmSNFTmQ+3XGp9F8Z2NlLgChjCACmC+Wyh13t23W6cAc03 QitQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="iQ9j/OaO"; dkim=neutral (no key) header.i=@linutronix.de header.b=XY1qhTh8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id jm7-20020a17090304c700b001c07bac13d0si5039077plb.383.2023.10.13.13.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 13:44:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="iQ9j/OaO"; dkim=neutral (no key) header.i=@linutronix.de header.b=XY1qhTh8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 05BAC8303B23; Fri, 13 Oct 2023 13:44:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231814AbjJMUnv (ORCPT + 19 others); Fri, 13 Oct 2023 16:43:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjJMUns (ORCPT ); Fri, 13 Oct 2023 16:43:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F27CB7 for ; Fri, 13 Oct 2023 13:43:47 -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=wWIIv+mLjlrT3V2Ul9kxF8dv9mzOp3dRSypIrr6l33g=; b=iQ9j/OaO0KmRmMgeb3zvonpmkyX4c5ltMPzzabjnEv9LTH/KM0QA/3FCN0HC2sEOYEczlk dDEeZAht2XukYEi2tuCNweaYqJ/CDzmOTDqW3c6AKtg8jsLkfYyAWmBs9GaR+8e3pFNBpr 9k80QK/8KqpEMxcge+27crw/oBWDh2aw0+pEIY65FLYPz+v8M1Y/D66qmR46egXRRV9KGe NAU13R6AZcjdYaKy9ESM8N2bT1uulWXGJkYtwR2FPftHjrXHmPHsh2liL3AkL1gq9k3uK3 8yIA0bTXL30BGh8qV8zx5QpI76nfTi0Rk/u4nkG/sez+mpfc6SqT4GI8ekxEYA== 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=wWIIv+mLjlrT3V2Ul9kxF8dv9mzOp3dRSypIrr6l33g=; b=XY1qhTh8fG/ononxo4SHAtdSqaxOydbsd2QVPEdbzEnvTF5wBVq1jJ2ulbRVTT2/GzIoUU bCfKAVtH5BYIrpBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 1/4] printk: For @suppress_panic_printk check other panic Date: Fri, 13 Oct 2023 22:49:37 +0206 Message-Id: <20231013204340.1112036-2-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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 13 Oct 2023 13:44:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779674501513444865 X-GMAIL-MSGID: 1779674501513444865 Currently @suppress_panic_printk is checked along with non-matching @panic_cpu and current CPU. This works because @suppress_panic_printk is only set when panic_in_progress() is true. Rather than relying on the @suppress_panic_printk semantics, use the concise helper function other_cpu_in_progress(). The helper function exists to avoid open coding such tests. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 80eb79177bab..abb6a50ee26f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2272,8 +2272,7 @@ asmlinkage int vprintk_emit(int facility, int level, if (unlikely(suppress_printk)) return 0; - if (unlikely(suppress_panic_printk) && - atomic_read(&panic_cpu) != raw_smp_processor_id()) + if (unlikely(suppress_panic_printk) && other_cpu_in_panic()) return 0; if (level == LOGLEVEL_SCHED) { 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 * From patchwork Fri Oct 13 20:43:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 152731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2144320vqb; Fri, 13 Oct 2023 13:44:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/303NBKJgSee5stnbRACITQQEFrwoIMggF8o0bM8u6VzmtqziLtlskwit4z6VAqHIQEf1 X-Received: by 2002:a05:6a21:a587:b0:163:c167:964a with SMTP id gd7-20020a056a21a58700b00163c167964amr34323352pzc.1.1697229865813; Fri, 13 Oct 2023 13:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697229865; cv=none; d=google.com; s=arc-20160816; b=DEaxQegpZ+iMClU4eLeT20rjCqDHtyHpLJsXTUjJy3Q8T6utOIjoJZV2PalypoI7sA HjbeQXgCK9R4UQHKuDw44Ib6JCFOBGVh6/oEy7K7HeaJiwdv5B4tfTdwITnqr5fdwVbR /u0Mqz1jcnD6OLzaR+iG68p95OWbYwMfSvdwQzVzZhtBEvWNcC7BO93OELwqybONkfvx kGb2LrFpvduQfssDkChakDNR3CyJqVkgJQeNygbvf/Q7/ufXe665NllGdEToVxzVLXgq 2X1VpLwm0oydmEJiJlPdj6iDRmBx8kBvH2UaYDQG7VvEo0wReJ6IDC5VQniBIWW05SKu 7dbw== 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=DhL7l1aUccuPRBI1pChRIFWIRZ0vcUeOr3QrzqxHYPw=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=yXOu0xnMoAb3NOW2r46ZxUyhyDsc3EY2TkWUBD8EtvzmynDJMLx8N06xg+UIyBnwBC D2pWAdikPSgcrEzbJdf971jGZUlt8FivWBDrDMaNzvFmykNHldNIBC8E/A4VoiM9jhFP ZwgJ5cclyKV44/tSBGbNkmaeLGK2tXTmUwe3GgYHjXaZTf+iI+beKsHZd+MqcTaU4Xkq iwmYv7U1rac0eWJdTefH5vveIIzQFs8nosMKqELB0bnEHDzZIiMAdmwiUTzlX3E3DnYc zaUTMdCo1RIx/LiRqi2izP9S9TTIUK1UGdkVxyyWDv5GUwiGMLKBtKri/8HgTZ0npH22 JbiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zU6f7JCL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=NseDkzKn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id u13-20020a170902e80d00b001b9e82a6beesi5530847plg.548.2023.10.13.13.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 13:44:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zU6f7JCL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=NseDkzKn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id B1EEB82D1C36; Fri, 13 Oct 2023 13:44:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231977AbjJMUnz (ORCPT + 19 others); Fri, 13 Oct 2023 16:43:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231553AbjJMUnt (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 5A8DABE 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=1697229827; 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=DhL7l1aUccuPRBI1pChRIFWIRZ0vcUeOr3QrzqxHYPw=; b=zU6f7JCLrru8rBmPXU4C7JSL7cEjLWttVRhyRM9WhTGarOxRzSSX6zw8AYM4T4XB5hQHZP n2Ynx/MXplkKuezM76hbxZ8h626Xfzl2tZ8DJ/Ei/vOBxIhT+zOWTb48qLitd1e3bH5Yqk pvEFuiyaEiNjgm82AWF/mt848qg41ort9HF5vdldWMS4TaFb2KNrwpR1aSf8Iaq9lPuHNS ppSsekSqvEFBAMe7UHduikjS0odsor6/pMYJoonuQOplsHOuw/CZP5BlNW03LgJMKGjRJF Qh3YHFT6s06M661wO499uZ2nXpoua6b7K6lvxaVPjFxgpOrJZ8hMCtB/JNInCA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697229827; 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=DhL7l1aUccuPRBI1pChRIFWIRZ0vcUeOr3QrzqxHYPw=; b=NseDkzKnu+69pUds5Z0kYR49DJsN5ek4ibBK34gcLW0kWLSuv0N98mqvAOIIqTdhVUs7W4 CDM9ihipdnvt2hBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 3/4] printk: Skip unfinalized records in panic Date: Fri, 13 Oct 2023 22:49:39 +0206 Message-Id: <20231013204340.1112036-4-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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 13 Oct 2023 13:44:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779674503805368326 X-GMAIL-MSGID: 1779674503805368326 Normally a reader will stop once reaching an unfinalized record. However, when a panic happens, writers from other CPUs (or an interrupted context on the panic CPU) may have been writing a record and were unable to finalize it. The panic CPU will reserve/commit/finalize its panic records, but these will be located after the unfinalized records. This results in panic() not flushing the panic messages. Add a special case to printk_get_next_message() to allow skipping over unfinalized records if on the panic CPU. Also refine the documentation of the ringbuffer reading functions to clarify that failure may also be due to an unfinalized record. Fixes: 896fbe20b4e2 ("printk: use the lockless ringbuffer") Signed-off-by: John Ogness --- kernel/printk/printk.c | 15 +++++++++++++-- kernel/printk/printk_ringbuffer.c | 9 +++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 19b752880879..56d9b4acbbf2 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2813,8 +2813,19 @@ static bool printk_get_next_message(struct printk_message *pmsg, u64 seq, else prb_rec_init_rd(&r, &info, outbuf, outbuf_sz); - if (!prb_read_valid(prb, seq, &r)) - return false; + while (!prb_read_valid(prb, seq, &r)) { + if (this_cpu_in_panic() && seq < prb_next_seq(prb)) { + /* + * The record @seq is not finalized and there may be + * more records in the ringbuffer. Since this is the + * panic CPU, skip over the unfinalized record and + * try to read a finalized record that may follow. + */ + seq++; + } else { + return false; + } + } pmsg->seq = r.info->seq; pmsg->dropped = r.info->seq - seq; diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index 2dc4d5a1f1ff..1bbc008109ef 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1876,8 +1876,9 @@ static u64 prb_first_seq(struct printk_ringbuffer *rb) } /* - * Non-blocking read of a record. Updates @seq to the last finalized record - * (which may have no data available). + * Non-blocking read of a record. Updates @seq to the record that was read + * (which may have no data available) or was attempted to be read (in case + * it was unfinalized or non-existent). * * See the description of prb_read_valid() and prb_read_valid_info() * for details. @@ -1932,7 +1933,7 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, * On success, the reader must check r->info.seq to see which record was * actually read. This allows the reader to detect dropped records. * - * Failure means @seq refers to a not yet written record. + * Failure means @seq refers to a not yet finalized or non-existing record. */ bool prb_read_valid(struct printk_ringbuffer *rb, u64 seq, struct printk_record *r) @@ -1962,7 +1963,7 @@ bool prb_read_valid(struct printk_ringbuffer *rb, u64 seq, * On success, the reader must check info->seq to see which record meta data * was actually read. This allows the reader to detect dropped records. * - * Failure means @seq refers to a not yet written record. + * Failure means @seq refers to a not yet finalized or non-existing record. */ bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq, struct printk_info *info, unsigned int *line_count) From patchwork Fri Oct 13 20:43:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 152729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2144302vqb; Fri, 13 Oct 2023 13:44:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNVOo/MgJejHUHwXlqolSDchHmxkS1qNa3uq/r3lRzxzkGfP6ulkFhOA3U5eYRupCz2L2P X-Received: by 2002:a05:6359:b9a:b0:147:eb87:3665 with SMTP id gf26-20020a0563590b9a00b00147eb873665mr23604318rwb.3.1697229863784; Fri, 13 Oct 2023 13:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697229863; cv=none; d=google.com; s=arc-20160816; b=CG9boHFMgBB6Dw+vPgYyKIqPEJJ9lHmIOxEr+giluDp4nmR6dowIlhvuyWXiYR7qUF RstsXg5edGkOX+/giLd5Fvk9cHyKzWkLnPL8qxP9/BaW4hifIIR4JA/ktXhLJGhOi4pX 2qQgYMPRbOPQf4ygLtTNyEvZop9hdWKvkNGS3fmqZrcgWltAeIahUVyQFT6S40HwPo+Q cFYNSxrVehzw5AybQYbck2n8ZWLpibr3S1Upiwe9KfslQNivln0OjxpSWsYoeirnnDMU W0MjNuvcanWeXkYcPvPqQtPuAIH6zuiD2iHWCBH4jmxTh33TKrLVXkBTfZr//PVbzYmY 7V4Q== 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=57p/+gSPfOoKdSF21ACUMUWvxO7+D7FS68Md7CNw7GE=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=lyZN5o3zkIvxFhl9cBgzzwofWXJMx2pl1SLm/zOAbnEJULxTK4QCcw5YNS0URljIwR 1VEW0Pyrd7s4qKYSrIytVP+/m1dn5LUyQy80nFkun41mghT3hWVxr/fb4zIU9vhmTRfF bQczVkkHWtUCCXB8VM/fA001J6KREs5O/kX0AoYNkdPekhdYfm6KO4WeRxTM63vwURrL KihwFJ8rQGuXEMIbJdse16goX5JWJhSqPBIKHuEhuWo8QLYgjcgXV5m7fN2Bbu0RZhY8 d5A9olr660DUf9Myk65B8/gPL2LCd2Y5LuJYDVQMuUNpH08rf/bsKM7782H3d5rkua3J 9z6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0xRJBwAV; 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:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id fi38-20020a056a0039a600b0068a54cfcd74si7820001pfb.192.2023.10.13.13.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 13:44:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0xRJBwAV; 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:6 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 pete.vger.email (Postfix) with ESMTP id D3EFB83BD980; Fri, 13 Oct 2023 13:44:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbjJMUn5 (ORCPT + 19 others); Fri, 13 Oct 2023 16:43:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231680AbjJMUnt (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 9A929BF 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=1697229827; 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=57p/+gSPfOoKdSF21ACUMUWvxO7+D7FS68Md7CNw7GE=; b=0xRJBwAVH/UTiYtp6zcbdVc+c0Ujn60Jf4rk/D5a8G9mOgHOZAlf9xbncVwPRgT3whA8UG usAZZVImCxA+5LUkUX0pJbTfFkF1Yyr+0nmjnyGfkoUytdC8YI9aWYIgqGLDhCKKBFyxX9 CcRrjmMV8iv5MYOaJNPKVsKKxKn+VCqJlQbjgaTwgonRP8+hD5HZmDhxl2DgY/BOIVl/om S7tGO1eHr5WwQ7uUHQfXpjE+XzYi8PZvYqZRPWmQtNC+sh6+w2D6p2OAEIA37PuOIukljA zm/FT01ylYVPgmyNl8aWYntBnyO0qKWK7xYqKINUcfPQG7M4Uje1SdMcTe6How== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697229827; 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=57p/+gSPfOoKdSF21ACUMUWvxO7+D7FS68Md7CNw7GE=; b=sWpIK1b2zhiGcoMSIFK4I5BAQHavPrQ7DURfIvSsasFZVR8eX4g/mmO0MgjRzw/pR7aUyp JRrs1TGPK14eyhAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 4/4] printk: Ignore waiter on panic Date: Fri, 13 Oct 2023 22:49:40 +0206 Message-Id: <20231013204340.1112036-5-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 pete.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 (pete.vger.email [0.0.0.0]); Fri, 13 Oct 2023 13:44:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779674501487842978 X-GMAIL-MSGID: 1779674501487842978 Commit d51507098ff91 ("printk: disable optimistic spin during panic") added checks to avoid becoming a console waiter if a panic is in progress. However, the transition to panic can occur while there is already a waiter. If the panic occurred in a context that does not support printing from the printk() caller context, the waiter CPU may become stopped while still stored as @console_waiter. Then when console_flush_on_panic() is called, the panic CPU will see @console_waiter and handover to the stopped CPU. Here a simple example: CPU0 CPU1 ---- ---- console_lock_spinning_enable() console_trylock_spinning() [set as console waiter] NMI: panic() panic_other_cpus_shutdown() [stopped as console waiter] console_flush_on_panic() console_lock_spinning_enable() [print 1 record] console_lock_spinning_disable_and_check() [handover to stopped CPU1] This results in panic() not flushing the panic messages. Fix this by ignoring any console waiter if the panic CPU is printing. Fixes: dbdda842fe96 ("printk: Add console owner and waiter logic to load balance console writes") Signed-off-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Petr Mladek Reviewed-by: John Ogness --- kernel/printk/printk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 56d9b4acbbf2..cd6493f12970 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1904,7 +1904,8 @@ static int console_lock_spinning_disable_and_check(int cookie) console_owner = NULL; raw_spin_unlock(&console_owner_lock); - if (!waiter) { + /* Waiters are ignored by the panic CPU. */ + if (!waiter || this_cpu_in_panic()) { spin_release(&console_owner_dep_map, _THIS_IP_); return 0; }