Skip to contentSkip to conversation

PATCH New [email protected] 1 participant 4 messages Oct 7, 2014

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

I'm dealing with issues with bad backtraces in MIPS kdumps. This patch series fixes the issues with these backtraces.

Note that this does not currently enable DWARF unwinding on the restore side. It's less useful (unless you have a backtrace that runs through the restore code). It could be done, I think, without major hassle, but I'll save that for future assuming these sorts of changes are ok.

Those moves a lot of generic stuff from the x86 dwarf2.h to a new asm-generic version, but does not make any functional changes to that code.

#1 lore raw

PATCH 1/3 mips: Save all registers when saving the frame

From: Corey Minyard <[email protected]>

The MIPS frame save code was just saving a few registers, enough to do a backtrace if every function set up a frame. However, this is not working if you are using DWARF unwinding, because most of the registers are wrong. This was causing kdump backtraces to be short or bogus.

So save all the registers.

---
 arch/mips/include/asm/stacktrace.h | 64 +++++++++++++++++++++++++++++---------
 1 file changed, 50 insertions(+), 14 deletions(-)
arch/mips/include/asm/stacktrace.h +50 -14
index 780ee2c..10c4e9c 100644
@@ -2,6 +2,8 @@
 #define _ASM_STACKTRACE_H
 
 #include <asm/ptrace.h>
+#include <asm/asm.h>
+#include <linux/stringify.h>
 
 #ifdef CONFIG_KALLSYMS
 extern int raw_show_trace;
@@ -20,6 +22,14 @@ static inline unsigned long unwind_stack(struct task_struct *task,
 }
 #endif
 
+#define STR_PTR_LA    __stringify(PTR_LA)
+#define STR_LONG_S    __stringify(LONG_S)
+#define STR_LONG_L    __stringify(LONG_L)
+#define STR_LONGSIZE  __stringify(LONGSIZE)
+
+#define STORE_ONE_REG(r) \
+    STR_LONG_S   " $" __stringify(r)",("STR_LONGSIZE"*"__stringify(r)")(%1)\n\t"
+
 static __always_inline void prepare_frametrace(struct pt_regs *regs)
 {
 #ifndef CONFIG_KALLSYMS
@@ -32,21 +42,47 @@ static __always_inline void prepare_frametrace(struct pt_regs *regs)
 	__asm__ __volatile__(
 		".set push\n\t"
 		".set noat\n\t"
-#ifdef CONFIG_64BIT
-		"1: dla $1, 1b\n\t"
-		"sd $1, %0\n\t"
-		"sd $29, %1\n\t"
-		"sd $31, %2\n\t"
-#else
-		"1: la $1, 1b\n\t"
-		"sw $1, %0\n\t"
-		"sw $29, %1\n\t"
-		"sw $31, %2\n\t"
-#endif
+		/* Store $1 so we can use it */
+		STR_LONG_S " $1,"STR_LONGSIZE"(%1)\n\t"
+		/* Store the PC */
+		"1: " STR_PTR_LA " $1, 1b\n\t"
+		STR_LONG_S " $1,%0\n\t"
+		STORE_ONE_REG(2)
+		STORE_ONE_REG(3)
+		STORE_ONE_REG(4)
+		STORE_ONE_REG(5)
+		STORE_ONE_REG(6)
+		STORE_ONE_REG(7)
+		STORE_ONE_REG(8)
+		STORE_ONE_REG(9)
+		STORE_ONE_REG(10)
+		STORE_ONE_REG(11)
+		STORE_ONE_REG(12)
+		STORE_ONE_REG(13)
+		STORE_ONE_REG(14)
+		STORE_ONE_REG(15)
+		STORE_ONE_REG(16)
+		STORE_ONE_REG(17)
+		STORE_ONE_REG(18)
+		STORE_ONE_REG(19)
+		STORE_ONE_REG(20)
+		STORE_ONE_REG(21)
+		STORE_ONE_REG(22)
+		STORE_ONE_REG(23)
+		STORE_ONE_REG(24)
+		STORE_ONE_REG(25)
+		STORE_ONE_REG(26)
+		STORE_ONE_REG(27)
+		STORE_ONE_REG(28)
+		STORE_ONE_REG(29)
+		STORE_ONE_REG(30)
+		STORE_ONE_REG(31)
+		/* Restore $1 */
+		STR_LONG_L " $1,"STR_LONGSIZE"(%1)\n\t"
 		".set pop\n\t"
-		: "=m" (regs->cp0_epc),
-		"=m" (regs->regs[29]), "=m" (regs->regs[31])
-		: : "memory");
+		: "=m" (regs->cp0_epc)
+		: "r" (regs->regs)
+		: "memory");
 }
 
 #endif /* _ASM_STACKTRACE_H */
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/3 Move generic dwarf2 operations from x86 to asm-generic

