* [PATCH v6] riscv: add userland instruction dump to RISC-V splats
@ 2023-09-12 2:13 Yunhui Cui
2023-09-12 12:13 ` Björn Töpel
2023-11-06 15:00 ` patchwork-bot+linux-riscv
0 siblings, 2 replies; 5+ messages in thread
From: Yunhui Cui @ 2023-09-12 2:13 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, guoren, bjorn, conor.dooley, jszhang,
andy.chiu, cuiyunhui, dave.hansen, elver, glider, cyphar,
kirill.shutemov, keescook, linux-riscv, linux-kernel
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
Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
---
arch/riscv/kernel/traps.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
index f798c853bede..bd2e8fa25c43 100644
--- a/arch/riscv/kernel/traps.c
+++ b/arch/riscv/kernel/traps.c
@@ -33,7 +33,21 @@ int show_unhandled_signals = 1;
static DEFINE_SPINLOCK(die_lock);
-static void dump_kernel_instr(const char *loglvl, struct pt_regs *regs)
+static int copy_code(struct pt_regs *regs, u16 *val, const u16 *insns)
+{
+ const void __user *uaddr = (__force const void __user *)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, uaddr, sizeof(*val));
+}
+
+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 +56,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 +85,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 +118,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);
--
2.20.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v6] riscv: add userland instruction dump to RISC-V splats
2023-09-12 2:13 [PATCH v6] riscv: add userland instruction dump to RISC-V splats Yunhui Cui
@ 2023-09-12 12:13 ` Björn Töpel
2023-10-11 3:23 ` [External] " yunhui cui
2023-11-06 15:00 ` patchwork-bot+linux-riscv
1 sibling, 1 reply; 5+ messages in thread
From: Björn Töpel @ 2023-09-12 12:13 UTC (permalink / raw)
To: Yunhui Cui, paul.walmsley, palmer, aou, guoren, bjorn,
conor.dooley, jszhang, andy.chiu, cuiyunhui, dave.hansen, elver,
glider, cyphar, kirill.shutemov, keescook, linux-riscv,
linux-kernel
Yunhui Cui <cuiyunhui@bytedance.com> writes:
> 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
>
> Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
Reviewed-by: Björn Töpel <bjorn@rivosinc.com>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [External] Re: [PATCH v6] riscv: add userland instruction dump to RISC-V splats
2023-09-12 12:13 ` Björn Töpel
@ 2023-10-11 3:23 ` yunhui cui
2023-10-11 13:20 ` Björn Töpel
0 siblings, 1 reply; 5+ messages in thread
From: yunhui cui @ 2023-10-11 3:23 UTC (permalink / raw)
To: Björn Töpel
Cc: paul.walmsley, palmer, aou, guoren, bjorn, conor.dooley, jszhang,
andy.chiu, dave.hansen, elver, glider, cyphar, kirill.shutemov,
keescook, linux-riscv, linux-kernel
Hi Björn,
On Tue, Sep 12, 2023 at 8:13 PM Björn Töpel <bjorn@kernel.org> wrote:
>
> Yunhui Cui <cuiyunhui@bytedance.com> writes:
>
> > 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
> >
> > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
>
> Reviewed-by: Björn Töpel <bjorn@rivosinc.com>
Could u help to merge this patch into linux-next? Or can anyone help
to merge it?
Thanks,
Yunhui
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [External] Re: [PATCH v6] riscv: add userland instruction dump to RISC-V splats
2023-10-11 3:23 ` [External] " yunhui cui
@ 2023-10-11 13:20 ` Björn Töpel
0 siblings, 0 replies; 5+ messages in thread
From: Björn Töpel @ 2023-10-11 13:20 UTC (permalink / raw)
To: yunhui cui
Cc: paul.walmsley, palmer, aou, guoren, bjorn, conor.dooley, jszhang,
andy.chiu, dave.hansen, elver, glider, cyphar, kirill.shutemov,
keescook, linux-riscv, linux-kernel
yunhui cui <cuiyunhui@bytedance.com> writes:
> Hi Björn,
>
> On Tue, Sep 12, 2023 at 8:13 PM Björn Töpel <bjorn@kernel.org> wrote:
>>
>> Yunhui Cui <cuiyunhui@bytedance.com> writes:
>>
>> > 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
>> >
>> > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
>>
>> Reviewed-by: Björn Töpel <bjorn@rivosinc.com>
>
> Could u help to merge this patch into linux-next? Or can anyone help
> to merge it?
Hey Yunhui,
The next merge-window opens soon, so I'd guess it'll be picked up then!
Cheers,
Björn
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v6] riscv: add userland instruction dump to RISC-V splats
2023-09-12 2:13 [PATCH v6] riscv: add userland instruction dump to RISC-V splats Yunhui Cui
2023-09-12 12:13 ` Björn Töpel
@ 2023-11-06 15:00 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+linux-riscv @ 2023-11-06 15:00 UTC (permalink / raw)
To: Yunhui Cui
Cc: linux-riscv, paul.walmsley, palmer, aou, guoren, bjorn,
conor.dooley, jszhang, andy.chiu, dave.hansen, elver, glider,
cyphar, kirill.shutemov, keescook, linux-kernel
Hello:
This patch was applied to riscv/linux.git (for-next)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Tue, 12 Sep 2023 10:13:49 +0800 you wrote:
> 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
>
> [...]
Here is the summary with links:
- [v6] riscv: add userland instruction dump to RISC-V splats
https://git.kernel.org/riscv/c/b8a03a634129
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-11-06 15:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-12 2:13 [PATCH v6] riscv: add userland instruction dump to RISC-V splats Yunhui Cui
2023-09-12 12:13 ` Björn Töpel
2023-10-11 3:23 ` [External] " yunhui cui
2023-10-11 13:20 ` Björn Töpel
2023-11-06 15:00 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox