mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-13 03:26:54 +07:00
b02fcf9ba1
There are at least two unwinder bugs hindering the debugging of stack-overflow crashes: - It doesn't deal gracefully with the case where the stack overflows and the stack pointer itself isn't on a valid stack but the to-be-dereferenced data *is*. - The ORC oops dump code doesn't know how to print partial pt_regs, for the case where if we get an interrupt/exception in *early* entry code before the full pt_regs have been saved. Fix both issues. http://lkml.kernel.org/r/20171126024031.uxi4numpbjm5rlbr@treble Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Borislav Petkov <bpetkov@suse.de> Cc: Andy Lutomirski <luto@kernel.org> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Laight <David.Laight@aculab.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Eduardo Valentin <eduval@amazon.com> Cc: Greg KH <gregkh@linuxfoundation.org> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Juergen Gross <jgross@suse.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Will Deacon <will.deacon@arm.com> Cc: aliguori@amazon.com Cc: daniel.gruss@iaik.tugraz.at Cc: hughd@google.com Cc: keescook@google.com Link: https://lkml.kernel.org/r/20171204150605.071425003@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
112 lines
2.9 KiB
C
112 lines
2.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _ASM_X86_UNWIND_H
|
|
#define _ASM_X86_UNWIND_H
|
|
|
|
#include <linux/sched.h>
|
|
#include <linux/ftrace.h>
|
|
#include <asm/ptrace.h>
|
|
#include <asm/stacktrace.h>
|
|
|
|
#define IRET_FRAME_OFFSET (offsetof(struct pt_regs, ip))
|
|
#define IRET_FRAME_SIZE (sizeof(struct pt_regs) - IRET_FRAME_OFFSET)
|
|
|
|
struct unwind_state {
|
|
struct stack_info stack_info;
|
|
unsigned long stack_mask;
|
|
struct task_struct *task;
|
|
int graph_idx;
|
|
bool error;
|
|
#if defined(CONFIG_UNWINDER_ORC)
|
|
bool signal, full_regs;
|
|
unsigned long sp, bp, ip;
|
|
struct pt_regs *regs;
|
|
#elif defined(CONFIG_UNWINDER_FRAME_POINTER)
|
|
bool got_irq;
|
|
unsigned long *bp, *orig_sp, ip;
|
|
struct pt_regs *regs;
|
|
#else
|
|
unsigned long *sp;
|
|
#endif
|
|
};
|
|
|
|
void __unwind_start(struct unwind_state *state, struct task_struct *task,
|
|
struct pt_regs *regs, unsigned long *first_frame);
|
|
bool unwind_next_frame(struct unwind_state *state);
|
|
unsigned long unwind_get_return_address(struct unwind_state *state);
|
|
unsigned long *unwind_get_return_address_ptr(struct unwind_state *state);
|
|
|
|
static inline bool unwind_done(struct unwind_state *state)
|
|
{
|
|
return state->stack_info.type == STACK_TYPE_UNKNOWN;
|
|
}
|
|
|
|
static inline bool unwind_error(struct unwind_state *state)
|
|
{
|
|
return state->error;
|
|
}
|
|
|
|
static inline
|
|
void unwind_start(struct unwind_state *state, struct task_struct *task,
|
|
struct pt_regs *regs, unsigned long *first_frame)
|
|
{
|
|
first_frame = first_frame ? : get_stack_pointer(task, regs);
|
|
|
|
__unwind_start(state, task, regs, first_frame);
|
|
}
|
|
|
|
#if defined(CONFIG_UNWINDER_ORC) || defined(CONFIG_UNWINDER_FRAME_POINTER)
|
|
/*
|
|
* WARNING: The entire pt_regs may not be safe to dereference. In some cases,
|
|
* only the iret frame registers are accessible. Use with caution!
|
|
*/
|
|
static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state)
|
|
{
|
|
if (unwind_done(state))
|
|
return NULL;
|
|
|
|
return state->regs;
|
|
}
|
|
#else
|
|
static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state)
|
|
{
|
|
return NULL;
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_UNWINDER_ORC
|
|
void unwind_init(void);
|
|
void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size,
|
|
void *orc, size_t orc_size);
|
|
#else
|
|
static inline void unwind_init(void) {}
|
|
static inline
|
|
void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size,
|
|
void *orc, size_t orc_size) {}
|
|
#endif
|
|
|
|
/*
|
|
* This disables KASAN checking when reading a value from another task's stack,
|
|
* since the other task could be running on another CPU and could have poisoned
|
|
* the stack in the meantime.
|
|
*/
|
|
#define READ_ONCE_TASK_STACK(task, x) \
|
|
({ \
|
|
unsigned long val; \
|
|
if (task == current) \
|
|
val = READ_ONCE(x); \
|
|
else \
|
|
val = READ_ONCE_NOCHECK(x); \
|
|
val; \
|
|
})
|
|
|
|
static inline bool task_on_another_cpu(struct task_struct *task)
|
|
{
|
|
#ifdef CONFIG_SMP
|
|
return task != current && task->on_cpu;
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
#endif /* _ASM_X86_UNWIND_H */
|