Skip to contentSkip to conversation

stacktrace: add saved stack traces to backtrace self-test

PATCH RESEND In review Vegard Nossum 2 participants 5 messages Jun 27, 2008 – Jun 30, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/2 stacktrace: add saved stack traces to backtrace self-test

Hi,

I'm not really sure to whom this goes. It seems that the original code came through the x86 tree, although the code itself seems to be entirely generic.

(The last time I sent it, it was to Andrew only, though he seemed to be on holidays at the time. Now I have a patch #2 as well!)

Arjan, are there any objections to this?

(This is not intended for 2.6.26. In case that wasn't obvious, heh.)

Vegard

From: Vegard Nossum <[email protected]>
Date: Thu, 26 Jun 2008 13:27:35 +0200
Subject: [PATCH] stacktrace: add saved stack traces to backtrace self-test

This patch adds saved stack-traces to the backtrace suite of self-tests.

Note that we don't depend on or unconditionally enable CONFIG_STACKTRACE because not all architectures may have it (and we still want to enable the other tests for those architectures).

Cc Arjan van de Ven <[email protected]>
---
 kernel/backtracetest.c |   30 +++++++++++++++++++++++++++++-
 lib/Kconfig.debug      |    3 +++
 2 files changed, 32 insertions(+), 1 deletions(-)
kernel/backtracetest.c +29 -1
index d1a7605..50f7abd 100644
@@ -10,9 +10,10 @@
  * of the License.
  */
 
+#include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/sched.h>
-#include <linux/delay.h>
+#include <linux/stacktrace.h>
 
 static struct timer_list backtrace_timer;
 
@@ -22,6 +23,31 @@ static void backtrace_test_timer(unsigned long data)
 	printk("The following trace is a kernel self test and not a bug!\n");
 	dump_stack();
 }
+
+#ifdef CONFIG_STACKTRACE
+static void backtrace_test_saved(void)
+{
+	struct stack_trace trace;
+	unsigned long entries[8];
+
+	printk("Testing a saved backtrace.\n");
+	printk("The following trace is a kernel self test and not a bug!\n");
+
+	trace.nr_entries = 0;
+	trace.max_entries = ARRAY_SIZE(entries);
+	trace.entries = entries;
+	trace.skip = 0;
+
+	save_stack_trace(&trace);
+	print_stack_trace(&trace, 0);
+}
+#else
+static void backtrace_test_saved(void)
+{
+	printk("Saved backtrace test skipped.\n");
+}
+#endif
+
 static int backtrace_regression_test(void)
 {
 	printk("====[ backtrace testing ]===========\n");
@@ -29,6 +55,8 @@ static int backtrace_regression_test(void)
 	printk("The following trace is a kernel self test and not a bug!\n");
 	dump_stack();
 
+	backtrace_test_saved();
+
 	init_timer(&backtrace_timer);
 	backtrace_timer.function = backtrace_test_timer;
 	mod_timer(&backtrace_timer, jiffies + 10);
lib/Kconfig.debug +3 -0
index d2099f4..4dac3c7 100644
@@ -563,6 +563,9 @@ config BACKTRACE_SELF_TEST
 	  for distributions or general kernels, but only for kernel
 	  developers working on architecture code.
 
+	  Note that if you want to also test saved backtraces, you will
+	  have to enable STACKTRACE as well.
+
 	  Say N if you are unsure.
 
 config LKDTM
Signature · 1 line
1.5.4.1
#1 lore raw
Quoted 5 lines · Vegard Nossum

Hi,

I'm not really sure to whom this goes. It seems that the original code came through the x86 tree, although the code itself seems to be entirely generic.

given that i've written the generic stacktrace code for lockdep, i guess it comes to me - the only question would be into which branch ;-)

fortunately there's already a tip/core/stacktrace topic, hosting a change for you as well:

Ingo Molnar (1):
debugging: make stacktrace independent from DEBUG_KERNEL

Johannes Berg (1):
stacktrace: don't crash on invalid stack trace structs

Vegard Nossum (1):
stacktrace: print_stack_trace() cleanup

i'll queue this one up there.

Ingo

#2 lore raw

FYI, it needed the fixlet below.

Ingo

------------->
commit 7bcebd2e3ee8435e2ff0f674a409f46961fda3cc

Author: Ingo Molnar <[email protected]>
Date:   Fri Jun 27 21:20:17 2008 +0200

stacktrace: export print_stack_trace and save_stack_trace

fix:

ERROR: "print_stack_trace" [kernel/backtracetest.ko] undefined!
ERROR: "save_stack_trace" [kernel/backtracetest.ko] undefined!

Conflicts:

arch/x86/kernel/stacktrace.c +1 -7
index c28c342..b7b483b 100644
@@ -74,10 +74,4 @@ void save_stack_trace(struct stack_trace *trace)
 	if (trace->nr_entries < trace->max_entries)
 		trace->entries[trace->nr_entries++] = ULONG_MAX;
 }
-
-void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
-{
-	dump_trace(tsk, NULL, NULL, 0, &save_stack_ops_nosched, trace);
-	if (trace->nr_entries < trace->max_entries)
-		trace->entries[trace->nr_entries++] = ULONG_MAX;
-}
+EXPORT_SYMBOL_GPL(save_stack_trace);
kernel/stacktrace.c +1 -0
index 7eaea9d..eda2f4c 100644
@@ -21,4 +21,5 @@ void print_stack_trace(struct stack_trace *trace, int spaces)
 		print_ip_sym(trace->entries[i]);
 	}
 }
