Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar |
| 3 | * |
| 4 | * This file contains the lowest level x86_64-specific interrupt |
| 5 | * entry and irq statistics code. All the remaining irq logic is |
| 6 | * done by the generic kernel/irq/ code and in the |
| 7 | * x86_64-specific irq controller code. (e.g. i8259.c and |
| 8 | * io_apic.c.) |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel_stat.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/seq_file.h> |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 14 | #include <linux/delay.h> |
Frederic Weisbecker | bcbc4f2 | 2008-12-09 23:54:20 +0100 | [diff] [blame] | 15 | #include <linux/ftrace.h> |
Jaswinder Singh Rajput | 5f66b2a | 2009-01-04 16:25:19 +0530 | [diff] [blame] | 16 | #include <linux/uaccess.h> |
| 17 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/io_apic.h> |
Andi Kleen | 95833c8 | 2006-01-11 22:44:36 +0100 | [diff] [blame] | 19 | #include <asm/idle.h> |
Brian Gerst | 3819cd4 | 2009-01-23 11:03:29 +0900 | [diff] [blame] | 20 | #include <asm/apic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Mitsuo Hayasaka | 55af779 | 2011-11-29 15:08:36 +0900 | [diff] [blame] | 22 | int sysctl_panic_on_stackoverflow; |
| 23 | |
Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 24 | /* |
| 25 | * Probabilistic stack overflow check: |
| 26 | * |
| 27 | * Only check the stack in process context, because everything else |
| 28 | * runs on the big interrupt stacks. Checking reliably is too expensive, |
| 29 | * so we just check from interrupts. |
| 30 | */ |
| 31 | static inline void stack_overflow_check(struct pt_regs *regs) |
| 32 | { |
Ingo Molnar | f377fa1 | 2008-11-23 09:02:26 +0100 | [diff] [blame] | 33 | #ifdef CONFIG_DEBUG_STACKOVERFLOW |
Mitsuo Hayasaka | d2db661 | 2011-12-07 17:29:10 +0900 | [diff] [blame] | 34 | #define STACK_TOP_MARGIN 128 |
Mitsuo Hayasaka | 37fe6a4 | 2011-11-29 15:08:29 +0900 | [diff] [blame] | 35 | struct orig_ist *oist; |
| 36 | u64 irq_stack_top, irq_stack_bottom; |
| 37 | u64 estack_top, estack_bottom; |
Roman Zippel | c9f4f06 | 2007-05-09 02:35:16 -0700 | [diff] [blame] | 38 | u64 curbase = (u64)task_stack_page(current); |
Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 39 | |
Andy Lutomirski | f39b6f0 | 2015-03-18 18:33:33 -0700 | [diff] [blame] | 40 | if (user_mode(regs)) |
Mitsuo Hayasaka | 69682b6 | 2011-11-29 15:08:21 +0900 | [diff] [blame] | 41 | return; |
| 42 | |
Andy Lutomirski | 15f4eae | 2016-09-13 14:29:25 -0700 | [diff] [blame] | 43 | if (regs->sp >= curbase + sizeof(struct pt_regs) + STACK_TOP_MARGIN && |
Mitsuo Hayasaka | 467e6b7 | 2011-11-29 15:08:45 +0900 | [diff] [blame] | 44 | regs->sp <= curbase + THREAD_SIZE) |
Mitsuo Hayasaka | 37fe6a4 | 2011-11-29 15:08:29 +0900 | [diff] [blame] | 45 | return; |
Ingo Molnar | f377fa1 | 2008-11-23 09:02:26 +0100 | [diff] [blame] | 46 | |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 47 | irq_stack_top = (u64)this_cpu_ptr(irq_stack_union.irq_stack) + |
Mitsuo Hayasaka | d2db661 | 2011-12-07 17:29:10 +0900 | [diff] [blame] | 48 | STACK_TOP_MARGIN; |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 49 | irq_stack_bottom = (u64)__this_cpu_read(irq_stack_ptr); |
Mitsuo Hayasaka | 37fe6a4 | 2011-11-29 15:08:29 +0900 | [diff] [blame] | 50 | if (regs->sp >= irq_stack_top && regs->sp <= irq_stack_bottom) |
| 51 | return; |
| 52 | |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 53 | oist = this_cpu_ptr(&orig_ist); |
Mitsuo Hayasaka | d2db661 | 2011-12-07 17:29:10 +0900 | [diff] [blame] | 54 | estack_top = (u64)oist->ist[0] - EXCEPTION_STKSZ + STACK_TOP_MARGIN; |
Mitsuo Hayasaka | 37fe6a4 | 2011-11-29 15:08:29 +0900 | [diff] [blame] | 55 | estack_bottom = (u64)oist->ist[N_EXCEPTION_STACKS - 1]; |
| 56 | if (regs->sp >= estack_top && regs->sp <= estack_bottom) |
| 57 | return; |
| 58 | |
| 59 | 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)\n", |
| 60 | current->comm, curbase, regs->sp, |
| 61 | irq_stack_top, irq_stack_bottom, |
| 62 | estack_top, estack_bottom); |
Mitsuo Hayasaka | 55af779 | 2011-11-29 15:08:36 +0900 | [diff] [blame] | 63 | |
| 64 | if (sysctl_panic_on_stackoverflow) |
| 65 | panic("low stack detected by irq handler - check messages\n"); |
Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 66 | #endif |
Ingo Molnar | f377fa1 | 2008-11-23 09:02:26 +0100 | [diff] [blame] | 67 | } |
Eric Sandeen | 4961f10 | 2006-06-26 14:00:05 +0200 | [diff] [blame] | 68 | |
Thomas Gleixner | a782a7e | 2015-08-02 20:38:27 +0000 | [diff] [blame] | 69 | bool handle_irq(struct irq_desc *desc, struct pt_regs *regs) |
Jeremy Fitzhardinge | 9b2b76a | 2009-02-06 14:09:40 -0800 | [diff] [blame] | 70 | { |
Jeremy Fitzhardinge | 9b2b76a | 2009-02-06 14:09:40 -0800 | [diff] [blame] | 71 | stack_overflow_check(regs); |
| 72 | |
Geliang Tang | a7e705a | 2015-10-01 10:55:29 +0800 | [diff] [blame] | 73 | if (IS_ERR_OR_NULL(desc)) |
Jeremy Fitzhardinge | 9b2b76a | 2009-02-06 14:09:40 -0800 | [diff] [blame] | 74 | return false; |
| 75 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 76 | generic_handle_irq_desc(desc); |
Jeremy Fitzhardinge | 9b2b76a | 2009-02-06 14:09:40 -0800 | [diff] [blame] | 77 | return true; |
| 78 | } |