[patch V3 05/32] x86/irq/64: Sanitize the top/bottom confusion

From: Thomas Gleixner
Date: Sun Apr 14 2019 - 12:02:31 EST


On x86 stacks go top to bottom, but the stack overflow check uses it the
other way round, which is just confusing. Clean it up and sanitize the
warning string a bit.

Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Reviewed-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx>
---
arch/x86/kernel/irq_64.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

--- a/arch/x86/kernel/irq_64.c
+++ b/arch/x86/kernel/irq_64.c
@@ -42,7 +42,7 @@ int sysctl_panic_on_stackoverflow;
static inline void stack_overflow_check(struct pt_regs *regs)
{
#ifdef CONFIG_DEBUG_STACKOVERFLOW
-#define STACK_TOP_MARGIN 128
+#define STACK_MARGIN 128
struct orig_ist *oist;
u64 irq_stack_top, irq_stack_bottom;
u64 estack_top, estack_bottom;
@@ -51,25 +51,25 @@ static inline void stack_overflow_check(
if (user_mode(regs))
return;

- if (regs->sp >= curbase + sizeof(struct pt_regs) + STACK_TOP_MARGIN &&
+ if (regs->sp >= curbase + sizeof(struct pt_regs) + STACK_MARGIN &&
regs->sp <= curbase + THREAD_SIZE)
return;

- irq_stack_bottom = (u64)__this_cpu_read(irq_stack_ptr);
- irq_stack_top = irq_stack_bottom - IRQ_STACK_SIZE + STACK_TOP_MARGIN;
- if (regs->sp >= irq_stack_top && regs->sp <= irq_stack_bottom)
+ irq_stack_top = (u64)__this_cpu_read(irq_stack_ptr);
+ irq_stack_bottom = irq_stack_top - IRQ_STACK_SIZE + STACK_MARGIN;
+ if (regs->sp >= irq_stack_bottom && regs->sp <= irq_stack_top)
return;

oist = this_cpu_ptr(&orig_ist);
- estack_bottom = (u64)oist->ist[DEBUG_STACK];
- estack_top = estack_bottom - DEBUG_STKSZ + STACK_TOP_MARGIN;
- if (regs->sp >= estack_top && regs->sp <= estack_bottom)
+ estack_top = (u64)oist->ist[DEBUG_STACK];
+ estack_bottom = estack_top - DEBUG_STKSZ + STACK_MARGIN;
+ if (regs->sp >= estack_bottom && regs->sp <= estack_top)
return;

- WARN_ONCE(1, "do_IRQ(): %s has overflown the kernel stack (cur:%Lx,sp:%lx,irq stk top-bottom:%Lx-%Lx,exception stk top-bottom:%Lx-%Lx,ip:%pF)\n",
+ WARN_ONCE(1, "do_IRQ(): %s has overflown the kernel stack (cur:%Lx,sp:%lx, irq stack:%Lx-%Lx, exception stack: %Lx-%Lx, ip:%pF)\n",
current->comm, curbase, regs->sp,
- irq_stack_top, irq_stack_bottom,
- estack_top, estack_bottom, (void *)regs->ip);
+ irq_stack_bottom, irq_stack_top,
+ estack_bottom, estack_top, (void *)regs->ip);

if (sysctl_panic_on_stackoverflow)
panic("low stack detected by irq handler - check messages\n");