]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/x86/kernel/entry_32.S
readahead: fault retry breaks mmap file read random detection
[mirror_ubuntu-zesty-kernel.git] / arch / x86 / kernel / entry_32.S
1 /*
2 *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 */
5
6 /*
7 * entry.S contains the system-call and fault low-level handling routines.
8 * This also contains the timer-interrupt handler, as well as all interrupts
9 * and faults that can result in a task-switch.
10 *
11 * NOTE: This code handles signal-recognition, which happens every time
12 * after a timer-interrupt and after each system call.
13 *
14 * I changed all the .align's to 4 (16 byte alignment), as that's faster
15 * on a 486.
16 *
17 * Stack layout in 'syscall_exit':
18 * ptrace needs to have all regs on the stack.
19 * if the order here is changed, it needs to be
20 * updated in fork.c:copy_process, signal.c:do_signal,
21 * ptrace.c and ptrace.h
22 *
23 * 0(%esp) - %ebx
24 * 4(%esp) - %ecx
25 * 8(%esp) - %edx
26 * C(%esp) - %esi
27 * 10(%esp) - %edi
28 * 14(%esp) - %ebp
29 * 18(%esp) - %eax
30 * 1C(%esp) - %ds
31 * 20(%esp) - %es
32 * 24(%esp) - %fs
33 * 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
34 * 2C(%esp) - orig_eax
35 * 30(%esp) - %eip
36 * 34(%esp) - %cs
37 * 38(%esp) - %eflags
38 * 3C(%esp) - %oldesp
39 * 40(%esp) - %oldss
40 *
41 * "current" is in register %ebx during any slow entries.
42 */
43
44 #include <linux/linkage.h>
45 #include <linux/err.h>
46 #include <asm/thread_info.h>
47 #include <asm/irqflags.h>
48 #include <asm/errno.h>
49 #include <asm/segment.h>
50 #include <asm/smp.h>
51 #include <asm/page_types.h>
52 #include <asm/percpu.h>
53 #include <asm/dwarf2.h>
54 #include <asm/processor-flags.h>
55 #include <asm/ftrace.h>
56 #include <asm/irq_vectors.h>
57 #include <asm/cpufeature.h>
58 #include <asm/alternative-asm.h>
59 #include <asm/asm.h>
60 #include <asm/smap.h>
61
62 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
63 #include <linux/elf-em.h>
64 #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
65 #define __AUDIT_ARCH_LE 0x40000000
66
67 #ifndef CONFIG_AUDITSYSCALL
68 #define sysenter_audit syscall_trace_entry
69 #define sysexit_audit syscall_exit_work
70 #endif
71
72 .section .entry.text, "ax"
73
74 /*
75 * We use macros for low-level operations which need to be overridden
76 * for paravirtualization. The following will never clobber any registers:
77 * INTERRUPT_RETURN (aka. "iret")
78 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
79 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
80 *
81 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
82 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
83 * Allowing a register to be clobbered can shrink the paravirt replacement
84 * enough to patch inline, increasing performance.
85 */
86
87 #ifdef CONFIG_PREEMPT
88 #define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
89 #else
90 #define preempt_stop(clobbers)
91 #define resume_kernel restore_all
92 #endif
93
94 .macro TRACE_IRQS_IRET
95 #ifdef CONFIG_TRACE_IRQFLAGS
96 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
97 jz 1f
98 TRACE_IRQS_ON
99 1:
100 #endif
101 .endm
102
103 /*
104 * User gs save/restore
105 *
106 * %gs is used for userland TLS and kernel only uses it for stack
107 * canary which is required to be at %gs:20 by gcc. Read the comment
108 * at the top of stackprotector.h for more info.
109 *
110 * Local labels 98 and 99 are used.
111 */
112 #ifdef CONFIG_X86_32_LAZY_GS
113
114 /* unfortunately push/pop can't be no-op */
115 .macro PUSH_GS
116 pushl_cfi $0
117 .endm
118 .macro POP_GS pop=0
119 addl $(4 + \pop), %esp
120 CFI_ADJUST_CFA_OFFSET -(4 + \pop)
121 .endm
122 .macro POP_GS_EX
123 .endm
124
125 /* all the rest are no-op */
126 .macro PTGS_TO_GS
127 .endm
128 .macro PTGS_TO_GS_EX
129 .endm
130 .macro GS_TO_REG reg
131 .endm
132 .macro REG_TO_PTGS reg
133 .endm
134 .macro SET_KERNEL_GS reg
135 .endm
136
137 #else /* CONFIG_X86_32_LAZY_GS */
138
139 .macro PUSH_GS
140 pushl_cfi %gs
141 /*CFI_REL_OFFSET gs, 0*/
142 .endm
143
144 .macro POP_GS pop=0
145 98: popl_cfi %gs
146 /*CFI_RESTORE gs*/
147 .if \pop <> 0
148 add $\pop, %esp
149 CFI_ADJUST_CFA_OFFSET -\pop
150 .endif
151 .endm
152 .macro POP_GS_EX
153 .pushsection .fixup, "ax"
154 99: movl $0, (%esp)
155 jmp 98b
156 .popsection
157 _ASM_EXTABLE(98b,99b)
158 .endm
159
160 .macro PTGS_TO_GS
161 98: mov PT_GS(%esp), %gs
162 .endm
163 .macro PTGS_TO_GS_EX
164 .pushsection .fixup, "ax"
165 99: movl $0, PT_GS(%esp)
166 jmp 98b
167 .popsection
168 _ASM_EXTABLE(98b,99b)
169 .endm
170
171 .macro GS_TO_REG reg
172 movl %gs, \reg
173 /*CFI_REGISTER gs, \reg*/
174 .endm
175 .macro REG_TO_PTGS reg
176 movl \reg, PT_GS(%esp)
177 /*CFI_REL_OFFSET gs, PT_GS*/
178 .endm
179 .macro SET_KERNEL_GS reg
180 movl $(__KERNEL_STACK_CANARY), \reg
181 movl \reg, %gs
182 .endm
183
184 #endif /* CONFIG_X86_32_LAZY_GS */
185
186 .macro SAVE_ALL
187 cld
188 PUSH_GS
189 pushl_cfi %fs
190 /*CFI_REL_OFFSET fs, 0;*/
191 pushl_cfi %es
192 /*CFI_REL_OFFSET es, 0;*/
193 pushl_cfi %ds
194 /*CFI_REL_OFFSET ds, 0;*/
195 pushl_cfi %eax
196 CFI_REL_OFFSET eax, 0
197 pushl_cfi %ebp
198 CFI_REL_OFFSET ebp, 0
199 pushl_cfi %edi
200 CFI_REL_OFFSET edi, 0
201 pushl_cfi %esi
202 CFI_REL_OFFSET esi, 0
203 pushl_cfi %edx
204 CFI_REL_OFFSET edx, 0
205 pushl_cfi %ecx
206 CFI_REL_OFFSET ecx, 0
207 pushl_cfi %ebx
208 CFI_REL_OFFSET ebx, 0
209 movl $(__USER_DS), %edx
210 movl %edx, %ds
211 movl %edx, %es
212 movl $(__KERNEL_PERCPU), %edx
213 movl %edx, %fs
214 SET_KERNEL_GS %edx
215 .endm
216
217 .macro RESTORE_INT_REGS
218 popl_cfi %ebx
219 CFI_RESTORE ebx
220 popl_cfi %ecx
221 CFI_RESTORE ecx
222 popl_cfi %edx
223 CFI_RESTORE edx
224 popl_cfi %esi
225 CFI_RESTORE esi
226 popl_cfi %edi
227 CFI_RESTORE edi
228 popl_cfi %ebp
229 CFI_RESTORE ebp
230 popl_cfi %eax
231 CFI_RESTORE eax
232 .endm
233
234 .macro RESTORE_REGS pop=0
235 RESTORE_INT_REGS
236 1: popl_cfi %ds
237 /*CFI_RESTORE ds;*/
238 2: popl_cfi %es
239 /*CFI_RESTORE es;*/
240 3: popl_cfi %fs
241 /*CFI_RESTORE fs;*/
242 POP_GS \pop
243 .pushsection .fixup, "ax"
244 4: movl $0, (%esp)
245 jmp 1b
246 5: movl $0, (%esp)
247 jmp 2b
248 6: movl $0, (%esp)
249 jmp 3b
250 .popsection
251 _ASM_EXTABLE(1b,4b)
252 _ASM_EXTABLE(2b,5b)
253 _ASM_EXTABLE(3b,6b)
254 POP_GS_EX
255 .endm
256
257 .macro RING0_INT_FRAME
258 CFI_STARTPROC simple
259 CFI_SIGNAL_FRAME
260 CFI_DEF_CFA esp, 3*4
261 /*CFI_OFFSET cs, -2*4;*/
262 CFI_OFFSET eip, -3*4
263 .endm
264
265 .macro RING0_EC_FRAME
266 CFI_STARTPROC simple
267 CFI_SIGNAL_FRAME
268 CFI_DEF_CFA esp, 4*4
269 /*CFI_OFFSET cs, -2*4;*/
270 CFI_OFFSET eip, -3*4
271 .endm
272
273 .macro RING0_PTREGS_FRAME
274 CFI_STARTPROC simple
275 CFI_SIGNAL_FRAME
276 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
277 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
278 CFI_OFFSET eip, PT_EIP-PT_OLDESP
279 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
280 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
281 CFI_OFFSET eax, PT_EAX-PT_OLDESP
282 CFI_OFFSET ebp, PT_EBP-PT_OLDESP
283 CFI_OFFSET edi, PT_EDI-PT_OLDESP
284 CFI_OFFSET esi, PT_ESI-PT_OLDESP
285 CFI_OFFSET edx, PT_EDX-PT_OLDESP
286 CFI_OFFSET ecx, PT_ECX-PT_OLDESP
287 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
288 .endm
289
290 ENTRY(ret_from_fork)
291 CFI_STARTPROC
292 pushl_cfi %eax
293 call schedule_tail
294 GET_THREAD_INFO(%ebp)
295 popl_cfi %eax
296 pushl_cfi $0x0202 # Reset kernel eflags
297 popfl_cfi
298 jmp syscall_exit
299 CFI_ENDPROC
300 END(ret_from_fork)
301
302 /*
303 * Interrupt exit functions should be protected against kprobes
304 */
305 .pushsection .kprobes.text, "ax"
306 /*
307 * Return to user mode is not as complex as all this looks,
308 * but we want the default path for a system call return to
309 * go as quickly as possible which is why some of this is
310 * less clear than it otherwise should be.
311 */
312
313 # userspace resumption stub bypassing syscall exit tracing
314 ALIGN
315 RING0_PTREGS_FRAME
316 ret_from_exception:
317 preempt_stop(CLBR_ANY)
318 ret_from_intr:
319 GET_THREAD_INFO(%ebp)
320 #ifdef CONFIG_VM86
321 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
322 movb PT_CS(%esp), %al
323 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
324 #else
325 /*
326 * We can be coming here from a syscall done in the kernel space,
327 * e.g. a failed kernel_execve().
328 */
329 movl PT_CS(%esp), %eax
330 andl $SEGMENT_RPL_MASK, %eax
331 #endif
332 cmpl $USER_RPL, %eax
333 jb resume_kernel # not returning to v8086 or userspace
334
335 ENTRY(resume_userspace)
336 LOCKDEP_SYS_EXIT
337 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
338 # setting need_resched or sigpending
339 # between sampling and the iret
340 TRACE_IRQS_OFF
341 movl TI_flags(%ebp), %ecx
342 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
343 # int/exception return?
344 jne work_pending
345 jmp restore_all
346 END(ret_from_exception)
347
348 #ifdef CONFIG_PREEMPT
349 ENTRY(resume_kernel)
350 DISABLE_INTERRUPTS(CLBR_ANY)
351 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
352 jnz restore_all
353 need_resched:
354 movl TI_flags(%ebp), %ecx # need_resched set ?
355 testb $_TIF_NEED_RESCHED, %cl
356 jz restore_all
357 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
358 jz restore_all
359 call preempt_schedule_irq
360 jmp need_resched
361 END(resume_kernel)
362 #endif
363 CFI_ENDPROC
364 /*
365 * End of kprobes section
366 */
367 .popsection
368
369 /* SYSENTER_RETURN points to after the "sysenter" instruction in
370 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
371
372 # sysenter call handler stub
373 ENTRY(ia32_sysenter_target)
374 CFI_STARTPROC simple
375 CFI_SIGNAL_FRAME
376 CFI_DEF_CFA esp, 0
377 CFI_REGISTER esp, ebp
378 movl TSS_sysenter_sp0(%esp),%esp
379 sysenter_past_esp:
380 /*
381 * Interrupts are disabled here, but we can't trace it until
382 * enough kernel state to call TRACE_IRQS_OFF can be called - but
383 * we immediately enable interrupts at that point anyway.
384 */
385 pushl_cfi $__USER_DS
386 /*CFI_REL_OFFSET ss, 0*/
387 pushl_cfi %ebp
388 CFI_REL_OFFSET esp, 0
389 pushfl_cfi
390 orl $X86_EFLAGS_IF, (%esp)
391 pushl_cfi $__USER_CS
392 /*CFI_REL_OFFSET cs, 0*/
393 /*
394 * Push current_thread_info()->sysenter_return to the stack.
395 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
396 * pushed above; +8 corresponds to copy_thread's esp0 setting.
397 */
398 pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
399 CFI_REL_OFFSET eip, 0
400
401 pushl_cfi %eax
402 SAVE_ALL
403 ENABLE_INTERRUPTS(CLBR_NONE)
404
405 /*
406 * Load the potential sixth argument from user stack.
407 * Careful about security.
408 */
409 cmpl $__PAGE_OFFSET-3,%ebp
410 jae syscall_fault
411 ASM_STAC
412 1: movl (%ebp),%ebp
413 ASM_CLAC
414 movl %ebp,PT_EBP(%esp)
415 _ASM_EXTABLE(1b,syscall_fault)
416
417 GET_THREAD_INFO(%ebp)
418
419 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
420 jnz sysenter_audit
421 sysenter_do_call:
422 cmpl $(NR_syscalls), %eax
423 jae syscall_badsys
424 call *sys_call_table(,%eax,4)
425 movl %eax,PT_EAX(%esp)
426 LOCKDEP_SYS_EXIT
427 DISABLE_INTERRUPTS(CLBR_ANY)
428 TRACE_IRQS_OFF
429 movl TI_flags(%ebp), %ecx
430 testl $_TIF_ALLWORK_MASK, %ecx
431 jne sysexit_audit
432 sysenter_exit:
433 /* if something modifies registers it must also disable sysexit */
434 movl PT_EIP(%esp), %edx
435 movl PT_OLDESP(%esp), %ecx
436 xorl %ebp,%ebp
437 TRACE_IRQS_ON
438 1: mov PT_FS(%esp), %fs
439 PTGS_TO_GS
440 ENABLE_INTERRUPTS_SYSEXIT
441
442 #ifdef CONFIG_AUDITSYSCALL
443 sysenter_audit:
444 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
445 jnz syscall_trace_entry
446 addl $4,%esp
447 CFI_ADJUST_CFA_OFFSET -4
448 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
449 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
450 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
451 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
452 movl %eax,%edx /* 2nd arg: syscall number */
453 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
454 call __audit_syscall_entry
455 pushl_cfi %ebx
456 movl PT_EAX(%esp),%eax /* reload syscall number */
457 jmp sysenter_do_call
458
459 sysexit_audit:
460 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
461 jne syscall_exit_work
462 TRACE_IRQS_ON
463 ENABLE_INTERRUPTS(CLBR_ANY)
464 movl %eax,%edx /* second arg, syscall return value */
465 cmpl $-MAX_ERRNO,%eax /* is it an error ? */
466 setbe %al /* 1 if so, 0 if not */
467 movzbl %al,%eax /* zero-extend that */
468 call __audit_syscall_exit
469 DISABLE_INTERRUPTS(CLBR_ANY)
470 TRACE_IRQS_OFF
471 movl TI_flags(%ebp), %ecx
472 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
473 jne syscall_exit_work
474 movl PT_EAX(%esp),%eax /* reload syscall return value */
475 jmp sysenter_exit
476 #endif
477
478 CFI_ENDPROC
479 .pushsection .fixup,"ax"
480 2: movl $0,PT_FS(%esp)
481 jmp 1b
482 .popsection
483 _ASM_EXTABLE(1b,2b)
484 PTGS_TO_GS_EX
485 ENDPROC(ia32_sysenter_target)
486
487 /*
488 * syscall stub including irq exit should be protected against kprobes
489 */
490 .pushsection .kprobes.text, "ax"
491 # system call handler stub
492 ENTRY(system_call)
493 RING0_INT_FRAME # can't unwind into user space anyway
494 ASM_CLAC
495 pushl_cfi %eax # save orig_eax
496 SAVE_ALL
497 GET_THREAD_INFO(%ebp)
498 # system call tracing in operation / emulation
499 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
500 jnz syscall_trace_entry
501 cmpl $(NR_syscalls), %eax
502 jae syscall_badsys
503 syscall_call:
504 call *sys_call_table(,%eax,4)
505 movl %eax,PT_EAX(%esp) # store the return value
506 syscall_exit:
507 LOCKDEP_SYS_EXIT
508 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
509 # setting need_resched or sigpending
510 # between sampling and the iret
511 TRACE_IRQS_OFF
512 movl TI_flags(%ebp), %ecx
513 testl $_TIF_ALLWORK_MASK, %ecx # current->work
514 jne syscall_exit_work
515
516 restore_all:
517 TRACE_IRQS_IRET
518 restore_all_notrace:
519 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
520 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
521 # are returning to the kernel.
522 # See comments in process.c:copy_thread() for details.
523 movb PT_OLDSS(%esp), %ah
524 movb PT_CS(%esp), %al
525 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
526 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
527 CFI_REMEMBER_STATE
528 je ldt_ss # returning to user-space with LDT SS
529 restore_nocheck:
530 RESTORE_REGS 4 # skip orig_eax/error_code
531 irq_return:
532 INTERRUPT_RETURN
533 .section .fixup,"ax"
534 ENTRY(iret_exc)
535 pushl $0 # no error code
536 pushl $do_iret_error
537 jmp error_code
538 .previous
539 _ASM_EXTABLE(irq_return,iret_exc)
540
541 CFI_RESTORE_STATE
542 ldt_ss:
543 larl PT_OLDSS(%esp), %eax
544 jnz restore_nocheck
545 testl $0x00400000, %eax # returning to 32bit stack?
546 jnz restore_nocheck # allright, normal return
547
548 #ifdef CONFIG_PARAVIRT
549 /*
550 * The kernel can't run on a non-flat stack if paravirt mode
551 * is active. Rather than try to fixup the high bits of
552 * ESP, bypass this code entirely. This may break DOSemu
553 * and/or Wine support in a paravirt VM, although the option
554 * is still available to implement the setting of the high
555 * 16-bits in the INTERRUPT_RETURN paravirt-op.
556 */
557 cmpl $0, pv_info+PARAVIRT_enabled
558 jne restore_nocheck
559 #endif
560
561 /*
562 * Setup and switch to ESPFIX stack
563 *
564 * We're returning to userspace with a 16 bit stack. The CPU will not
565 * restore the high word of ESP for us on executing iret... This is an
566 * "official" bug of all the x86-compatible CPUs, which we can work
567 * around to make dosemu and wine happy. We do this by preloading the
568 * high word of ESP with the high word of the userspace ESP while
569 * compensating for the offset by changing to the ESPFIX segment with
570 * a base address that matches for the difference.
571 */
572 #define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
573 mov %esp, %edx /* load kernel esp */
574 mov PT_OLDESP(%esp), %eax /* load userspace esp */
575 mov %dx, %ax /* eax: new kernel esp */
576 sub %eax, %edx /* offset (low word is 0) */
577 shr $16, %edx
578 mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
579 mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
580 pushl_cfi $__ESPFIX_SS
581 pushl_cfi %eax /* new kernel esp */
582 /* Disable interrupts, but do not irqtrace this section: we
583 * will soon execute iret and the tracer was already set to
584 * the irqstate after the iret */
585 DISABLE_INTERRUPTS(CLBR_EAX)
586 lss (%esp), %esp /* switch to espfix segment */
587 CFI_ADJUST_CFA_OFFSET -8
588 jmp restore_nocheck
589 CFI_ENDPROC
590 ENDPROC(system_call)
591
592 # perform work that needs to be done immediately before resumption
593 ALIGN
594 RING0_PTREGS_FRAME # can't unwind into user space anyway
595 work_pending:
596 testb $_TIF_NEED_RESCHED, %cl
597 jz work_notifysig
598 work_resched:
599 call schedule
600 LOCKDEP_SYS_EXIT
601 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
602 # setting need_resched or sigpending
603 # between sampling and the iret
604 TRACE_IRQS_OFF
605 movl TI_flags(%ebp), %ecx
606 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
607 # than syscall tracing?
608 jz restore_all
609 testb $_TIF_NEED_RESCHED, %cl
610 jnz work_resched
611
612 work_notifysig: # deal with pending signals and
613 # notify-resume requests
614 #ifdef CONFIG_VM86
615 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
616 movl %esp, %eax
617 jne work_notifysig_v86 # returning to kernel-space or
618 # vm86-space
619 TRACE_IRQS_ON
620 ENABLE_INTERRUPTS(CLBR_NONE)
621 movb PT_CS(%esp), %bl
622 andb $SEGMENT_RPL_MASK, %bl
623 cmpb $USER_RPL, %bl
624 jb resume_kernel
625 xorl %edx, %edx
626 call do_notify_resume
627 jmp resume_userspace
628
629 ALIGN
630 work_notifysig_v86:
631 pushl_cfi %ecx # save ti_flags for do_notify_resume
632 call save_v86_state # %eax contains pt_regs pointer
633 popl_cfi %ecx
634 movl %eax, %esp
635 #else
636 movl %esp, %eax
637 #endif
638 TRACE_IRQS_ON
639 ENABLE_INTERRUPTS(CLBR_NONE)
640 movb PT_CS(%esp), %bl
641 andb $SEGMENT_RPL_MASK, %bl
642 cmpb $USER_RPL, %bl
643 jb resume_kernel
644 xorl %edx, %edx
645 call do_notify_resume
646 jmp resume_userspace
647 END(work_pending)
648
649 # perform syscall exit tracing
650 ALIGN
651 syscall_trace_entry:
652 movl $-ENOSYS,PT_EAX(%esp)
653 movl %esp, %eax
654 call syscall_trace_enter
655 /* What it returned is what we'll actually use. */
656 cmpl $(NR_syscalls), %eax
657 jnae syscall_call
658 jmp syscall_exit
659 END(syscall_trace_entry)
660
661 # perform syscall exit tracing
662 ALIGN
663 syscall_exit_work:
664 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
665 jz work_pending
666 TRACE_IRQS_ON
667 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
668 # schedule() instead
669 movl %esp, %eax
670 call syscall_trace_leave
671 jmp resume_userspace
672 END(syscall_exit_work)
673 CFI_ENDPROC
674
675 RING0_INT_FRAME # can't unwind into user space anyway
676 syscall_fault:
677 ASM_CLAC
678 GET_THREAD_INFO(%ebp)
679 movl $-EFAULT,PT_EAX(%esp)
680 jmp resume_userspace
681 END(syscall_fault)
682
683 syscall_badsys:
684 movl $-ENOSYS,PT_EAX(%esp)
685 jmp resume_userspace
686 END(syscall_badsys)
687 CFI_ENDPROC
688 /*
689 * End of kprobes section
690 */
691 .popsection
692
693 /*
694 * System calls that need a pt_regs pointer.
695 */
696 #define PTREGSCALL0(name) \
697 ENTRY(ptregs_##name) ; \
698 leal 4(%esp),%eax; \
699 jmp sys_##name; \
700 ENDPROC(ptregs_##name)
701
702 #define PTREGSCALL1(name) \
703 ENTRY(ptregs_##name) ; \
704 leal 4(%esp),%edx; \
705 movl (PT_EBX+4)(%esp),%eax; \
706 jmp sys_##name; \
707 ENDPROC(ptregs_##name)
708
709 #define PTREGSCALL2(name) \
710 ENTRY(ptregs_##name) ; \
711 leal 4(%esp),%ecx; \
712 movl (PT_ECX+4)(%esp),%edx; \
713 movl (PT_EBX+4)(%esp),%eax; \
714 jmp sys_##name; \
715 ENDPROC(ptregs_##name)
716
717 #define PTREGSCALL3(name) \
718 ENTRY(ptregs_##name) ; \
719 CFI_STARTPROC; \
720 leal 4(%esp),%eax; \
721 pushl_cfi %eax; \
722 movl PT_EDX(%eax),%ecx; \
723 movl PT_ECX(%eax),%edx; \
724 movl PT_EBX(%eax),%eax; \
725 call sys_##name; \
726 addl $4,%esp; \
727 CFI_ADJUST_CFA_OFFSET -4; \
728 ret; \
729 CFI_ENDPROC; \
730 ENDPROC(ptregs_##name)
731
732 PTREGSCALL1(iopl)
733 PTREGSCALL0(fork)
734 PTREGSCALL0(vfork)
735 PTREGSCALL3(execve)
736 PTREGSCALL2(sigaltstack)
737 PTREGSCALL0(sigreturn)
738 PTREGSCALL0(rt_sigreturn)
739 PTREGSCALL2(vm86)
740 PTREGSCALL1(vm86old)
741
742 /* Clone is an oddball. The 4th arg is in %edi */
743 ENTRY(ptregs_clone)
744 CFI_STARTPROC
745 leal 4(%esp),%eax
746 pushl_cfi %eax
747 pushl_cfi PT_EDI(%eax)
748 movl PT_EDX(%eax),%ecx
749 movl PT_ECX(%eax),%edx
750 movl PT_EBX(%eax),%eax
751 call sys_clone
752 addl $8,%esp
753 CFI_ADJUST_CFA_OFFSET -8
754 ret
755 CFI_ENDPROC
756 ENDPROC(ptregs_clone)
757
758 .macro FIXUP_ESPFIX_STACK
759 /*
760 * Switch back for ESPFIX stack to the normal zerobased stack
761 *
762 * We can't call C functions using the ESPFIX stack. This code reads
763 * the high word of the segment base from the GDT and swiches to the
764 * normal stack and adjusts ESP with the matching offset.
765 */
766 /* fixup the stack */
767 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
768 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
769 shl $16, %eax
770 addl %esp, %eax /* the adjusted stack pointer */
771 pushl_cfi $__KERNEL_DS
772 pushl_cfi %eax
773 lss (%esp), %esp /* switch to the normal stack segment */
774 CFI_ADJUST_CFA_OFFSET -8
775 .endm
776 .macro UNWIND_ESPFIX_STACK
777 movl %ss, %eax
778 /* see if on espfix stack */
779 cmpw $__ESPFIX_SS, %ax
780 jne 27f
781 movl $__KERNEL_DS, %eax
782 movl %eax, %ds
783 movl %eax, %es
784 /* switch to normal stack */
785 FIXUP_ESPFIX_STACK
786 27:
787 .endm
788
789 /*
790 * Build the entry stubs and pointer table with some assembler magic.
791 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
792 * single cache line on all modern x86 implementations.
793 */
794 .section .init.rodata,"a"
795 ENTRY(interrupt)
796 .section .entry.text, "ax"
797 .p2align 5
798 .p2align CONFIG_X86_L1_CACHE_SHIFT
799 ENTRY(irq_entries_start)
800 RING0_INT_FRAME
801 vector=FIRST_EXTERNAL_VECTOR
802 .rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
803 .balign 32
804 .rept 7
805 .if vector < NR_VECTORS
806 .if vector <> FIRST_EXTERNAL_VECTOR
807 CFI_ADJUST_CFA_OFFSET -4
808 .endif
809 1: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
810 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
811 jmp 2f
812 .endif
813 .previous
814 .long 1b
815 .section .entry.text, "ax"
816 vector=vector+1
817 .endif
818 .endr
819 2: jmp common_interrupt
820 .endr
821 END(irq_entries_start)
822
823 .previous
824 END(interrupt)
825 .previous
826
827 /*
828 * the CPU automatically disables interrupts when executing an IRQ vector,
829 * so IRQ-flags tracing has to follow that:
830 */
831 .p2align CONFIG_X86_L1_CACHE_SHIFT
832 common_interrupt:
833 ASM_CLAC
834 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
835 SAVE_ALL
836 TRACE_IRQS_OFF
837 movl %esp,%eax
838 call do_IRQ
839 jmp ret_from_intr
840 ENDPROC(common_interrupt)
841 CFI_ENDPROC
842
843 /*
844 * Irq entries should be protected against kprobes
845 */
846 .pushsection .kprobes.text, "ax"
847 #define BUILD_INTERRUPT3(name, nr, fn) \
848 ENTRY(name) \
849 RING0_INT_FRAME; \
850 ASM_CLAC; \
851 pushl_cfi $~(nr); \
852 SAVE_ALL; \
853 TRACE_IRQS_OFF \
854 movl %esp,%eax; \
855 call fn; \
856 jmp ret_from_intr; \
857 CFI_ENDPROC; \
858 ENDPROC(name)
859
860 #define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
861
862 /* The include is where all of the SMP etc. interrupts come from */
863 #include <asm/entry_arch.h>
864
865 ENTRY(coprocessor_error)
866 RING0_INT_FRAME
867 ASM_CLAC
868 pushl_cfi $0
869 pushl_cfi $do_coprocessor_error
870 jmp error_code
871 CFI_ENDPROC
872 END(coprocessor_error)
873
874 ENTRY(simd_coprocessor_error)
875 RING0_INT_FRAME
876 ASM_CLAC
877 pushl_cfi $0
878 #ifdef CONFIG_X86_INVD_BUG
879 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
880 661: pushl_cfi $do_general_protection
881 662:
882 .section .altinstructions,"a"
883 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
884 .previous
885 .section .altinstr_replacement,"ax"
886 663: pushl $do_simd_coprocessor_error
887 664:
888 .previous
889 #else
890 pushl_cfi $do_simd_coprocessor_error
891 #endif
892 jmp error_code
893 CFI_ENDPROC
894 END(simd_coprocessor_error)
895
896 ENTRY(device_not_available)
897 RING0_INT_FRAME
898 ASM_CLAC
899 pushl_cfi $-1 # mark this as an int
900 pushl_cfi $do_device_not_available
901 jmp error_code
902 CFI_ENDPROC
903 END(device_not_available)
904
905 #ifdef CONFIG_PARAVIRT
906 ENTRY(native_iret)
907 iret
908 _ASM_EXTABLE(native_iret, iret_exc)
909 END(native_iret)
910
911 ENTRY(native_irq_enable_sysexit)
912 sti
913 sysexit
914 END(native_irq_enable_sysexit)
915 #endif
916
917 ENTRY(overflow)
918 RING0_INT_FRAME
919 ASM_CLAC
920 pushl_cfi $0
921 pushl_cfi $do_overflow
922 jmp error_code
923 CFI_ENDPROC
924 END(overflow)
925
926 ENTRY(bounds)
927 RING0_INT_FRAME
928 ASM_CLAC
929 pushl_cfi $0
930 pushl_cfi $do_bounds
931 jmp error_code
932 CFI_ENDPROC
933 END(bounds)
934
935 ENTRY(invalid_op)
936 RING0_INT_FRAME
937 ASM_CLAC
938 pushl_cfi $0
939 pushl_cfi $do_invalid_op
940 jmp error_code
941 CFI_ENDPROC
942 END(invalid_op)
943
944 ENTRY(coprocessor_segment_overrun)
945 RING0_INT_FRAME
946 ASM_CLAC
947 pushl_cfi $0
948 pushl_cfi $do_coprocessor_segment_overrun
949 jmp error_code
950 CFI_ENDPROC
951 END(coprocessor_segment_overrun)
952
953 ENTRY(invalid_TSS)
954 RING0_EC_FRAME
955 ASM_CLAC
956 pushl_cfi $do_invalid_TSS
957 jmp error_code
958 CFI_ENDPROC
959 END(invalid_TSS)
960
961 ENTRY(segment_not_present)
962 RING0_EC_FRAME
963 ASM_CLAC
964 pushl_cfi $do_segment_not_present
965 jmp error_code
966 CFI_ENDPROC
967 END(segment_not_present)
968
969 ENTRY(stack_segment)
970 RING0_EC_FRAME
971 ASM_CLAC
972 pushl_cfi $do_stack_segment
973 jmp error_code
974 CFI_ENDPROC
975 END(stack_segment)
976
977 ENTRY(alignment_check)
978 RING0_EC_FRAME
979 ASM_CLAC
980 pushl_cfi $do_alignment_check
981 jmp error_code
982 CFI_ENDPROC
983 END(alignment_check)
984
985 ENTRY(divide_error)
986 RING0_INT_FRAME
987 ASM_CLAC
988 pushl_cfi $0 # no error code
989 pushl_cfi $do_divide_error
990 jmp error_code
991 CFI_ENDPROC
992 END(divide_error)
993
994 #ifdef CONFIG_X86_MCE
995 ENTRY(machine_check)
996 RING0_INT_FRAME
997 ASM_CLAC
998 pushl_cfi $0
999 pushl_cfi machine_check_vector
1000 jmp error_code
1001 CFI_ENDPROC
1002 END(machine_check)
1003 #endif
1004
1005 ENTRY(spurious_interrupt_bug)
1006 RING0_INT_FRAME
1007 ASM_CLAC
1008 pushl_cfi $0
1009 pushl_cfi $do_spurious_interrupt_bug
1010 jmp error_code
1011 CFI_ENDPROC
1012 END(spurious_interrupt_bug)
1013 /*
1014 * End of kprobes section
1015 */
1016 .popsection
1017
1018 ENTRY(kernel_thread_helper)
1019 pushl $0 # fake return address for unwinder
1020 CFI_STARTPROC
1021 movl %edi,%eax
1022 call *%esi
1023 call do_exit
1024 ud2 # padding for call trace
1025 CFI_ENDPROC
1026 ENDPROC(kernel_thread_helper)
1027
1028 #ifdef CONFIG_XEN
1029 /* Xen doesn't set %esp to be precisely what the normal sysenter
1030 entrypoint expects, so fix it up before using the normal path. */
1031 ENTRY(xen_sysenter_target)
1032 RING0_INT_FRAME
1033 addl $5*4, %esp /* remove xen-provided frame */
1034 CFI_ADJUST_CFA_OFFSET -5*4
1035 jmp sysenter_past_esp
1036 CFI_ENDPROC
1037
1038 ENTRY(xen_hypervisor_callback)
1039 CFI_STARTPROC
1040 pushl_cfi $0
1041 SAVE_ALL
1042 TRACE_IRQS_OFF
1043
1044 /* Check to see if we got the event in the critical
1045 region in xen_iret_direct, after we've reenabled
1046 events and checked for pending events. This simulates
1047 iret instruction's behaviour where it delivers a
1048 pending interrupt when enabling interrupts. */
1049 movl PT_EIP(%esp),%eax
1050 cmpl $xen_iret_start_crit,%eax
1051 jb 1f
1052 cmpl $xen_iret_end_crit,%eax
1053 jae 1f
1054
1055 jmp xen_iret_crit_fixup
1056
1057 ENTRY(xen_do_upcall)
1058 1: mov %esp, %eax
1059 call xen_evtchn_do_upcall
1060 jmp ret_from_intr
1061 CFI_ENDPROC
1062 ENDPROC(xen_hypervisor_callback)
1063
1064 # Hypervisor uses this for application faults while it executes.
1065 # We get here for two reasons:
1066 # 1. Fault while reloading DS, ES, FS or GS
1067 # 2. Fault while executing IRET
1068 # Category 1 we fix up by reattempting the load, and zeroing the segment
1069 # register if the load fails.
1070 # Category 2 we fix up by jumping to do_iret_error. We cannot use the
1071 # normal Linux return path in this case because if we use the IRET hypercall
1072 # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1073 # We distinguish between categories by maintaining a status value in EAX.
1074 ENTRY(xen_failsafe_callback)
1075 CFI_STARTPROC
1076 pushl_cfi %eax
1077 movl $1,%eax
1078 1: mov 4(%esp),%ds
1079 2: mov 8(%esp),%es
1080 3: mov 12(%esp),%fs
1081 4: mov 16(%esp),%gs
1082 testl %eax,%eax
1083 popl_cfi %eax
1084 lea 16(%esp),%esp
1085 CFI_ADJUST_CFA_OFFSET -16
1086 jz 5f
1087 addl $16,%esp
1088 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
1089 5: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
1090 SAVE_ALL
1091 jmp ret_from_exception
1092 CFI_ENDPROC
1093
1094 .section .fixup,"ax"
1095 6: xorl %eax,%eax
1096 movl %eax,4(%esp)
1097 jmp 1b
1098 7: xorl %eax,%eax
1099 movl %eax,8(%esp)
1100 jmp 2b
1101 8: xorl %eax,%eax
1102 movl %eax,12(%esp)
1103 jmp 3b
1104 9: xorl %eax,%eax
1105 movl %eax,16(%esp)
1106 jmp 4b
1107 .previous
1108 _ASM_EXTABLE(1b,6b)
1109 _ASM_EXTABLE(2b,7b)
1110 _ASM_EXTABLE(3b,8b)
1111 _ASM_EXTABLE(4b,9b)
1112 ENDPROC(xen_failsafe_callback)
1113
1114 BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
1115 xen_evtchn_do_upcall)
1116
1117 #endif /* CONFIG_XEN */
1118
1119 #ifdef CONFIG_FUNCTION_TRACER
1120 #ifdef CONFIG_DYNAMIC_FTRACE
1121
1122 ENTRY(mcount)
1123 ret
1124 END(mcount)
1125
1126 ENTRY(ftrace_caller)
1127 cmpl $0, function_trace_stop
1128 jne ftrace_stub
1129
1130 pushl %eax
1131 pushl %ecx
1132 pushl %edx
1133 pushl $0 /* Pass NULL as regs pointer */
1134 movl 4*4(%esp), %eax
1135 movl 0x4(%ebp), %edx
1136 leal function_trace_op, %ecx
1137 subl $MCOUNT_INSN_SIZE, %eax
1138
1139 .globl ftrace_call
1140 ftrace_call:
1141 call ftrace_stub
1142
1143 addl $4,%esp /* skip NULL pointer */
1144 popl %edx
1145 popl %ecx
1146 popl %eax
1147 ftrace_ret:
1148 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1149 .globl ftrace_graph_call
1150 ftrace_graph_call:
1151 jmp ftrace_stub
1152 #endif
1153
1154 .globl ftrace_stub
1155 ftrace_stub:
1156 ret
1157 END(ftrace_caller)
1158
1159 ENTRY(ftrace_regs_caller)
1160 pushf /* push flags before compare (in cs location) */
1161 cmpl $0, function_trace_stop
1162 jne ftrace_restore_flags
1163
1164 /*
1165 * i386 does not save SS and ESP when coming from kernel.
1166 * Instead, to get sp, &regs->sp is used (see ptrace.h).
1167 * Unfortunately, that means eflags must be at the same location
1168 * as the current return ip is. We move the return ip into the
1169 * ip location, and move flags into the return ip location.
1170 */
1171 pushl 4(%esp) /* save return ip into ip slot */
1172
1173 pushl $0 /* Load 0 into orig_ax */
1174 pushl %gs
1175 pushl %fs
1176 pushl %es
1177 pushl %ds
1178 pushl %eax
1179 pushl %ebp
1180 pushl %edi
1181 pushl %esi
1182 pushl %edx
1183 pushl %ecx
1184 pushl %ebx
1185
1186 movl 13*4(%esp), %eax /* Get the saved flags */
1187 movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */
1188 /* clobbering return ip */
1189 movl $__KERNEL_CS,13*4(%esp)
1190
1191 movl 12*4(%esp), %eax /* Load ip (1st parameter) */
1192 subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
1193 movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
1194 leal function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
1195 pushl %esp /* Save pt_regs as 4th parameter */
1196
1197 GLOBAL(ftrace_regs_call)
1198 call ftrace_stub
1199
1200 addl $4, %esp /* Skip pt_regs */
1201 movl 14*4(%esp), %eax /* Move flags back into cs */
1202 movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */
1203 movl 12*4(%esp), %eax /* Get return ip from regs->ip */
1204 movl %eax, 14*4(%esp) /* Put return ip back for ret */
1205
1206 popl %ebx
1207 popl %ecx
1208 popl %edx
1209 popl %esi
1210 popl %edi
1211 popl %ebp
1212 popl %eax
1213 popl %ds
1214 popl %es
1215 popl %fs
1216 popl %gs
1217 addl $8, %esp /* Skip orig_ax and ip */
1218 popf /* Pop flags at end (no addl to corrupt flags) */
1219 jmp ftrace_ret
1220
1221 ftrace_restore_flags:
1222 popf
1223 jmp ftrace_stub
1224 #else /* ! CONFIG_DYNAMIC_FTRACE */
1225
1226 ENTRY(mcount)
1227 cmpl $0, function_trace_stop
1228 jne ftrace_stub
1229
1230 cmpl $ftrace_stub, ftrace_trace_function
1231 jnz trace
1232 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1233 cmpl $ftrace_stub, ftrace_graph_return
1234 jnz ftrace_graph_caller
1235
1236 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1237 jnz ftrace_graph_caller
1238 #endif
1239 .globl ftrace_stub
1240 ftrace_stub:
1241 ret
1242
1243 /* taken from glibc */
1244 trace:
1245 pushl %eax
1246 pushl %ecx
1247 pushl %edx
1248 movl 0xc(%esp), %eax
1249 movl 0x4(%ebp), %edx
1250 subl $MCOUNT_INSN_SIZE, %eax
1251
1252 call *ftrace_trace_function
1253
1254 popl %edx
1255 popl %ecx
1256 popl %eax
1257 jmp ftrace_stub
1258 END(mcount)
1259 #endif /* CONFIG_DYNAMIC_FTRACE */
1260 #endif /* CONFIG_FUNCTION_TRACER */
1261
1262 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1263 ENTRY(ftrace_graph_caller)
1264 pushl %eax
1265 pushl %ecx
1266 pushl %edx
1267 movl 0xc(%esp), %edx
1268 lea 0x4(%ebp), %eax
1269 movl (%ebp), %ecx
1270 subl $MCOUNT_INSN_SIZE, %edx
1271 call prepare_ftrace_return
1272 popl %edx
1273 popl %ecx
1274 popl %eax
1275 ret
1276 END(ftrace_graph_caller)
1277
1278 .globl return_to_handler
1279 return_to_handler:
1280 pushl %eax
1281 pushl %edx
1282 movl %ebp, %eax
1283 call ftrace_return_to_handler
1284 movl %eax, %ecx
1285 popl %edx
1286 popl %eax
1287 jmp *%ecx
1288 #endif
1289
1290 /*
1291 * Some functions should be protected against kprobes
1292 */
1293 .pushsection .kprobes.text, "ax"
1294
1295 ENTRY(page_fault)
1296 RING0_EC_FRAME
1297 ASM_CLAC
1298 pushl_cfi $do_page_fault
1299 ALIGN
1300 error_code:
1301 /* the function address is in %gs's slot on the stack */
1302 pushl_cfi %fs
1303 /*CFI_REL_OFFSET fs, 0*/
1304 pushl_cfi %es
1305 /*CFI_REL_OFFSET es, 0*/
1306 pushl_cfi %ds
1307 /*CFI_REL_OFFSET ds, 0*/
1308 pushl_cfi %eax
1309 CFI_REL_OFFSET eax, 0
1310 pushl_cfi %ebp
1311 CFI_REL_OFFSET ebp, 0
1312 pushl_cfi %edi
1313 CFI_REL_OFFSET edi, 0
1314 pushl_cfi %esi
1315 CFI_REL_OFFSET esi, 0
1316 pushl_cfi %edx
1317 CFI_REL_OFFSET edx, 0
1318 pushl_cfi %ecx
1319 CFI_REL_OFFSET ecx, 0
1320 pushl_cfi %ebx
1321 CFI_REL_OFFSET ebx, 0
1322 cld
1323 movl $(__KERNEL_PERCPU), %ecx
1324 movl %ecx, %fs
1325 UNWIND_ESPFIX_STACK
1326 GS_TO_REG %ecx
1327 movl PT_GS(%esp), %edi # get the function address
1328 movl PT_ORIG_EAX(%esp), %edx # get the error code
1329 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
1330 REG_TO_PTGS %ecx
1331 SET_KERNEL_GS %ecx
1332 movl $(__USER_DS), %ecx
1333 movl %ecx, %ds
1334 movl %ecx, %es
1335 TRACE_IRQS_OFF
1336 movl %esp,%eax # pt_regs pointer
1337 call *%edi
1338 jmp ret_from_exception
1339 CFI_ENDPROC
1340 END(page_fault)
1341
1342 /*
1343 * Debug traps and NMI can happen at the one SYSENTER instruction
1344 * that sets up the real kernel stack. Check here, since we can't
1345 * allow the wrong stack to be used.
1346 *
1347 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1348 * already pushed 3 words if it hits on the sysenter instruction:
1349 * eflags, cs and eip.
1350 *
1351 * We just load the right stack, and push the three (known) values
1352 * by hand onto the new stack - while updating the return eip past
1353 * the instruction that would have done it for sysenter.
1354 */
1355 .macro FIX_STACK offset ok label
1356 cmpw $__KERNEL_CS, 4(%esp)
1357 jne \ok
1358 \label:
1359 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1360 CFI_DEF_CFA esp, 0
1361 CFI_UNDEFINED eip
1362 pushfl_cfi
1363 pushl_cfi $__KERNEL_CS
1364 pushl_cfi $sysenter_past_esp
1365 CFI_REL_OFFSET eip, 0
1366 .endm
1367
1368 ENTRY(debug)
1369 RING0_INT_FRAME
1370 ASM_CLAC
1371 cmpl $ia32_sysenter_target,(%esp)
1372 jne debug_stack_correct
1373 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
1374 debug_stack_correct:
1375 pushl_cfi $-1 # mark this as an int
1376 SAVE_ALL
1377 TRACE_IRQS_OFF
1378 xorl %edx,%edx # error code 0
1379 movl %esp,%eax # pt_regs pointer
1380 call do_debug
1381 jmp ret_from_exception
1382 CFI_ENDPROC
1383 END(debug)
1384
1385 /*
1386 * NMI is doubly nasty. It can happen _while_ we're handling
1387 * a debug fault, and the debug fault hasn't yet been able to
1388 * clear up the stack. So we first check whether we got an
1389 * NMI on the sysenter entry path, but after that we need to
1390 * check whether we got an NMI on the debug path where the debug
1391 * fault happened on the sysenter path.
1392 */
1393 ENTRY(nmi)
1394 RING0_INT_FRAME
1395 ASM_CLAC
1396 pushl_cfi %eax
1397 movl %ss, %eax
1398 cmpw $__ESPFIX_SS, %ax
1399 popl_cfi %eax
1400 je nmi_espfix_stack
1401 cmpl $ia32_sysenter_target,(%esp)
1402 je nmi_stack_fixup
1403 pushl_cfi %eax
1404 movl %esp,%eax
1405 /* Do not access memory above the end of our stack page,
1406 * it might not exist.
1407 */
1408 andl $(THREAD_SIZE-1),%eax
1409 cmpl $(THREAD_SIZE-20),%eax
1410 popl_cfi %eax
1411 jae nmi_stack_correct
1412 cmpl $ia32_sysenter_target,12(%esp)
1413 je nmi_debug_stack_check
1414 nmi_stack_correct:
1415 /* We have a RING0_INT_FRAME here */
1416 pushl_cfi %eax
1417 SAVE_ALL
1418 xorl %edx,%edx # zero error code
1419 movl %esp,%eax # pt_regs pointer
1420 call do_nmi
1421 jmp restore_all_notrace
1422 CFI_ENDPROC
1423
1424 nmi_stack_fixup:
1425 RING0_INT_FRAME
1426 FIX_STACK 12, nmi_stack_correct, 1
1427 jmp nmi_stack_correct
1428
1429 nmi_debug_stack_check:
1430 /* We have a RING0_INT_FRAME here */
1431 cmpw $__KERNEL_CS,16(%esp)
1432 jne nmi_stack_correct
1433 cmpl $debug,(%esp)
1434 jb nmi_stack_correct
1435 cmpl $debug_esp_fix_insn,(%esp)
1436 ja nmi_stack_correct
1437 FIX_STACK 24, nmi_stack_correct, 1
1438 jmp nmi_stack_correct
1439
1440 nmi_espfix_stack:
1441 /* We have a RING0_INT_FRAME here.
1442 *
1443 * create the pointer to lss back
1444 */
1445 pushl_cfi %ss
1446 pushl_cfi %esp
1447 addl $4, (%esp)
1448 /* copy the iret frame of 12 bytes */
1449 .rept 3
1450 pushl_cfi 16(%esp)
1451 .endr
1452 pushl_cfi %eax
1453 SAVE_ALL
1454 FIXUP_ESPFIX_STACK # %eax == %esp
1455 xorl %edx,%edx # zero error code
1456 call do_nmi
1457 RESTORE_REGS
1458 lss 12+4(%esp), %esp # back to espfix stack
1459 CFI_ADJUST_CFA_OFFSET -24
1460 jmp irq_return
1461 CFI_ENDPROC
1462 END(nmi)
1463
1464 ENTRY(int3)
1465 RING0_INT_FRAME
1466 ASM_CLAC
1467 pushl_cfi $-1 # mark this as an int
1468 SAVE_ALL
1469 TRACE_IRQS_OFF
1470 xorl %edx,%edx # zero error code
1471 movl %esp,%eax # pt_regs pointer
1472 call do_int3
1473 jmp ret_from_exception
1474 CFI_ENDPROC
1475 END(int3)
1476
1477 ENTRY(general_protection)
1478 RING0_EC_FRAME
1479 pushl_cfi $do_general_protection
1480 jmp error_code
1481 CFI_ENDPROC
1482 END(general_protection)
1483
1484 #ifdef CONFIG_KVM_GUEST
1485 ENTRY(async_page_fault)
1486 RING0_EC_FRAME
1487 ASM_CLAC
1488 pushl_cfi $do_async_page_fault
1489 jmp error_code
1490 CFI_ENDPROC
1491 END(async_page_fault)
1492 #endif
1493
1494 /*
1495 * End of kprobes section
1496 */
1497 .popsection