In reply to [email protected]

From: Corey Minyard <[email protected]>

A lot of arch/x86/include/asm/dwarf2.h was generic, move it to asm-generic so other arches can get to it.

---
 arch/x86/include/asm/dwarf2.h | 74 +----------------------------------------
 include/asm-generic/dwarf2.h  | 77 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 73 deletions(-)
 create mode 100644 include/asm-generic/dwarf2.h
arch/x86/include/asm/dwarf2.h +1 -73
index f6f1598..3360e2a 100644
@@ -1,79 +1,7 @@
 #ifndef _ASM_X86_DWARF2_H
 #define _ASM_X86_DWARF2_H
 
-#ifndef __ASSEMBLY__
-#warning "asm/dwarf2.h should be only included in pure assembly files"
-#endif
-
-/*
- * Macros for dwarf2 CFI unwind table entries.
- * See "as.info" for details on these pseudo ops. Unfortunately
- * they are only supported in very new binutils, so define them
- * away for older version.
- */
-
-#ifdef CONFIG_AS_CFI
-
-#define CFI_STARTPROC		.cfi_startproc
-#define CFI_ENDPROC		.cfi_endproc
-#define CFI_DEF_CFA		.cfi_def_cfa
-#define CFI_DEF_CFA_REGISTER	.cfi_def_cfa_register
-#define CFI_DEF_CFA_OFFSET	.cfi_def_cfa_offset
-#define CFI_ADJUST_CFA_OFFSET	.cfi_adjust_cfa_offset
-#define CFI_OFFSET		.cfi_offset
-#define CFI_REL_OFFSET		.cfi_rel_offset
-#define CFI_REGISTER		.cfi_register
-#define CFI_RESTORE		.cfi_restore
-#define CFI_REMEMBER_STATE	.cfi_remember_state
-#define CFI_RESTORE_STATE	.cfi_restore_state
-#define CFI_UNDEFINED		.cfi_undefined
-#define CFI_ESCAPE		.cfi_escape
-
-#ifdef CONFIG_AS_CFI_SIGNAL_FRAME
-#define CFI_SIGNAL_FRAME	.cfi_signal_frame
-#else
-#define CFI_SIGNAL_FRAME
-#endif
-
-#if defined(CONFIG_AS_CFI_SECTIONS) && defined(__ASSEMBLY__)
-	/*
-	 * Emit CFI data in .debug_frame sections, not .eh_frame sections.
-	 * The latter we currently just discard since we don't do DWARF
-	 * unwinding at runtime.  So only the offline DWARF information is
-	 * useful to anyone.  Note we should not use this directive if this
-	 * file is used in the vDSO assembly, or if vmlinux.lds.S gets
-	 * changed so it doesn't discard .eh_frame.
-	 */
-	.cfi_sections .debug_frame
-#endif
-
-#else
-
-/*
- * Due to the structure of pre-exisiting code, don't use assembler line
- * comment character # to ignore the arguments. Instead, use a dummy macro.
- */
-.macro cfi_ignore a=0, b=0, c=0, d=0
-.endm
-
-#define CFI_STARTPROC		cfi_ignore
-#define CFI_ENDPROC		cfi_ignore
-#define CFI_DEF_CFA		cfi_ignore
-#define CFI_DEF_CFA_REGISTER	cfi_ignore
-#define CFI_DEF_CFA_OFFSET	cfi_ignore
-#define CFI_ADJUST_CFA_OFFSET	cfi_ignore
-#define CFI_OFFSET		cfi_ignore
-#define CFI_REL_OFFSET		cfi_ignore
-#define CFI_REGISTER		cfi_ignore
-#define CFI_RESTORE		cfi_ignore
-#define CFI_REMEMBER_STATE	cfi_ignore
-#define CFI_RESTORE_STATE	cfi_ignore
-#define CFI_UNDEFINED		cfi_ignore
-#define CFI_ESCAPE		cfi_ignore
-#define CFI_SIGNAL_FRAME	cfi_ignore
-
-#endif
-
+#include <asm-generic/dwarf2.h>
 /*
  * An attempt to make CFI annotations more or less
  * correct and shorter. It is implied that you know
include/asm-generic/dwarf2.h new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/3 mips: Add DWARF unwinding to assembly

In reply to [email protected]

From: Corey Minyard <[email protected]>

This will allow kdump dumps and kgdb to work correctly with MIPS.

---
 arch/mips/Makefile                 |  14 ++-
 arch/mips/include/asm/asm.h        |  13 +-
 arch/mips/include/asm/dwarf2.h     |   6 +
 arch/mips/include/asm/stackframe.h | 245 +++++++++++++++++++++----------------
 arch/mips/kernel/entry.S           |   2 +-
 arch/mips/kernel/genex.S           |  21 ++--
 arch/mips/mm/tlbex-fault.S         |   7 +-
 7 files changed, 187 insertions(+), 121 deletions(-)
 create mode 100644 arch/mips/include/asm/dwarf2.h
arch/mips/Makefile +13 -1
index bbac51e1..6a76ee6 100644
@@ -238,11 +238,23 @@ ifdef CONFIG_64BIT
   endif
 endif
 
-KBUILD_AFLAGS	+= $(cflags-y)
+
+# do binutils support CFI?
+cfireg := $$$$0
+cfi := $(call as-instr,.cfi_startproc\n.cfi_rel_offset $(cfireg)$(comma)0\n.cfi_endproc,-DCONFIG_AS_CFI=1)
+# is .cfi_signal_frame supported too?
+cfi-sigframe := $(call as-instr,.cfi_startproc\n.cfi_signal_frame\n.cfi_endproc,-DCONFIG_AS_CFI_SIGNAL_FRAME=1)
+cfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTIONS=1)
+
+KBUILD_AFLAGS	+= $(cfi) $(cfi-sigframe) $(cfi-sections) $(cflags-y)
 KBUILD_CFLAGS	+= $(cflags-y)
 KBUILD_CPPFLAGS += -DVMLINUX_LOAD_ADDRESS=$(load-y)
 KBUILD_CPPFLAGS += -DDATAOFFSET=$(if $(dataoffset-y),$(dataoffset-y),0)
 
+# This is required to get dwarf unwinding tables into .debug_frame
+# instead of .eh_frame so we don't discard them.
+KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
+
 bootvars-y	= VMLINUX_LOAD_ADDRESS=$(load-y) \
 		  VMLINUX_ENTRY_ADDRESS=$(entry-y)
 
arch/mips/include/asm/asm.h +10 -3
index 7c26b28..8eb79862 100644
@@ -19,6 +19,9 @@
 
 #include <asm/sgidefs.h>
 #include <asm/asm-eva.h>
+#ifdef __ASSEMBLY__
+#include <asm/dwarf2.h>
+#endif
 
 #ifndef CAT
 #ifdef __STDC__
@@ -54,7 +57,9 @@
 		.align	2;				\
 		.type	symbol, @function;		\
 		.ent	symbol, 0;			\
-symbol:		.frame	sp, 0, ra
+symbol:		.frame	sp, 0, ra;			\
+		CFI_STARTPROC
+
 
 /*
  * NESTED - declare nested routine entry point
@@ -63,13 +68,15 @@ symbol:		.frame	sp, 0, ra
 		.globl	symbol;				\
 		.align	2;				\
 		.type	symbol, @function;		\
-		.ent	symbol, 0;			 \
-symbol:		.frame	sp, framesize, rpc
+		.ent	symbol, 0;			\
+symbol:		.frame	sp, framesize, rpc;		\
+		CFI_STARTPROC
 
 /*
  * END - mark end of function
  */
 #define END(function)					\
