Skip to contentSkip to conversation

arm64: Call __show_regs directly

PATCH Superseded Kefeng Wang 3 participants 9 messages May 8, 2017 – May 25, 2017 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 arm64: Call __show_regs directly

Call __show_regs directly in longjmp_break_handler() and __do_user_fault(), it is to prepare for dump stack when softlockup detected.

---
 arch/arm64/kernel/probes/kprobes.c | 4 ++--
 arch/arm64/mm/fault.c              | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kernel/probes/kprobes.c +2 -2
index c5c4594..d849d98 100644
@@ -522,9 +522,9 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
 		pr_err("current sp %lx does not match saved sp %lx\n",
 		       orig_sp, stack_addr);
 		pr_err("Saved registers for jprobe %p\n", jp);
-		show_regs(saved_regs);
+		__show_regs(saved_regs);
 		pr_err("Current registers\n");
-		show_regs(regs);
+		__show_regs(regs);
 		BUG();
 	}
 	unpause_graph_tracing();
arch/arm64/mm/fault.c +1 -1
index 37b95df..c3f2b10 100644
@@ -250,7 +250,7 @@ static void __do_user_fault(struct task_struct *tsk, unsigned long addr,
 			tsk->comm, task_pid_nr(tsk), inf->name, sig,
 			addr, esr);
 		show_pte(tsk->mm, addr);
-		show_regs(regs);
+		__show_regs(regs);
 	}
 
 	tsk->thread.fault_address = addr;
Signature · 1 line
1.7.12.4
#1 lore raw

PATCH 2/2 arm64: Add dump_backtrace() in show_regs

When the system trigger a softlockup(eg, infinite loop when PREEMPT_NONE), it only shows regs without stack trace, which makes it difficult to adress the issue.

---
 arch/arm64/include/asm/stacktrace.h | 1 +
 arch/arm64/kernel/process.c         | 1 +
 arch/arm64/kernel/traps.c           | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)
arch/arm64/include/asm/stacktrace.h +1 -0
index 801a16db..5b6eafc 100644
@@ -30,5 +30,6 @@ struct stackframe {
 extern int unwind_frame(struct task_struct *tsk, struct stackframe *frame);
 extern void walk_stackframe(struct task_struct *tsk, struct stackframe *frame,
 			    int (*fn)(struct stackframe *, void *), void *data);
+extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk);
 
 #endif	/* __ASM_STACKTRACE_H */
arch/arm64/kernel/process.c +1 -0
index ae2a835..af1ea25 100644
@@ -210,6 +210,7 @@ void __show_regs(struct pt_regs *regs)
 void show_regs(struct pt_regs * regs)
 {
 	__show_regs(regs);
+	dump_backtrace(regs, NULL);
 }
 
 static void tls_thread_flush(void)
arch/arm64/kernel/traps.c +1 -1
index d4d6ae0..368c3c8 100644
@@ -140,7 +140,7 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
 	}
 }
 
-static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
+void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
 {
 	struct stackframe frame;
 	unsigned long irq_stack_ptr;
Signature · 1 line
1.7.12.4
reviewer
#2 lore raw

PATCH 2/2 arm64: Add dump_backtrace() in show_regs

Quoted 3 lines · Kefeng Wang

When the system trigger a softlockup(eg, infinite loop when PREEMPT_NONE), it only shows regs without stack trace, which makes it difficult to adress the issue.

How about:

Generic code expects show_regs() to dump the stack, but arm64's show_regs() does not. This makes it hard to debug softlockups and other issues that reesult in show_regs() being called.

This patch updates arm64's show_regs() to dump the stack, as common code expects.

Quoted 23 lines
---
 arch/arm64/include/asm/stacktrace.h | 1 +
 arch/arm64/kernel/process.c         | 1 +
 arch/arm64/kernel/traps.c           | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)
arch/arm64/include/asm/stacktrace.h +1 -0
index 801a16db..5b6eafc 100644
@@ -30,5 +30,6 @@ struct stackframe {
 extern int unwind_frame(struct task_struct *tsk, struct stackframe *frame);
 extern void walk_stackframe(struct task_struct *tsk, struct stackframe *frame,
 			    int (*fn)(struct stackframe *, void *), void *data);
+extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk);
 
 #endif	/* __ASM_STACKTRACE_H */
arch/arm64/kernel/process.c +0 -0
index ae2a835..af1ea25 100644

