Skip to content

Commit de7edd3

Browse files
committed
tracing: Disable tracing on warning
Add a traceoff_on_warning option in both the kernel command line as well as a sysctl option. When set, any WARN*() function that is hit will cause the tracing_on variable to be cleared, which disables writing to the ring buffer. This is useful especially when tracing a bug with function tracing. When a warning is hit, the print caused by the warning can flood the trace with the functions that producing the output for the warning. This can make the resulting trace useless by either hiding where the bug happened, or worse, by overflowing the buffer and losing the trace of the bug totally. Acked-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent c3e13c7 commit de7edd3

5 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,6 +3069,19 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
30693069
See also Documentation/trace/ftrace.txt "trace options"
30703070
section.
30713071

3072+
traceoff_on_warning
3073+
[FTRACE] enable this option to disable tracing when a
3074+
warning is hit. This turns off "tracing_on". Tracing can
3075+
be enabled again by echoing '1' into the "tracing_on"
3076+
file located in /sys/kernel/debug/tracing/
3077+
3078+
This option is useful, as it disables the trace before
3079+
the WARNING dump is called, which prevents the trace to
3080+
be filled with content caused by the warning output.
3081+
3082+
This option can also be set at run time via the sysctl
3083+
option: kernel/traceoff_on_warning
3084+
30723085
transparent_hugepage=
30733086
[KNL]
30743087
Format: [always|madvise|never]

‎include/linux/ftrace.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,15 @@ enum ftrace_dump_mode;
824824

825825
extern enum ftrace_dump_mode ftrace_dump_on_oops;
826826

827+
extern void disable_trace_on_warning(void);
828+
extern int __disable_trace_on_warning;
829+
827830
#ifdef CONFIG_PREEMPT
828831
#define INIT_TRACE_RECURSION .trace_recursion = 0,
829832
#endif
830833

834+
#else /* CONFIG_TRACING */
835+
static inline void disable_trace_on_warning(void) { }
831836
#endif /* CONFIG_TRACING */
832837

833838
#ifndef INIT_TRACE_RECURSION

‎kernel/panic.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/notifier.h>
1616
#include <linux/module.h>
1717
#include <linux/random.h>
18+
#include <linux/ftrace.h>
1819
#include <linux/reboot.h>
1920
#include <linux/delay.h>
2021
#include <linux/kexec.h>
@@ -399,6 +400,8 @@ struct slowpath_args {
399400
static void warn_slowpath_common(const char *file, int line, void *caller,
400401
unsigned taint, struct slowpath_args *args)
401402
{
403+
disable_trace_on_warning();
404+
402405
printk(KERN_WARNING "------------[ cut here ]------------\n");
403406
printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
404407

‎kernel/sysctl.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,13 @@ static struct ctl_table kern_table[] = {
600600
.mode = 0644,
601601
.proc_handler = proc_dointvec,
602602
},
603+
{
604+
.procname = "traceoff_on_warning",
605+
.data = &__disable_trace_on_warning,
606+
.maxlen = sizeof(__disable_trace_on_warning),
607+
.mode = 0644,
608+
.proc_handler = proc_dointvec,
609+
},
603610
#endif
604611
#ifdef CONFIG_MODULES
605612
{

‎kernel/trace/trace.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ cpumask_var_t __read_mostly tracing_buffer_mask;
115115

116116
enum ftrace_dump_mode ftrace_dump_on_oops;
117117

118+
/* When set, tracing will stop when a WARN*() is hit */
119+
int __disable_trace_on_warning;
120+
118121
static int tracing_set_tracer(const char *buf);
119122

120123
#define MAX_TRACER_SIZE 100
@@ -149,6 +152,13 @@ static int __init set_ftrace_dump_on_oops(char *str)
149152
}
150153
__setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops);
151154

155+
static int __init stop_trace_on_warning(char *str)
156+
{
157+
__disable_trace_on_warning = 1;
158+
return 1;
159+
}
160+
__setup("traceoff_on_warning=", stop_trace_on_warning);
161+
152162
static int __init boot_alloc_snapshot(char *str)
153163
{
154164
allocate_snapshot = true;
@@ -170,6 +180,7 @@ static int __init set_trace_boot_options(char *str)
170180
}
171181
__setup("trace_options=", set_trace_boot_options);
172182

183+
173184
unsigned long long ns2usecs(cycle_t nsec)
174185
{
175186
nsec += 500;
@@ -562,6 +573,12 @@ void tracing_off(void)
562573
}
563574
EXPORT_SYMBOL_GPL(tracing_off);
564575

576+
void disable_trace_on_warning(void)
577+
{
578+
if (__disable_trace_on_warning)
579+
tracing_off();
580+
}
581+
565582
/**
566583
* tracing_is_on - show state of ring buffers enabled
567584
*/

0 commit comments

Comments
 (0)