• Madhavan T. Venkataraman's avatar
    arm64: Implement stack trace termination record · 7d7b720a
    Madhavan T. Venkataraman authored
    Reliable stacktracing requires that we identify when a stacktrace is
    terminated early. We can do this by ensuring all tasks have a final
    frame record at a known location on their task stack, and checking
    that this is the final frame record in the chain.
    
    We'd like to use task_pt_regs(task)->stackframe as the final frame
    record, as this is already setup upon exception entry from EL0. For
    kernel tasks we need to consistently reserve the pt_regs and point x29
    at this, which we can do with small changes to __primary_switched,
    __secondary_switched, and copy_process().
    
    Since the final frame record must be at a specific location, we must
    create the final frame record in __primary_switched and
    __secondary_switched rather than leaving this to start_kernel and
    secondary_start_kernel. Thus, __primary_switched and
    __secondary_switched will now show up in stacktraces for the idle tasks.
    
    Since the final frame record is now identified by its location rather
    than by its contents, we identify it at the start of unwind_frame(),
    before we read any values from it.
    
    External debuggers may terminate the stack trace when FP == 0. In the
    pt_regs->stackframe, the PC is 0 as well. So, stack traces taken in the
    debugger may print an extra record 0x0 at the end. While this is not
    pretty, this does not do any harm. This is a small price to pay for
    having reliable stack trace termination in the kernel. That said, gdb
    does not show the extra record probably because it uses DWARF and not
    frame pointers for stack traces.
    Signed-off-by: default avatarMadhavan T. Venkataraman <madvenka@linux.microsoft.com>
    Reviewed-by: default avatarMark Brown <broonie@kernel.org>
    [Mark: rebase, use ASM_BUG(), update comments, update commit message]
    Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
    Link: https://lore.kernel.org/r/20210510110026.18061-1-mark.rutland@arm.comSigned-off-by: default avatarWill Deacon <will@kernel.org>
    7d7b720a
entry.S 28.3 KB