mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-22 21:15:44 +07:00
7326749801
As it turns out, the unwind code is slightly broken, and probably has been for a while. The problem is in the dumping of the exception stack, which is intended to dump the contents of the pt_regs struct at each level in the call stack where an exception was taken and routed to a routine marked as __exception (which means its stack frame is right below the pt_regs struct on the stack). 'Right below the pt_regs struct' is ill defined, though: the unwind code assigns 'frame pointer + 0x10' to the .sp member of the stackframe struct at each level, and dump_backtrace() happily dereferences that as the pt_regs pointer when encountering an __exception routine. However, the actual size of the stack frame created by this routine (which could be one of many __exception routines we have in the kernel) is not known, and so frame.sp is pretty useless to figure out where struct pt_regs really is. So it seems the only way to ensure that we can find our struct pt_regs when walking the stack frames is to put it at a known fixed offset of the stack frame pointer that is passed to such __exception routines. The simplest way to do that is to put it inside pt_regs itself, which is the main change implemented by this patch. As a bonus, doing this allows us to get rid of a fair amount of cruft related to walking from one stack to the other, which is especially nice since we intend to introduce yet another stack for overflow handling once we add support for vmapped stacks. It also fixes an inconsistency where we only add a stack frame pointing to ELR_EL1 if we are executing from the IRQ stack but not when we are executing from the task stack. To consistly identify exceptions regs even in the presence of exceptions taken from entry code, we must check whether the next frame was created by entry text, rather than whether the current frame was crated by exception text. To avoid backtracing using PCs that fall in the idmap, or are controlled by userspace, we must explcitly zero the FP and LR in startup paths, and must ensure that the frame embedded in pt_regs is zeroed upon entry from EL0. To avoid these NULL entries showin in the backtrace, unwind_frame() is updated to avoid them. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [Mark: compare current frame against .entry.text, avoid bogus PCs] Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: James Morse <james.morse@arm.com> Cc: Will Deacon <will.deacon@arm.com>
69 lines
1.7 KiB
C
69 lines
1.7 KiB
C
/*
|
|
* Based on arch/arm/include/asm/traps.h
|
|
*
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef __ASM_TRAP_H
|
|
#define __ASM_TRAP_H
|
|
|
|
#include <linux/list.h>
|
|
#include <asm/sections.h>
|
|
|
|
struct pt_regs;
|
|
|
|
struct undef_hook {
|
|
struct list_head node;
|
|
u32 instr_mask;
|
|
u32 instr_val;
|
|
u64 pstate_mask;
|
|
u64 pstate_val;
|
|
int (*fn)(struct pt_regs *regs, u32 instr);
|
|
};
|
|
|
|
void register_undef_hook(struct undef_hook *hook);
|
|
void unregister_undef_hook(struct undef_hook *hook);
|
|
|
|
void arm64_notify_segfault(struct pt_regs *regs, unsigned long addr);
|
|
|
|
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
|
static inline int __in_irqentry_text(unsigned long ptr)
|
|
{
|
|
return ptr >= (unsigned long)&__irqentry_text_start &&
|
|
ptr < (unsigned long)&__irqentry_text_end;
|
|
}
|
|
#else
|
|
static inline int __in_irqentry_text(unsigned long ptr)
|
|
{
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
static inline int in_exception_text(unsigned long ptr)
|
|
{
|
|
int in;
|
|
|
|
in = ptr >= (unsigned long)&__exception_text_start &&
|
|
ptr < (unsigned long)&__exception_text_end;
|
|
|
|
return in ? : __in_irqentry_text(ptr);
|
|
}
|
|
|
|
static inline int in_entry_text(unsigned long ptr)
|
|
{
|
|
return ptr >= (unsigned long)&__entry_text_start &&
|
|
ptr < (unsigned long)&__entry_text_end;
|
|
}
|
|
#endif
|