Received: by 2002:ab3:689a:0:b0:1da:d01c:d2b2 with SMTP id t26csp9751ltj; Fri, 19 Aug 2022 16:08:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR7iQ6e5Vn4SBbgsiTLAuvZKjusCa2ojCX5Amq7+Fyu+Y2yyYS47sb5Wus7jBNsl69cT5TK9 X-Received: by 2002:a17:907:9605:b0:6f5:c66:7c13 with SMTP id gb5-20020a170907960500b006f50c667c13mr6582756ejc.66.1660950487720; Fri, 19 Aug 2022 16:08:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660950487; cv=none; d=google.com; s=arc-20160816; b=bQpFAlfGsU1Dep6eJclqcDvNv9WRdE1gitDVqQissvI/6wLpVwNg5rbpucOwhDoRuS zZXznnJOvMK7EViqp5L9mFE1MhkkfuxavhN8blmny9AgGQJnx2VJ5YidMJvgE4WYsQCv zP/aogx28TtlLFO3oORaZT+04uNHnTCPrG+g2yt8euogV/VNHKDjmpPboghCJFiKrUjo sN2UK6ZOlBh/bpykBFfplOqa6zCSnA6+/wUS6s6pgM0WLdlhJpm8uAsw2cb00cx+34/w MQSnZPcMQ3qcVm/zPRASy4QkXWSWRrWJKvvkNlFnQDBRGru0ymwMHaeTxS6puRdXcfiF otRw== 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:from :dkim-signature; bh=bzGFkTIN1eV205ENSSxwAqghJ7GC09NvM0cYNIKPVVQ=; b=y3+g4NUGn8AVB7KFWZSObA4RIOUtMNTY0Nz6VAOPlX8EsjsjTw+h6ijrJ/R28fmff1 jTKTuhxOd+q36BNpUg9jpdhw0iExrNfQY2q4Uc3JfNK1obOuJwUOB9AsbCGoDMwcYIJz D86blc4gpJNKn14dyxdSNlyu4NGRv/2PrJrnPGzwyUrQ9ctq0AfFJoTUThPosKOfan6Q vpYuSRUQS8j2oAliA7Gr3ukii2m/xMsC/tPTc/DZwQ1vCL1v1rK2VlLYLozfkpNWrF1C eKIf64mtRSqE7IZi/u5Vls9nMokU48Y+DXXxlQGoB5J7Zb5dnhDl8yfYC6uyrmNvhHu5 vcWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=AzhVCmuS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a50fd11000000b0044362798fc7si3626728eds.375.2022.08.19.16.07.32; Fri, 19 Aug 2022 16:08:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=AzhVCmuS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241454AbiHSWW5 (ORCPT + 99 others); Fri, 19 Aug 2022 18:22:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241663AbiHSWW4 (ORCPT ); Fri, 19 Aug 2022 18:22:56 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B01F10E7A9; Fri, 19 Aug 2022 15:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=bzGFkTIN1eV205ENSSxwAqghJ7GC09NvM0cYNIKPVVQ=; b=AzhVCmuSU/fFLe+lgazLXq461g rWlTcBz9vzc3hztKuV11gnmPJswp6BdDA2jApg28Fy+Uo2w61g7jZlJSXeOqTAQYbVZxSGy9JipuB 6w7S/xilAxGAmXMMVnsYag9AJ+2gUD82er23HSQWvozHBeiRK2SK9iQGsZSKhn9yyPpV8Pco+4beC LVCpCvRAuYF1FRW9z15Q1dRf5AvSGwUDCjCSlsSDONAkH3xZJOPZl/xFtZVkciKJXIQWlQoy0I/lV RZgBWuBnkOilm2cYi45ZELRyofmCUHbAX09+35QI1M15oTbM/cFqG5awxE9GY4iottk4EyI2EzvjL nk7fIA2w==; Received: from [179.232.144.59] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1oPAO6-00Cb4O-O3; Sat, 20 Aug 2022 00:22:51 +0200 From: "Guilherme G. Piccoli" To: akpm@linux-foundation.org, bhe@redhat.com, pmladek@suse.com, kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, x86@kernel.org, kernel-dev@igalia.com, kernel@gpiccoli.net, halves@canonical.com, fabiomirmar@gmail.com, alejandro.j.jimenez@oracle.com, andriy.shevchenko@linux.intel.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, d.hatayama@jp.fujitsu.com, dave.hansen@linux.intel.com, dyoung@redhat.com, feng.tang@intel.com, gregkh@linuxfoundation.org, mikelley@microsoft.com, hidehiro.kawai.ez@hitachi.com, jgross@suse.com, john.ogness@linutronix.de, keescook@chromium.org, luto@kernel.org, mhiramat@kernel.org, mingo@redhat.com, paulmck@kernel.org, peterz@infradead.org, rostedt@goodmis.org, senozhatsky@chromium.org, stern@rowland.harvard.edu, tglx@linutronix.de, vgoyal@redhat.com, vkuznets@redhat.com, will@kernel.org, xuqiang36@huawei.com, "Guilherme G. Piccoli" , Sergei Shtylyov Subject: [PATCH V3 06/11] tracing: Improve panic/die notifiers Date: Fri, 19 Aug 2022 19:17:26 -0300 Message-Id: <20220819221731.480795-7-gpiccoli@igalia.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819221731.480795-1-gpiccoli@igalia.com> References: <20220819221731.480795-1-gpiccoli@igalia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Currently the tracing dump_on_oops feature is implemented through separate notifiers, one for die/oops and the other for panic; given they have the same functionality, let's unify them. Also improve the function comment and change the priority of the notifier to make it execute earlier, avoiding showing useless trace data (like the callback names for the other notifiers); finally, we also removed an unnecessary header inclusion. Cc: Petr Mladek Cc: Sergei Shtylyov Cc: Steven Rostedt Signed-off-by: Guilherme G. Piccoli --- V3: - Removed goto usage, as per Steven suggestion (thanks!). V2: - Different approach; instead of using IDs to distinguish die and panic events, rely on address comparison like other notifiers do and as per Petr's suggestion; - Removed ACK from Steven since the code changed. kernel/trace/trace.c | 55 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index d3005279165d..0bacdbcb132f 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -9776,40 +9775,40 @@ static __init int tracer_init_tracefs(void) fs_initcall(tracer_init_tracefs); -static int trace_panic_handler(struct notifier_block *this, - unsigned long event, void *unused) -{ - if (ftrace_dump_on_oops) - ftrace_dump(ftrace_dump_on_oops); - return NOTIFY_OK; -} +static int trace_die_panic_handler(struct notifier_block *self, + unsigned long ev, void *unused); static struct notifier_block trace_panic_notifier = { - .notifier_call = trace_panic_handler, - .next = NULL, - .priority = 150 /* priority: INT_MAX >= x >= 0 */ + .notifier_call = trace_die_panic_handler, + .priority = INT_MAX - 1, }; -static int trace_die_handler(struct notifier_block *self, - unsigned long val, - void *data) -{ - switch (val) { - case DIE_OOPS: - if (ftrace_dump_on_oops) - ftrace_dump(ftrace_dump_on_oops); - break; - default: - break; - } - return NOTIFY_OK; -} - static struct notifier_block trace_die_notifier = { - .notifier_call = trace_die_handler, - .priority = 200 + .notifier_call = trace_die_panic_handler, + .priority = INT_MAX - 1, }; +/* + * The idea is to execute the following die/panic callback early, in order + * to avoid showing irrelevant information in the trace (like other panic + * notifier functions); we are the 2nd to run, after hung_task/rcu_stall + * warnings get disabled (to prevent potential log flooding). + */ +static int trace_die_panic_handler(struct notifier_block *self, + unsigned long ev, void *unused) +{ + if (!ftrace_dump_on_oops) + return NOTIFY_DONE; + + /* The die notifier requires DIE_OOPS to trigger */ + if (self == &trace_die_notifier && ev != DIE_OOPS) + return NOTIFY_DONE; + + ftrace_dump(ftrace_dump_on_oops); + + return NOTIFY_DONE; +} + /* * printk is set to max of 1024, we really don't need it that big. * Nothing should be printing 1000 characters anyway. -- 2.37.2