Re: [GIT PULL] s390 updates for 5.15 merge window

From: Vasily Gorbik
Date: Wed Sep 01 2021 - 10:04:25 EST


On Tue, Aug 31, 2021 at 05:02:15PM +0200, Marco Elver wrote:
> 2. stack_trace_save() is subtly broken on s390: it starts the trace in
> stack_trace_save() itself. This is incorrect, as the trace should
> start with the caller. We reported something similar to arm64, also
> because one of our sanitizer tests failed:
> https://lkml.kernel.org/r/20210319184106.5688-1-mark.rutland@xxxxxxx

Thanks a lot for looking into it and debugging it!

> Fix it by skipping the initial entry in s390's arch_stack_walk().

...

> diff --git a/arch/s390/kernel/stacktrace.c b/arch/s390/kernel/stacktrace.c
> index 101477b3e263..47d1841af03e 100644
> --- a/arch/s390/kernel/stacktrace.c
> +++ b/arch/s390/kernel/stacktrace.c
> @@ -16,11 +16,16 @@ void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
> {
> struct unwind_state state;
> unsigned long addr;
> + bool init = true;
>
> unwind_for_each_frame(&state, task, regs, 0) {
> addr = unwind_get_return_address(&state);
> - if (!addr || !consume_entry(cookie, addr))
> + if (!addr)
> + break;
> +
> + if (!init && !consume_entry(cookie, addr))
> break;
> + init = false;
> }

I believe we don't need to skip the first unwinder result if task != current
or regs != NULL. Same for arch_stack_walk_reliable.

But after you pinpointed the problem I see that the actual difference
with x86 implementation comes from get_stack_pointer(). I'll send a patch
as reply.