Skip to contentSkip to conversation

x86, add hypervisor name to dump_stack() [v2]

PATCH In review Prarit Bhargava 2 participants 2 messages Oct 26, 2012

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

PATCH 1/1 x86, add hypervisor name to dump_stack() [v2]

Debugging crash, panics, stack trace WARN_ONs, etc., from both virtual and bare-metal boots can get difficult very quickly. While there are ways to decipher the output and determine if the output is from a virtual guest, the in-kernel hypervisors now have a single registration point and set x86_hyper. We can use this to output additional debug information during a panic/oops/stack trace.

Cc Avi Kivity <[email protected]>
Cc Gleb Natapov <[email protected]>
Cc Alex Williamson <[email protected]>
Cc Marcelo Tostatti <[email protected]>
Cc Ingo Molnar <[email protected]>

[v2]: Modifications suggested by Ingo and added changes for similar output
from process.c

---
 arch/x86/kernel/dumpstack.c |   11 ++++++++++-
 arch/x86/kernel/process.c   |   12 +++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)
arch/x86/kernel/dumpstack.c +10 -1
index ae42418b..5dd680f 100644
@@ -16,6 +16,7 @@
 #include <linux/nmi.h>
 #include <linux/sysfs.h>
 
+#include <asm/hypervisor.h>
 #include <asm/stacktrace.h>
 
 
@@ -186,9 +187,17 @@ void dump_stack(void)
 {
 	unsigned long bp;
 	unsigned long stack;
+	const char *machine_name = "x86";
+	const char *kernel_type = "native";
+
+	if (x86_hyper) {
+		machine_name = x86_hyper->name;
+		kernel_type = "guest";
+	}
 
 	bp = stack_frame(current, NULL);
-	printk("Pid: %d, comm: %.20s %s %s %.*s\n",
+	printk("[%s %s kernel] Pid: %d, comm: %.20s %s %s %.*s\n",
+		machine_name, kernel_type,
 		current->pid, current->comm, print_tainted(),
 		init_utsname()->release,
 		(int)strcspn(init_utsname()->version, " "),
arch/x86/kernel/process.c +11 -1
index b644e1c..14bd064 100644
@@ -28,6 +28,7 @@
 #include <asm/fpu-internal.h>
 #include <asm/debugreg.h>
 #include <asm/nmi.h>
+#include <asm/hypervisor.h>
 
 /*
  * per-CPU TSS segments. Threads are completely 'soft' on Linux,
@@ -124,6 +125,13 @@ void exit_thread(void)
 void show_regs_common(void)
 {
 	const char *vendor, *product, *board;
+	const char *machine_name = "x86";
+	const char *kernel_type = "native";
+
+	if (x86_hyper) {
+		machine_name = x86_hyper->name;
+		kernel_type = "guest";
+	}
 
 	vendor = dmi_get_system_info(DMI_SYS_VENDOR);
 	if (!vendor)
@@ -135,7 +143,9 @@ void show_regs_common(void)
 	/* Board Name is optional */
 	board = dmi_get_system_info(DMI_BOARD_NAME);
 
-	printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
+	printk(KERN_DEFAULT
+	       "[%s %s kernel] Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
+	       machine_name, kernel_type,
 	       current->pid, current->comm, print_tainted(),
 	       init_utsname()->release,
 	       (int)strcspn(init_utsname()->version, " "),
Signature · 1 line
1.7.9.3
#1 lore raw
Quoted 41 lines · Prarit Bhargava

Debugging crash, panics, stack trace WARN_ONs, etc., from both virtual and bare-metal boots can get difficult very quickly. While there are ways to decipher the output and determine if the output is from a virtual guest, the in-kernel hypervisors now have a single registration point and set x86_hyper. We can use this to output additional debug information during a panic/oops/stack trace.

Cc Avi Kivity <[email protected]>
Cc Gleb Natapov <[email protected]>
Cc Alex Williamson <[email protected]>
Cc Marcelo Tostatti <[email protected]>
Cc Ingo Molnar <[email protected]>

[v2]: Modifications suggested by Ingo and added changes for similar output
from process.c

---
 arch/x86/kernel/dumpstack.c |   11 ++++++++++-
 arch/x86/kernel/process.c   |   12 +++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)
arch/x86/kernel/dumpstack.c +3 -0
index ae42418b..5dd680f 100644
@@ -16,6 +16,7 @@
 #include <linux/nmi.h>
 #include <linux/sysfs.h>
 
+#include <asm/hypervisor.h>
 #include <asm/stacktrace.h>
 
 
@@ -186,9 +187,17 @@ void dump_stack(void)
 {
 	unsigned long bp;
 	unsigned long stack;
+	const char *machine_name = "x86";
+	const char *kernel_type = "native";

arch/x86/kernel/dumpstack.c void dump_stack(void) · line 200

Quoted 10 lines
arch/x86/kernel/dumpstack.c +7 -1
+
+	if (x86_hyper) {
+		machine_name = x86_hyper->name;
+		kernel_type = "guest";
+	}
 
 	bp = stack_frame(current, NULL);
-	printk("Pid: %d, comm: %.20s %s %s %.*s\n",
+	printk("[%s %s kernel] Pid: %d, comm: %.20s %s %s %.*s\n",
+		machine_name, kernel_type,

I'd put the kernel info at the end of the line.

It's all very exciting I know, because we are working on this printout right now and all that - but to users and developers the PID/comm output plus the backtrace is far more important.

Quoted 30 lines
arch/x86/kernel/dumpstack.c +0 -0
 		current->pid, current->comm, print_tainted(),
 		init_utsname()->release,
 		(int)strcspn(init_utsname()->version, " "),
arch/x86/kernel/process.c +8 -0
index b644e1c..14bd064 100644
@@ -28,6 +28,7 @@
 #include <asm/fpu-internal.h>
 #include <asm/debugreg.h>
 #include <asm/nmi.h>
+#include <asm/hypervisor.h>
 
 /*
  * per-CPU TSS segments. Threads are completely 'soft' on Linux,
@@ -124,6 +125,13 @@ void exit_thread(void)
 void show_regs_common(void)
 {
 	const char *vendor, *product, *board;
+	const char *machine_name = "x86";
+	const char *kernel_type = "native";
+
+	if (x86_hyper) {
+		machine_name = x86_hyper->name;
+		kernel_type = "guest";
+	}
 
 	vendor = dmi_get_system_info(DMI_SYS_VENDOR);
 	if (!vendor)

arch/x86/kernel/process.c void show_regs_common(void) · line 151

Quoted 10 lines
arch/x86/kernel/process.c +3 -1
@@ -135,7 +143,9 @@ void show_regs_common(void)
 	/* Board Name is optional */
 	board = dmi_get_system_info(DMI_BOARD_NAME);
 
-	printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
+	printk(KERN_DEFAULT
+	       "[%s %s kernel] Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
+	       machine_name, kernel_type,
 	       current->pid, current->comm, print_tainted(),
 	       init_utsname()->release,
 	       (int)strcspn(init_utsname()->version, " "),

Ha, duplicate code doing almost the same thing!

I suspect you know what my next suggestion would be? :-)

Thanks,

Ingo