2012-03-05 18:49:27 +07:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2014-11-18 18:41:22 +07:00
|
|
|
#include <linux/list.h>
|
2018-01-16 02:38:57 +07:00
|
|
|
#include <asm/esr.h>
|
2016-08-25 00:27:28 +07:00
|
|
|
#include <asm/sections.h>
|
2014-11-18 18:41:22 +07:00
|
|
|
|
|
|
|
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);
|
2018-02-20 21:16:29 +07:00
|
|
|
void force_signal_inject(int signal, int code, unsigned long address);
|
|
|
|
void arm64_notify_segfault(unsigned long addr);
|
2018-02-20 20:46:05 +07:00
|
|
|
void arm64_force_sig_info(struct siginfo *info, const char *str,
|
|
|
|
struct task_struct *tsk);
|
2016-06-29 00:07:31 +07:00
|
|
|
|
2017-10-25 16:04:33 +07:00
|
|
|
/*
|
|
|
|
* Move regs->pc to next instruction and do necessary setup before it
|
|
|
|
* is executed.
|
|
|
|
*/
|
|
|
|
void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size);
|
|
|
|
|
2015-08-12 21:16:19 +07:00
|
|
|
static inline int __in_irqentry_text(unsigned long ptr)
|
|
|
|
{
|
|
|
|
return ptr >= (unsigned long)&__irqentry_text_start &&
|
|
|
|
ptr < (unsigned long)&__irqentry_text_end;
|
|
|
|
}
|
|
|
|
|
2012-03-05 18:49:27 +07:00
|
|
|
static inline int in_exception_text(unsigned long ptr)
|
|
|
|
{
|
2015-08-12 21:16:19 +07:00
|
|
|
int in;
|
|
|
|
|
|
|
|
in = ptr >= (unsigned long)&__exception_text_start &&
|
|
|
|
ptr < (unsigned long)&__exception_text_end;
|
2012-03-05 18:49:27 +07:00
|
|
|
|
2015-08-12 21:16:19 +07:00
|
|
|
return in ? : __in_irqentry_text(ptr);
|
2012-03-05 18:49:27 +07:00
|
|
|
}
|
|
|
|
|
arm64: unwind: reference pt_regs via embedded stack frame
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>
2017-07-23 00:45:33 +07:00
|
|
|
static inline int in_entry_text(unsigned long ptr)
|
|
|
|
{
|
|
|
|
return ptr >= (unsigned long)&__entry_text_start &&
|
|
|
|
ptr < (unsigned long)&__entry_text_end;
|
|
|
|
}
|
2018-01-16 02:38:57 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CPUs with the RAS extensions have an Implementation-Defined-Syndrome bit
|
|
|
|
* to indicate whether this ESR has a RAS encoding. CPUs without this feature
|
|
|
|
* have a ISS-Valid bit in the same position.
|
|
|
|
* If this bit is set, we know its not a RAS SError.
|
|
|
|
* If its clear, we need to know if the CPU supports RAS. Uncategorized RAS
|
|
|
|
* errors share the same encoding as an all-zeros encoding from a CPU that
|
|
|
|
* doesn't support RAS.
|
|
|
|
*/
|
|
|
|
static inline bool arm64_is_ras_serror(u32 esr)
|
|
|
|
{
|
|
|
|
WARN_ON(preemptible());
|
|
|
|
|
|
|
|
if (esr & ESR_ELx_IDS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (this_cpu_has_cap(ARM64_HAS_RAS_EXTN))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the AET bits from a RAS SError's ESR.
|
|
|
|
*
|
|
|
|
* It is implementation defined whether Uncategorized errors are containable.
|
|
|
|
* We treat them as Uncontainable.
|
|
|
|
* Non-RAS SError's are reported as Uncontained/Uncategorized.
|
|
|
|
*/
|
|
|
|
static inline u32 arm64_ras_serror_get_severity(u32 esr)
|
|
|
|
{
|
|
|
|
u32 aet = esr & ESR_ELx_AET;
|
|
|
|
|
|
|
|
if (!arm64_is_ras_serror(esr)) {
|
|
|
|
/* Not a RAS error, we can't interpret the ESR. */
|
|
|
|
return ESR_ELx_AET_UC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AET is RES0 if 'the value returned in the DFSC field is not
|
|
|
|
* [ESR_ELx_FSC_SERROR]'
|
|
|
|
*/
|
|
|
|
if ((esr & ESR_ELx_FSC) != ESR_ELx_FSC_SERROR) {
|
|
|
|
/* No severity information : Uncategorized */
|
|
|
|
return ESR_ELx_AET_UC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aet;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool arm64_is_fatal_ras_serror(struct pt_regs *regs, unsigned int esr);
|
|
|
|
void __noreturn arm64_serror_panic(struct pt_regs *regs, u32 esr);
|
2012-03-05 18:49:27 +07:00
|
|
|
#endif
|