Skip to content

Commit

Permalink
core/backtrace: Serialise printing backtraces
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
oohal authored and stewartsmith committed Jul 25, 2017
1 parent 72aa080 commit 024bbfd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/stack.c
Expand Up @@ -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);
Expand Down

0 comments on commit 024bbfd

Please sign in to comment.