diff mbox

core/backtrace: Serialise printing backtraces

Message ID 20170725020550.5535-1-oohall@gmail.com
State Accepted
Headers show

Commit Message

Oliver O'Halloran July 25, 2017, 2:05 a.m. UTC
Add a lock so that only one thread can print a backtrace at a time.
This should prevent multiple threads from garbaling each other's
backtraces.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 core/stack.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Stewart Smith July 25, 2017, 8:19 a.m. UTC | #1
Oliver O'Halloran <oohall@gmail.com> writes:
> Add a lock so that only one thread can print a backtrace at a time.
> This should prevent multiple threads from garbaling each other's
> backtraces.

I'm sure that discovering this meant that you were in a situation where
everything was perfect and nothing at all was terrible :)

Merged to master as of 024bbfd036bed080a21e30f5a62d287c7e3a42c2
diff mbox

Patch

diff --git a/core/stack.c b/core/stack.c
index 17a4ca43985d..bb7fa625a48c 100644
--- a/core/stack.c
+++ b/core/stack.c
@@ -104,12 +104,24 @@  void __print_backtrace(unsigned int pir,
 		*len = l;
 }
 
+/*
+ * To ensure that we always get backtrace output we bypass the usual console
+ * locking paths. The downside is that when multiple threads need to print
+ * a backtrace they garble each other. To prevent this we use a seperate
+ * lock to serialise printing of the dumps.
+ */
+struct lock bt_lock = LOCK_UNLOCKED;
+
 void backtrace(void)
 {
 	unsigned int ents = STACK_BUF_ENTRIES;
 
+	lock(&bt_lock);
+
 	__backtrace(bt_buf, &ents);
 	__print_backtrace(mfspr(SPR_PIR), bt_buf, ents, NULL, NULL, true);
+
+	unlock(&bt_lock);
 }
 
 void __nomcount __stack_chk_fail(void);