+		CFI_ENDPROC;				\
 		.end	function;			\
 		.size	function, .-function
 
arch/mips/include/asm/dwarf2.h new file +6 -0
new file mode 100644
index 0000000..1728acd
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_DWARF2_H
+#define _ASM_MIPS_DWARF2_H
+
+#include <asm-generic/dwarf2.h>
+
+#endif /* _ASM_MIPS_DWARF2_H */
arch/mips/include/asm/stackframe.h +141 -104

375 lines not on this page · raw message

arch/mips/kernel/entry.S +1 -1
index 4353d32..6eb3b28 100644
@@ -144,7 +144,7 @@ FEXPORT(syscall_exit_partial)
 	li	t0, _TIF_ALLWORK_MASK
 	and	t0, a2
 	beqz	t0, restore_partial
-	SAVE_STATIC
+	SAVE_STATIC docfi=0
 syscall_exit_work:
 	LONG_L	t0, PT_STATUS(sp)		# returning to kernel mode?
 	andi	t0, t0, KU_USER
arch/mips/kernel/genex.S +12 -9
index ac35e12..68c8d34 100644
@@ -151,6 +151,7 @@ LEAF(__r4k_wait)
 	.align	5
 BUILD_ROLLBACK_PROLOGUE handle_int
 NESTED(handle_int, PT_SIZE, sp)
