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