Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/x86_64/entry.S |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs |
| 6 | * Copyright (C) 2000 Pavel Machek <pavel@suse.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * entry.S contains the system-call and fault low-level handling routines. |
| 11 | * |
| 12 | * NOTE: This code handles signal-recognition, which happens every time |
| 13 | * after an interrupt and after each system call. |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 14 | * |
| 15 | * Normal syscalls and interrupts don't save a full stack frame, this is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * only done for syscall tracing, signals or fork/exec et.al. |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 17 | * |
| 18 | * A note on terminology: |
| 19 | * - top of stack: Architecture defined interrupt frame from SS to RIP |
| 20 | * at the top of the kernel process stack. |
Lucas De Marchi | 0d2eb44 | 2011-03-17 16:24:16 -0300 | [diff] [blame] | 21 | * - partial stack frame: partially saved registers up to R11. |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 22 | * - full stack frame: Like partial stack frame, but all register saved. |
Andi Kleen | 2e91a17 | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 23 | * |
| 24 | * Some macro usage: |
| 25 | * - CFI macros are used to generate dwarf2 unwind information for better |
| 26 | * backtraces. They don't change any code. |
| 27 | * - SAVE_ALL/RESTORE_ALL - Save/restore all registers |
| 28 | * - SAVE_ARGS/RESTORE_ARGS - Save/restore registers that C functions modify. |
| 29 | * There are unfortunately lots of special cases where some registers |
| 30 | * not touched. The macro is a big mess that should be cleaned up. |
| 31 | * - SAVE_REST/RESTORE_REST - Handle the registers not saved by SAVE_ARGS. |
| 32 | * Gives a full stack frame. |
| 33 | * - ENTRY/END Define functions in the symbol table. |
| 34 | * - FIXUP_TOP_OF_STACK/RESTORE_TOP_OF_STACK - Fix up the hardware stack |
| 35 | * frame that is otherwise undefined after a SYSCALL |
| 36 | * - TRACE_IRQ_* - Trace hard interrupt state for lock debugging. |
| 37 | * - errorentry/paranoidentry/zeroentry - Define exception entry points. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | */ |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/linkage.h> |
| 41 | #include <asm/segment.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/cache.h> |
| 43 | #include <asm/errno.h> |
| 44 | #include <asm/dwarf2.h> |
| 45 | #include <asm/calling.h> |
Sam Ravnborg | e2d5df9 | 2005-09-09 21:28:48 +0200 | [diff] [blame] | 46 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <asm/msr.h> |
| 48 | #include <asm/unistd.h> |
| 49 | #include <asm/thread_info.h> |
| 50 | #include <asm/hw_irq.h> |
Jeremy Fitzhardinge | 0341c14 | 2009-02-13 11:14:01 -0800 | [diff] [blame] | 51 | #include <asm/page_types.h> |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 52 | #include <asm/irqflags.h> |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 53 | #include <asm/paravirt.h> |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 54 | #include <asm/ftrace.h> |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 55 | #include <asm/percpu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 57 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ |
| 58 | #include <linux/elf-em.h> |
| 59 | #define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
| 60 | #define __AUDIT_ARCH_64BIT 0x80000000 |
| 61 | #define __AUDIT_ARCH_LE 0x40000000 |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | .code64 |
Jiri Olsa | ea71454 | 2011-03-07 19:10:39 +0100 | [diff] [blame] | 64 | .section .entry.text, "ax" |
| 65 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 66 | #ifdef CONFIG_FUNCTION_TRACER |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 67 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 68 | ENTRY(mcount) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 69 | retq |
| 70 | END(mcount) |
| 71 | |
| 72 | ENTRY(ftrace_caller) |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 73 | cmpl $0, function_trace_stop |
| 74 | jne ftrace_stub |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 75 | |
Cyrill Gorcunov | d680fe4 | 2008-12-13 00:09:08 +0300 | [diff] [blame] | 76 | MCOUNT_SAVE_FRAME |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 77 | |
| 78 | movq 0x38(%rsp), %rdi |
| 79 | movq 8(%rbp), %rsi |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 80 | subq $MCOUNT_INSN_SIZE, %rdi |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 81 | |
Cyrill Gorcunov | bc8b2b9 | 2009-02-23 22:57:01 +0300 | [diff] [blame] | 82 | GLOBAL(ftrace_call) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 83 | call ftrace_stub |
| 84 | |
Cyrill Gorcunov | d680fe4 | 2008-12-13 00:09:08 +0300 | [diff] [blame] | 85 | MCOUNT_RESTORE_FRAME |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 86 | |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 87 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Cyrill Gorcunov | bc8b2b9 | 2009-02-23 22:57:01 +0300 | [diff] [blame] | 88 | GLOBAL(ftrace_graph_call) |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 89 | jmp ftrace_stub |
| 90 | #endif |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 91 | |
Cyrill Gorcunov | bc8b2b9 | 2009-02-23 22:57:01 +0300 | [diff] [blame] | 92 | GLOBAL(ftrace_stub) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 93 | retq |
| 94 | END(ftrace_caller) |
| 95 | |
| 96 | #else /* ! CONFIG_DYNAMIC_FTRACE */ |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 97 | ENTRY(mcount) |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 98 | cmpl $0, function_trace_stop |
| 99 | jne ftrace_stub |
| 100 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 101 | cmpq $ftrace_stub, ftrace_trace_function |
| 102 | jnz trace |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 103 | |
| 104 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 105 | cmpq $ftrace_stub, ftrace_graph_return |
| 106 | jnz ftrace_graph_caller |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 107 | |
| 108 | cmpq $ftrace_graph_entry_stub, ftrace_graph_entry |
| 109 | jnz ftrace_graph_caller |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 110 | #endif |
| 111 | |
Cyrill Gorcunov | bc8b2b9 | 2009-02-23 22:57:01 +0300 | [diff] [blame] | 112 | GLOBAL(ftrace_stub) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 113 | retq |
| 114 | |
| 115 | trace: |
Cyrill Gorcunov | d680fe4 | 2008-12-13 00:09:08 +0300 | [diff] [blame] | 116 | MCOUNT_SAVE_FRAME |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 117 | |
| 118 | movq 0x38(%rsp), %rdi |
| 119 | movq 8(%rbp), %rsi |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 120 | subq $MCOUNT_INSN_SIZE, %rdi |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 121 | |
| 122 | call *ftrace_trace_function |
| 123 | |
Cyrill Gorcunov | d680fe4 | 2008-12-13 00:09:08 +0300 | [diff] [blame] | 124 | MCOUNT_RESTORE_FRAME |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 125 | |
| 126 | jmp ftrace_stub |
| 127 | END(mcount) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 128 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 129 | #endif /* CONFIG_FUNCTION_TRACER */ |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 130 | |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 131 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 132 | ENTRY(ftrace_graph_caller) |
| 133 | cmpl $0, function_trace_stop |
| 134 | jne ftrace_stub |
| 135 | |
Cyrill Gorcunov | d680fe4 | 2008-12-13 00:09:08 +0300 | [diff] [blame] | 136 | MCOUNT_SAVE_FRAME |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 137 | |
| 138 | leaq 8(%rbp), %rdi |
| 139 | movq 0x38(%rsp), %rsi |
Steven Rostedt | 71e308a | 2009-06-18 12:45:08 -0400 | [diff] [blame] | 140 | movq (%rbp), %rdx |
Steven Rostedt | bb4304c | 2008-12-02 15:34:09 -0500 | [diff] [blame] | 141 | subq $MCOUNT_INSN_SIZE, %rsi |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 142 | |
| 143 | call prepare_ftrace_return |
| 144 | |
Cyrill Gorcunov | d680fe4 | 2008-12-13 00:09:08 +0300 | [diff] [blame] | 145 | MCOUNT_RESTORE_FRAME |
| 146 | |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 147 | retq |
| 148 | END(ftrace_graph_caller) |
| 149 | |
Cyrill Gorcunov | bc8b2b9 | 2009-02-23 22:57:01 +0300 | [diff] [blame] | 150 | GLOBAL(return_to_handler) |
Jiri Olsa | 4818d80 | 2009-07-29 10:58:37 +0200 | [diff] [blame] | 151 | subq $24, %rsp |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 152 | |
Steven Rostedt | e71e99c | 2009-03-25 14:30:04 -0400 | [diff] [blame] | 153 | /* Save the return values */ |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 154 | movq %rax, (%rsp) |
Steven Rostedt | e71e99c | 2009-03-25 14:30:04 -0400 | [diff] [blame] | 155 | movq %rdx, 8(%rsp) |
Steven Rostedt | 71e308a | 2009-06-18 12:45:08 -0400 | [diff] [blame] | 156 | movq %rbp, %rdi |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 157 | |
| 158 | call ftrace_return_to_handler |
| 159 | |
Steven Rostedt | 194ec34 | 2009-10-13 16:33:50 -0400 | [diff] [blame] | 160 | movq %rax, %rdi |
Steven Rostedt | e71e99c | 2009-03-25 14:30:04 -0400 | [diff] [blame] | 161 | movq 8(%rsp), %rdx |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 162 | movq (%rsp), %rax |
Steven Rostedt | 194ec34 | 2009-10-13 16:33:50 -0400 | [diff] [blame] | 163 | addq $24, %rsp |
| 164 | jmp *%rdi |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 165 | #endif |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | #ifndef CONFIG_PREEMPT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | #define retint_kernel retint_restore_args |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 170 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | #ifdef CONFIG_PARAVIRT |
| 173 | ENTRY(native_usergs_sysret64) |
| 174 | swapgs |
| 175 | sysretq |
Cyrill Gorcunov | b3baaa1 | 2009-02-23 22:57:00 +0300 | [diff] [blame] | 176 | ENDPROC(native_usergs_sysret64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | #endif /* CONFIG_PARAVIRT */ |
| 178 | |
| 179 | |
| 180 | .macro TRACE_IRQS_IRETQ offset=ARGOFFSET |
| 181 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 182 | bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */ |
| 183 | jnc 1f |
| 184 | TRACE_IRQS_ON |
| 185 | 1: |
| 186 | #endif |
| 187 | .endm |
| 188 | |
| 189 | /* |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 190 | * C code is not supposed to know about undefined top of stack. Every time |
| 191 | * a C function with an pt_regs argument is called from the SYSCALL based |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | * fast path FIXUP_TOP_OF_STACK is needed. |
| 193 | * RESTORE_TOP_OF_STACK syncs the syscall state after any possible ptregs |
| 194 | * manipulation. |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 195 | */ |
| 196 | |
| 197 | /* %rsp:at FRAMEEND */ |
Alexander van Heukelum | c002a1e | 2008-11-21 16:41:55 +0100 | [diff] [blame] | 198 | .macro FIXUP_TOP_OF_STACK tmp offset=0 |
Brian Gerst | 3d1e42a | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 199 | movq PER_CPU_VAR(old_rsp),\tmp |
Alexander van Heukelum | c002a1e | 2008-11-21 16:41:55 +0100 | [diff] [blame] | 200 | movq \tmp,RSP+\offset(%rsp) |
| 201 | movq $__USER_DS,SS+\offset(%rsp) |
| 202 | movq $__USER_CS,CS+\offset(%rsp) |
| 203 | movq $-1,RCX+\offset(%rsp) |
| 204 | movq R11+\offset(%rsp),\tmp /* get eflags */ |
| 205 | movq \tmp,EFLAGS+\offset(%rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | .endm |
| 207 | |
Alexander van Heukelum | c002a1e | 2008-11-21 16:41:55 +0100 | [diff] [blame] | 208 | .macro RESTORE_TOP_OF_STACK tmp offset=0 |
| 209 | movq RSP+\offset(%rsp),\tmp |
Brian Gerst | 3d1e42a | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 210 | movq \tmp,PER_CPU_VAR(old_rsp) |
Alexander van Heukelum | c002a1e | 2008-11-21 16:41:55 +0100 | [diff] [blame] | 211 | movq EFLAGS+\offset(%rsp),\tmp |
| 212 | movq \tmp,R11+\offset(%rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | .endm |
| 214 | |
| 215 | .macro FAKE_STACK_FRAME child_rip |
| 216 | /* push in order ss, rsp, eflags, cs, rip */ |
| 217 | xorl %eax, %eax |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 218 | pushq_cfi $__KERNEL_DS /* ss */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | /*CFI_REL_OFFSET ss,0*/ |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 220 | pushq_cfi %rax /* rsp */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | CFI_REL_OFFSET rsp,0 |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 222 | pushq_cfi $X86_EFLAGS_IF /* eflags - interrupts on */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | /*CFI_REL_OFFSET rflags,0*/ |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 224 | pushq_cfi $__KERNEL_CS /* cs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | /*CFI_REL_OFFSET cs,0*/ |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 226 | pushq_cfi \child_rip /* rip */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | CFI_REL_OFFSET rip,0 |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 228 | pushq_cfi %rax /* orig rax */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | .endm |
| 230 | |
| 231 | .macro UNFAKE_STACK_FRAME |
| 232 | addq $8*6, %rsp |
| 233 | CFI_ADJUST_CFA_OFFSET -(6*8) |
| 234 | .endm |
| 235 | |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 236 | /* |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 237 | * initial frame state for interrupts (and exceptions without error code) |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 238 | */ |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 239 | .macro EMPTY_FRAME start=1 offset=0 |
| 240 | .if \start |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 241 | CFI_STARTPROC simple |
| 242 | CFI_SIGNAL_FRAME |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 243 | CFI_DEF_CFA rsp,8+\offset |
| 244 | .else |
| 245 | CFI_DEF_CFA_OFFSET 8+\offset |
| 246 | .endif |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 247 | .endm |
| 248 | |
| 249 | /* |
| 250 | * initial frame state for interrupts (and exceptions without error code) |
| 251 | */ |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 252 | .macro INTR_FRAME start=1 offset=0 |
Ingo Molnar | e8a0e27 | 2008-11-21 15:11:32 +0100 | [diff] [blame] | 253 | EMPTY_FRAME \start, SS+8+\offset-RIP |
| 254 | /*CFI_REL_OFFSET ss, SS+\offset-RIP*/ |
| 255 | CFI_REL_OFFSET rsp, RSP+\offset-RIP |
| 256 | /*CFI_REL_OFFSET rflags, EFLAGS+\offset-RIP*/ |
| 257 | /*CFI_REL_OFFSET cs, CS+\offset-RIP*/ |
| 258 | CFI_REL_OFFSET rip, RIP+\offset-RIP |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 259 | .endm |
| 260 | |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 261 | /* |
| 262 | * initial frame state for exceptions with error code (and interrupts |
| 263 | * with vector already pushed) |
| 264 | */ |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 265 | .macro XCPT_FRAME start=1 offset=0 |
Ingo Molnar | e8a0e27 | 2008-11-21 15:11:32 +0100 | [diff] [blame] | 266 | INTR_FRAME \start, RIP+\offset-ORIG_RAX |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 267 | /*CFI_REL_OFFSET orig_rax, ORIG_RAX-ORIG_RAX*/ |
| 268 | .endm |
| 269 | |
| 270 | /* |
| 271 | * frame that enables calling into C. |
| 272 | */ |
| 273 | .macro PARTIAL_FRAME start=1 offset=0 |
Ingo Molnar | e8a0e27 | 2008-11-21 15:11:32 +0100 | [diff] [blame] | 274 | XCPT_FRAME \start, ORIG_RAX+\offset-ARGOFFSET |
| 275 | CFI_REL_OFFSET rdi, RDI+\offset-ARGOFFSET |
| 276 | CFI_REL_OFFSET rsi, RSI+\offset-ARGOFFSET |
| 277 | CFI_REL_OFFSET rdx, RDX+\offset-ARGOFFSET |
| 278 | CFI_REL_OFFSET rcx, RCX+\offset-ARGOFFSET |
| 279 | CFI_REL_OFFSET rax, RAX+\offset-ARGOFFSET |
| 280 | CFI_REL_OFFSET r8, R8+\offset-ARGOFFSET |
| 281 | CFI_REL_OFFSET r9, R9+\offset-ARGOFFSET |
| 282 | CFI_REL_OFFSET r10, R10+\offset-ARGOFFSET |
| 283 | CFI_REL_OFFSET r11, R11+\offset-ARGOFFSET |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 284 | .endm |
| 285 | |
| 286 | /* |
| 287 | * frame that enables passing a complete pt_regs to a C function. |
| 288 | */ |
| 289 | .macro DEFAULT_FRAME start=1 offset=0 |
Ingo Molnar | e8a0e27 | 2008-11-21 15:11:32 +0100 | [diff] [blame] | 290 | PARTIAL_FRAME \start, R11+\offset-R15 |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 291 | CFI_REL_OFFSET rbx, RBX+\offset |
| 292 | CFI_REL_OFFSET rbp, RBP+\offset |
| 293 | CFI_REL_OFFSET r12, R12+\offset |
| 294 | CFI_REL_OFFSET r13, R13+\offset |
| 295 | CFI_REL_OFFSET r14, R14+\offset |
| 296 | CFI_REL_OFFSET r15, R15+\offset |
| 297 | .endm |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 298 | |
| 299 | /* save partial stack frame */ |
Frederic Weisbecker | 1871853 | 2011-07-01 01:51:22 +0200 | [diff] [blame^] | 300 | .macro SAVE_ARGS_IRQ |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 301 | cld |
Frederic Weisbecker | 1871853 | 2011-07-01 01:51:22 +0200 | [diff] [blame^] | 302 | /* start from rbp in pt_regs and jump over */ |
| 303 | movq_cfi rdi, RDI-RBP |
| 304 | movq_cfi rsi, RSI-RBP |
| 305 | movq_cfi rdx, RDX-RBP |
| 306 | movq_cfi rcx, RCX-RBP |
| 307 | movq_cfi rax, RAX-RBP |
| 308 | movq_cfi r8, R8-RBP |
| 309 | movq_cfi r9, R9-RBP |
| 310 | movq_cfi r10, R10-RBP |
| 311 | movq_cfi r11, R11-RBP |
Ingo Molnar | 14ae22b | 2008-11-21 15:20:47 +0100 | [diff] [blame] | 312 | |
Frederic Weisbecker | 1871853 | 2011-07-01 01:51:22 +0200 | [diff] [blame^] | 313 | leaq -RBP(%rsp),%rdi /* arg1 for handler */ |
| 314 | movq_cfi rbp, 0 /* push %rbp */ |
| 315 | movq %rsp, %rbp |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 316 | testl $3, CS(%rdi) |
| 317 | je 1f |
| 318 | SWAPGS |
| 319 | /* |
Brian Gerst | 5689553 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 320 | * irq_count is used to check if a CPU is already on an interrupt stack |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 321 | * or not. While this is essentially redundant with preempt_count it is |
| 322 | * a little cheaper to use a separate counter in the PDA (short of |
| 323 | * moving irq_enter into assembly, which would be too much work) |
| 324 | */ |
Brian Gerst | 5689553 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 325 | 1: incl PER_CPU_VAR(irq_count) |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 326 | jne 2f |
Brian Gerst | 26f80bd | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 327 | mov PER_CPU_VAR(irq_stack_ptr),%rsp |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 328 | EMPTY_FRAME 0 |
Martin Hicks | a67798c | 2009-01-30 10:50:54 -0600 | [diff] [blame] | 329 | pushq_cfi %rbp /* backlink for unwinder */ |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 330 | /* |
| 331 | * We entered an interrupt context - irqs are off: |
| 332 | */ |
| 333 | 2: TRACE_IRQS_OFF |
Frederic Weisbecker | 1871853 | 2011-07-01 01:51:22 +0200 | [diff] [blame^] | 334 | .endm |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 335 | |
Alexander van Heukelum | c002a1e | 2008-11-21 16:41:55 +0100 | [diff] [blame] | 336 | ENTRY(save_rest) |
| 337 | PARTIAL_FRAME 1 REST_SKIP+8 |
| 338 | movq 5*8+16(%rsp), %r11 /* save return address */ |
| 339 | movq_cfi rbx, RBX+16 |
| 340 | movq_cfi rbp, RBP+16 |
| 341 | movq_cfi r12, R12+16 |
| 342 | movq_cfi r13, R13+16 |
| 343 | movq_cfi r14, R14+16 |
| 344 | movq_cfi r15, R15+16 |
| 345 | movq %r11, 8(%rsp) /* return address */ |
| 346 | FIXUP_TOP_OF_STACK %r11, 16 |
| 347 | ret |
| 348 | CFI_ENDPROC |
| 349 | END(save_rest) |
| 350 | |
Alexander van Heukelum | e2f6bc2 | 2008-11-21 16:43:18 +0100 | [diff] [blame] | 351 | /* save complete stack frame */ |
Jan Beulich | c281018 | 2009-03-12 10:38:55 +0000 | [diff] [blame] | 352 | .pushsection .kprobes.text, "ax" |
Alexander van Heukelum | e2f6bc2 | 2008-11-21 16:43:18 +0100 | [diff] [blame] | 353 | ENTRY(save_paranoid) |
| 354 | XCPT_FRAME 1 RDI+8 |
| 355 | cld |
| 356 | movq_cfi rdi, RDI+8 |
| 357 | movq_cfi rsi, RSI+8 |
| 358 | movq_cfi rdx, RDX+8 |
| 359 | movq_cfi rcx, RCX+8 |
| 360 | movq_cfi rax, RAX+8 |
| 361 | movq_cfi r8, R8+8 |
| 362 | movq_cfi r9, R9+8 |
| 363 | movq_cfi r10, R10+8 |
| 364 | movq_cfi r11, R11+8 |
| 365 | movq_cfi rbx, RBX+8 |
| 366 | movq_cfi rbp, RBP+8 |
| 367 | movq_cfi r12, R12+8 |
| 368 | movq_cfi r13, R13+8 |
| 369 | movq_cfi r14, R14+8 |
| 370 | movq_cfi r15, R15+8 |
| 371 | movl $1,%ebx |
| 372 | movl $MSR_GS_BASE,%ecx |
| 373 | rdmsr |
| 374 | testl %edx,%edx |
| 375 | js 1f /* negative -> in kernel */ |
| 376 | SWAPGS |
| 377 | xorl %ebx,%ebx |
| 378 | 1: ret |
| 379 | CFI_ENDPROC |
| 380 | END(save_paranoid) |
Jan Beulich | c281018 | 2009-03-12 10:38:55 +0000 | [diff] [blame] | 381 | .popsection |
Alexander van Heukelum | e2f6bc2 | 2008-11-21 16:43:18 +0100 | [diff] [blame] | 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /* |
Ingo Molnar | 5b3eec0 | 2008-11-27 14:41:21 +0100 | [diff] [blame] | 384 | * A newly forked process directly context switches into this address. |
| 385 | * |
| 386 | * rdi: prev task we switched from |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 387 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | ENTRY(ret_from_fork) |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 389 | DEFAULT_FRAME |
Ingo Molnar | 5b3eec0 | 2008-11-27 14:41:21 +0100 | [diff] [blame] | 390 | |
Benjamin LaHaise | 7106a5a | 2009-01-10 23:00:22 -0500 | [diff] [blame] | 391 | LOCK ; btr $TIF_FORK,TI_flags(%r8) |
| 392 | |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 393 | pushq_cfi kernel_eflags(%rip) |
| 394 | popfq_cfi # reset kernel eflags |
Ingo Molnar | 5b3eec0 | 2008-11-27 14:41:21 +0100 | [diff] [blame] | 395 | |
| 396 | call schedule_tail # rdi: 'prev' task parameter |
| 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | GET_THREAD_INFO(%rcx) |
Ingo Molnar | 5b3eec0 | 2008-11-27 14:41:21 +0100 | [diff] [blame] | 399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | RESTORE_REST |
Ingo Molnar | 5b3eec0 | 2008-11-27 14:41:21 +0100 | [diff] [blame] | 401 | |
| 402 | testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | je int_ret_from_sys_call |
Ingo Molnar | 5b3eec0 | 2008-11-27 14:41:21 +0100 | [diff] [blame] | 404 | |
| 405 | testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | jnz int_ret_from_sys_call |
Ingo Molnar | 5b3eec0 | 2008-11-27 14:41:21 +0100 | [diff] [blame] | 407 | |
Alexander van Heukelum | c002a1e | 2008-11-21 16:41:55 +0100 | [diff] [blame] | 408 | RESTORE_TOP_OF_STACK %rdi, -ARGOFFSET |
Ingo Molnar | 5b3eec0 | 2008-11-27 14:41:21 +0100 | [diff] [blame] | 409 | jmp ret_from_sys_call # go to the SYSRET fastpath |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 412 | END(ret_from_fork) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
| 414 | /* |
Lucas De Marchi | 0d2eb44 | 2011-03-17 16:24:16 -0300 | [diff] [blame] | 415 | * System call entry. Up to 6 arguments in registers are supported. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | * |
| 417 | * SYSCALL does not save anything on the stack and does not change the |
| 418 | * stack pointer. |
| 419 | */ |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | /* |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 422 | * Register setup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | * rax system call number |
| 424 | * rdi arg0 |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 425 | * rcx return address for syscall/sysret, C arg3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | * rsi arg1 |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 427 | * rdx arg2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | * r10 arg3 (--> moved to rcx for C) |
| 429 | * r8 arg4 |
| 430 | * r9 arg5 |
| 431 | * r11 eflags for syscall/sysret, temporary for C |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 432 | * r12-r15,rbp,rbx saved by C code, not touched. |
| 433 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | * Interrupts are off on entry. |
| 435 | * Only called from user space. |
| 436 | * |
| 437 | * XXX if we had a free scratch register we could save the RSP into the stack frame |
| 438 | * and report it properly in ps. Unfortunately we haven't. |
Andi Kleen | 7bf36bb | 2006-04-07 19:50:00 +0200 | [diff] [blame] | 439 | * |
| 440 | * When user can change the frames always force IRET. That is because |
| 441 | * it deals with uncanonical addresses better. SYSRET has trouble |
| 442 | * with them due to bugs in both AMD and Intel CPUs. |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 443 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | ENTRY(system_call) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 446 | CFI_STARTPROC simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 447 | CFI_SIGNAL_FRAME |
Brian Gerst | 9af4565 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 448 | CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 449 | CFI_REGISTER rip,rcx |
| 450 | /*CFI_REGISTER rflags,r11*/ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 451 | SWAPGS_UNSAFE_STACK |
| 452 | /* |
| 453 | * A hypervisor implementation might want to use a label |
| 454 | * after the swapgs, so that it can do the swapgs |
| 455 | * for the guest and jump here on syscall. |
| 456 | */ |
| 457 | ENTRY(system_call_after_swapgs) |
| 458 | |
Brian Gerst | 3d1e42a | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 459 | movq %rsp,PER_CPU_VAR(old_rsp) |
Brian Gerst | 9af4565 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 460 | movq PER_CPU_VAR(kernel_stack),%rsp |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 461 | /* |
| 462 | * No need to follow this irqs off/on section - it's straight |
| 463 | * and short: |
| 464 | */ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 465 | ENABLE_INTERRUPTS(CLBR_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | SAVE_ARGS 8,1 |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 467 | movq %rax,ORIG_RAX-ARGOFFSET(%rsp) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 468 | movq %rcx,RIP-ARGOFFSET(%rsp) |
| 469 | CFI_REL_OFFSET rip,RIP-ARGOFFSET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | GET_THREAD_INFO(%rcx) |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 471 | testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | jnz tracesys |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 473 | system_call_fastpath: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | cmpq $__NR_syscall_max,%rax |
| 475 | ja badsys |
| 476 | movq %r10,%rcx |
| 477 | call *sys_call_table(,%rax,8) # XXX: rip relative |
| 478 | movq %rax,RAX-ARGOFFSET(%rsp) |
| 479 | /* |
| 480 | * Syscall return path ending with SYSRET (fast path) |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 481 | * Has incomplete stack frame and undefined top of stack. |
| 482 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | ret_from_sys_call: |
Andi Kleen | 11b854b | 2005-04-16 15:25:02 -0700 | [diff] [blame] | 484 | movl $_TIF_ALLWORK_MASK,%edi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | /* edi: flagmask */ |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 486 | sysret_check: |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 487 | LOCKDEP_SYS_EXIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | GET_THREAD_INFO(%rcx) |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 489 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 490 | TRACE_IRQS_OFF |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 491 | movl TI_flags(%rcx),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | andl %edi,%edx |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 493 | jnz sysret_careful |
Jan Beulich | bcddc01 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 494 | CFI_REMEMBER_STATE |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 495 | /* |
| 496 | * sysretq will re-enable interrupts: |
| 497 | */ |
| 498 | TRACE_IRQS_ON |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | movq RIP-ARGOFFSET(%rsp),%rcx |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 500 | CFI_REGISTER rip,rcx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | RESTORE_ARGS 0,-ARG_SKIP,1 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 502 | /*CFI_REGISTER rflags,r11*/ |
Brian Gerst | 3d1e42a | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 503 | movq PER_CPU_VAR(old_rsp), %rsp |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 504 | USERGS_SYSRET64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Jan Beulich | bcddc01 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 506 | CFI_RESTORE_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | /* Handle reschedules */ |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 508 | /* edx: work, edi: workmask */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | sysret_careful: |
| 510 | bt $TIF_NEED_RESCHED,%edx |
| 511 | jnc sysret_signal |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 512 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 513 | ENABLE_INTERRUPTS(CLBR_NONE) |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 514 | pushq_cfi %rdi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | call schedule |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 516 | popq_cfi %rdi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | jmp sysret_check |
| 518 | |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 519 | /* Handle a signal */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | sysret_signal: |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 521 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 522 | ENABLE_INTERRUPTS(CLBR_NONE) |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 523 | #ifdef CONFIG_AUDITSYSCALL |
| 524 | bt $TIF_SYSCALL_AUDIT,%edx |
| 525 | jc sysret_audit |
| 526 | #endif |
Roland McGrath | b60e714 | 2009-09-22 16:46:34 -0700 | [diff] [blame] | 527 | /* |
| 528 | * We have a signal, or exit tracing or single-step. |
| 529 | * These all wind up with the iret return path anyway, |
| 530 | * so just join that path right now. |
| 531 | */ |
| 532 | FIXUP_TOP_OF_STACK %r11, -ARGOFFSET |
| 533 | jmp int_check_syscall_exit_work |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 534 | |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 535 | badsys: |
| 536 | movq $-ENOSYS,RAX-ARGOFFSET(%rsp) |
| 537 | jmp ret_from_sys_call |
| 538 | |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 539 | #ifdef CONFIG_AUDITSYSCALL |
| 540 | /* |
| 541 | * Fast path for syscall audit without full syscall trace. |
| 542 | * We just call audit_syscall_entry() directly, and then |
| 543 | * jump back to the normal fast path. |
| 544 | */ |
| 545 | auditsys: |
| 546 | movq %r10,%r9 /* 6th arg: 4th syscall arg */ |
| 547 | movq %rdx,%r8 /* 5th arg: 3rd syscall arg */ |
| 548 | movq %rsi,%rcx /* 4th arg: 2nd syscall arg */ |
| 549 | movq %rdi,%rdx /* 3rd arg: 1st syscall arg */ |
| 550 | movq %rax,%rsi /* 2nd arg: syscall number */ |
| 551 | movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */ |
| 552 | call audit_syscall_entry |
| 553 | LOAD_ARGS 0 /* reload call-clobbered registers */ |
| 554 | jmp system_call_fastpath |
| 555 | |
| 556 | /* |
| 557 | * Return fast path for syscall audit. Call audit_syscall_exit() |
| 558 | * directly and then jump back to the fast path with TIF_SYSCALL_AUDIT |
| 559 | * masked off. |
| 560 | */ |
| 561 | sysret_audit: |
Roland McGrath | 0327559 | 2010-07-21 17:44:12 -0700 | [diff] [blame] | 562 | movq RAX-ARGOFFSET(%rsp),%rsi /* second arg, syscall return value */ |
| 563 | cmpq $0,%rsi /* is it < 0? */ |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 564 | setl %al /* 1 if so, 0 if not */ |
| 565 | movzbl %al,%edi /* zero-extend that into %edi */ |
| 566 | inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */ |
| 567 | call audit_syscall_exit |
| 568 | movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi |
| 569 | jmp sysret_check |
| 570 | #endif /* CONFIG_AUDITSYSCALL */ |
| 571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | /* Do syscall tracing */ |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 573 | tracesys: |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 574 | #ifdef CONFIG_AUDITSYSCALL |
| 575 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx) |
| 576 | jz auditsys |
| 577 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | SAVE_REST |
Roland McGrath | a31f8dd | 2008-03-16 21:59:11 -0700 | [diff] [blame] | 579 | movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | FIXUP_TOP_OF_STACK %rdi |
| 581 | movq %rsp,%rdi |
| 582 | call syscall_trace_enter |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 583 | /* |
| 584 | * Reload arg registers from stack in case ptrace changed them. |
| 585 | * We don't reload %rax because syscall_trace_enter() returned |
| 586 | * the value it wants us to use in the table lookup. |
| 587 | */ |
| 588 | LOAD_ARGS ARGOFFSET, 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | RESTORE_REST |
| 590 | cmpq $__NR_syscall_max,%rax |
Roland McGrath | a31f8dd | 2008-03-16 21:59:11 -0700 | [diff] [blame] | 591 | ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | movq %r10,%rcx /* fixup for C */ |
| 593 | call *sys_call_table(,%rax,8) |
Roland McGrath | a31f8dd | 2008-03-16 21:59:11 -0700 | [diff] [blame] | 594 | movq %rax,RAX-ARGOFFSET(%rsp) |
Andi Kleen | 7bf36bb | 2006-04-07 19:50:00 +0200 | [diff] [blame] | 595 | /* Use IRET because user could have changed frame */ |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 596 | |
| 597 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | * Syscall return path ending with IRET. |
| 599 | * Has correct top of stack, but partial stack frame. |
Jan Beulich | bcddc01 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 600 | */ |
Cyrill Gorcunov | bc8b2b9 | 2009-02-23 22:57:01 +0300 | [diff] [blame] | 601 | GLOBAL(int_ret_from_sys_call) |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 602 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 603 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | testl $3,CS-ARGOFFSET(%rsp) |
| 605 | je retint_restore_args |
| 606 | movl $_TIF_ALLWORK_MASK,%edi |
| 607 | /* edi: mask to check */ |
Cyrill Gorcunov | bc8b2b9 | 2009-02-23 22:57:01 +0300 | [diff] [blame] | 608 | GLOBAL(int_with_check) |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 609 | LOCKDEP_SYS_EXIT_IRQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | GET_THREAD_INFO(%rcx) |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 611 | movl TI_flags(%rcx),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | andl %edi,%edx |
| 613 | jnz int_careful |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 614 | andl $~TS_COMPAT,TI_status(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | jmp retint_swapgs |
| 616 | |
| 617 | /* Either reschedule or signal or syscall exit tracking needed. */ |
| 618 | /* First do a reschedule test. */ |
| 619 | /* edx: work, edi: workmask */ |
| 620 | int_careful: |
| 621 | bt $TIF_NEED_RESCHED,%edx |
| 622 | jnc int_very_careful |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 623 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 624 | ENABLE_INTERRUPTS(CLBR_NONE) |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 625 | pushq_cfi %rdi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | call schedule |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 627 | popq_cfi %rdi |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 628 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 629 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | jmp int_with_check |
| 631 | |
| 632 | /* handle signals and tracing -- both require a full stack frame */ |
| 633 | int_very_careful: |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 634 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 635 | ENABLE_INTERRUPTS(CLBR_NONE) |
Roland McGrath | b60e714 | 2009-09-22 16:46:34 -0700 | [diff] [blame] | 636 | int_check_syscall_exit_work: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | SAVE_REST |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 638 | /* Check for syscall exit trace */ |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 639 | testl $_TIF_WORK_SYSCALL_EXIT,%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | jz int_signal |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 641 | pushq_cfi %rdi |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 642 | leaq 8(%rsp),%rdi # &ptregs -> arg1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | call syscall_trace_leave |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 644 | popq_cfi %rdi |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 645 | andl $~(_TIF_WORK_SYSCALL_EXIT|_TIF_SYSCALL_EMU),%edi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | jmp int_restore_rest |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | int_signal: |
Peter Zijlstra | 8f4d37e | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 649 | testl $_TIF_DO_NOTIFY_MASK,%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | jz 1f |
| 651 | movq %rsp,%rdi # &ptregs -> arg1 |
| 652 | xorl %esi,%esi # oldset -> arg2 |
| 653 | call do_notify_resume |
Roland McGrath | eca91e7 | 2008-07-10 14:50:39 -0700 | [diff] [blame] | 654 | 1: movl $_TIF_WORK_MASK,%edi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | int_restore_rest: |
| 656 | RESTORE_REST |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 657 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 658 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | jmp int_with_check |
| 660 | CFI_ENDPROC |
Jan Beulich | bcddc01 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 661 | END(system_call) |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 662 | |
| 663 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | * Certain special system calls that need to save a complete full stack frame. |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 665 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | .macro PTREGSCALL label,func,arg |
Alexander van Heukelum | c002a1e | 2008-11-21 16:41:55 +0100 | [diff] [blame] | 667 | ENTRY(\label) |
| 668 | PARTIAL_FRAME 1 8 /* offset 8: return address */ |
| 669 | subq $REST_SKIP, %rsp |
| 670 | CFI_ADJUST_CFA_OFFSET REST_SKIP |
| 671 | call save_rest |
| 672 | DEFAULT_FRAME 0 8 /* offset 8: return address */ |
| 673 | leaq 8(%rsp), \arg /* pt_regs pointer */ |
| 674 | call \func |
| 675 | jmp ptregscall_common |
| 676 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 677 | END(\label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | .endm |
| 679 | |
| 680 | PTREGSCALL stub_clone, sys_clone, %r8 |
| 681 | PTREGSCALL stub_fork, sys_fork, %rdi |
| 682 | PTREGSCALL stub_vfork, sys_vfork, %rdi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx |
| 684 | PTREGSCALL stub_iopl, sys_iopl, %rsi |
| 685 | |
| 686 | ENTRY(ptregscall_common) |
Alexander van Heukelum | c002a1e | 2008-11-21 16:41:55 +0100 | [diff] [blame] | 687 | DEFAULT_FRAME 1 8 /* offset 8: return address */ |
| 688 | RESTORE_TOP_OF_STACK %r11, 8 |
| 689 | movq_cfi_restore R15+8, r15 |
| 690 | movq_cfi_restore R14+8, r14 |
| 691 | movq_cfi_restore R13+8, r13 |
| 692 | movq_cfi_restore R12+8, r12 |
| 693 | movq_cfi_restore RBP+8, rbp |
| 694 | movq_cfi_restore RBX+8, rbx |
| 695 | ret $REST_SKIP /* pop extended registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 697 | END(ptregscall_common) |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | ENTRY(stub_execve) |
| 700 | CFI_STARTPROC |
Jan Beulich | e6b04b6 | 2010-09-02 13:52:45 +0100 | [diff] [blame] | 701 | addq $8, %rsp |
| 702 | PARTIAL_FRAME 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | SAVE_REST |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | FIXUP_TOP_OF_STACK %r11 |
Ingo Molnar | 5d119b2 | 2008-02-26 12:55:57 +0100 | [diff] [blame] | 705 | movq %rsp, %rcx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | call sys_execve |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | RESTORE_TOP_OF_STACK %r11 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | movq %rax,RAX(%rsp) |
| 709 | RESTORE_REST |
| 710 | jmp int_ret_from_sys_call |
| 711 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 712 | END(stub_execve) |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | /* |
| 715 | * sigreturn is special because it needs to restore all registers on return. |
| 716 | * This cannot be done with SYSRET, so use the IRET return path instead. |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 717 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | ENTRY(stub_rt_sigreturn) |
| 719 | CFI_STARTPROC |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 720 | addq $8, %rsp |
Jan Beulich | e6b04b6 | 2010-09-02 13:52:45 +0100 | [diff] [blame] | 721 | PARTIAL_FRAME 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | SAVE_REST |
| 723 | movq %rsp,%rdi |
| 724 | FIXUP_TOP_OF_STACK %r11 |
| 725 | call sys_rt_sigreturn |
| 726 | movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer |
| 727 | RESTORE_REST |
| 728 | jmp int_ret_from_sys_call |
| 729 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 730 | END(stub_rt_sigreturn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 732 | /* |
H. Peter Anvin | 939b787 | 2008-11-11 13:51:52 -0800 | [diff] [blame] | 733 | * Build the entry stubs and pointer table with some assembler magic. |
| 734 | * We pack 7 stubs into a single 32-byte chunk, which will fit in a |
| 735 | * single cache line on all modern x86 implementations. |
| 736 | */ |
| 737 | .section .init.rodata,"a" |
| 738 | ENTRY(interrupt) |
Jiri Olsa | ea71454 | 2011-03-07 19:10:39 +0100 | [diff] [blame] | 739 | .section .entry.text |
H. Peter Anvin | 939b787 | 2008-11-11 13:51:52 -0800 | [diff] [blame] | 740 | .p2align 5 |
| 741 | .p2align CONFIG_X86_L1_CACHE_SHIFT |
| 742 | ENTRY(irq_entries_start) |
| 743 | INTR_FRAME |
| 744 | vector=FIRST_EXTERNAL_VECTOR |
| 745 | .rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7 |
| 746 | .balign 32 |
| 747 | .rept 7 |
| 748 | .if vector < NR_VECTORS |
H. Peter Anvin | 8665596 | 2008-11-12 10:27:35 -0800 | [diff] [blame] | 749 | .if vector <> FIRST_EXTERNAL_VECTOR |
H. Peter Anvin | 939b787 | 2008-11-11 13:51:52 -0800 | [diff] [blame] | 750 | CFI_ADJUST_CFA_OFFSET -8 |
| 751 | .endif |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 752 | 1: pushq_cfi $(~vector+0x80) /* Note: always in signed byte range */ |
H. Peter Anvin | 8665596 | 2008-11-12 10:27:35 -0800 | [diff] [blame] | 753 | .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6 |
H. Peter Anvin | 939b787 | 2008-11-11 13:51:52 -0800 | [diff] [blame] | 754 | jmp 2f |
| 755 | .endif |
| 756 | .previous |
| 757 | .quad 1b |
Jiri Olsa | ea71454 | 2011-03-07 19:10:39 +0100 | [diff] [blame] | 758 | .section .entry.text |
H. Peter Anvin | 939b787 | 2008-11-11 13:51:52 -0800 | [diff] [blame] | 759 | vector=vector+1 |
| 760 | .endif |
| 761 | .endr |
| 762 | 2: jmp common_interrupt |
| 763 | .endr |
| 764 | CFI_ENDPROC |
| 765 | END(irq_entries_start) |
| 766 | |
| 767 | .previous |
| 768 | END(interrupt) |
| 769 | .previous |
| 770 | |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 771 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | * Interrupt entry/exit. |
| 773 | * |
| 774 | * Interrupt entry points save only callee clobbered registers in fast path. |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 775 | * |
| 776 | * Entry runs with interrupts off. |
| 777 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Alexander van Heukelum | 722024d | 2008-11-13 13:50:20 +0100 | [diff] [blame] | 779 | /* 0(%rsp): ~(interrupt number) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | .macro interrupt func |
Frederic Weisbecker | 625dbc3b | 2011-01-06 15:22:47 +0100 | [diff] [blame] | 781 | /* reserve pt_regs for scratch regs and rbp */ |
| 782 | subq $ORIG_RAX-RBP, %rsp |
| 783 | CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP |
Frederic Weisbecker | 1871853 | 2011-07-01 01:51:22 +0200 | [diff] [blame^] | 784 | SAVE_ARGS_IRQ |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 785 | PARTIAL_FRAME 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | call \func |
| 787 | .endm |
| 788 | |
Masami Hiramatsu | 8222d71 | 2009-08-27 13:23:25 -0400 | [diff] [blame] | 789 | /* |
| 790 | * Interrupt entry/exit should be protected against kprobes |
| 791 | */ |
| 792 | .pushsection .kprobes.text, "ax" |
Alexander van Heukelum | 722024d | 2008-11-13 13:50:20 +0100 | [diff] [blame] | 793 | /* |
| 794 | * The interrupt stubs push (~vector+0x80) onto the stack and |
| 795 | * then jump to common_interrupt. |
| 796 | */ |
H. Peter Anvin | 939b787 | 2008-11-11 13:51:52 -0800 | [diff] [blame] | 797 | .p2align CONFIG_X86_L1_CACHE_SHIFT |
| 798 | common_interrupt: |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 799 | XCPT_FRAME |
Alexander van Heukelum | 722024d | 2008-11-13 13:50:20 +0100 | [diff] [blame] | 800 | addq $-0x80,(%rsp) /* Adjust vector to [-256,-1] range */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | interrupt do_IRQ |
Brian Gerst | 3d1e42a | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 802 | /* 0(%rsp): old_rsp-ARGOFFSET */ |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 803 | ret_from_intr: |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 804 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 805 | TRACE_IRQS_OFF |
Brian Gerst | 5689553 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 806 | decl PER_CPU_VAR(irq_count) |
Jan Beulich | 1de9c3f | 2006-06-26 13:57:35 +0200 | [diff] [blame] | 807 | leaveq |
Frederic Weisbecker | 625dbc3b | 2011-01-06 15:22:47 +0100 | [diff] [blame] | 808 | |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 809 | CFI_RESTORE rbp |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 810 | CFI_DEF_CFA_REGISTER rsp |
Jan Beulich | 1de9c3f | 2006-06-26 13:57:35 +0200 | [diff] [blame] | 811 | CFI_ADJUST_CFA_OFFSET -8 |
Frederic Weisbecker | 625dbc3b | 2011-01-06 15:22:47 +0100 | [diff] [blame] | 812 | |
| 813 | /* we did not save rbx, restore only from ARGOFFSET */ |
| 814 | addq $8, %rsp |
| 815 | CFI_ADJUST_CFA_OFFSET -8 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 816 | exit_intr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | GET_THREAD_INFO(%rcx) |
| 818 | testl $3,CS-ARGOFFSET(%rsp) |
| 819 | je retint_kernel |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | /* Interrupt came from user space */ |
| 822 | /* |
| 823 | * Has a correct top of stack, but a partial stack frame |
| 824 | * %rcx: thread info. Interrupts off. |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 825 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | retint_with_reschedule: |
| 827 | movl $_TIF_WORK_MASK,%edi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 828 | retint_check: |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 829 | LOCKDEP_SYS_EXIT_IRQ |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 830 | movl TI_flags(%rcx),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | andl %edi,%edx |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 832 | CFI_REMEMBER_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | jnz retint_careful |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 834 | |
| 835 | retint_swapgs: /* return to user-space */ |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 836 | /* |
| 837 | * The iretq could re-enable interrupts: |
| 838 | */ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 839 | DISABLE_INTERRUPTS(CLBR_ANY) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 840 | TRACE_IRQS_IRETQ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 841 | SWAPGS |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 842 | jmp restore_args |
| 843 | |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 844 | retint_restore_args: /* return to kernel space */ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 845 | DISABLE_INTERRUPTS(CLBR_ANY) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 846 | /* |
| 847 | * The iretq could re-enable interrupts: |
| 848 | */ |
| 849 | TRACE_IRQS_IRETQ |
| 850 | restore_args: |
Ingo Molnar | 3701d863 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 851 | RESTORE_ARGS 0,8,0 |
| 852 | |
Adrian Bunk | f7f3d79 | 2008-02-13 23:29:53 +0200 | [diff] [blame] | 853 | irq_return: |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 854 | INTERRUPT_RETURN |
Ingo Molnar | 3701d863 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 855 | |
| 856 | .section __ex_table, "a" |
| 857 | .quad irq_return, bad_iret |
| 858 | .previous |
| 859 | |
| 860 | #ifdef CONFIG_PARAVIRT |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 861 | ENTRY(native_iret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | iretq |
| 863 | |
| 864 | .section __ex_table,"a" |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 865 | .quad native_iret, bad_iret |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | .previous |
Ingo Molnar | 3701d863 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 867 | #endif |
| 868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | .section .fixup,"ax" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | bad_iret: |
Roland McGrath | 3aa4b37 | 2008-02-06 22:39:43 +0100 | [diff] [blame] | 871 | /* |
| 872 | * The iret traps when the %cs or %ss being restored is bogus. |
| 873 | * We've lost the original trap vector and error code. |
| 874 | * #GPF is the most likely one to get for an invalid selector. |
| 875 | * So pretend we completed the iret and took the #GPF in user mode. |
| 876 | * |
| 877 | * We are now running with the kernel GS after exception recovery. |
| 878 | * But error_entry expects us to have user GS to match the user %cs, |
| 879 | * so swap back. |
| 880 | */ |
| 881 | pushq $0 |
| 882 | |
| 883 | SWAPGS |
| 884 | jmp general_protection |
| 885 | |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 886 | .previous |
| 887 | |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 888 | /* edi: workmask, edx: work */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | retint_careful: |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 890 | CFI_RESTORE_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | bt $TIF_NEED_RESCHED,%edx |
| 892 | jnc retint_signal |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 893 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 894 | ENABLE_INTERRUPTS(CLBR_NONE) |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 895 | pushq_cfi %rdi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | call schedule |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 897 | popq_cfi %rdi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | GET_THREAD_INFO(%rcx) |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 899 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 900 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | jmp retint_check |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 902 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | retint_signal: |
Peter Zijlstra | 8f4d37e | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 904 | testl $_TIF_DO_NOTIFY_MASK,%edx |
Andi Kleen | 10ffdbb | 2005-05-16 21:53:19 -0700 | [diff] [blame] | 905 | jz retint_swapgs |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 906 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 907 | ENABLE_INTERRUPTS(CLBR_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | SAVE_REST |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 909 | movq $-1,ORIG_RAX(%rsp) |
Andi Kleen | 3829ee6 | 2005-07-28 21:15:48 -0700 | [diff] [blame] | 910 | xorl %esi,%esi # oldset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | movq %rsp,%rdi # &pt_regs |
| 912 | call do_notify_resume |
| 913 | RESTORE_REST |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 914 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 915 | TRACE_IRQS_OFF |
Andi Kleen | be9e687 | 2005-05-01 08:58:51 -0700 | [diff] [blame] | 916 | GET_THREAD_INFO(%rcx) |
Roland McGrath | eca91e7 | 2008-07-10 14:50:39 -0700 | [diff] [blame] | 917 | jmp retint_with_reschedule |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
| 919 | #ifdef CONFIG_PREEMPT |
| 920 | /* Returning to kernel space. Check if we need preemption */ |
| 921 | /* rcx: threadinfo. interrupts off. */ |
Andi Kleen | b06baba | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 922 | ENTRY(retint_kernel) |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 923 | cmpl $0,TI_preempt_count(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | jnz retint_restore_args |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 925 | bt $TIF_NEED_RESCHED,TI_flags(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | jnc retint_restore_args |
| 927 | bt $9,EFLAGS-ARGOFFSET(%rsp) /* interrupts off? */ |
| 928 | jnc retint_restore_args |
| 929 | call preempt_schedule_irq |
| 930 | jmp exit_intr |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 931 | #endif |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 934 | END(common_interrupt) |
Masami Hiramatsu | 8222d71 | 2009-08-27 13:23:25 -0400 | [diff] [blame] | 935 | /* |
| 936 | * End of kprobes section |
| 937 | */ |
| 938 | .popsection |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | /* |
| 941 | * APIC interrupts. |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 942 | */ |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 943 | .macro apicinterrupt num sym do_sym |
| 944 | ENTRY(\sym) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 945 | INTR_FRAME |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 946 | pushq_cfi $~(\num) |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 947 | interrupt \do_sym |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | jmp ret_from_intr |
| 949 | CFI_ENDPROC |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 950 | END(\sym) |
| 951 | .endm |
Jacob Shin | 89b831e | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 952 | |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 953 | #ifdef CONFIG_SMP |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 954 | apicinterrupt IRQ_MOVE_CLEANUP_VECTOR \ |
| 955 | irq_move_cleanup_interrupt smp_irq_move_cleanup_interrupt |
Andi Kleen | 4ef702c | 2009-05-27 21:56:52 +0200 | [diff] [blame] | 956 | apicinterrupt REBOOT_VECTOR \ |
| 957 | reboot_interrupt smp_reboot_interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | #endif |
| 959 | |
Nick Piggin | 03b4863 | 2009-01-20 04:36:04 +0100 | [diff] [blame] | 960 | #ifdef CONFIG_X86_UV |
Cyrill Gorcunov | 5ae3a13 | 2008-11-27 00:02:10 +0300 | [diff] [blame] | 961 | apicinterrupt UV_BAU_MESSAGE \ |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 962 | uv_bau_message_intr1 uv_bau_message_interrupt |
Nick Piggin | 03b4863 | 2009-01-20 04:36:04 +0100 | [diff] [blame] | 963 | #endif |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 964 | apicinterrupt LOCAL_TIMER_VECTOR \ |
| 965 | apic_timer_interrupt smp_apic_timer_interrupt |
Dimitri Sivanich | 4a4de9c | 2009-10-14 09:22:57 -0500 | [diff] [blame] | 966 | apicinterrupt X86_PLATFORM_IPI_VECTOR \ |
| 967 | x86_platform_ipi smp_x86_platform_ipi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 969 | #ifdef CONFIG_SMP |
Shaohua Li | 3a09fb4 | 2011-01-17 10:52:05 +0800 | [diff] [blame] | 970 | .irp idx,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, \ |
| 971 | 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 |
| 972 | .if NUM_INVALIDATE_TLB_VECTORS > \idx |
Jan Beulich | 3234282 | 2010-10-19 14:52:26 +0100 | [diff] [blame] | 973 | apicinterrupt (INVALIDATE_TLB_VECTOR_START)+\idx \ |
| 974 | invalidate_interrupt\idx smp_invalidate_interrupt |
Shaohua Li | 3a09fb4 | 2011-01-17 10:52:05 +0800 | [diff] [blame] | 975 | .endif |
Jan Beulich | 3234282 | 2010-10-19 14:52:26 +0100 | [diff] [blame] | 976 | .endr |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 977 | #endif |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 978 | |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 979 | apicinterrupt THRESHOLD_APIC_VECTOR \ |
Andi Kleen | 7856f6c | 2009-04-28 23:32:56 +0200 | [diff] [blame] | 980 | threshold_interrupt smp_threshold_interrupt |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 981 | apicinterrupt THERMAL_APIC_VECTOR \ |
| 982 | thermal_interrupt smp_thermal_interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
Andi Kleen | ccc3c31 | 2009-05-27 21:56:54 +0200 | [diff] [blame] | 984 | #ifdef CONFIG_X86_MCE |
| 985 | apicinterrupt MCE_SELF_VECTOR \ |
| 986 | mce_self_interrupt smp_mce_self_interrupt |
| 987 | #endif |
| 988 | |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 989 | #ifdef CONFIG_SMP |
| 990 | apicinterrupt CALL_FUNCTION_SINGLE_VECTOR \ |
| 991 | call_function_single_interrupt smp_call_function_single_interrupt |
| 992 | apicinterrupt CALL_FUNCTION_VECTOR \ |
| 993 | call_function_interrupt smp_call_function_interrupt |
| 994 | apicinterrupt RESCHEDULE_VECTOR \ |
| 995 | reschedule_interrupt smp_reschedule_interrupt |
| 996 | #endif |
| 997 | |
| 998 | apicinterrupt ERROR_APIC_VECTOR \ |
| 999 | error_interrupt smp_error_interrupt |
| 1000 | apicinterrupt SPURIOUS_APIC_VECTOR \ |
| 1001 | spurious_interrupt smp_spurious_interrupt |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 1002 | |
Peter Zijlstra | e360adb | 2010-10-14 14:01:34 +0800 | [diff] [blame] | 1003 | #ifdef CONFIG_IRQ_WORK |
| 1004 | apicinterrupt IRQ_WORK_VECTOR \ |
| 1005 | irq_work_interrupt smp_irq_work_interrupt |
Ingo Molnar | 241771e | 2008-12-03 10:39:53 +0100 | [diff] [blame] | 1006 | #endif |
| 1007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | /* |
| 1009 | * Exception entry points. |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 1010 | */ |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1011 | .macro zeroentry sym do_sym |
| 1012 | ENTRY(\sym) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1013 | INTR_FRAME |
Jeremy Fitzhardinge | fab5842 | 2008-06-25 00:19:31 -0400 | [diff] [blame] | 1014 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Ingo Molnar | 14ae22b | 2008-11-21 15:20:47 +0100 | [diff] [blame] | 1015 | pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */ |
Jan Beulich | b1cccb1 | 2010-09-02 13:55:11 +0100 | [diff] [blame] | 1016 | subq $ORIG_RAX-R15, %rsp |
| 1017 | CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15 |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 1018 | call error_entry |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 1019 | DEFAULT_FRAME 0 |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 1020 | movq %rsp,%rdi /* pt_regs pointer */ |
| 1021 | xorl %esi,%esi /* no error code */ |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1022 | call \do_sym |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 1023 | jmp error_exit /* %ebx: no swapgs flag */ |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1024 | CFI_ENDPROC |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1025 | END(\sym) |
| 1026 | .endm |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1028 | .macro paranoidzeroentry sym do_sym |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1029 | ENTRY(\sym) |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1030 | INTR_FRAME |
| 1031 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Jan Beulich | b1cccb1 | 2010-09-02 13:55:11 +0100 | [diff] [blame] | 1032 | pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */ |
| 1033 | subq $ORIG_RAX-R15, %rsp |
| 1034 | CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15 |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1035 | call save_paranoid |
| 1036 | TRACE_IRQS_OFF |
| 1037 | movq %rsp,%rdi /* pt_regs pointer */ |
| 1038 | xorl %esi,%esi /* no error code */ |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1039 | call \do_sym |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1040 | jmp paranoid_exit /* %ebx: no swapgs flag */ |
| 1041 | CFI_ENDPROC |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1042 | END(\sym) |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1043 | .endm |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1044 | |
Brian Gerst | c15a5958 | 2010-07-31 12:48:22 -0400 | [diff] [blame] | 1045 | #define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8) |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1046 | .macro paranoidzeroentry_ist sym do_sym ist |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1047 | ENTRY(\sym) |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1048 | INTR_FRAME |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1049 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Jan Beulich | b1cccb1 | 2010-09-02 13:55:11 +0100 | [diff] [blame] | 1050 | pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */ |
| 1051 | subq $ORIG_RAX-R15, %rsp |
| 1052 | CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15 |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1053 | call save_paranoid |
| 1054 | TRACE_IRQS_OFF |
| 1055 | movq %rsp,%rdi /* pt_regs pointer */ |
| 1056 | xorl %esi,%esi /* no error code */ |
Brian Gerst | c15a5958 | 2010-07-31 12:48:22 -0400 | [diff] [blame] | 1057 | subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist) |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1058 | call \do_sym |
Brian Gerst | c15a5958 | 2010-07-31 12:48:22 -0400 | [diff] [blame] | 1059 | addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist) |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1060 | jmp paranoid_exit /* %ebx: no swapgs flag */ |
| 1061 | CFI_ENDPROC |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1062 | END(\sym) |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1063 | .endm |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1064 | |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1065 | .macro errorentry sym do_sym |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1066 | ENTRY(\sym) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1067 | XCPT_FRAME |
Jeremy Fitzhardinge | fab5842 | 2008-06-25 00:19:31 -0400 | [diff] [blame] | 1068 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Jan Beulich | b1cccb1 | 2010-09-02 13:55:11 +0100 | [diff] [blame] | 1069 | subq $ORIG_RAX-R15, %rsp |
| 1070 | CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15 |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 1071 | call error_entry |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 1072 | DEFAULT_FRAME 0 |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 1073 | movq %rsp,%rdi /* pt_regs pointer */ |
| 1074 | movq ORIG_RAX(%rsp),%rsi /* get error code */ |
| 1075 | movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */ |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1076 | call \do_sym |
Alexander van Heukelum | d99015b | 2008-11-19 01:18:11 +0100 | [diff] [blame] | 1077 | jmp error_exit /* %ebx: no swapgs flag */ |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1078 | CFI_ENDPROC |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1079 | END(\sym) |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1080 | .endm |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
| 1082 | /* error code is on the stack already */ |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1083 | .macro paranoiderrorentry sym do_sym |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1084 | ENTRY(\sym) |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1085 | XCPT_FRAME |
| 1086 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Jan Beulich | b1cccb1 | 2010-09-02 13:55:11 +0100 | [diff] [blame] | 1087 | subq $ORIG_RAX-R15, %rsp |
| 1088 | CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15 |
Alexander van Heukelum | e2f6bc2 | 2008-11-21 16:43:18 +0100 | [diff] [blame] | 1089 | call save_paranoid |
| 1090 | DEFAULT_FRAME 0 |
Alexander van Heukelum | 7e61a79 | 2008-09-26 14:03:03 +0200 | [diff] [blame] | 1091 | TRACE_IRQS_OFF |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1092 | movq %rsp,%rdi /* pt_regs pointer */ |
| 1093 | movq ORIG_RAX(%rsp),%rsi /* get error code */ |
| 1094 | movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */ |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1095 | call \do_sym |
Alexander van Heukelum | b8b1d08 | 2008-11-21 16:44:28 +0100 | [diff] [blame] | 1096 | jmp paranoid_exit /* %ebx: no swapgs flag */ |
| 1097 | CFI_ENDPROC |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1098 | END(\sym) |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1099 | .endm |
| 1100 | |
| 1101 | zeroentry divide_error do_divide_error |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1102 | zeroentry overflow do_overflow |
| 1103 | zeroentry bounds do_bounds |
| 1104 | zeroentry invalid_op do_invalid_op |
| 1105 | zeroentry device_not_available do_device_not_available |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1106 | paranoiderrorentry double_fault do_double_fault |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1107 | zeroentry coprocessor_segment_overrun do_coprocessor_segment_overrun |
| 1108 | errorentry invalid_TSS do_invalid_TSS |
| 1109 | errorentry segment_not_present do_segment_not_present |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1110 | zeroentry spurious_interrupt_bug do_spurious_interrupt_bug |
| 1111 | zeroentry coprocessor_error do_coprocessor_error |
| 1112 | errorentry alignment_check do_alignment_check |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1113 | zeroentry simd_coprocessor_error do_simd_coprocessor_error |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 1114 | |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1115 | /* Reload gs selector with exception handling */ |
| 1116 | /* edi: new selector */ |
Jeremy Fitzhardinge | 9f9d489 | 2008-06-25 00:19:32 -0400 | [diff] [blame] | 1117 | ENTRY(native_load_gs_index) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1118 | CFI_STARTPROC |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 1119 | pushfq_cfi |
Jeremy Fitzhardinge | b8aa287 | 2009-01-28 14:35:03 -0800 | [diff] [blame] | 1120 | DISABLE_INTERRUPTS(CLBR_ANY & ~CLBR_RDI) |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1121 | SWAPGS |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 1122 | gs_change: |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1123 | movl %edi,%gs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | 2: mfence /* workaround */ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 1125 | SWAPGS |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 1126 | popfq_cfi |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1127 | ret |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1128 | CFI_ENDPROC |
Alexander van Heukelum | 6efdcfa | 2008-11-23 10:15:32 +0100 | [diff] [blame] | 1129 | END(native_load_gs_index) |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 1130 | |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1131 | .section __ex_table,"a" |
| 1132 | .align 8 |
| 1133 | .quad gs_change,bad_gs |
| 1134 | .previous |
| 1135 | .section .fixup,"ax" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | /* running with kernelgs */ |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 1137 | bad_gs: |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 1138 | SWAPGS /* switch back to user gs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | xorl %eax,%eax |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1140 | movl %eax,%gs |
| 1141 | jmp 2b |
| 1142 | .previous |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 1143 | |
Brian Gerst | 3bd95df | 2009-12-09 12:34:40 -0500 | [diff] [blame] | 1144 | ENTRY(kernel_thread_helper) |
Andi Kleen | c05991e | 2006-08-30 19:37:08 +0200 | [diff] [blame] | 1145 | pushq $0 # fake return address |
| 1146 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | /* |
| 1148 | * Here we are in the child and the registers are set as they were |
| 1149 | * at kernel_thread() invocation in the parent. |
| 1150 | */ |
Brian Gerst | 3bd95df | 2009-12-09 12:34:40 -0500 | [diff] [blame] | 1151 | call *%rsi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | # exit |
Andrey Mirkin | 1c5b5cf | 2007-10-17 18:04:33 +0200 | [diff] [blame] | 1153 | mov %eax, %edi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | call do_exit |
jia zhang | 5f5db59 | 2008-11-23 22:47:10 +0800 | [diff] [blame] | 1155 | ud2 # padding for call trace |
Andi Kleen | c05991e | 2006-08-30 19:37:08 +0200 | [diff] [blame] | 1156 | CFI_ENDPROC |
Brian Gerst | 3bd95df | 2009-12-09 12:34:40 -0500 | [diff] [blame] | 1157 | END(kernel_thread_helper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
| 1159 | /* |
| 1160 | * execve(). This function needs to use IRET, not SYSRET, to set up all state properly. |
| 1161 | * |
| 1162 | * C extern interface: |
David Howells | c788732 | 2010-08-11 11:26:22 +0100 | [diff] [blame] | 1163 | * extern long execve(const char *name, char **argv, char **envp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | * |
| 1165 | * asm input arguments: |
| 1166 | * rdi: name, rsi: argv, rdx: envp |
| 1167 | * |
| 1168 | * We want to fallback into: |
David Howells | c788732 | 2010-08-11 11:26:22 +0100 | [diff] [blame] | 1169 | * extern long sys_execve(const char *name, char **argv,char **envp, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | * |
| 1171 | * do_sys_execve asm fallback arguments: |
Ingo Molnar | 5d119b2 | 2008-02-26 12:55:57 +0100 | [diff] [blame] | 1172 | * rdi: name, rsi: argv, rdx: envp, rcx: fake frame on the stack |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | */ |
Arnd Bergmann | 3db03b4 | 2006-10-02 02:18:31 -0700 | [diff] [blame] | 1174 | ENTRY(kernel_execve) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | CFI_STARTPROC |
| 1176 | FAKE_STACK_FRAME $0 |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 1177 | SAVE_ALL |
Ingo Molnar | 5d119b2 | 2008-02-26 12:55:57 +0100 | [diff] [blame] | 1178 | movq %rsp,%rcx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | call sys_execve |
Alexander van Heukelum | 0bd7b79 | 2008-11-16 15:29:00 +0100 | [diff] [blame] | 1180 | movq %rax, RAX(%rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | RESTORE_REST |
| 1182 | testq %rax,%rax |
| 1183 | je int_ret_from_sys_call |
| 1184 | RESTORE_ARGS |
| 1185 | UNFAKE_STACK_FRAME |
| 1186 | ret |
| 1187 | CFI_ENDPROC |
Alexander van Heukelum | 6efdcfa | 2008-11-23 10:15:32 +0100 | [diff] [blame] | 1188 | END(kernel_execve) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 1190 | /* Call softirq on interrupt stack. Interrupts are off. */ |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 1191 | ENTRY(call_softirq) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1192 | CFI_STARTPROC |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 1193 | pushq_cfi %rbp |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 1194 | CFI_REL_OFFSET rbp,0 |
| 1195 | mov %rsp,%rbp |
| 1196 | CFI_DEF_CFA_REGISTER rbp |
Brian Gerst | 5689553 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 1197 | incl PER_CPU_VAR(irq_count) |
Brian Gerst | 26f80bd | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 1198 | cmove PER_CPU_VAR(irq_stack_ptr),%rsp |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 1199 | push %rbp # backlink for old unwinder |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 1200 | call __do_softirq |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 1201 | leaveq |
Jan Beulich | df5d187 | 2010-09-02 14:07:16 +0100 | [diff] [blame] | 1202 | CFI_RESTORE rbp |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1203 | CFI_DEF_CFA_REGISTER rsp |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 1204 | CFI_ADJUST_CFA_OFFSET -8 |
Brian Gerst | 5689553 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 1205 | decl PER_CPU_VAR(irq_count) |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 1206 | ret |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1207 | CFI_ENDPROC |
Alexander van Heukelum | 6efdcfa | 2008-11-23 10:15:32 +0100 | [diff] [blame] | 1208 | END(call_softirq) |
Andi Kleen | 75154f4 | 2007-06-23 02:29:25 +0200 | [diff] [blame] | 1209 | |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1210 | #ifdef CONFIG_XEN |
Alexander van Heukelum | 322648d | 2008-11-23 10:08:28 +0100 | [diff] [blame] | 1211 | zeroentry xen_hypervisor_callback xen_do_hypervisor_callback |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1212 | |
| 1213 | /* |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1214 | * A note on the "critical region" in our callback handler. |
| 1215 | * We want to avoid stacking callback handlers due to events occurring |
| 1216 | * during handling of the last event. To do this, we keep events disabled |
| 1217 | * until we've done all processing. HOWEVER, we must enable events before |
| 1218 | * popping the stack frame (can't be done atomically) and so it would still |
| 1219 | * be possible to get enough handler activations to overflow the stack. |
| 1220 | * Although unlikely, bugs of that kind are hard to track down, so we'd |
| 1221 | * like to avoid the possibility. |
| 1222 | * So, on entry to the handler we detect whether we interrupted an |
| 1223 | * existing activation in its critical region -- if so, we pop the current |
| 1224 | * activation and restart the handler using the previous one. |
| 1225 | */ |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1226 | ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs) |
| 1227 | CFI_STARTPROC |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1228 | /* |
| 1229 | * Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will |
| 1230 | * see the correct pointer to the pt_regs |
| 1231 | */ |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1232 | movq %rdi, %rsp # we don't return, adjust the stack frame |
| 1233 | CFI_ENDPROC |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 1234 | DEFAULT_FRAME |
Brian Gerst | 5689553 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 1235 | 11: incl PER_CPU_VAR(irq_count) |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1236 | movq %rsp,%rbp |
| 1237 | CFI_DEF_CFA_REGISTER rbp |
Brian Gerst | 26f80bd | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 1238 | cmovzq PER_CPU_VAR(irq_stack_ptr),%rsp |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1239 | pushq %rbp # backlink for old unwinder |
| 1240 | call xen_evtchn_do_upcall |
| 1241 | popq %rsp |
| 1242 | CFI_DEF_CFA_REGISTER rsp |
Brian Gerst | 5689553 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 1243 | decl PER_CPU_VAR(irq_count) |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1244 | jmp error_exit |
| 1245 | CFI_ENDPROC |
Alexander van Heukelum | 371c394 | 2011-03-11 21:59:38 +0100 | [diff] [blame] | 1246 | END(xen_do_hypervisor_callback) |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1247 | |
| 1248 | /* |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1249 | * Hypervisor uses this for application faults while it executes. |
| 1250 | * We get here for two reasons: |
| 1251 | * 1. Fault while reloading DS, ES, FS or GS |
| 1252 | * 2. Fault while executing IRET |
| 1253 | * Category 1 we do not need to fix up as Xen has already reloaded all segment |
| 1254 | * registers that could be reloaded and zeroed the others. |
| 1255 | * Category 2 we fix up by killing the current process. We cannot use the |
| 1256 | * normal Linux return path in this case because if we use the IRET hypercall |
| 1257 | * to pop the stack frame we end up in an infinite loop of failsafe callbacks. |
| 1258 | * We distinguish between categories by comparing each saved segment register |
| 1259 | * with its current contents: any discrepancy means we in category 1. |
| 1260 | */ |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1261 | ENTRY(xen_failsafe_callback) |
Alexander van Heukelum | dcd072e | 2008-11-20 14:40:11 +0100 | [diff] [blame] | 1262 | INTR_FRAME 1 (6*8) |
| 1263 | /*CFI_REL_OFFSET gs,GS*/ |
| 1264 | /*CFI_REL_OFFSET fs,FS*/ |
| 1265 | /*CFI_REL_OFFSET es,ES*/ |
| 1266 | /*CFI_REL_OFFSET ds,DS*/ |
| 1267 | CFI_REL_OFFSET r11,8 |
| 1268 | CFI_REL_OFFSET rcx,0 |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1269 | movw %ds,%cx |
| 1270 | cmpw %cx,0x10(%rsp) |
| 1271 | CFI_REMEMBER_STATE |
| 1272 | jne 1f |
| 1273 | movw %es,%cx |
| 1274 | cmpw %cx,0x18(%rsp) |
| 1275 | jne 1f |
| 1276 | movw %fs,%cx |
| 1277 | cmpw %cx,0x20(%rsp) |
| 1278 | jne 1f |
| 1279 | movw %gs,%cx |
| 1280 | cmpw %cx,0x28(%rsp) |
| 1281 | jne 1f |
| 1282 | /* All segments match their saved values => Category 2 (Bad IRET). */ |
| 1283 | movq (%rsp),%rcx |
| 1284 | CFI_RESTORE rcx |
| 1285 | movq 8(%rsp),%r11 |
| 1286 | CFI_RESTORE r11 |
| 1287 | addq $0x30,%rsp |
| 1288 | CFI_ADJUST_CFA_OFFSET -0x30 |
Ingo Molnar | 14ae22b | 2008-11-21 15:20:47 +0100 | [diff] [blame] | 1289 | pushq_cfi $0 /* RIP */ |
| 1290 | pushq_cfi %r11 |
| 1291 | pushq_cfi %rcx |
Jeremy Fitzhardinge | 4a5c3e7 | 2008-07-08 15:07:09 -0700 | [diff] [blame] | 1292 | jmp general_protection |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1293 | CFI_RESTORE_STATE |
| 1294 | 1: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */ |
| 1295 | movq (%rsp),%rcx |
| 1296 | CFI_RESTORE rcx |
| 1297 | movq 8(%rsp),%r11 |
| 1298 | CFI_RESTORE r11 |
| 1299 | addq $0x30,%rsp |
| 1300 | CFI_ADJUST_CFA_OFFSET -0x30 |
Ingo Molnar | 14ae22b | 2008-11-21 15:20:47 +0100 | [diff] [blame] | 1301 | pushq_cfi $0 |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1302 | SAVE_ALL |
| 1303 | jmp error_exit |
| 1304 | CFI_ENDPROC |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1305 | END(xen_failsafe_callback) |
| 1306 | |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 1307 | apicinterrupt XEN_HVM_EVTCHN_CALLBACK \ |
| 1308 | xen_hvm_callback_vector xen_evtchn_do_upcall |
| 1309 | |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1310 | #endif /* CONFIG_XEN */ |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1311 | |
| 1312 | /* |
| 1313 | * Some functions should be protected against kprobes |
| 1314 | */ |
| 1315 | .pushsection .kprobes.text, "ax" |
| 1316 | |
| 1317 | paranoidzeroentry_ist debug do_debug DEBUG_STACK |
| 1318 | paranoidzeroentry_ist int3 do_int3 DEBUG_STACK |
| 1319 | paranoiderrorentry stack_segment do_stack_segment |
Jeremy Fitzhardinge | 6cac5a9 | 2009-03-29 19:56:29 -0700 | [diff] [blame] | 1320 | #ifdef CONFIG_XEN |
| 1321 | zeroentry xen_debug do_debug |
| 1322 | zeroentry xen_int3 do_int3 |
| 1323 | errorentry xen_stack_segment do_stack_segment |
| 1324 | #endif |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1325 | errorentry general_protection do_general_protection |
| 1326 | errorentry page_fault do_page_fault |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 1327 | #ifdef CONFIG_KVM_GUEST |
| 1328 | errorentry async_page_fault do_async_page_fault |
| 1329 | #endif |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1330 | #ifdef CONFIG_X86_MCE |
Andi Kleen | 5d72792 | 2009-04-27 19:25:48 +0200 | [diff] [blame] | 1331 | paranoidzeroentry machine_check *machine_check_vector(%rip) |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1332 | #endif |
| 1333 | |
| 1334 | /* |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1335 | * "Paranoid" exit path from exception stack. |
| 1336 | * Paranoid because this is used by NMIs and cannot take |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1337 | * any kernel state for granted. |
| 1338 | * We don't do kernel preemption checks here, because only |
| 1339 | * NMI should be common and it does not enable IRQs and |
| 1340 | * cannot get reschedule ticks. |
| 1341 | * |
| 1342 | * "trace" is 0 for the NMI handler only, because irq-tracing |
| 1343 | * is fundamentally NMI-unsafe. (we cannot change the soft and |
| 1344 | * hard flags at once, atomically) |
| 1345 | */ |
| 1346 | |
| 1347 | /* ebx: no swapgs flag */ |
| 1348 | ENTRY(paranoid_exit) |
Jan Beulich | 1f130a7 | 2010-09-02 13:54:32 +0100 | [diff] [blame] | 1349 | DEFAULT_FRAME |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1350 | DISABLE_INTERRUPTS(CLBR_NONE) |
| 1351 | TRACE_IRQS_OFF |
| 1352 | testl %ebx,%ebx /* swapgs needed? */ |
| 1353 | jnz paranoid_restore |
| 1354 | testl $3,CS(%rsp) |
| 1355 | jnz paranoid_userspace |
| 1356 | paranoid_swapgs: |
| 1357 | TRACE_IRQS_IRETQ 0 |
| 1358 | SWAPGS_UNSAFE_STACK |
Steven Rostedt | 0300e7f1 | 2009-04-17 08:33:52 -0400 | [diff] [blame] | 1359 | RESTORE_ALL 8 |
| 1360 | jmp irq_return |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1361 | paranoid_restore: |
Steven Rostedt | 0300e7f1 | 2009-04-17 08:33:52 -0400 | [diff] [blame] | 1362 | TRACE_IRQS_IRETQ 0 |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1363 | RESTORE_ALL 8 |
| 1364 | jmp irq_return |
| 1365 | paranoid_userspace: |
| 1366 | GET_THREAD_INFO(%rcx) |
| 1367 | movl TI_flags(%rcx),%ebx |
| 1368 | andl $_TIF_WORK_MASK,%ebx |
| 1369 | jz paranoid_swapgs |
| 1370 | movq %rsp,%rdi /* &pt_regs */ |
| 1371 | call sync_regs |
| 1372 | movq %rax,%rsp /* switch stack for scheduling */ |
| 1373 | testl $_TIF_NEED_RESCHED,%ebx |
| 1374 | jnz paranoid_schedule |
| 1375 | movl %ebx,%edx /* arg3: thread flags */ |
| 1376 | TRACE_IRQS_ON |
| 1377 | ENABLE_INTERRUPTS(CLBR_NONE) |
| 1378 | xorl %esi,%esi /* arg2: oldset */ |
| 1379 | movq %rsp,%rdi /* arg1: &pt_regs */ |
| 1380 | call do_notify_resume |
| 1381 | DISABLE_INTERRUPTS(CLBR_NONE) |
| 1382 | TRACE_IRQS_OFF |
| 1383 | jmp paranoid_userspace |
| 1384 | paranoid_schedule: |
| 1385 | TRACE_IRQS_ON |
| 1386 | ENABLE_INTERRUPTS(CLBR_ANY) |
| 1387 | call schedule |
| 1388 | DISABLE_INTERRUPTS(CLBR_ANY) |
| 1389 | TRACE_IRQS_OFF |
| 1390 | jmp paranoid_userspace |
| 1391 | CFI_ENDPROC |
| 1392 | END(paranoid_exit) |
| 1393 | |
| 1394 | /* |
| 1395 | * Exception entry point. This expects an error code/orig_rax on the stack. |
| 1396 | * returns in "no swapgs flag" in %ebx. |
| 1397 | */ |
| 1398 | ENTRY(error_entry) |
| 1399 | XCPT_FRAME |
| 1400 | CFI_ADJUST_CFA_OFFSET 15*8 |
| 1401 | /* oldrax contains error code */ |
| 1402 | cld |
| 1403 | movq_cfi rdi, RDI+8 |
| 1404 | movq_cfi rsi, RSI+8 |
| 1405 | movq_cfi rdx, RDX+8 |
| 1406 | movq_cfi rcx, RCX+8 |
| 1407 | movq_cfi rax, RAX+8 |
| 1408 | movq_cfi r8, R8+8 |
| 1409 | movq_cfi r9, R9+8 |
| 1410 | movq_cfi r10, R10+8 |
| 1411 | movq_cfi r11, R11+8 |
| 1412 | movq_cfi rbx, RBX+8 |
| 1413 | movq_cfi rbp, RBP+8 |
| 1414 | movq_cfi r12, R12+8 |
| 1415 | movq_cfi r13, R13+8 |
| 1416 | movq_cfi r14, R14+8 |
| 1417 | movq_cfi r15, R15+8 |
| 1418 | xorl %ebx,%ebx |
| 1419 | testl $3,CS+8(%rsp) |
| 1420 | je error_kernelspace |
| 1421 | error_swapgs: |
| 1422 | SWAPGS |
| 1423 | error_sti: |
| 1424 | TRACE_IRQS_OFF |
| 1425 | ret |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1426 | |
| 1427 | /* |
| 1428 | * There are two places in the kernel that can potentially fault with |
| 1429 | * usergs. Handle them here. The exception handlers after iret run with |
| 1430 | * kernel gs again, so don't set the user space flag. B stepping K8s |
| 1431 | * sometimes report an truncated RIP for IRET exceptions returning to |
| 1432 | * compat mode. Check for these here too. |
| 1433 | */ |
| 1434 | error_kernelspace: |
| 1435 | incl %ebx |
| 1436 | leaq irq_return(%rip),%rcx |
| 1437 | cmpq %rcx,RIP+8(%rsp) |
| 1438 | je error_swapgs |
Brian Gerst | ae24ffe | 2009-10-12 10:18:23 -0400 | [diff] [blame] | 1439 | movl %ecx,%eax /* zero extend */ |
| 1440 | cmpq %rax,RIP+8(%rsp) |
| 1441 | je bstep_iret |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1442 | cmpq $gs_change,RIP+8(%rsp) |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1443 | je error_swapgs |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1444 | jmp error_sti |
Brian Gerst | ae24ffe | 2009-10-12 10:18:23 -0400 | [diff] [blame] | 1445 | |
| 1446 | bstep_iret: |
| 1447 | /* Fix truncated RIP */ |
| 1448 | movq %rcx,RIP+8(%rsp) |
Brian Gerst | 97829de | 2009-11-03 14:02:05 -0500 | [diff] [blame] | 1449 | jmp error_swapgs |
Jan Beulich | e6b04b6 | 2010-09-02 13:52:45 +0100 | [diff] [blame] | 1450 | CFI_ENDPROC |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1451 | END(error_entry) |
| 1452 | |
| 1453 | |
| 1454 | /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */ |
| 1455 | ENTRY(error_exit) |
| 1456 | DEFAULT_FRAME |
| 1457 | movl %ebx,%eax |
| 1458 | RESTORE_REST |
| 1459 | DISABLE_INTERRUPTS(CLBR_NONE) |
| 1460 | TRACE_IRQS_OFF |
| 1461 | GET_THREAD_INFO(%rcx) |
| 1462 | testl %eax,%eax |
| 1463 | jne retint_kernel |
| 1464 | LOCKDEP_SYS_EXIT_IRQ |
| 1465 | movl TI_flags(%rcx),%edx |
| 1466 | movl $_TIF_WORK_MASK,%edi |
| 1467 | andl %edi,%edx |
| 1468 | jnz retint_careful |
| 1469 | jmp retint_swapgs |
| 1470 | CFI_ENDPROC |
| 1471 | END(error_exit) |
| 1472 | |
| 1473 | |
| 1474 | /* runs on exception stack */ |
| 1475 | ENTRY(nmi) |
| 1476 | INTR_FRAME |
| 1477 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
| 1478 | pushq_cfi $-1 |
Jan Beulich | b1cccb1 | 2010-09-02 13:55:11 +0100 | [diff] [blame] | 1479 | subq $ORIG_RAX-R15, %rsp |
| 1480 | CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15 |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1481 | call save_paranoid |
| 1482 | DEFAULT_FRAME 0 |
| 1483 | /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */ |
| 1484 | movq %rsp,%rdi |
| 1485 | movq $-1,%rsi |
| 1486 | call do_nmi |
| 1487 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 1488 | /* paranoidexit; without TRACE_IRQS_OFF */ |
| 1489 | /* ebx: no swapgs flag */ |
| 1490 | DISABLE_INTERRUPTS(CLBR_NONE) |
| 1491 | testl %ebx,%ebx /* swapgs needed? */ |
| 1492 | jnz nmi_restore |
| 1493 | testl $3,CS(%rsp) |
| 1494 | jnz nmi_userspace |
| 1495 | nmi_swapgs: |
| 1496 | SWAPGS_UNSAFE_STACK |
| 1497 | nmi_restore: |
| 1498 | RESTORE_ALL 8 |
| 1499 | jmp irq_return |
| 1500 | nmi_userspace: |
| 1501 | GET_THREAD_INFO(%rcx) |
| 1502 | movl TI_flags(%rcx),%ebx |
| 1503 | andl $_TIF_WORK_MASK,%ebx |
| 1504 | jz nmi_swapgs |
| 1505 | movq %rsp,%rdi /* &pt_regs */ |
| 1506 | call sync_regs |
| 1507 | movq %rax,%rsp /* switch stack for scheduling */ |
| 1508 | testl $_TIF_NEED_RESCHED,%ebx |
| 1509 | jnz nmi_schedule |
| 1510 | movl %ebx,%edx /* arg3: thread flags */ |
| 1511 | ENABLE_INTERRUPTS(CLBR_NONE) |
| 1512 | xorl %esi,%esi /* arg2: oldset */ |
| 1513 | movq %rsp,%rdi /* arg1: &pt_regs */ |
| 1514 | call do_notify_resume |
| 1515 | DISABLE_INTERRUPTS(CLBR_NONE) |
| 1516 | jmp nmi_userspace |
| 1517 | nmi_schedule: |
| 1518 | ENABLE_INTERRUPTS(CLBR_ANY) |
| 1519 | call schedule |
| 1520 | DISABLE_INTERRUPTS(CLBR_ANY) |
| 1521 | jmp nmi_userspace |
| 1522 | CFI_ENDPROC |
| 1523 | #else |
| 1524 | jmp paranoid_exit |
Cyrill Gorcunov | 9f1e87e | 2008-11-27 21:10:08 +0300 | [diff] [blame] | 1525 | CFI_ENDPROC |
Alexander van Heukelum | ddeb8f2 | 2008-11-24 13:24:28 +0100 | [diff] [blame] | 1526 | #endif |
| 1527 | END(nmi) |
| 1528 | |
| 1529 | ENTRY(ignore_sysret) |
| 1530 | CFI_STARTPROC |
| 1531 | mov $-ENOSYS,%eax |
| 1532 | sysret |
| 1533 | CFI_ENDPROC |
| 1534 | END(ignore_sysret) |
| 1535 | |
| 1536 | /* |
| 1537 | * End of kprobes section |
| 1538 | */ |
| 1539 | .popsection |