riscv: add userland instruction dump to RISC-V splats
PATCH v4 1/1 riscv: add userland instruction dump to RISC-V splats
Add userland instruction dump and rename dump_kernel_instr() to dump_instr().
An example:
[ 0.822439] Freeing unused kernel image (initmem) memory: 6916K [ 0.823817] Run /init as init process [ 0.839411] init[1]: unhandled signal 4 code 0x1 at 0x000000000005be18 in bb[10000+5fb000] [ 0.840751] CPU: 0 PID: 1 Comm: init Not tainted 5.14.0-rc4-00049-gbd644290aa72-dirty #187 [ 0.841373] Hardware name: , BIOS [ 0.841743] epc : 000000000005be18 ra : 0000000000079e74 sp : 0000003fffcafda0 [ 0.842271] gp : ffffffff816e9dc8 tp : 0000000000000000 t0 : 0000000000000000 [ 0.842947] t1 : 0000003fffc9fdf0 t2 : 0000000000000000 s0 : 0000000000000000 [ 0.843434] s1 : 0000000000000000 a0 : 0000003fffca0190 a1 : 0000003fffcafe18 [ 0.843891] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 [ 0.844357] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000000 [ 0.844803] s2 : 0000000000000000 s3 : 0000000000000000 s4 : 0000000000000000 [ 0.845253] s5 : 0000000000000000 s6 : 0000000000000000 s7 : 0000000000000000 [ 0.845722] s8 : 0000000000000000 s9 : 0000000000000000 s10: 0000000000000000 [ 0.846180] s11: 0000000000d144e0 t3 : 0000000000000000 t4 : 0000000000000000 [ 0.846616] t5 : 0000000000000000 t6 : 0000000000000000 [ 0.847204] status: 0000000200000020 badaddr: 00000000f0028053 cause: 0000000000000002 [ 0.848219] Code: f06f ff5f 3823 fa11 0113 fb01 2e23 0201 0293 0000 (8053) f002 [ 0.851016] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
--- arch/riscv/kernel/traps.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
arch/riscv/kernel/traps.c +21 -3
@@ -33,7 +33,24 @@ int show_unhandled_signals = 1;static DEFINE_SPINLOCK (die_lock); -static void dump_kernel_instr (const char *loglvl,struct pt_regs *regs) +#define get_user_nofault (val, ptr) ({ \ + const typeof(val) *__gk_ptr = (ptr); \ + copy_from_user_nofault(&(val), __gk_ptr, sizeof(val));\ +}) + +static int copy_code (struct pt_regs *regs,u16 *val,const u16 *insns) +{ +if (!user_mode (regs)) +return get_kernel_nofault (*val, insns); + +/* The user space code from other tasks cannot be accessed. */ +if (regs !=task_pt_regs (current)) +return -EPERM ; + +return get_user_nofault (*val, insns); +} + +static void dump_instr (const char *loglvl,struct pt_regs *regs) {char str[sizeof ("0000 " ) *12 +2 +1 ], *p = str;const u16 *insns = (u16 *)instruction_pointer (regs);
@@ -42,7 +59,7 @@ static void dump_kernel_instr(const char *loglvl, struct pt_regs *regs)int i;for (i =-10 ; i <2 ; i++) { - bad =get_kernel_nofault (val, &insns[i]); + bad =copy_code (regs, &val, &insns[i]);if (!bad) { p +=sprintf (p, i ==0 ?"(%04hx) " :"%04hx " , val); }else {
@@ -71,7 +88,7 @@ void die(struct pt_regs *regs, const char *str)print_modules ();if (regs) {show_regs (regs); -dump_kernel_instr (KERN_EMERG , regs); +dump_instr (KERN_EMERG , regs); } cause = regs ? regs->cause :-1 ;
@@ -104,6 +121,7 @@ void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr)print_vma_addr (KERN_CONT " in " ,instruction_pointer (regs));pr_cont ("\n" );__show_regs (regs); +dump_instr (KERN_EMERG , regs); }force_sig_fault (signo, code, (void __user *)addr);
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 24 lines · Yunhui Cui
Add userland instruction dump and rename
dump_kernel_instr()todump_instr().An example:
[ 0.822439] Freeing unused kernel image (initmem) memory: 6916K [ 0.823817] Run /init as init process [ 0.839411] init[1]: unhandled signal 4 code 0x1 at 0x000000000005be18 in bb[10000+5fb000] [ 0.840751] CPU: 0 PID: 1 Comm: init Not tainted 5.14.0-rc4-00049-gbd644290aa72-dirty #187 [ 0.841373] Hardware name: , BIOS [ 0.841743] epc : 000000000005be18 ra : 0000000000079e74 sp : 0000003fffcafda0 [ 0.842271] gp : ffffffff816e9dc8 tp : 0000000000000000 t0 : 0000000000000000 [ 0.842947] t1 : 0000003fffc9fdf0 t2 : 0000000000000000 s0 : 0000000000000000 [ 0.843434] s1 : 0000000000000000 a0 : 0000003fffca0190 a1 : 0000003fffcafe18 [ 0.843891] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 [ 0.844357] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000000 [ 0.844803] s2 : 0000000000000000 s3 : 0000000000000000 s4 : 0000000000000000 [ 0.845253] s5 : 0000000000000000 s6 : 0000000000000000 s7 : 0000000000000000 [ 0.845722] s8 : 0000000000000000 s9 : 0000000000000000 s10: 0000000000000000 [ 0.846180] s11: 0000000000d144e0 t3 : 0000000000000000 t4 : 0000000000000000 [ 0.846616] t5 : 0000000000000000 t6 : 0000000000000000 [ 0.847204] status: 0000000200000020 badaddr: 00000000f0028053 cause: 0000000000000002 [ 0.848219] Code: f06f ff5f 3823 fa11 0113 fb01 2e23 0201 0293 0000 (8053) f002 [ 0.851016] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
Quoted 1 line
Signed-off-by Yunhui Cui <[email protected]>
Nice!
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Hi Björn,
Quoted 27 lines · Björn Töpel
Quoted 24 lines · Yunhui Cui
Add userland instruction dump and rename
dump_kernel_instr()todump_instr().An example:
[ 0.822439] Freeing unused kernel image (initmem) memory: 6916K [ 0.823817] Run /init as init process [ 0.839411] init[1]: unhandled signal 4 code 0x1 at 0x000000000005be18 in bb[10000+5fb000] [ 0.840751] CPU: 0 PID: 1 Comm: init Not tainted 5.14.0-rc4-00049-gbd644290aa72-dirty #187 [ 0.841373] Hardware name: , BIOS [ 0.841743] epc : 000000000005be18 ra : 0000000000079e74 sp : 0000003fffcafda0 [ 0.842271] gp : ffffffff816e9dc8 tp : 0000000000000000 t0 : 0000000000000000 [ 0.842947] t1 : 0000003fffc9fdf0 t2 : 0000000000000000 s0 : 0000000000000000 [ 0.843434] s1 : 0000000000000000 a0 : 0000003fffca0190 a1 : 0000003fffcafe18 [ 0.843891] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 [ 0.844357] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000000 [ 0.844803] s2 : 0000000000000000 s3 : 0000000000000000 s4 : 0000000000000000 [ 0.845253] s5 : 0000000000000000 s6 : 0000000000000000 s7 : 0000000000000000 [ 0.845722] s8 : 0000000000000000 s9 : 0000000000000000 s10: 0000000000000000 [ 0.846180] s11: 0000000000d144e0 t3 : 0000000000000000 t4 : 0000000000000000 [ 0.846616] t5 : 0000000000000000 t6 : 0000000000000000 [ 0.847204] status: 0000000200000020 badaddr: 00000000f0028053 cause: 0000000000000002 [ 0.848219] Code: f06f ff5f 3823 fa11 0113 fb01 2e23 0201 0293 0000 (8053) f002 [ 0.851016] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
Quoted 5 lines
Quoted 1 line
Signed-off-by Yunhui Cui <[email protected]>Nice!
Reviewed-by Björn Töpel <[email protected]>
When can this patch be applied to the linux-next branch?
Thanks,
Yunhui
Quoted 30 lines · yunhui cui
Hi Björn,
Quoted 27 lines · Björn Töpel
Quoted 24 lines · Yunhui Cui
Add userland instruction dump and rename
dump_kernel_instr()todump_instr().An example:
[ 0.822439] Freeing unused kernel image (initmem) memory: 6916K [ 0.823817] Run /init as init process [ 0.839411] init[1]: unhandled signal 4 code 0x1 at 0x000000000005be18 in bb[10000+5fb000] [ 0.840751] CPU: 0 PID: 1 Comm: init Not tainted 5.14.0-rc4-00049-gbd644290aa72-dirty #187 [ 0.841373] Hardware name: , BIOS [ 0.841743] epc : 000000000005be18 ra : 0000000000079e74 sp : 0000003fffcafda0 [ 0.842271] gp : ffffffff816e9dc8 tp : 0000000000000000 t0 : 0000000000000000 [ 0.842947] t1 : 0000003fffc9fdf0 t2 : 0000000000000000 s0 : 0000000000000000 [ 0.843434] s1 : 0000000000000000 a0 : 0000003fffca0190 a1 : 0000003fffcafe18 [ 0.843891] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 [ 0.844357] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000000 [ 0.844803] s2 : 0000000000000000 s3 : 0000000000000000 s4 : 0000000000000000 [ 0.845253] s5 : 0000000000000000 s6 : 0000000000000000 s7 : 0000000000000000 [ 0.845722] s8 : 0000000000000000 s9 : 0000000000000000 s10: 0000000000000000 [ 0.846180] s11: 0000000000d144e0 t3 : 0000000000000000 t4 : 0000000000000000 [ 0.846616] t5 : 0000000000000000 t6 : 0000000000000000 [ 0.847204] status: 0000000200000020 badaddr: 00000000f0028053 cause: 0000000000000002 [ 0.848219] Code: f06f ff5f 3823 fa11 0113 fb01 2e23 0201 0293 0000 (8053) f002 [ 0.851016] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Yunhui Cui <[email protected]>Nice!
Reviewed-by Björn Töpel <[email protected]>When can this patch be applied to the linux-next branch?
It looks like you're getting a sparse warning on the patch [1], and that's probably why it hasn't been considered. You need something like:
--
arch/riscv/kernel/traps.c +1 -2
@@ -34,7 +34,7 @@ int show_unhandled_signals = 1;static DEFINE_SPINLOCK (die_lock);#define get_user_nofault (val, ptr) ({ \ - const typeof(val) *__gk_ptr = (ptr); \ + const typeof(val) __user *__gk_ptr = (__force const typeof(val) __user *)(ptr); \ copy_from_user_nofault(&(val), __gk_ptr, sizeof(val));\ }) --
IDK, maybe it worth removing the define all together, and just open code it.
When you're submitting patches, it's a good thing to track patchwork for warnings/errors.
Björn
[1] https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
Hi Björn,
Quoted 62 lines · Björn Töpel
Quoted 30 lines · yunhui cui
Hi Björn,
Quoted 27 lines · Björn Töpel
Quoted 24 lines · Yunhui Cui
Add userland instruction dump and rename
dump_kernel_instr()todump_instr().An example:
[ 0.822439] Freeing unused kernel image (initmem) memory: 6916K [ 0.823817] Run /init as init process [ 0.839411] init[1]: unhandled signal 4 code 0x1 at 0x000000000005be18 in bb[10000+5fb000] [ 0.840751] CPU: 0 PID: 1 Comm: init Not tainted 5.14.0-rc4-00049-gbd644290aa72-dirty #187 [ 0.841373] Hardware name: , BIOS [ 0.841743] epc : 000000000005be18 ra : 0000000000079e74 sp : 0000003fffcafda0 [ 0.842271] gp : ffffffff816e9dc8 tp : 0000000000000000 t0 : 0000000000000000 [ 0.842947] t1 : 0000003fffc9fdf0 t2 : 0000000000000000 s0 : 0000000000000000 [ 0.843434] s1 : 0000000000000000 a0 : 0000003fffca0190 a1 : 0000003fffcafe18 [ 0.843891] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 [ 0.844357] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000000 [ 0.844803] s2 : 0000000000000000 s3 : 0000000000000000 s4 : 0000000000000000 [ 0.845253] s5 : 0000000000000000 s6 : 0000000000000000 s7 : 0000000000000000 [ 0.845722] s8 : 0000000000000000 s9 : 0000000000000000 s10: 0000000000000000 [ 0.846180] s11: 0000000000d144e0 t3 : 0000000000000000 t4 : 0000000000000000 [ 0.846616] t5 : 0000000000000000 t6 : 0000000000000000 [ 0.847204] status: 0000000200000020 badaddr: 00000000f0028053 cause: 0000000000000002 [ 0.848219] Code: f06f ff5f 3823 fa11 0113 fb01 2e23 0201 0293 0000 (8053) f002 [ 0.851016] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Yunhui Cui <[email protected]>Nice!
Reviewed-by Björn Töpel <[email protected]>When can this patch be applied to the linux-next branch?
It looks like you're getting a sparse warning on the patch [1], and that's probably why it hasn't been considered. You need something like:
--
arch/riscv/kernel/traps.c +1
-2@@ -34,7 +34,7 @@ int show_unhandled_signals = 1;static DEFINE_SPINLOCK (die_lock);#define get_user_nofault (val, ptr) ({ \ - const typeof(val) *__gk_ptr = (ptr); \ + const typeof(val) __user *__gk_ptr = (__force const typeof(val) __user *)(ptr); \ copy_from_user_nofault(&(val), __gk_ptr, sizeof(val));\ }) --IDK, maybe it worth removing the define all together, and just open code it.
Quoted 7 lines
When you're submitting patches, it's a good thing to track patchwork for warnings/errors.
Björn
[1] https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
Okay, I might as well remove the macro, after all, the definition is only here. I'll update it v5 like:
+static int copy_code(struct pt_regs *regs, u16 *val, const u16 *insns) +{
+ if (!user_mode(regs))
+ return get_kernel_nofault(*val, insns);
+
+ /* The user space code from other tasks cannot be accessed. */
+ if (regs != task_pt_regs(current))
+ return -EPERM;
+
+ return copy_from_user_nofault(val, insns, sizeof(*val));
+}
Thanks,
Yunhui
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv