LoongArch: Check unwind_error() in show_backtrace()
PATCH 1/1 LoongArch: Check unwind_error() in show_backtrace()
While tracking down the CPU stall issues ([0]), I saw that show_backtrace() stuck in an infinite loop ([1]):
[ 153.610816] Call Trace: [ 153.610929] [<9000000002723eb8>] show_stack+0x5c/0x180 [ 153.611252] [<90000000038e9954>] dump_stack_lvl+0x60/0x88 [ 153.611349] [<90000000038cf8ec>] rcu_dump_cpu_stacks+0xf8/0x150 [ 153.611452] [<90000000027dc5dc>] rcu_sched_clock_irq+0x69c/0xf10 [ 153.611585] [<90000000027f0dfc>] update_process_times+0x6c/0xb4 [ 153.611696] [<9000000002801fb8>] tick_nohz_highres_handler+0x54/0xe0 [ 153.611808] [<90000000027f1898>] __hrtimer_run_queues+0x178/0x344 [ 153.611909] [<90000000027f29dc>] hrtimer_interrupt+0x108/0x28c [ 153.612009] [<90000000027269c4>] constant_timer_interrupt+0x38/0x48 [ 153.612113] [<90000000027b7824>] __handle_irq_event_percpu+0x68/0x24c [ 153.612223] [<90000000027b7a20>] handle_irq_event_percpu+0x18/0x6c [ 153.612327] [<90000000027bdae0>] handle_percpu_irq+0x54/0x88 [ 153.612420] [<90000000027b6af8>] generic_handle_domain_irq+0x28/0x40 [ 153.612524] [<9000000003085b0c>] handle_cpu_irq+0x6c/0xa8 [ 153.612621] [<90000000038e9c28>] handle_loongarch_irq+0x30/0x48 [ 153.612721] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612906] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612985] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613066] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613150] [<90000000038e9cc0>] do_vint+0x80/0xb4 ...
This is because the unwinder does not stop immediately when it reaches non-kernel stackframe at which point it sets unwind_state::error. Add the missing unwind_error() check to resolve the issue.
[0]: https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
[1]: https://github.com/chenhengqi/public/blob/main/verifier_movsx
--- arch/loongarch/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/loongarch/kernel/traps.c +2 -1
@@ -65,7 +65,8 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,printk ("%sCall Trace:" , loglvl);for (unwind_start (&state, task, pregs); - !unwind_done (&state);unwind_next_frame (&state)) { + !unwind_done (&state) && !unwind_error (&state); +unwind_next_frame (&state)) { addr =unwind_get_return_address (&state);print_ip_sym (loglvl, addr); }
Signature · 1 line
2.34.1
Quoted 26 lines · Hengqi Chen
While tracking down the CPU stall issues ([0]), I saw that
show_backtrace()stuck in an infinite loop ([1]):[ 153.610816] Call Trace: [ 153.610929] [<9000000002723eb8>] show_stack+0x5c/0x180 [ 153.611252] [<90000000038e9954>] dump_stack_lvl+0x60/0x88 [ 153.611349] [<90000000038cf8ec>] rcu_dump_cpu_stacks+0xf8/0x150 [ 153.611452] [<90000000027dc5dc>] rcu_sched_clock_irq+0x69c/0xf10 [ 153.611585] [<90000000027f0dfc>] update_process_times+0x6c/0xb4 [ 153.611696] [<9000000002801fb8>] tick_nohz_highres_handler+0x54/0xe0 [ 153.611808] [<90000000027f1898>] __hrtimer_run_queues+0x178/0x344 [ 153.611909] [<90000000027f29dc>] hrtimer_interrupt+0x108/0x28c [ 153.612009] [<90000000027269c4>] constant_timer_interrupt+0x38/0x48 [ 153.612113] [<90000000027b7824>] __handle_irq_event_percpu+0x68/0x24c [ 153.612223] [<90000000027b7a20>] handle_irq_event_percpu+0x18/0x6c [ 153.612327] [<90000000027bdae0>] handle_percpu_irq+0x54/0x88 [ 153.612420] [<90000000027b6af8>] generic_handle_domain_irq+0x28/0x40 [ 153.612524] [<9000000003085b0c>] handle_cpu_irq+0x6c/0xa8 [ 153.612621] [<90000000038e9c28>] handle_loongarch_irq+0x30/0x48 [ 153.612721] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612906] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612985] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613066] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613150] [<90000000038e9cc0>] do_vint+0x80/0xb4 ...
Quoted 3 lines
This is because the unwinder does not stop immediately when it reaches non-kernel stackframe at which point it sets
unwind_state::error.
Hi, Hengqi,
I think we can set state->stack_info.type = STACK_TYPE_UNKNOWN in next_frame() where set state->error = true.
Stack type change to unknown also indicate that the unwind should stop.
The patch way makes us need fix the other place where call unwind_XXX().
Seems commit 370a3b8f5874 ("LoongArch: Check unwind_error() in arch_stack_walk()") can be improved.
Thanks,
Jinyang
Quoted 25 lines
Add the missing
unwind_error()check
to resolve the issue.[0]: https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
[1]: https://github.com/chenhengqi/public/blob/main/verifier_movsxSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +2
-1@@ -65,7 +65,8 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,printk ("%sCall Trace:" , loglvl);for (unwind_start (&state, task, pregs); - !unwind_done (&state);unwind_next_frame (&state)) { + !unwind_done (&state) && !unwind_error (&state); +unwind_next_frame (&state)) { addr =unwind_get_return_address (&state);print_ip_sym (loglvl, addr); }
Huacai Chen
maintainerHi, Hengqi,
Quoted 27 lines · Hengqi Chen
While tracking down the CPU stall issues ([0]), I saw that
show_backtrace()stuck in an infinite loop ([1]):[ 153.610816] Call Trace: [ 153.610929] [<9000000002723eb8>] show_stack+0x5c/0x180 [ 153.611252] [<90000000038e9954>] dump_stack_lvl+0x60/0x88 [ 153.611349] [<90000000038cf8ec>] rcu_dump_cpu_stacks+0xf8/0x150 [ 153.611452] [<90000000027dc5dc>] rcu_sched_clock_irq+0x69c/0xf10 [ 153.611585] [<90000000027f0dfc>] update_process_times+0x6c/0xb4 [ 153.611696] [<9000000002801fb8>] tick_nohz_highres_handler+0x54/0xe0 [ 153.611808] [<90000000027f1898>] __hrtimer_run_queues+0x178/0x344 [ 153.611909] [<90000000027f29dc>] hrtimer_interrupt+0x108/0x28c [ 153.612009] [<90000000027269c4>] constant_timer_interrupt+0x38/0x48 [ 153.612113] [<90000000027b7824>] __handle_irq_event_percpu+0x68/0x24c [ 153.612223] [<90000000027b7a20>] handle_irq_event_percpu+0x18/0x6c [ 153.612327] [<90000000027bdae0>] handle_percpu_irq+0x54/0x88 [ 153.612420] [<90000000027b6af8>] generic_handle_domain_irq+0x28/0x40 [ 153.612524] [<9000000003085b0c>] handle_cpu_irq+0x6c/0xa8 [ 153.612621] [<90000000038e9c28>] handle_loongarch_irq+0x30/0x48 [ 153.612721] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612906] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612985] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613066] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613150] [<90000000038e9cc0>] do_vint+0x80/0xb4 ...
Quoted 4 lines
This is because the unwinder does not stop immediately when it reaches non-kernel stackframe at which point it sets
unwind_state::error. Add the missingunwind_error()check to resolve the issue.
I think this patch doesn't really fix this?
https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
Huacai
Quoted 27 lines
[0]: https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
[1]: https://github.com/chenhengqi/public/blob/main/verifier_movsxSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +2
-2@@ -65,7 +65,8 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,printk ("%sCall Trace:" , loglvl);for (unwind_start (&state, task, pregs); - !unwind_done (&state);unwind_next_frame (&state)) { + !unwind_done (&state) && !unwind_error (&state); +unwind_next_frame (&state)) { addr =unwind_get_return_address (&state);print_ip_sym (loglvl, addr); } --2.34.1
Quoted 33 lines · Jinyang He
Quoted 26 lines · Hengqi Chen
While tracking down the CPU stall issues ([0]), I saw that
show_backtrace()stuck in an infinite loop ([1]):[ 153.610816] Call Trace: [ 153.610929] [<9000000002723eb8>] show_stack+0x5c/0x180 [ 153.611252] [<90000000038e9954>] dump_stack_lvl+0x60/0x88 [ 153.611349] [<90000000038cf8ec>] rcu_dump_cpu_stacks+0xf8/0x150 [ 153.611452] [<90000000027dc5dc>] rcu_sched_clock_irq+0x69c/0xf10 [ 153.611585] [<90000000027f0dfc>] update_process_times+0x6c/0xb4 [ 153.611696] [<9000000002801fb8>] tick_nohz_highres_handler+0x54/0xe0 [ 153.611808] [<90000000027f1898>] __hrtimer_run_queues+0x178/0x344 [ 153.611909] [<90000000027f29dc>] hrtimer_interrupt+0x108/0x28c [ 153.612009] [<90000000027269c4>] constant_timer_interrupt+0x38/0x48 [ 153.612113] [<90000000027b7824>] __handle_irq_event_percpu+0x68/0x24c [ 153.612223] [<90000000027b7a20>] handle_irq_event_percpu+0x18/0x6c [ 153.612327] [<90000000027bdae0>] handle_percpu_irq+0x54/0x88 [ 153.612420] [<90000000027b6af8>] generic_handle_domain_irq+0x28/0x40 [ 153.612524] [<9000000003085b0c>] handle_cpu_irq+0x6c/0xa8 [ 153.612621] [<90000000038e9c28>] handle_loongarch_irq+0x30/0x48 [ 153.612721] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612906] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612985] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613066] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613150] [<90000000038e9cc0>] do_vint+0x80/0xb4 ...Quoted 3 lines
This is because the unwinder does not stop immediately when it reaches non-kernel stackframe at which point it sets
unwind_state::error.
Quoted 8 lines
Hi, Hengqi,
I think we can set
state->stack_info.type = STACK_TYPE_UNKNOWNinnext_frame()where setstate->error = true.Stack type change to unknown also indicate that the unwind should stop.
OK, will do.
Quoted 37 lines
The patch way makes us need fix the other place where call
unwind_XXX().Seems commit
370a3b8f5874("LoongArch: Checkunwind_error()inarch_stack_walk()") can be improved.Thanks,
Jinyang
Quoted 25 lines
Add the missing
unwind_error()check
to resolve the issue.[0]: https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
[1]: https://github.com/chenhengqi/public/blob/main/verifier_movsxSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +2
-1@@ -65,7 +65,8 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,printk ("%sCall Trace:" , loglvl);for (unwind_start (&state, task, pregs); - !unwind_done (&state);unwind_next_frame (&state)) { + !unwind_done (&state) && !unwind_error (&state); +unwind_next_frame (&state)) { addr =unwind_get_return_address (&state);print_ip_sym (loglvl, addr); }
Huacai Chen
maintainerHi, Jinyang,
Quoted 33 lines · Jinyang He
Quoted 26 lines · Hengqi Chen
While tracking down the CPU stall issues ([0]), I saw that
show_backtrace()stuck in an infinite loop ([1]):[ 153.610816] Call Trace: [ 153.610929] [<9000000002723eb8>] show_stack+0x5c/0x180 [ 153.611252] [<90000000038e9954>] dump_stack_lvl+0x60/0x88 [ 153.611349] [<90000000038cf8ec>] rcu_dump_cpu_stacks+0xf8/0x150 [ 153.611452] [<90000000027dc5dc>] rcu_sched_clock_irq+0x69c/0xf10 [ 153.611585] [<90000000027f0dfc>] update_process_times+0x6c/0xb4 [ 153.611696] [<9000000002801fb8>] tick_nohz_highres_handler+0x54/0xe0 [ 153.611808] [<90000000027f1898>] __hrtimer_run_queues+0x178/0x344 [ 153.611909] [<90000000027f29dc>] hrtimer_interrupt+0x108/0x28c [ 153.612009] [<90000000027269c4>] constant_timer_interrupt+0x38/0x48 [ 153.612113] [<90000000027b7824>] __handle_irq_event_percpu+0x68/0x24c [ 153.612223] [<90000000027b7a20>] handle_irq_event_percpu+0x18/0x6c [ 153.612327] [<90000000027bdae0>] handle_percpu_irq+0x54/0x88 [ 153.612420] [<90000000027b6af8>] generic_handle_domain_irq+0x28/0x40 [ 153.612524] [<9000000003085b0c>] handle_cpu_irq+0x6c/0xa8 [ 153.612621] [<90000000038e9c28>] handle_loongarch_irq+0x30/0x48 [ 153.612721] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612906] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612985] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613066] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613150] [<90000000038e9cc0>] do_vint+0x80/0xb4 ...Quoted 3 lines
This is because the unwinder does not stop immediately when it reaches non-kernel stackframe at which point it sets
unwind_state::error.
Quoted 7 lines
Hi, Hengqi,
I think we can set
state->stack_info.type = STACK_TYPE_UNKNOWNinnext_frame()where setstate->error = true.Stack type change to unknown also indicate that the unwind should stop.
In this way arch_stack_walk() don't need to call unwind_error() any more? But then what is the real difference between unwind_done() and unwind_error()?
Huacai
Quoted 38 lines
The patch way makes us need fix the other place where call
unwind_XXX().Seems commit
370a3b8f5874("LoongArch: Checkunwind_error()inarch_stack_walk()") can be improved.Thanks,
Jinyang
Quoted 25 lines
Add the missing
unwind_error()check
to resolve the issue.[0]: https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
[1]: https://github.com/chenhengqi/public/blob/main/verifier_movsxSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +2
-1@@ -65,7 +65,8 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,printk ("%sCall Trace:" , loglvl);for (unwind_start (&state, task, pregs); - !unwind_done (&state);unwind_next_frame (&state)) { + !unwind_done (&state) && !unwind_error (&state); +unwind_next_frame (&state)) { addr =unwind_get_return_address (&state);print_ip_sym (loglvl, addr); }
Quoted 37 lines · Huacai Chen
Hi, Jinyang,
Quoted 34 lines · Jinyang He
Quoted 26 lines · Hengqi Chen
While tracking down the CPU stall issues ([0]), I saw that
show_backtrace()stuck in an infinite loop ([1]):[ 153.610816] Call Trace: [ 153.610929] [<9000000002723eb8>] show_stack+0x5c/0x180 [ 153.611252] [<90000000038e9954>] dump_stack_lvl+0x60/0x88 [ 153.611349] [<90000000038cf8ec>] rcu_dump_cpu_stacks+0xf8/0x150 [ 153.611452] [<90000000027dc5dc>] rcu_sched_clock_irq+0x69c/0xf10 [ 153.611585] [<90000000027f0dfc>] update_process_times+0x6c/0xb4 [ 153.611696] [<9000000002801fb8>] tick_nohz_highres_handler+0x54/0xe0 [ 153.611808] [<90000000027f1898>] __hrtimer_run_queues+0x178/0x344 [ 153.611909] [<90000000027f29dc>] hrtimer_interrupt+0x108/0x28c [ 153.612009] [<90000000027269c4>] constant_timer_interrupt+0x38/0x48 [ 153.612113] [<90000000027b7824>] __handle_irq_event_percpu+0x68/0x24c [ 153.612223] [<90000000027b7a20>] handle_irq_event_percpu+0x18/0x6c [ 153.612327] [<90000000027bdae0>] handle_percpu_irq+0x54/0x88 [ 153.612420] [<90000000027b6af8>] generic_handle_domain_irq+0x28/0x40 [ 153.612524] [<9000000003085b0c>] handle_cpu_irq+0x6c/0xa8 [ 153.612621] [<90000000038e9c28>] handle_loongarch_irq+0x30/0x48 [ 153.612721] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612906] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612985] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613066] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613150] [<90000000038e9cc0>] do_vint+0x80/0xb4 ...Quoted 3 lines
This is because the unwinder does not stop immediately when it reaches non-kernel stackframe at which point it sets
unwind_state::error.Hi, Hengqi,
Quoted 6 lines
Quoted 4 lines
I think we can set
state->stack_info.type = STACK_TYPE_UNKNOWNinnext_frame()where setstate->error = true.Stack type change to unknown also indicate that the unwind should stop.
In this way
arch_stack_walk()don't need to callunwind_error()any more?
Yes. But I think we should not set error in next_frame if (user_mode(regs) || !__kernel_text_address(pc)), because it indicate it should be user stack. Set state->stack_info.type = STACK_TYPE_UNKNOWN is ok, or call get_stack_info() may also be ok. See [1] and follows,
Quoted 2 lines
But then what is the real difference between
unwind_done()andunwind_error()?
unwind_done() means we should finish unwind because stack type is unexpected, not in irq stack or in task stack. Usually unwind exit when it meets user stack, it is probably a normal exit. In most cases it should be a flag of normal exit. unwind_error() means we should finish unwind because something unexpected which maybe caused by previous wrong unwind. For ORC unwinder, we may meet unexpected ORC info and set error. unwind_error() shows stack is unreliable.
Jinyang
Quoted 39 lines
Huacai
Quoted 36 lines
The patch way makes us need fix the other place where call
unwind_XXX().Seems commit
370a3b8f5874("LoongArch: Checkunwind_error()inarch_stack_walk()") can be improved.Thanks,
Jinyang
Quoted 25 lines
Add the missing
unwind_error()check
to resolve the issue.[0]: https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
[1]: https://github.com/chenhengqi/public/blob/main/verifier_movsxSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +2
-1@@ -65,7 +65,8 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,printk ("%sCall Trace:" , loglvl);for (unwind_start (&state, task, pregs); - !unwind_done (&state);unwind_next_frame (&state)) { + !unwind_done (&state) && !unwind_error (&state); +unwind_next_frame (&state)) { addr =unwind_get_return_address (&state);print_ip_sym (loglvl, addr); }
Huacai Chen
maintainerQuoted 56 lines · Jinyang He
Quoted 37 lines · Huacai Chen
Hi, Jinyang,
Quoted 34 lines · Jinyang He
Quoted 26 lines · Hengqi Chen
While tracking down the CPU stall issues ([0]), I saw that
show_backtrace()stuck in an infinite loop ([1]):[ 153.610816] Call Trace: [ 153.610929] [<9000000002723eb8>] show_stack+0x5c/0x180 [ 153.611252] [<90000000038e9954>] dump_stack_lvl+0x60/0x88 [ 153.611349] [<90000000038cf8ec>] rcu_dump_cpu_stacks+0xf8/0x150 [ 153.611452] [<90000000027dc5dc>] rcu_sched_clock_irq+0x69c/0xf10 [ 153.611585] [<90000000027f0dfc>] update_process_times+0x6c/0xb4 [ 153.611696] [<9000000002801fb8>] tick_nohz_highres_handler+0x54/0xe0 [ 153.611808] [<90000000027f1898>] __hrtimer_run_queues+0x178/0x344 [ 153.611909] [<90000000027f29dc>] hrtimer_interrupt+0x108/0x28c [ 153.612009] [<90000000027269c4>] constant_timer_interrupt+0x38/0x48 [ 153.612113] [<90000000027b7824>] __handle_irq_event_percpu+0x68/0x24c [ 153.612223] [<90000000027b7a20>] handle_irq_event_percpu+0x18/0x6c [ 153.612327] [<90000000027bdae0>] handle_percpu_irq+0x54/0x88 [ 153.612420] [<90000000027b6af8>] generic_handle_domain_irq+0x28/0x40 [ 153.612524] [<9000000003085b0c>] handle_cpu_irq+0x6c/0xa8 [ 153.612621] [<90000000038e9c28>] handle_loongarch_irq+0x30/0x48 [ 153.612721] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612906] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612985] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613066] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613150] [<90000000038e9cc0>] do_vint+0x80/0xb4 ...Quoted 3 lines
This is because the unwinder does not stop immediately when it reaches non-kernel stackframe at which point it sets
unwind_state::error.Hi, Hengqi,
Quoted 6 lines
Quoted 4 lines
I think we can set
state->stack_info.type = STACK_TYPE_UNKNOWNinnext_frame()where setstate->error = true.Stack type change to unknown also indicate that the unwind should stop.
In this way
arch_stack_walk()don't need to callunwind_error()any more?Yes. But I think we should not set error in
next_frameif (user_mode(regs) || !__kernel_text_address(pc)), because it indicate it should be user stack. Setstate->stack_info.type = STACK_TYPE_UNKNOWNis ok, or callget_stack_info()may also be ok. See [1] and follows,Quoted 2 lines
But then what is the real difference between
unwind_done()andunwind_error()?
Quoted 8 lines
unwind_done()means we should finish unwind because stack type is unexpected, not in irq stack or in task stack. Usually unwind exit when it meets user stack, it is probably a normal exit. In most cases it should be a flag of normal exit.unwind_error()means we should finish unwind because something unexpected which maybe caused by previous wrong unwind. For ORC unwinder, we may meet unexpected ORC info and set error.unwind_error()shows stack is unreliable.
Then you mean replace state->error = true with state->stack_info.type = STACK_TYPE_UNKNOWN rather than add state->stack_info.type = STACK_TYPE_UNKNOWN after state->error = true in Tiezhu's patch? If so, I suggest you submit a patch because Hengqi may also be confusing (but I'm not sure) here.
Huacai
Quoted 49 lines
Jinyang
Quoted 39 lines
Huacai
Quoted 36 lines
The patch way makes us need fix the other place where call
unwind_XXX().Seems commit
370a3b8f5874("LoongArch: Checkunwind_error()inarch_stack_walk()") can be improved.Thanks,
Jinyang
Quoted 25 lines
Add the missing
unwind_error()check
to resolve the issue.[0]: https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
[1]: https://github.com/chenhengqi/public/blob/main/verifier_movsxSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +2
-1@@ -65,7 +65,8 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,printk ("%sCall Trace:" , loglvl);for (unwind_start (&state, task, pregs); - !unwind_done (&state);unwind_next_frame (&state)) { + !unwind_done (&state) && !unwind_error (&state); +unwind_next_frame (&state)) { addr =unwind_get_return_address (&state);print_ip_sym (loglvl, addr); }
Quoted 61 lines · Huacai Chen
Quoted 52 lines · Jinyang He
Quoted 36 lines · Huacai Chen
Hi, Jinyang,
Quoted 33 lines · Jinyang He
Quoted 26 lines · Hengqi Chen
While tracking down the CPU stall issues ([0]), I saw that
show_backtrace()stuck in an infinite loop ([1]):[ 153.610816] Call Trace: [ 153.610929] [<9000000002723eb8>] show_stack+0x5c/0x180 [ 153.611252] [<90000000038e9954>] dump_stack_lvl+0x60/0x88 [ 153.611349] [<90000000038cf8ec>] rcu_dump_cpu_stacks+0xf8/0x150 [ 153.611452] [<90000000027dc5dc>] rcu_sched_clock_irq+0x69c/0xf10 [ 153.611585] [<90000000027f0dfc>] update_process_times+0x6c/0xb4 [ 153.611696] [<9000000002801fb8>] tick_nohz_highres_handler+0x54/0xe0 [ 153.611808] [<90000000027f1898>] __hrtimer_run_queues+0x178/0x344 [ 153.611909] [<90000000027f29dc>] hrtimer_interrupt+0x108/0x28c [ 153.612009] [<90000000027269c4>] constant_timer_interrupt+0x38/0x48 [ 153.612113] [<90000000027b7824>] __handle_irq_event_percpu+0x68/0x24c [ 153.612223] [<90000000027b7a20>] handle_irq_event_percpu+0x18/0x6c [ 153.612327] [<90000000027bdae0>] handle_percpu_irq+0x54/0x88 [ 153.612420] [<90000000027b6af8>] generic_handle_domain_irq+0x28/0x40 [ 153.612524] [<9000000003085b0c>] handle_cpu_irq+0x6c/0xa8 [ 153.612621] [<90000000038e9c28>] handle_loongarch_irq+0x30/0x48 [ 153.612721] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612906] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612985] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613066] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613150] [<90000000038e9cc0>] do_vint+0x80/0xb4 ...Quoted 3 lines
This is because the unwinder does not stop immediately when it reaches non-kernel stackframe at which point it sets
unwind_state::error.Hi, Hengqi,
Quoted 6 lines
Quoted 4 lines
I think we can set
state->stack_info.type = STACK_TYPE_UNKNOWNinnext_frame()where setstate->error = true.Stack type change to unknown also indicate that the unwind should stop.
In this way
arch_stack_walk()don't need to callunwind_error()any more?Yes. But I think we should not set error in
next_frameif (user_mode(regs) || !__kernel_text_address(pc)), because it indicate it should be user stack. Setstate->stack_info.type = STACK_TYPE_UNKNOWNis ok, or callget_stack_info()may also be ok. See [1] and follows,Quoted 2 lines
But then what is the real difference between
unwind_done()andunwind_error()?Quoted 8 lines
unwind_done()means we should finish unwind because stack type is unexpected, not in irq stack or in task stack. Usually unwind exit when it meets user stack, it is probably a normal exit. In most cases it should be a flag of normal exit.unwind_error()means we should finish unwind because something unexpected which maybe caused by previous wrong unwind. For ORC unwinder, we may meet unexpected ORC info and set error.unwind_error()shows stack is unreliable.
Quoted 5 lines
Then you mean replace
state->error = truewithstate->stack_info.type = STACK_TYPE_UNKNOWNrather than addstate->stack_info.type = STACK_TYPE_UNKNOWNafterstate->error = truein Tiezhu's patch? If so, I suggest you submit a patch because Hengqi may also be confusing (but I'm not sure) here.
Hi, Hengqi,
I created a diff as follows. But I couldn't test it by the way mentioned in [2],
(and I always got the right result in Qemu). Can you test it in your way?
As Huacai said, if you're confused about this, I'm happy to submit this diff as well.
arch/loongarch/kernel/stacktrace.c +0 -0
@@ -32,7 +32,7 @@ void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
}
for (unwind_start(&state, task, regs);
- !unwind_done(&state) && !unwind_error(&state); unwind_next_frame(&state)) { + !unwind_done(&state); unwind_next_frame(&state)) {
addr = unwind_get_return_address(&state);
if (!addr || !consume_entry(cookie, addr))
break;
arch/loongarch/kernel/unwind.c +0 -0
@@ -28,6 +28,5 @@ bool default_next_frame(struct unwind_state *state)
} while (!get_stack_info(state->sp, state->task, info));
- state->error = true;
return false;
}
arch/loongarch/kernel/unwind_prologue.c +0 -0
@@ -227,7 +227,7 @@ static bool next_frame(struct unwind_state *state)
} while (!get_stack_info(state->sp, state->task, info));
out:
- state->error = true;
+ state->stack_info.type = STACK_TYPE_UNKNOWN;
return false;
}
[2] https://lore.kernel.org/all/[email protected]/
Thanks,
Jinyang
Quoted 47 lines
Huacai
Quoted 46 lines
Jinyang
Quoted 38 lines
Huacai
Quoted 36 lines
The patch way makes us need fix the other place where call
unwind_XXX().Seems commit
370a3b8f5874("LoongArch: Checkunwind_error()inarch_stack_walk()") can be improved.Thanks,
Jinyang
Quoted 25 lines
Add the missing
unwind_error()check
to resolve the issue.[0]: https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
[1]: https://github.com/chenhengqi/public/blob/main/verifier_movsxSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +2
-1@@ -65,7 +65,8 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,printk ("%sCall Trace:" , loglvl);for (unwind_start (&state, task, pregs); - !unwind_done (&state);unwind_next_frame (&state)) { + !unwind_done (&state) && !unwind_error (&state); +unwind_next_frame (&state)) { addr =unwind_get_return_address (&state);print_ip_sym (loglvl, addr); }
Huacai Chen
maintainerHi, Jinyang,
Quoted 102 lines · Jinyang He
Quoted 61 lines · Huacai Chen
Quoted 52 lines · Jinyang He
Quoted 36 lines · Huacai Chen
Hi, Jinyang,
Quoted 33 lines · Jinyang He
Quoted 26 lines · Hengqi Chen
While tracking down the CPU stall issues ([0]), I saw that
show_backtrace()stuck in an infinite loop ([1]):[ 153.610816] Call Trace: [ 153.610929] [<9000000002723eb8>] show_stack+0x5c/0x180 [ 153.611252] [<90000000038e9954>] dump_stack_lvl+0x60/0x88 [ 153.611349] [<90000000038cf8ec>] rcu_dump_cpu_stacks+0xf8/0x150 [ 153.611452] [<90000000027dc5dc>] rcu_sched_clock_irq+0x69c/0xf10 [ 153.611585] [<90000000027f0dfc>] update_process_times+0x6c/0xb4 [ 153.611696] [<9000000002801fb8>] tick_nohz_highres_handler+0x54/0xe0 [ 153.611808] [<90000000027f1898>] __hrtimer_run_queues+0x178/0x344 [ 153.611909] [<90000000027f29dc>] hrtimer_interrupt+0x108/0x28c [ 153.612009] [<90000000027269c4>] constant_timer_interrupt+0x38/0x48 [ 153.612113] [<90000000027b7824>] __handle_irq_event_percpu+0x68/0x24c [ 153.612223] [<90000000027b7a20>] handle_irq_event_percpu+0x18/0x6c [ 153.612327] [<90000000027bdae0>] handle_percpu_irq+0x54/0x88 [ 153.612420] [<90000000027b6af8>] generic_handle_domain_irq+0x28/0x40 [ 153.612524] [<9000000003085b0c>] handle_cpu_irq+0x6c/0xa8 [ 153.612621] [<90000000038e9c28>] handle_loongarch_irq+0x30/0x48 [ 153.612721] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612906] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612985] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613066] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613150] [<90000000038e9cc0>] do_vint+0x80/0xb4 ...Quoted 3 lines
This is because the unwinder does not stop immediately when it reaches non-kernel stackframe at which point it sets
unwind_state::error.Hi, Hengqi,
Quoted 6 lines
Quoted 4 lines
I think we can set
state->stack_info.type = STACK_TYPE_UNKNOWNinnext_frame()where setstate->error = true.Stack type change to unknown also indicate that the unwind should stop.
In this way
arch_stack_walk()don't need to callunwind_error()any more?Yes. But I think we should not set error in
next_frameif (user_mode(regs) || !__kernel_text_address(pc)), because it indicate it should be user stack. Setstate->stack_info.type = STACK_TYPE_UNKNOWNis ok, or callget_stack_info()may also be ok. See [1] and follows,Quoted 2 lines
But then what is the real difference between
unwind_done()andunwind_error()?Quoted 8 lines
unwind_done()means we should finish unwind because stack type is unexpected, not in irq stack or in task stack. Usually unwind exit when it meets user stack, it is probably a normal exit. In most cases it should be a flag of normal exit.unwind_error()means we should finish unwind because something unexpected which maybe caused by previous wrong unwind. For ORC unwinder, we may meet unexpected ORC info and set error.unwind_error()shows stack is unreliable.Quoted 5 lines
Then you mean replace
state->error = truewithstate->stack_info.type = STACK_TYPE_UNKNOWNrather than addstate->stack_info.type = STACK_TYPE_UNKNOWNafterstate->error = truein Tiezhu's patch? If so, I suggest you submit a patch because Hengqi may also be confusing (but I'm not sure) here.Hi, Hengqi,
I created a diff as follows. But I couldn't test it by the way mentioned in [2],
(and I always got the right result in Qemu). Can you test it in your way?
As Huacai said, if you're confused about this, I'm happy to submit this diff as well.
arch/loongarch/kernel/stacktrace.c +1
-1@@ -32,7 +32,7 @@ void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, }for (unwind_start (&state, task, regs); - !unwind_done (&state) && !unwind_error (&state); unwind_next_frame(&state)) { + !unwind_done(&state); unwind_next_frame(&state)) { addr =unwind_get_return_address (&state);if (!addr || !consume_entry(cookie, addr)) break;arch/loongarch/kernel/unwind.c +0
-0
arch/loongarch/kernel/unwind.c bool default_next_frame(struct unwind_state *state) · line 31
Quoted 4 lines
arch/loongarch/kernel/unwind.c +0
-1@@ -28,6 +28,5 @@ bool default_next_frame(struct unwind_state *state) }while (!get_stack_info (state->sp, state->task, info)); - state->error = true;
We don't need "state->stack_info.type = STACK_TYPE_UNKNOWN" in any case if we use GUESS unwinder?
Huacai
Quoted 73 lines
arch/loongarch/kernel/unwind.c +0
-0return false; }arch/loongarch/kernel/unwind_prologue.c +1
-1@@ -227,7 +227,7 @@ static bool next_frame(struct unwind_state *state) }while (!get_stack_info (state->sp, state->task, info)); out: - state->error = true; + state->stack_info.type =STACK_TYPE_UNKNOWN ;return false; }[2]
https://lore.kernel.org/all/[email protected]/Thanks,
Jinyang
Quoted 47 lines
Huacai
Quoted 46 lines
Jinyang
Quoted 38 lines
Huacai
Quoted 36 lines
The patch way makes us need fix the other place where call
unwind_XXX().Seems commit
370a3b8f5874("LoongArch: Checkunwind_error()inarch_stack_walk()") can be improved.Thanks,
Jinyang
Quoted 25 lines
Add the missing
unwind_error()check
to resolve the issue.[0]: https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
[1]: https://github.com/chenhengqi/public/blob/main/verifier_movsxSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +2
-1@@ -65,7 +65,8 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,printk ("%sCall Trace:" , loglvl);for (unwind_start (&state, task, pregs); - !unwind_done (&state);unwind_next_frame (&state)) { + !unwind_done (&state) && !unwind_error (&state); +unwind_next_frame (&state)) { addr =unwind_get_return_address (&state);print_ip_sym (loglvl, addr); }
Quoted 104 lines · Huacai Chen
Hi, Jinyang,
Quoted 101 lines · Jinyang He
Quoted 61 lines · Huacai Chen
Quoted 52 lines · Jinyang He
Quoted 36 lines · Huacai Chen
Hi, Jinyang,
Quoted 33 lines · Jinyang He
Quoted 26 lines · Hengqi Chen
While tracking down the CPU stall issues ([0]), I saw that
show_backtrace()stuck in an infinite loop ([1]):[ 153.610816] Call Trace: [ 153.610929] [<9000000002723eb8>] show_stack+0x5c/0x180 [ 153.611252] [<90000000038e9954>] dump_stack_lvl+0x60/0x88 [ 153.611349] [<90000000038cf8ec>] rcu_dump_cpu_stacks+0xf8/0x150 [ 153.611452] [<90000000027dc5dc>] rcu_sched_clock_irq+0x69c/0xf10 [ 153.611585] [<90000000027f0dfc>] update_process_times+0x6c/0xb4 [ 153.611696] [<9000000002801fb8>] tick_nohz_highres_handler+0x54/0xe0 [ 153.611808] [<90000000027f1898>] __hrtimer_run_queues+0x178/0x344 [ 153.611909] [<90000000027f29dc>] hrtimer_interrupt+0x108/0x28c [ 153.612009] [<90000000027269c4>] constant_timer_interrupt+0x38/0x48 [ 153.612113] [<90000000027b7824>] __handle_irq_event_percpu+0x68/0x24c [ 153.612223] [<90000000027b7a20>] handle_irq_event_percpu+0x18/0x6c [ 153.612327] [<90000000027bdae0>] handle_percpu_irq+0x54/0x88 [ 153.612420] [<90000000027b6af8>] generic_handle_domain_irq+0x28/0x40 [ 153.612524] [<9000000003085b0c>] handle_cpu_irq+0x6c/0xa8 [ 153.612621] [<90000000038e9c28>] handle_loongarch_irq+0x30/0x48 [ 153.612721] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612906] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.612985] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613066] [<90000000038e9cc0>] do_vint+0x80/0xb4 [ 153.613150] [<90000000038e9cc0>] do_vint+0x80/0xb4 ...Quoted 3 lines
This is because the unwinder does not stop immediately when it reaches non-kernel stackframe at which point it sets
unwind_state::error.Hi, Hengqi,
Quoted 6 lines
Quoted 4 lines
I think we can set
state->stack_info.type = STACK_TYPE_UNKNOWNinnext_frame()where setstate->error = true.Stack type change to unknown also indicate that the unwind should stop.
In this way
arch_stack_walk()don't need to callunwind_error()any more?Yes. But I think we should not set error in
next_frameif (user_mode(regs) || !__kernel_text_address(pc)), because it indicate it should be user stack. Setstate->stack_info.type = STACK_TYPE_UNKNOWNis ok, or callget_stack_info()may also be ok. See [1] and follows,Quoted 2 lines
But then what is the real difference between
unwind_done()andunwind_error()?Quoted 8 lines
unwind_done()means we should finish unwind because stack type is unexpected, not in irq stack or in task stack. Usually unwind exit when it meets user stack, it is probably a normal exit. In most cases it should be a flag of normal exit.unwind_error()means we should finish unwind because something unexpected which maybe caused by previous wrong unwind. For ORC unwinder, we may meet unexpected ORC info and set error.unwind_error()shows stack is unreliable.Quoted 5 lines
Then you mean replace
state->error = truewithstate->stack_info.type = STACK_TYPE_UNKNOWNrather than addstate->stack_info.type = STACK_TYPE_UNKNOWNafterstate->error = truein Tiezhu's patch? If so, I suggest you submit a patch because Hengqi may also be confusing (but I'm not sure) here.Hi, Hengqi,
I created a diff as follows. But I couldn't test it by the way mentioned in [2],
(and I always got the right result in Qemu). Can you test it in your way?
As Huacai said, if you're confused about this, I'm happy to submit this diff as well.
arch/loongarch/kernel/stacktrace.c +1
-1@@ -32,7 +32,7 @@ void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, }for (unwind_start (&state, task, regs); - !unwind_done (&state) && !unwind_error (&state); unwind_next_frame(&state)) { + !unwind_done(&state); unwind_next_frame(&state)) { addr =unwind_get_return_address (&state);if (!addr || !consume_entry(cookie, addr)) break;arch/loongarch/kernel/unwind.c +0
-0@@ -28,6 +28,5 @@ bool default_next_frame(struct unwind_state *state)
Quoted 5 lines
arch/loongarch/kernel/unwind.c bool default_next_frame(struct unwind_state *state) · line 31
Quoted 3 lines
arch/loongarch/kernel/unwind.c +0
-1}while (!get_stack_info (state->sp, state->task, info)); - state->error = true;We don't need "
state->stack_info.type=STACK_TYPE_UNKNOWN" in any case if we use GUESS unwinder?
The do-while loop has only one break condition to return false is !get_stack_info(), which will set stack type to unknown.
Jinyang
Quoted 74 lines
Huacai
Quoted 71 lines
arch/loongarch/kernel/unwind.c +0
-0return false; }arch/loongarch/kernel/unwind_prologue.c +1
-1@@ -227,7 +227,7 @@ static bool next_frame(struct unwind_state *state) }while (!get_stack_info (state->sp, state->task, info)); out: - state->error = true; + state->stack_info.type =STACK_TYPE_UNKNOWN ;return false; }[2]
https://lore.kernel.org/all/[email protected]/Thanks,
Jinyang
Quoted 46 lines
Huacai
Quoted 45 lines
Jinyang
Quoted 38 lines
Huacai
Quoted 36 lines
The patch way makes us need fix the other place where call
unwind_XXX().Seems commit
370a3b8f5874("LoongArch: Checkunwind_error()inarch_stack_walk()") can be improved.Thanks,
Jinyang
Quoted 25 lines
Add the missing
unwind_error()check
to resolve the issue.[0]: https://lore.kernel.org/loongarch/CAEyhmHT6UOryPZi7eEfw01Y_CjAqxy8NM6eKkdvdojJqB9P7eQ@mail.gmail.com/T/#u
[1]: https://github.com/chenhengqi/public/blob/main/verifier_movsxSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/kernel/traps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/loongarch/kernel/traps.c +2
-1@@ -65,7 +65,8 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,printk ("%sCall Trace:" , loglvl);for (unwind_start (&state, task, pregs); - !unwind_done (&state);unwind_next_frame (&state)) { + !unwind_done (&state) && !unwind_error (&state); +unwind_next_frame (&state)) { addr =unwind_get_return_address (&state);print_ip_sym (loglvl, addr); }