arch/arm64/kernel/process.c void __show_regs(struct pt_regs *regs) · line 214

Quoted 5 lines
arch/arm64/kernel/process.c +1 -0
@@ -210,6 +210,7 @@ void __show_regs(struct pt_regs *regs)
 void show_regs(struct pt_regs * regs)
 {
 	__show_regs(regs);
+	dump_backtrace(regs, NULL);
 }

I believe that as we pass the regs down, this should trigger the frame skipping that we want, as I mentioned in reply to v1 [1].

So FWIW, with the commit message fixup:

Thanks,
Mark.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2017-March/496377.html

Quoted 17 lines
arch/arm64/kernel/process.c +0 -0
 static void tls_thread_flush(void)
arch/arm64/kernel/traps.c +1 -1
index d4d6ae0..368c3c8 100644
@@ -140,7 +140,7 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
 	}
 }
 
-static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
+void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
 {
 	struct stackframe frame;
 	unsigned long irq_stack_ptr;
Signature · 1 line
1.7.12.4
#3 lore raw

PATCH 2/2 arm64: Add dump_backtrace() in show_regs

Quoted 5 lines · Mark Rutland
Quoted 3 lines · Kefeng Wang

When the system trigger a softlockup(eg, infinite loop when PREEMPT_NONE), it only shows regs without stack trace, which makes it difficult to adress the issue.

Quoted 9 lines

How about:

Generic code expects show_regs() to dump the stack, but arm64's show_regs() does not. This makes it hard to debug softlockups and other issues that reesult in show_regs() being called.

This patch updates arm64's show_regs() to dump the stack, as common code expects.

Will update, thanks.

Quoted 32 lines
Quoted 23 lines
---
 arch/arm64/include/asm/stacktrace.h | 1 +
 arch/arm64/kernel/process.c         | 1 +
 arch/arm64/kernel/traps.c           | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)
arch/arm64/include/asm/stacktrace.h +1 -0
index 801a16db..5b6eafc 100644
@@ -30,5 +30,6 @@ struct stackframe {
 extern int unwind_frame(struct task_struct *tsk, struct stackframe *frame);
 extern void walk_stackframe(struct task_struct *tsk, struct stackframe *frame,
 			    int (*fn)(struct stackframe *, void *), void *data);
+extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk);
 
 #endif	/* __ASM_STACKTRACE_H */
arch/arm64/kernel/process.c +0 -0
index ae2a835..af1ea25 100644

arch/arm64/kernel/process.c void __show_regs(struct pt_regs *regs) · line 214

Quoted 5 lines
arch/arm64/kernel/process.c +1 -0
@@ -210,6 +210,7 @@ void __show_regs(struct pt_regs *regs)
 void show_regs(struct pt_regs * regs)
 {
 	__show_regs(regs);
+	dump_backtrace(regs, NULL);
 }

I believe that as we pass the regs down, this should trigger the frame skipping that we want, as I mentioned in reply to v1 [1].

Quoted 3 lines

So FWIW, with the commit message fixup:

Thanks for your careful guidance, will update both.

Kefeng

Quoted 26 lines

Thanks,
Mark.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2017-March/496377.html

Quoted 17 lines
arch/arm64/kernel/process.c +0 -0
 static void tls_thread_flush(void)
arch/arm64/kernel/traps.c +1 -1
index d4d6ae0..368c3c8 100644
@@ -140,7 +140,7 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
 	}
 }
 
-static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
+void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
 {
 	struct stackframe frame;
 	unsigned long irq_stack_ptr;
Signature · 1 line
1.7.12.4

.

reviewer
#4 lore raw

PATCH 1/2 arm64: Call __show_regs directly

In reply to Kefeng Wang

Hi,

I see these patches are effectively a v2 of [1].

Please cite prior patch series when posting updates. The context really helps review.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2017-March/494840.html

Quoted 5 lines · Kefeng Wang

Call __show_regs directly in longjmp_break_handler() and __do_user_fault(), it is to prepare for dump stack when softlockup detected.

The above doesn't explain the problem clearly. How about:

Generic code expects show_regs() to also dump the stack, but arm64's show_reg() does not do this. Some arm64 callers of show_regs() *only* want the registers dumped, without the stack.

To enable generic code to work as expected, we need to make show_regs() dump the stack. Where we only want the registers dumped, we must use __show_regs().

This patch updates code to use __show_regs() where only registers are desired. A subsequent patch will modify show_regs().

... with that:

Thanks,
Mark.

Quoted 37 lines
---
 arch/arm64/kernel/probes/kprobes.c | 4 ++--
 arch/arm64/mm/fault.c              | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kernel/probes/kprobes.c +2 -2
index c5c4594..d849d98 100644
@@ -522,9 +522,9 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
 		pr_err("current sp %lx does not match saved sp %lx\n",
 		       orig_sp, stack_addr);
 		pr_err("Saved registers for jprobe %p\n", jp);
-		show_regs(saved_regs);
+		__show_regs(saved_regs);
 		pr_err("Current registers\n");
-		show_regs(regs);
+		__show_regs(regs);
 		BUG();
 	}
 	unpause_graph_tracing();
