mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 05:48:40 +00:00
![Thomas Gleixner](/assets/img/avatar_default.png)
The debug IST stack is actually two separate debug stacks to handle #DB recursion. This is required because the CPU starts always at top of stack on exception entry, which means on #DB recursion the second #DB would overwrite the stack of the first. The low level entry code therefore adjusts the top of stack on entry so a secondary #DB starts from a different stack page. But the stack pages are adjacent without a guard page between them. Split the debug stack into 3 stacks which are separated by guard pages. The 3rd stack is never mapped into the cpu_entry_area and is only there to catch triple #DB nesting: --- top of DB_stack <- Initial stack --- end of DB_stack guard page --- top of DB1_stack <- Top of stack after entering first #DB --- end of DB1_stack guard page --- top of DB2_stack <- Top of stack after entering second #DB --- end of DB2_stack guard page If DB2 would not act as the final guard hole, a second #DB would point the top of #DB stack to the stack below #DB1 which would be valid and not catch the not so desired triple nesting. The backing store does not allocate any memory for DB2 and its guard page as it is not going to be mapped into the cpu_entry_area. - Adjust the low level entry code so it adjusts top of #DB with the offset between the stacks instead of exception stack size. - Make the dumpstack code aware of the new stacks. - Adjust the in_debug_stack() implementation and move it into the NMI code where it belongs. As this is NMI hotpath code, it just checks the full area between top of DB_stack and bottom of DB1_stack without checking for the guard page. That's correct because the NMI cannot hit a stackpointer pointing to the guard page between DB and DB1 stack. Even if it would, then the NMI operation still is unaffected, but the resume of the debug exception on the topmost DB stack will crash by touching the guard page. [ bp: Make exception_stack_names static const char * const ] Suggested-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Baoquan He <bhe@redhat.com> Cc: "Chang S. Bae" <chang.seok.bae@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Joerg Roedel <jroedel@suse.de> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Juergen Gross <jgross@suse.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: linux-doc@vger.kernel.org Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Qian Cai <cai@lca.pw> Cc: Sean Christopherson <sean.j.christopherson@intel.com> Cc: x86-ml <x86@kernel.org> Link: https://lkml.kernel.org/r/20190414160145.439944544@linutronix.de
122 lines
2.6 KiB
C
122 lines
2.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _ASM_X86_DEBUGREG_H
|
|
#define _ASM_X86_DEBUGREG_H
|
|
|
|
|
|
#include <linux/bug.h>
|
|
#include <uapi/asm/debugreg.h>
|
|
|
|
DECLARE_PER_CPU(unsigned long, cpu_dr7);
|
|
|
|
#ifndef CONFIG_PARAVIRT_XXL
|
|
/*
|
|
* These special macros can be used to get or set a debugging register
|
|
*/
|
|
#define get_debugreg(var, register) \
|
|
(var) = native_get_debugreg(register)
|
|
#define set_debugreg(value, register) \
|
|
native_set_debugreg(register, value)
|
|
#endif
|
|
|
|
static inline unsigned long native_get_debugreg(int regno)
|
|
{
|
|
unsigned long val = 0; /* Damn you, gcc! */
|
|
|
|
switch (regno) {
|
|
case 0:
|
|
asm("mov %%db0, %0" :"=r" (val));
|
|
break;
|
|
case 1:
|
|
asm("mov %%db1, %0" :"=r" (val));
|
|
break;
|
|
case 2:
|
|
asm("mov %%db2, %0" :"=r" (val));
|
|
break;
|
|
case 3:
|
|
asm("mov %%db3, %0" :"=r" (val));
|
|
break;
|
|
case 6:
|
|
asm("mov %%db6, %0" :"=r" (val));
|
|
break;
|
|
case 7:
|
|
asm("mov %%db7, %0" :"=r" (val));
|
|
break;
|
|
default:
|
|
BUG();
|
|
}
|
|
return val;
|
|
}
|
|
|
|
static inline void native_set_debugreg(int regno, unsigned long value)
|
|
{
|
|
switch (regno) {
|
|
case 0:
|
|
asm("mov %0, %%db0" ::"r" (value));
|
|
break;
|
|
case 1:
|
|
asm("mov %0, %%db1" ::"r" (value));
|
|
break;
|
|
case 2:
|
|
asm("mov %0, %%db2" ::"r" (value));
|
|
break;
|
|
case 3:
|
|
asm("mov %0, %%db3" ::"r" (value));
|
|
break;
|
|
case 6:
|
|
asm("mov %0, %%db6" ::"r" (value));
|
|
break;
|
|
case 7:
|
|
asm("mov %0, %%db7" ::"r" (value));
|
|
break;
|
|
default:
|
|
BUG();
|
|
}
|
|
}
|
|
|
|
static inline void hw_breakpoint_disable(void)
|
|
{
|
|
/* Zero the control register for HW Breakpoint */
|
|
set_debugreg(0UL, 7);
|
|
|
|
/* Zero-out the individual HW breakpoint address registers */
|
|
set_debugreg(0UL, 0);
|
|
set_debugreg(0UL, 1);
|
|
set_debugreg(0UL, 2);
|
|
set_debugreg(0UL, 3);
|
|
}
|
|
|
|
static inline int hw_breakpoint_active(void)
|
|
{
|
|
return __this_cpu_read(cpu_dr7) & DR_GLOBAL_ENABLE_MASK;
|
|
}
|
|
|
|
extern void aout_dump_debugregs(struct user *dump);
|
|
|
|
extern void hw_breakpoint_restore(void);
|
|
|
|
#ifdef CONFIG_X86_64
|
|
DECLARE_PER_CPU(int, debug_stack_usage);
|
|
static inline void debug_stack_usage_inc(void)
|
|
{
|
|
__this_cpu_inc(debug_stack_usage);
|
|
}
|
|
static inline void debug_stack_usage_dec(void)
|
|
{
|
|
__this_cpu_dec(debug_stack_usage);
|
|
}
|
|
void debug_stack_set_zero(void);
|
|
void debug_stack_reset(void);
|
|
#else /* !X86_64 */
|
|
static inline void debug_stack_set_zero(void) { }
|
|
static inline void debug_stack_reset(void) { }
|
|
static inline void debug_stack_usage_inc(void) { }
|
|
static inline void debug_stack_usage_dec(void) { }
|
|
#endif /* X86_64 */
|
|
|
|
#ifdef CONFIG_CPU_SUP_AMD
|
|
extern void set_dr_addr_mask(unsigned long mask, int dr);
|
|
#else
|
|
static inline void set_dr_addr_mask(unsigned long mask, int dr) { }
|
|
#endif
|
|
|
|
#endif /* _ASM_X86_DEBUGREG_H */
|