+EXPORT_SYMBOL_GPL(print_stack_trace);
 
#3 lore raw
Quoted 5 lines · Ingo Molnar

FYI, it needed the fixlet below.

Ingo

Oh. I'm sorry :-(

(I'll admit that I've never worked with modules before. I'll try to remember now.)

Quoted 23 lines

------------->
commit 7bcebd2e3ee8435e2ff0f674a409f46961fda3cc

Author: Ingo Molnar <[email protected]>
Date:   Fri Jun 27 21:20:17 2008 +0200

stacktrace: export print_stack_trace and save_stack_trace

fix:

ERROR: "print_stack_trace" [kernel/backtracetest.ko] undefined!
ERROR: "save_stack_trace" [kernel/backtracetest.ko] undefined!

Conflicts:

arch/x86/kernel/stacktrace.c +0 -0
index c28c342..b7b483b 100644

arch/x86/kernel/stacktrace.c void save_stack_trace(struct stack_trace *trace) · line 83

Quoted 10 lines
arch/x86/kernel/stacktrace.c +0 -7
@@ -74,10 +74,4 @@ void save_stack_trace(struct stack_trace *trace)
       if (trace->nr_entries < trace->max_entries)
               trace->entries[trace->nr_entries++] = ULONG_MAX;
 }
-
-void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
-{
-       dump_trace(tsk, NULL, NULL, 0, &save_stack_ops_nosched, trace);
-       if (trace->nr_entries < trace->max_entries)
-               trace->entries[trace->nr_entries++] = ULONG_MAX;
-}

Why is this removed, though? (It seems unrelated, and that's a useful function.)

Vegard

Signature · 4 lines
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
	-- E. W. Dijkstra, EWD1036
#4 lore raw
Quoted 11 lines · Vegard Nossum
Quoted 5 lines · Ingo Molnar

FYI, it needed the fixlet below.

Ingo

Oh. I'm sorry :-(

(I'll admit that I've never worked with modules before. I'll try to remember now.)

i too work with bzImages most of the time. They are convenient single-file objects that are easy to distribute and easy to use, and they also have no Linux-distribution-flavor dependencies. (module load order can be influenced by things like /etc/modprobe.conf and other details - make reproduction harder and testing less conclusive, etc.)

Quoted 28 lines
Quoted 28 lines

------------->
commit 7bcebd2e3ee8435e2ff0f674a409f46961fda3cc

Author: Ingo Molnar <[email protected]>
Date:   Fri Jun 27 21:20:17 2008 +0200

stacktrace: export print_stack_trace and save_stack_trace

fix:

ERROR: "print_stack_trace" [kernel/backtracetest.ko] undefined!
ERROR: "save_stack_trace" [kernel/backtracetest.ko] undefined!

Conflicts:

arch/x86/kernel/stacktrace.c +0 -2
index c28c342..b7b483b 100644
@@ -74,10 +74,4 @@ void save_stack_trace(struct stack_trace *trace)
       if (trace->nr_entries < trace->max_entries)
               trace->entries[trace->nr_entries++] = ULONG_MAX;
 }
-
-void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
Quoted 8 lines

arch/x86/kernel/stacktrace.c void save_stack_trace(struct stack_trace *trace) · line 83

Quoted 5 lines
arch/x86/kernel/stacktrace.c +0 -5
-{
-       dump_trace(tsk, NULL, NULL, 0, &save_stack_ops_nosched, trace);
-       if (trace->nr_entries < trace->max_entries)
-               trace->entries[trace->nr_entries++] = ULONG_MAX;
-}

Why is this removed, though? (It seems unrelated, and that's a useful function.)

that was an oversight - thanks - fixed it - updated commit below.

Ingo

---------------->
commit a73d1be0974856741a258928966b8a03ae6bb74f

Author: Ingo Molnar <[email protected]>
Date:   Fri Jun 27 21:20:17 2008 +0200

stacktrace: fix modular build, export print_stack_trace and save_stack_trace

fix:

ERROR: "print_stack_trace" [kernel/backtracetest.ko] undefined!
ERROR: "save_stack_trace" [kernel/backtracetest.ko] undefined!

and fix:

Building modules, stage 2.
MODPOST 376 modules
ERROR: "print_stack_trace" [kernel/backtracetest.ko] undefined! make[1]: *** [__modpost] Error 1

arch/x86/kernel/stacktrace.c +2 -0
index c28c342..a03e7f6 100644
@@ -74,6 +74,7 @@ void save_stack_trace(struct stack_trace *trace)
 	if (trace->nr_entries < trace->max_entries)
 		trace->entries[trace->nr_entries++] = ULONG_MAX;
 }
+EXPORT_SYMBOL_GPL(save_stack_trace);
 
 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
 {
@@ -81,3 +82,4 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
 	if (trace->nr_entries < trace->max_entries)
 		trace->entries[trace->nr_entries++] = ULONG_MAX;
 }
+EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
kernel/stacktrace.c +2 -0
index 7eaea9d..94b527e 100644
@@ -6,6 +6,7 @@
  *  Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <[email protected]>
  */
 #include <linux/sched.h>
+#include <linux/module.h>
 #include <linux/kallsyms.h>
 #include <linux/stacktrace.h>
 
@@ -21,4 +22,5 @@ void print_stack_trace(struct stack_trace *trace, int spaces)
 		print_ip_sym(trace->entries[i]);
 	}
 }
+EXPORT_SYMBOL_GPL(print_stack_trace);