arch/arm64/mm/fault.c +1 -1
index 37b95df..c3f2b10 100644
@@ -250,7 +250,7 @@ static void __do_user_fault(struct task_struct *tsk, unsigned long addr,
 			tsk->comm, task_pid_nr(tsk), inf->name, sig,
 			addr, esr);
 		show_pte(tsk->mm, addr);
-		show_regs(regs);
+		__show_regs(regs);
 	}
 
 	tsk->thread.fault_address = addr;
Signature · 1 line
1.7.12.4
#5 lore raw

PATCH v2 1/2 arm64: Call __show_regs directly

Generic code expects show_regs() to also dump the stack, but arm64's show_reg() does not do this. Some arm64 callers of show_regs() *only* want the registers dumped, without the stack.

To enable generic code to work as expected, we need to make show_regs() dump the stack. Where we only want the registers dumped, we must use __show_regs().

This patch updates code to use __show_regs() where only registers are desired. A subsequent patch will modify show_regs().

---

v1->v2:
- Update the changelog according to Mark's kindly review, thanks Mark again.

Please see the background from link [1].

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2017-March/494840.html

 arch/arm64/kernel/probes/kprobes.c | 4 ++--
 arch/arm64/mm/fault.c              | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/arm64/kernel/probes/kprobes.c +2 -2
index c5c4594..d849d98 100644
@@ -522,9 +522,9 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
 		pr_err("current sp %lx does not match saved sp %lx\n",
 		       orig_sp, stack_addr);
 		pr_err("Saved registers for jprobe %p\n", jp);
-		show_regs(saved_regs);
+		__show_regs(saved_regs);
 		pr_err("Current registers\n");
-		show_regs(regs);
+		__show_regs(regs);
 		BUG();
 	}
 	unpause_graph_tracing();
arch/arm64/mm/fault.c +1 -1
index 37b95df..c3f2b10 100644
@@ -250,7 +250,7 @@ static void __do_user_fault(struct task_struct *tsk, unsigned long addr,
 			tsk->comm, task_pid_nr(tsk), inf->name, sig,
 			addr, esr);
 		show_pte(tsk->mm, addr);
-		show_regs(regs);
+		__show_regs(regs);
 	}
 
 	tsk->thread.fault_address = addr;
Signature · 1 line
1.7.12.4
#6 lore raw

PATCH v2 2/2 arm64: Add dump_backtrace() in show_regs

Generic code expects show_regs() to dump the stack, but arm64's show_regs() does not. This makes it hard to debug softlockups and other issues that result in show_regs() being called.

This patch updates arm64's show_regs() to dump the stack, as common code expects.

---
 arch/arm64/include/asm/stacktrace.h | 1 +
 arch/arm64/kernel/process.c         | 1 +
 arch/arm64/kernel/traps.c           | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)
arch/arm64/include/asm/stacktrace.h +1 -0
index 801a16db..5b6eafc 100644
@@ -30,5 +30,6 @@ struct stackframe {
 extern int unwind_frame(struct task_struct *tsk, struct stackframe *frame);
 extern void walk_stackframe(struct task_struct *tsk, struct stackframe *frame,
 			    int (*fn)(struct stackframe *, void *), void *data);
+extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk);
 
 #endif	/* __ASM_STACKTRACE_H */
arch/arm64/kernel/process.c +1 -0
index ae2a835..af1ea25 100644
@@ -210,6 +210,7 @@ void __show_regs(struct pt_regs *regs)
 void show_regs(struct pt_regs * regs)
 {
 	__show_regs(regs);
+	dump_backtrace(regs, NULL);
 }
 
 static void tls_thread_flush(void)
