Skip to content

Commit b19aa28

Browse files
Merge patch series "riscv: Dump faulting instructions in oops handler"
Björn Töpel <[email protected]> says: From: Björn Töpel <[email protected]> RISC-V does not dump faulting instructions in the oops handler. This series adds "Code:" dumps to the oops output together with scripts/decodecode support. * b4-shazam-merge: scripts/decodecode: Add support for RISC-V riscv: Add instruction dump to RISC-V splats Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents 91612cf + 00b2425 commit b19aa28

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

arch/riscv/kernel/traps.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ int show_unhandled_signals = 1;
2929

3030
static DEFINE_SPINLOCK(die_lock);
3131

32+
static void dump_kernel_instr(const char *loglvl, struct pt_regs *regs)
33+
{
34+
char str[sizeof("0000 ") * 12 + 2 + 1], *p = str;
35+
const u16 *insns = (u16 *)instruction_pointer(regs);
36+
long bad;
37+
u16 val;
38+
int i;
39+
40+
for (i = -10; i < 2; i++) {
41+
bad = get_kernel_nofault(val, &insns[i]);
42+
if (!bad) {
43+
p += sprintf(p, i == 0 ? "(%04hx) " : "%04hx ", val);
44+
} else {
45+
printk("%sCode: Unable to access instruction at 0x%px.\n",
46+
loglvl, &insns[i]);
47+
return;
48+
}
49+
}
50+
printk("%sCode: %s\n", loglvl, str);
51+
}
52+
3253
void die(struct pt_regs *regs, const char *str)
3354
{
3455
static int die_counter;
@@ -44,8 +65,10 @@ void die(struct pt_regs *regs, const char *str)
4465

4566
pr_emerg("%s [#%d]\n", str, ++die_counter);
4667
print_modules();
47-
if (regs)
68+
if (regs) {
4869
show_regs(regs);
70+
dump_kernel_instr(KERN_EMERG, regs);
71+
}
4972

5073
cause = regs ? regs->cause : -1;
5174
ret = notify_die(DIE_OOPS, str, regs, 0, cause, SIGSEGV);

scripts/decodecode

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ disas() {
9393
${CROSS_COMPILE}strip $t.o
9494
fi
9595

96+
if [ "$ARCH" = "riscv" ]; then
97+
OBJDUMPFLAGS="-M no-aliases --section=.text -D"
98+
${CROSS_COMPILE}strip $t.o
99+
fi
100+
96101
if [ $pc_sub -ne 0 ]; then
97102
if [ $PC ]; then
98103
adj_vma=$(( $PC - $pc_sub ))
@@ -126,8 +131,13 @@ get_substr_opcode_bytes_num()
126131
do
127132
substr+="$opc"
128133

134+
opcode="$substr"
135+
if [ "$ARCH" = "riscv" ]; then
136+
opcode=$(echo $opcode | tr ' ' '\n' | tac | tr -d '\n')
137+
fi
138+
129139
# return if opcode bytes do not match @opline anymore
130-
if ! echo $opline | grep -q "$substr";
140+
if ! echo $opline | grep -q "$opcode";
131141
then
132142
break
133143
fi

0 commit comments

Comments
 (0)