Skip to content

Commit

Permalink
powerpc/process: Fix interleaved output in show_user_instructions()
Browse files Browse the repository at this point in the history
When two processes crash at the same time, we sometimes encounter
interleaving in the middle of a line:

  init[1]: segfault (11) at 0 nip 0 lr 0 code 1
  init[1]: code: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
  init[74]: segfault (11) at 10a74 nip 1000c198 lr 100078c8 code 1 in sh[10000000+14000]
  XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
  init[1]: code: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
  init[74]: code: 90010024 bf61000c 91490a7c 3fa01002 3be00000 7d3e4b78 3bbd0c20 3b600000
  init[74]: code: 3b9d0040 7c7fe02e 2f830000 419e0028 <89230000> 2f890000 41be001c 4b7f6e79

This patch fixes it by preparing complete lines in a buffer and
printing it at once.

Fixes: 88b0fe1 ("powerpc: Add show_user_instructions()")
Reviewed-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
[mpe: Use seq_buf_printf() not seq_buf_puts() which doesn't NULL terminate]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Christophe Leroy authored and Michael Ellerman committed Oct 13, 2018
1 parent c9386bf commit fb2d950
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions arch/powerpc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <linux/uaccess.h>
#include <linux/elf-randomize.h>
#include <linux/pkeys.h>
#include <linux/seq_buf.h>

#include <asm/pgtable.h>
#include <asm/io.h>
Expand Down Expand Up @@ -1300,7 +1301,9 @@ static void show_instructions(struct pt_regs *regs)
void show_user_instructions(struct pt_regs *regs)
{
unsigned long pc;
int i;
int n = instructions_to_print;
struct seq_buf s;
char buf[96]; /* enough for 8 times 9 + 2 chars */

pc = regs->nip - (instructions_to_print * 3 / 4 * sizeof(int));

Expand All @@ -1314,29 +1317,27 @@ void show_user_instructions(struct pt_regs *regs)
return;
}

pr_info("%s[%d]: code: ", current->comm, current->pid);
seq_buf_init(&s, buf, sizeof(buf));

for (i = 0; i < instructions_to_print; i++) {
int instr;
while (n) {
int i;

if (!(i % 8) && (i > 0)) {
pr_cont("\n");
pr_info("%s[%d]: code: ", current->comm, current->pid);
}
seq_buf_clear(&s);

if (probe_kernel_address((const void *)pc, instr)) {
pr_cont("XXXXXXXX ");
} else {
if (regs->nip == pc)
pr_cont("<%08x> ", instr);
else
pr_cont("%08x ", instr);
for (i = 0; i < 8 && n; i++, n--, pc += sizeof(int)) {
int instr;

if (probe_kernel_address((const void *)pc, instr)) {
seq_buf_printf(&s, "XXXXXXXX ");
continue;
}
seq_buf_printf(&s, regs->nip == pc ? "<%08x> " : "%08x ", instr);
}

pc += sizeof(int);
if (!seq_buf_has_overflowed(&s))
pr_info("%s[%d]: code: %s\n", current->comm,
current->pid, s.buffer);
}

pr_cont("\n");
}

struct regbit {
Expand Down

0 comments on commit fb2d950

Please sign in to comment.