+	CFI_SIGNAL_FRAME
 #ifdef CONFIG_TRACE_IRQFLAGS
 	/*
 	 * Check to see if the interrupted code has just disabled
@@ -182,18 +183,18 @@ NESTED(handle_int, PT_SIZE, sp)
 1:
 	.set pop
 #endif
-	SAVE_ALL
+	SAVE_ALL docfi=1
 	CLI
 	TRACE_IRQS_OFF
 
 	LONG_L	s0, TI_REGS($28)
 	LONG_S	sp, TI_REGS($28)
-	PTR_LA	ra, ret_from_irq
 	PTR_LA  v0, plat_irq_dispatch
-	jr	v0
+	jal	v0
 #ifdef CONFIG_CPU_MICROMIPS
 	nop
 #endif
+	j	ret_from_irq
 	END(handle_int)
 
 	__INIT
@@ -233,8 +234,8 @@ NESTED(except_vec_ejtag_debug, 0, sp)
  */
 BUILD_ROLLBACK_PROLOGUE except_vec_vi
 NESTED(except_vec_vi, 0, sp)
-	SAVE_SOME
-	SAVE_AT
+	SAVE_SOME docfi=1
+	SAVE_AT docfi=1
 	.set	push
 	.set	noreorder
 	PTR_LA	v1, except_vec_vi_handler
@@ -263,8 +264,8 @@ NESTED(except_vec_vi_handler, 0, sp)
 
 	LONG_L	s0, TI_REGS($28)
 	LONG_S	sp, TI_REGS($28)
-	PTR_LA	ra, ret_from_irq
-	jr	v0
+	jal	v0
+	j	ret_from_irq
 	END(except_vec_vi_handler)
 
 /*
@@ -322,6 +323,7 @@ NESTED(except_vec_nmi, 0, sp)
 	__FINIT
 
 NESTED(nmi_handler, PT_SIZE, sp)
+	CFI_SIGNAL_FRAME
 	.set	push
 	.set	noat
 	/*
@@ -400,6 +402,7 @@ NESTED(nmi_handler, PT_SIZE, sp)
 	.macro	__BUILD_HANDLER exception handler clear verbose ext
 	.align	5
 	NESTED(handle_\exception, PT_SIZE, sp)
+	CFI_SIGNAL_FRAME
 	.set	noat
 	SAVE_ALL
 	FEXPORT(handle_\exception\ext)
@@ -407,8 +410,8 @@ NESTED(nmi_handler, PT_SIZE, sp)
 	.set	at
 	__BUILD_\verbose \exception
 	move	a0, sp
-	PTR_LA	ra, ret_from_exception
-	j	do_\handler
+	jal	do_\handler
+	j	ret_from_exception
 	END(handle_\exception)
 	.endm
 
arch/mips/mm/tlbex-fault.S +4 -3
index 318855e..c91cde8 100644
@@ -12,14 +12,15 @@
 
 	.macro tlb_do_page_fault, write
 	NESTED(tlb_do_page_fault_\write, PT_SIZE, sp)
-	SAVE_ALL
+	CFI_SIGNAL_FRAME
+	SAVE_ALL docfi=1
 	MFC0	a2, CP0_BADVADDR
 	KMODE
 	move	a0, sp
 	REG_S	a2, PT_BVADDR(sp)
 	li	a1, \write
-	PTR_LA	ra, ret_from_exception
-	j	do_page_fault
+	jal	do_page_fault
+	j	ret_from_exception
 	END(tlb_do_page_fault_\write)
 	.endm
 
Signature · 1 line
1.8.3.1