arch/arm64/kernel/traps.c +1 -1
index d4d6ae0..368c3c8 100644
@@ -140,7 +140,7 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
 	}
 }
 
-static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
+void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
 {
 	struct stackframe frame;
 	unsigned long irq_stack_ptr;
Signature · 1 line
1.7.12.4
reviewer
#7 lore raw

PATCH v2 2/2 arm64: Add dump_backtrace() in show_regs

Hi,

Quoted 43 lines · Kefeng Wang

Generic code expects show_regs() to dump the stack, but arm64's show_regs() does not. This makes it hard to debug softlockups and other issues that result in show_regs() being called.

This patch updates arm64's show_regs() to dump the stack, as common code expects.

---
 arch/arm64/include/asm/stacktrace.h | 1 +
 arch/arm64/kernel/process.c         | 1 +
 arch/arm64/kernel/traps.c           | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)
arch/arm64/include/asm/stacktrace.h +1 -0
index 801a16db..5b6eafc 100644
@@ -30,5 +30,6 @@ struct stackframe {
 extern int unwind_frame(struct task_struct *tsk, struct stackframe *frame);
 extern void walk_stackframe(struct task_struct *tsk, struct stackframe *frame,
 			    int (*fn)(struct stackframe *, void *), void *data);
+extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk);
 
 #endif	/* __ASM_STACKTRACE_H */
arch/arm64/kernel/process.c +1 -0
index ae2a835..af1ea25 100644
@@ -210,6 +210,7 @@ void __show_regs(struct pt_regs *regs)
 void show_regs(struct pt_regs * regs)
 {
 	__show_regs(regs);
+	dump_backtrace(regs, NULL);
 }
 
 static void tls_thread_flush(void)
arch/arm64/kernel/traps.c +0 -0
index d4d6ae0..368c3c8 100644

arch/arm64/kernel/traps.c static void dump_instr(const char *lvl, struct pt_regs *regs) · line 146

Quoted 8 lines
arch/arm64/kernel/traps.c +1 -1
@@ -140,7 +140,7 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
 	}
 }
 
-static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
+void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
 {
 	struct stackframe frame;
 	unsigned long irq_stack_ptr;

I just realised that we'll need one additional fixup:

arch/arm64/kernel/traps.c +0 -2
index 0805b44..f452fcc 100644
@@ -728,8 +728,6 @@ static int bug_handler(struct pt_regs *regs, unsigned int esr)
                break;
 
        case BUG_TRAP_TYPE_WARN:
-               /* Ideally, report_bug() should backtrace for us... but no. */
-               dump_backtrace(regs, NULL);
                break;
 
        default:

... since report_bug() will call show_regs(), and dump the stack itself now.

With that change, these patches will also fix *_ONCE() traps spewing backtraces every time they're invoked, which was a side-effect of commit:

19d436268dde9538 ("debug: Add _ONCE() logic to report_bug()")

Would you mind folding that into a v3?

Thanks,
Mark.

#8 lore raw

PATCH v2 2/2 arm64: Add dump_backtrace() in show_regs

Quoted 10 lines · Mark Rutland
Quoted 9 lines · Kefeng Wang

Generic code expects show_regs() to dump the stack, but arm64's show_regs() does not. This makes it hard to debug softlockups and other issues that result in show_regs() being called.

This patch updates arm64's show_regs() to dump the stack, as common code expects.

[...]

Quoted 17 lines
arch/arm64/kernel/traps.c +0 -2
index 0805b44..f452fcc 100644
@@ -728,8 +728,6 @@ static int bug_handler(struct pt_regs *regs, unsigned int esr)
                break;
 
        case BUG_TRAP_TYPE_WARN:
-               /* Ideally, report_bug() should backtrace for us... but no. */
-               dump_backtrace(regs, NULL);
                break;
 
        default:

... since report_bug() will call show_regs(), and dump the stack itself now.

Quoted 7 lines

With that change, these patches will also fix *_ONCE() traps spewing backtraces every time they're invoked, which was a side-effect of commit:

19d436268dde9538 ("debug: Add _ONCE() logic to report_bug()")

Would you mind folding that into a v3?

I've queued this locally, so I can just fold that in too. No need to repost.

I'll push what I have at -rc3.

Cheers,

Will