]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/x86/kernel/irq_32.c
x86/retpoline/checksum32: Convert assembler indirect jumps
[mirror_ubuntu-artful-kernel.git] / arch / x86 / kernel / irq_32.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
3 *
4 * This file contains the lowest level x86-specific interrupt
5 * entry, irq-stacks and irq statistics code. All the remaining
6 * irq logic is done by the generic kernel/irq/ code and
7 * by the x86-specific irq controller code. (e.g. i8259.c and
8 * io_apic.c.)
9 */
10
1da177e4
LT
11#include <linux/seq_file.h>
12#include <linux/interrupt.h>
13#include <linux/kernel_stat.h>
f3705136
ZM
14#include <linux/notifier.h>
15#include <linux/cpu.h>
16#include <linux/delay.h>
72ade5f9 17#include <linux/uaccess.h>
42f8faec 18#include <linux/percpu.h>
5c1eb089 19#include <linux/mm.h>
1da177e4 20
e05d723f 21#include <asm/apic.h>
e05d723f 22
de9b10af 23#ifdef CONFIG_DEBUG_STACKOVERFLOW
53b56502
IM
24
25int sysctl_panic_on_stackoverflow __read_mostly;
26
de9b10af
TG
27/* Debugging check for stack overflow: is there less than 1KB free? */
28static int check_stack_overflow(void)
29{
30 long sp;
31
32 __asm__ __volatile__("andl %%esp,%0" :
33 "=r" (sp) : "0" (THREAD_SIZE - 1));
34
35 return sp < (sizeof(struct thread_info) + STACK_WARN);
36}
37
38static void print_stack_overflow(void)
39{
40 printk(KERN_WARNING "low stack detected by irq handler\n");
41 dump_stack();
55af7796
MH
42 if (sysctl_panic_on_stackoverflow)
43 panic("low stack detected by irq handler - check messages\n");
de9b10af
TG
44}
45
46#else
47static inline int check_stack_overflow(void) { return 0; }
48static inline void print_stack_overflow(void) { }
49#endif
50
198d208d
SR
51DEFINE_PER_CPU(struct irq_stack *, hardirq_stack);
52DEFINE_PER_CPU(struct irq_stack *, softirq_stack);
1da177e4 53
403d8efc 54static void call_on_stack(void *func, void *stack)
04b361ab 55{
403d8efc
TG
56 asm volatile("xchgl %%ebx,%%esp \n"
57 "call *%%edi \n"
58 "movl %%ebx,%%esp \n"
59 : "=b" (stack)
60 : "0" (stack),
61 "D"(func)
62 : "memory", "cc", "edx", "ecx", "eax");
04b361ab 63}
1da177e4 64
198d208d
SR
65static inline void *current_stack(void)
66{
83653c16 67 return (void *)(current_stack_pointer() & ~(THREAD_SIZE - 1));
198d208d
SR
68}
69
bd0b9ac4 70static inline int execute_on_irq_stack(int overflow, struct irq_desc *desc)
de9b10af 71{
198d208d 72 struct irq_stack *curstk, *irqstk;
bd0b9ac4 73 u32 *isp, *prev_esp, arg1;
1da177e4 74
198d208d
SR
75 curstk = (struct irq_stack *) current_stack();
76 irqstk = __this_cpu_read(hardirq_stack);
1da177e4
LT
77
78 /*
79 * this is where we switch to the IRQ stack. However, if we are
80 * already using the IRQ stack (because we interrupted a hardirq
81 * handler) we can't do that and just have to keep using the
82 * current stack (which is the irq stack already after all)
83 */
198d208d 84 if (unlikely(curstk == irqstk))
de9b10af 85 return 0;
1da177e4 86
198d208d
SR
87 isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
88
89 /* Save the next esp at the bottom of the stack */
90 prev_esp = (u32 *)irqstk;
83653c16 91 *prev_esp = current_stack_pointer();
1da177e4 92
de9b10af 93 if (unlikely(overflow))
403d8efc
TG
94 call_on_stack(print_stack_overflow, isp);
95
96 asm volatile("xchgl %%ebx,%%esp \n"
97 "call *%%edi \n"
98 "movl %%ebx,%%esp \n"
bd0b9ac4
TG
99 : "=a" (arg1), "=b" (isp)
100 : "0" (desc), "1" (isp),
403d8efc
TG
101 "D" (desc->handle_irq)
102 : "memory", "cc", "ecx");
1da177e4
LT
103 return 1;
104}
105
1da177e4
LT
106/*
107 * allocate per-cpu stacks for hardirq and for softirq processing
108 */
148f9bb8 109void irq_ctx_init(int cpu)
1da177e4 110{
198d208d 111 struct irq_stack *irqstk;
1da177e4 112
198d208d 113 if (per_cpu(hardirq_stack, cpu))
1da177e4
LT
114 return;
115
198d208d 116 irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
38e7c572
TG
117 THREADINFO_GFP,
118 THREAD_SIZE_ORDER));
198d208d 119 per_cpu(hardirq_stack, cpu) = irqstk;
1da177e4 120
198d208d 121 irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
38e7c572
TG
122 THREADINFO_GFP,
123 THREAD_SIZE_ORDER));
198d208d 124 per_cpu(softirq_stack, cpu) = irqstk;
1da177e4 125
403d8efc 126 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
198d208d 127 cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
1da177e4
LT
128}
129
7d65f4a6 130void do_softirq_own_stack(void)
1da177e4 131{
198d208d 132 struct irq_stack *irqstk;
0788aa6a 133 u32 *isp, *prev_esp;
1da177e4 134
198d208d 135 irqstk = __this_cpu_read(softirq_stack);
1da177e4 136
7d65f4a6 137 /* build the stack frame on the softirq stack */
198d208d 138 isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
1da177e4 139
0788aa6a 140 /* Push the previous esp onto the stack */
198d208d 141 prev_esp = (u32 *)irqstk;
83653c16 142 *prev_esp = current_stack_pointer();
0788aa6a 143
7d65f4a6 144 call_on_stack(__do_softirq, isp);
1da177e4 145}
403d8efc 146
a782a7e4 147bool handle_irq(struct irq_desc *desc, struct pt_regs *regs)
9b2b76a3 148{
bd0b9ac4 149 int overflow = check_stack_overflow();
9b2b76a3 150
a782a7e4 151 if (IS_ERR_OR_NULL(desc))
9b2b76a3
JF
152 return false;
153
bd0b9ac4 154 if (user_mode(regs) || !execute_on_irq_stack(overflow, desc)) {
9b2b76a3
JF
155 if (unlikely(overflow))
156 print_stack_overflow();
bd0b9ac4 157 generic_handle_irq_desc(desc);
9b2b76a3
JF
158 }
159
160 return true;
161}