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