Message ID | 20230113144552.138081-2-bjorn@kernel.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | riscv: Add "Code:", and decodecode support | expand |
Context | Check | Description |
---|---|---|
conchuod/patch_count | success | Link |
conchuod/cover_letter | success | Series has a cover letter |
conchuod/tree_selection | success | Guessed tree name to be for-next |
conchuod/fixes_present | success | Fixes tag not required for -next series |
conchuod/maintainers_pattern | success | MAINTAINERS pattern errors before the patch: 13 and now 13 |
conchuod/verify_signedoff | success | Signed-off-by tag matches author and committer |
conchuod/kdoc | success | Errors and warnings before: 0 this patch: 0 |
conchuod/module_param | success | Was 0 now: 0 |
conchuod/build_rv64_gcc_allmodconfig | success | Errors and warnings before: 0 this patch: 0 |
conchuod/alphanumeric_selects | success | Out of order selects before the patch: 57 and now 57 |
conchuod/build_rv32_defconfig | success | Build OK |
conchuod/dtb_warn_rv64 | success | Errors and warnings before: 4 this patch: 4 |
conchuod/header_inline | success | No static functions without inline keyword in header files |
conchuod/checkpatch | warning | WARNING: printk() should include KERN_<LEVEL> facility level |
conchuod/source_inline | success | Was 0 now: 0 |
conchuod/build_rv64_nommu_k210_defconfig | success | Build OK |
conchuod/verify_fixes | success | No Fixes tag |
conchuod/build_rv64_nommu_virt_defconfig | success | Build OK |
On Jan 13 2023, Björn Töpel wrote: > From: Björn Töpel <bjorn@rivosinc.com> > > Add "Code:" output to RISC-V splats. Mimic x86-64's byte-for-byte > dumps. RISC-V insns are organised in 16-bit parcels, it probably make sense to present them that way.
Andreas Schwab <schwab@linux-m68k.org> writes: >> Add "Code:" output to RISC-V splats. Mimic x86-64's byte-for-byte >> dumps. > > RISC-V insns are organised in 16-bit parcels, it probably make sense to > present them that way. Good point! I'll spin a v2. Thanks for having a look, Björn
diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 549bde5c970a..efadff4190e0 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -29,6 +29,33 @@ int show_unhandled_signals = 1; static DEFINE_SPINLOCK(die_lock); +static void dump_kernel_instr(const char *loglvl, struct pt_regs *regs) +{ +#define PROLOGUE_SIZE 20 +#define EPILOGUE_SIZE 3 +#define OPCODE_BUFSIZE (PROLOGUE_SIZE + 1 + EPILOGUE_SIZE) + u8 opcodes[OPCODE_BUFSIZE]; + unsigned long prologue = regs->epc - PROLOGUE_SIZE; + + if (user_mode(regs)) + return; + + switch (copy_from_kernel_nofault(opcodes, (u8 *)prologue, sizeof(opcodes))) { + case 0: + printk("%sCode: %" __stringify(PROLOGUE_SIZE) "ph <%02x> %" + __stringify(EPILOGUE_SIZE) "ph\n", loglvl, opcodes, + opcodes[PROLOGUE_SIZE], opcodes + PROLOGUE_SIZE + 1); + break; + case -EPERM: + /* No access to the user space stack of other tasks. Ignore. */ + break; + default: + printk("%sCode: Unable to access opcode bytes at 0x%lx.\n", + loglvl, prologue); + break; + } +} + void die(struct pt_regs *regs, const char *str) { static int die_counter; @@ -43,8 +70,10 @@ void die(struct pt_regs *regs, const char *str) pr_emerg("%s [#%d]\n", str, ++die_counter); print_modules(); - if (regs) + if (regs) { show_regs(regs); + dump_kernel_instr(KERN_EMERG, regs); + } cause = regs ? regs->cause : -1; ret = notify_die(DIE_OOPS, str, regs, 0, cause, SIGSEGV);