2 * linux/arch/x86_64/entry.S
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>
10 * entry.S contains the system-call and fault low-level handling routines.
12 * NOTE: This code handles signal-recognition, which happens every time
13 * after an interrupt and after each system call.
15 * Normal syscalls and interrupts don't save a full stack frame, this is
16 * only done for syscall tracing, signals or fork/exec et.al.
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.
21 * - partial stack frame: partially saved registers upto R11.
22 * - full stack frame: Like partial stack frame, but all register saved.
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.
40 #include <linux/linkage.h>
41 #include <asm/segment.h>
42 #include <asm/cache.h>
43 #include <asm/errno.h>
44 #include <asm/dwarf2.h>
45 #include <asm/calling.h>
46 #include <asm/asm-offsets.h>
48 #include <asm/unistd.h>
49 #include <asm/thread_info.h>
50 #include <asm/hw_irq.h>
52 #include <asm/irqflags.h>
53 #include <asm/paravirt.h>
54 #include <asm/ftrace.h>
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
64 #ifdef CONFIG_FUNCTION_TRACER
65 #ifdef CONFIG_DYNAMIC_FTRACE
71 cmpl $0, function_trace_stop
78 subq $MCOUNT_INSN_SIZE, %rdi
86 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
87 .globl ftrace_graph_call
97 #else /* ! CONFIG_DYNAMIC_FTRACE */
99 cmpl $0, function_trace_stop
102 cmpq $ftrace_stub, ftrace_trace_function
105 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
106 cmpq $ftrace_stub, ftrace_graph_return
107 jnz ftrace_graph_caller
109 cmpq $ftrace_graph_entry_stub, ftrace_graph_entry
110 jnz ftrace_graph_caller
120 movq 0x38(%rsp), %rdi
122 subq $MCOUNT_INSN_SIZE, %rdi
124 call *ftrace_trace_function
130 #endif /* CONFIG_DYNAMIC_FTRACE */
131 #endif /* CONFIG_FUNCTION_TRACER */
133 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
134 ENTRY(ftrace_graph_caller)
135 cmpl $0, function_trace_stop
141 movq 0x38(%rsp), %rsi
142 subq $MCOUNT_INSN_SIZE, %rsi
144 call prepare_ftrace_return
149 END(ftrace_graph_caller)
152 .globl return_to_handler
166 call ftrace_return_to_handler
183 #ifndef CONFIG_PREEMPT
184 #define retint_kernel retint_restore_args
187 #ifdef CONFIG_PARAVIRT
188 ENTRY(native_usergs_sysret64)
191 #endif /* CONFIG_PARAVIRT */
194 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
195 #ifdef CONFIG_TRACE_IRQFLAGS
196 bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
204 * C code is not supposed to know about undefined top of stack. Every time
205 * a C function with an pt_regs argument is called from the SYSCALL based
206 * fast path FIXUP_TOP_OF_STACK is needed.
207 * RESTORE_TOP_OF_STACK syncs the syscall state after any possible ptregs
211 /* %rsp:at FRAMEEND */
212 .macro FIXUP_TOP_OF_STACK tmp
213 movq %gs:pda_oldrsp,\tmp
215 movq $__USER_DS,SS(%rsp)
216 movq $__USER_CS,CS(%rsp)
218 movq R11(%rsp),\tmp /* get eflags */
219 movq \tmp,EFLAGS(%rsp)
222 .macro RESTORE_TOP_OF_STACK tmp,offset=0
223 movq RSP-\offset(%rsp),\tmp
224 movq \tmp,%gs:pda_oldrsp
225 movq EFLAGS-\offset(%rsp),\tmp
226 movq \tmp,R11-\offset(%rsp)
229 .macro FAKE_STACK_FRAME child_rip
230 /* push in order ss, rsp, eflags, cs, rip */
232 pushq $__KERNEL_DS /* ss */
233 CFI_ADJUST_CFA_OFFSET 8
234 /*CFI_REL_OFFSET ss,0*/
236 CFI_ADJUST_CFA_OFFSET 8
238 pushq $(1<<9) /* eflags - interrupts on */
239 CFI_ADJUST_CFA_OFFSET 8
240 /*CFI_REL_OFFSET rflags,0*/
241 pushq $__KERNEL_CS /* cs */
242 CFI_ADJUST_CFA_OFFSET 8
243 /*CFI_REL_OFFSET cs,0*/
244 pushq \child_rip /* rip */
245 CFI_ADJUST_CFA_OFFSET 8
247 pushq %rax /* orig rax */
248 CFI_ADJUST_CFA_OFFSET 8
251 .macro UNFAKE_STACK_FRAME
253 CFI_ADJUST_CFA_OFFSET -(6*8)
256 .macro CFI_DEFAULT_STACK start=1
262 CFI_DEF_CFA_OFFSET SS+8
264 CFI_REL_OFFSET r15,R15
265 CFI_REL_OFFSET r14,R14
266 CFI_REL_OFFSET r13,R13
267 CFI_REL_OFFSET r12,R12
268 CFI_REL_OFFSET rbp,RBP
269 CFI_REL_OFFSET rbx,RBX
270 CFI_REL_OFFSET r11,R11
271 CFI_REL_OFFSET r10,R10
274 CFI_REL_OFFSET rax,RAX
275 CFI_REL_OFFSET rcx,RCX
276 CFI_REL_OFFSET rdx,RDX
277 CFI_REL_OFFSET rsi,RSI
278 CFI_REL_OFFSET rdi,RDI
279 CFI_REL_OFFSET rip,RIP
280 /*CFI_REL_OFFSET cs,CS*/
281 /*CFI_REL_OFFSET rflags,EFLAGS*/
282 CFI_REL_OFFSET rsp,RSP
283 /*CFI_REL_OFFSET ss,SS*/
286 * A newly forked process directly context switches into this.
291 push kernel_eflags(%rip)
292 CFI_ADJUST_CFA_OFFSET 8
293 popf # reset kernel eflags
294 CFI_ADJUST_CFA_OFFSET -8
296 GET_THREAD_INFO(%rcx)
297 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
301 testl $3,CS-ARGOFFSET(%rsp) # from kernel_thread?
302 je int_ret_from_sys_call
303 testl $_TIF_IA32,TI_flags(%rcx)
304 jnz int_ret_from_sys_call
305 RESTORE_TOP_OF_STACK %rdi,ARGOFFSET
306 jmp ret_from_sys_call
309 call syscall_trace_leave
310 GET_THREAD_INFO(%rcx)
316 * System call entry. Upto 6 arguments in registers are supported.
318 * SYSCALL does not save anything on the stack and does not change the
324 * rax system call number
326 * rcx return address for syscall/sysret, C arg3
329 * r10 arg3 (--> moved to rcx for C)
332 * r11 eflags for syscall/sysret, temporary for C
333 * r12-r15,rbp,rbx saved by C code, not touched.
335 * Interrupts are off on entry.
336 * Only called from user space.
338 * XXX if we had a free scratch register we could save the RSP into the stack frame
339 * and report it properly in ps. Unfortunately we haven't.
341 * When user can change the frames always force IRET. That is because
342 * it deals with uncanonical addresses better. SYSRET has trouble
343 * with them due to bugs in both AMD and Intel CPUs.
349 CFI_DEF_CFA rsp,PDA_STACKOFFSET
351 /*CFI_REGISTER rflags,r11*/
354 * A hypervisor implementation might want to use a label
355 * after the swapgs, so that it can do the swapgs
356 * for the guest and jump here on syscall.
358 ENTRY(system_call_after_swapgs)
360 movq %rsp,%gs:pda_oldrsp
361 movq %gs:pda_kernelstack,%rsp
363 * No need to follow this irqs off/on section - it's straight
366 ENABLE_INTERRUPTS(CLBR_NONE)
368 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
369 movq %rcx,RIP-ARGOFFSET(%rsp)
370 CFI_REL_OFFSET rip,RIP-ARGOFFSET
371 GET_THREAD_INFO(%rcx)
372 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
374 system_call_fastpath:
375 cmpq $__NR_syscall_max,%rax
378 call *sys_call_table(,%rax,8) # XXX: rip relative
379 movq %rax,RAX-ARGOFFSET(%rsp)
381 * Syscall return path ending with SYSRET (fast path)
382 * Has incomplete stack frame and undefined top of stack.
385 movl $_TIF_ALLWORK_MASK,%edi
389 GET_THREAD_INFO(%rcx)
390 DISABLE_INTERRUPTS(CLBR_NONE)
392 movl TI_flags(%rcx),%edx
397 * sysretq will re-enable interrupts:
400 movq RIP-ARGOFFSET(%rsp),%rcx
402 RESTORE_ARGS 0,-ARG_SKIP,1
403 /*CFI_REGISTER rflags,r11*/
404 movq %gs:pda_oldrsp, %rsp
408 /* Handle reschedules */
409 /* edx: work, edi: workmask */
411 bt $TIF_NEED_RESCHED,%edx
414 ENABLE_INTERRUPTS(CLBR_NONE)
416 CFI_ADJUST_CFA_OFFSET 8
419 CFI_ADJUST_CFA_OFFSET -8
422 /* Handle a signal */
425 ENABLE_INTERRUPTS(CLBR_NONE)
426 #ifdef CONFIG_AUDITSYSCALL
427 bt $TIF_SYSCALL_AUDIT,%edx
430 /* edx: work flags (arg3) */
431 leaq do_notify_resume(%rip),%rax
432 leaq -ARGOFFSET(%rsp),%rdi # &pt_regs -> arg1
433 xorl %esi,%esi # oldset -> arg2
434 call ptregscall_common
435 movl $_TIF_WORK_MASK,%edi
436 /* Use IRET because user could have changed frame. This
437 works because ptregscall_common has called FIXUP_TOP_OF_STACK. */
438 DISABLE_INTERRUPTS(CLBR_NONE)
443 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
444 jmp ret_from_sys_call
446 #ifdef CONFIG_AUDITSYSCALL
448 * Fast path for syscall audit without full syscall trace.
449 * We just call audit_syscall_entry() directly, and then
450 * jump back to the normal fast path.
453 movq %r10,%r9 /* 6th arg: 4th syscall arg */
454 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
455 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
456 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
457 movq %rax,%rsi /* 2nd arg: syscall number */
458 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
459 call audit_syscall_entry
460 LOAD_ARGS 0 /* reload call-clobbered registers */
461 jmp system_call_fastpath
464 * Return fast path for syscall audit. Call audit_syscall_exit()
465 * directly and then jump back to the fast path with TIF_SYSCALL_AUDIT
469 movq %rax,%rsi /* second arg, syscall return value */
470 cmpq $0,%rax /* is it < 0? */
471 setl %al /* 1 if so, 0 if not */
472 movzbl %al,%edi /* zero-extend that into %edi */
473 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
474 call audit_syscall_exit
475 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
477 #endif /* CONFIG_AUDITSYSCALL */
479 /* Do syscall tracing */
481 #ifdef CONFIG_AUDITSYSCALL
482 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
486 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
487 FIXUP_TOP_OF_STACK %rdi
489 call syscall_trace_enter
491 * Reload arg registers from stack in case ptrace changed them.
492 * We don't reload %rax because syscall_trace_enter() returned
493 * the value it wants us to use in the table lookup.
495 LOAD_ARGS ARGOFFSET, 1
497 cmpq $__NR_syscall_max,%rax
498 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
499 movq %r10,%rcx /* fixup for C */
500 call *sys_call_table(,%rax,8)
501 movq %rax,RAX-ARGOFFSET(%rsp)
502 /* Use IRET because user could have changed frame */
505 * Syscall return path ending with IRET.
506 * Has correct top of stack, but partial stack frame.
508 .globl int_ret_from_sys_call
509 .globl int_with_check
510 int_ret_from_sys_call:
511 DISABLE_INTERRUPTS(CLBR_NONE)
513 testl $3,CS-ARGOFFSET(%rsp)
514 je retint_restore_args
515 movl $_TIF_ALLWORK_MASK,%edi
516 /* edi: mask to check */
519 GET_THREAD_INFO(%rcx)
520 movl TI_flags(%rcx),%edx
523 andl $~TS_COMPAT,TI_status(%rcx)
526 /* Either reschedule or signal or syscall exit tracking needed. */
527 /* First do a reschedule test. */
528 /* edx: work, edi: workmask */
530 bt $TIF_NEED_RESCHED,%edx
533 ENABLE_INTERRUPTS(CLBR_NONE)
535 CFI_ADJUST_CFA_OFFSET 8
538 CFI_ADJUST_CFA_OFFSET -8
539 DISABLE_INTERRUPTS(CLBR_NONE)
543 /* handle signals and tracing -- both require a full stack frame */
546 ENABLE_INTERRUPTS(CLBR_NONE)
548 /* Check for syscall exit trace */
549 testl $_TIF_WORK_SYSCALL_EXIT,%edx
552 CFI_ADJUST_CFA_OFFSET 8
553 leaq 8(%rsp),%rdi # &ptregs -> arg1
554 call syscall_trace_leave
556 CFI_ADJUST_CFA_OFFSET -8
557 andl $~(_TIF_WORK_SYSCALL_EXIT|_TIF_SYSCALL_EMU),%edi
561 testl $_TIF_DO_NOTIFY_MASK,%edx
563 movq %rsp,%rdi # &ptregs -> arg1
564 xorl %esi,%esi # oldset -> arg2
565 call do_notify_resume
566 1: movl $_TIF_WORK_MASK,%edi
569 DISABLE_INTERRUPTS(CLBR_NONE)
576 * Certain special system calls that need to save a complete full stack frame.
579 .macro PTREGSCALL label,func,arg
582 leaq \func(%rip),%rax
583 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
584 jmp ptregscall_common
590 PTREGSCALL stub_clone, sys_clone, %r8
591 PTREGSCALL stub_fork, sys_fork, %rdi
592 PTREGSCALL stub_vfork, sys_vfork, %rdi
593 PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx
594 PTREGSCALL stub_iopl, sys_iopl, %rsi
596 ENTRY(ptregscall_common)
598 CFI_ADJUST_CFA_OFFSET -8
599 CFI_REGISTER rip, r11
602 CFI_REGISTER rip, r15
603 FIXUP_TOP_OF_STACK %r11
605 RESTORE_TOP_OF_STACK %r11
607 CFI_REGISTER rip, r11
610 CFI_ADJUST_CFA_OFFSET 8
611 CFI_REL_OFFSET rip, 0
614 END(ptregscall_common)
619 CFI_ADJUST_CFA_OFFSET -8
620 CFI_REGISTER rip, r11
622 FIXUP_TOP_OF_STACK %r11
625 RESTORE_TOP_OF_STACK %r11
628 jmp int_ret_from_sys_call
633 * sigreturn is special because it needs to restore all registers on return.
634 * This cannot be done with SYSRET, so use the IRET return path instead.
636 ENTRY(stub_rt_sigreturn)
639 CFI_ADJUST_CFA_OFFSET -8
642 FIXUP_TOP_OF_STACK %r11
643 call sys_rt_sigreturn
644 movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
646 jmp int_ret_from_sys_call
648 END(stub_rt_sigreturn)
651 * initial frame state for interrupts and exceptions
656 CFI_DEF_CFA rsp,SS+8-\ref
657 /*CFI_REL_OFFSET ss,SS-\ref*/
658 CFI_REL_OFFSET rsp,RSP-\ref
659 /*CFI_REL_OFFSET rflags,EFLAGS-\ref*/
660 /*CFI_REL_OFFSET cs,CS-\ref*/
661 CFI_REL_OFFSET rip,RIP-\ref
664 /* initial frame state for interrupts (and exceptions without error code) */
665 #define INTR_FRAME _frame RIP
666 /* initial frame state for exceptions with error code (and interrupts with
667 vector already pushed) */
668 #define XCPT_FRAME _frame ORIG_RAX
671 * Interrupt entry/exit.
673 * Interrupt entry points save only callee clobbered registers in fast path.
675 * Entry runs with interrupts off.
678 /* 0(%rsp): interrupt number */
679 .macro interrupt func
682 leaq -ARGOFFSET(%rsp),%rdi # arg1 for handler
685 * Save rbp twice: One is for marking the stack frame, as usual, and the
686 * other, to fill pt_regs properly. This is because bx comes right
687 * before the last saved register in that structure, and not bp. If the
688 * base pointer were in the place bx is today, this would not be needed.
691 CFI_ADJUST_CFA_OFFSET 8
692 CFI_REL_OFFSET rbp, 0
694 CFI_DEF_CFA_REGISTER rbp
698 /* irqcount is used to check if a CPU is already on an interrupt
699 stack or not. While this is essentially redundant with preempt_count
700 it is a little cheaper to use a separate counter in the PDA
701 (short of moving irq_enter into assembly, which would be too
703 1: incl %gs:pda_irqcount
704 cmoveq %gs:pda_irqstackptr,%rsp
705 push %rbp # backlink for old unwinder
707 * We entered an interrupt context - irqs are off:
713 ENTRY(common_interrupt)
716 /* 0(%rsp): oldrsp-ARGOFFSET */
718 DISABLE_INTERRUPTS(CLBR_NONE)
720 decl %gs:pda_irqcount
722 CFI_DEF_CFA_REGISTER rsp
723 CFI_ADJUST_CFA_OFFSET -8
725 GET_THREAD_INFO(%rcx)
726 testl $3,CS-ARGOFFSET(%rsp)
729 /* Interrupt came from user space */
731 * Has a correct top of stack, but a partial stack frame
732 * %rcx: thread info. Interrupts off.
734 retint_with_reschedule:
735 movl $_TIF_WORK_MASK,%edi
738 movl TI_flags(%rcx),%edx
743 retint_swapgs: /* return to user-space */
745 * The iretq could re-enable interrupts:
747 DISABLE_INTERRUPTS(CLBR_ANY)
752 retint_restore_args: /* return to kernel space */
753 DISABLE_INTERRUPTS(CLBR_ANY)
755 * The iretq could re-enable interrupts:
764 .section __ex_table, "a"
765 .quad irq_return, bad_iret
768 #ifdef CONFIG_PARAVIRT
772 .section __ex_table,"a"
773 .quad native_iret, bad_iret
780 * The iret traps when the %cs or %ss being restored is bogus.
781 * We've lost the original trap vector and error code.
782 * #GPF is the most likely one to get for an invalid selector.
783 * So pretend we completed the iret and took the #GPF in user mode.
785 * We are now running with the kernel GS after exception recovery.
786 * But error_entry expects us to have user GS to match the user %cs,
792 jmp general_protection
796 /* edi: workmask, edx: work */
799 bt $TIF_NEED_RESCHED,%edx
802 ENABLE_INTERRUPTS(CLBR_NONE)
804 CFI_ADJUST_CFA_OFFSET 8
807 CFI_ADJUST_CFA_OFFSET -8
808 GET_THREAD_INFO(%rcx)
809 DISABLE_INTERRUPTS(CLBR_NONE)
814 testl $_TIF_DO_NOTIFY_MASK,%edx
817 ENABLE_INTERRUPTS(CLBR_NONE)
819 movq $-1,ORIG_RAX(%rsp)
820 xorl %esi,%esi # oldset
821 movq %rsp,%rdi # &pt_regs
822 call do_notify_resume
824 DISABLE_INTERRUPTS(CLBR_NONE)
826 GET_THREAD_INFO(%rcx)
827 jmp retint_with_reschedule
829 #ifdef CONFIG_PREEMPT
830 /* Returning to kernel space. Check if we need preemption */
831 /* rcx: threadinfo. interrupts off. */
833 cmpl $0,TI_preempt_count(%rcx)
834 jnz retint_restore_args
835 bt $TIF_NEED_RESCHED,TI_flags(%rcx)
836 jnc retint_restore_args
837 bt $9,EFLAGS-ARGOFFSET(%rsp) /* interrupts off? */
838 jnc retint_restore_args
839 call preempt_schedule_irq
844 END(common_interrupt)
849 .macro apicinterrupt num,func
852 CFI_ADJUST_CFA_OFFSET 8
858 ENTRY(thermal_interrupt)
859 apicinterrupt THERMAL_APIC_VECTOR,smp_thermal_interrupt
860 END(thermal_interrupt)
862 ENTRY(threshold_interrupt)
863 apicinterrupt THRESHOLD_APIC_VECTOR,mce_threshold_interrupt
864 END(threshold_interrupt)
867 ENTRY(reschedule_interrupt)
868 apicinterrupt RESCHEDULE_VECTOR,smp_reschedule_interrupt
869 END(reschedule_interrupt)
871 .macro INVALIDATE_ENTRY num
872 ENTRY(invalidate_interrupt\num)
873 apicinterrupt INVALIDATE_TLB_VECTOR_START+\num,smp_invalidate_interrupt
874 END(invalidate_interrupt\num)
886 ENTRY(call_function_interrupt)
887 apicinterrupt CALL_FUNCTION_VECTOR,smp_call_function_interrupt
888 END(call_function_interrupt)
889 ENTRY(call_function_single_interrupt)
890 apicinterrupt CALL_FUNCTION_SINGLE_VECTOR,smp_call_function_single_interrupt
891 END(call_function_single_interrupt)
892 ENTRY(irq_move_cleanup_interrupt)
893 apicinterrupt IRQ_MOVE_CLEANUP_VECTOR,smp_irq_move_cleanup_interrupt
894 END(irq_move_cleanup_interrupt)
897 ENTRY(apic_timer_interrupt)
898 apicinterrupt LOCAL_TIMER_VECTOR,smp_apic_timer_interrupt
899 END(apic_timer_interrupt)
901 ENTRY(uv_bau_message_intr1)
902 apicinterrupt 220,uv_bau_message_interrupt
903 END(uv_bau_message_intr1)
905 ENTRY(error_interrupt)
906 apicinterrupt ERROR_APIC_VECTOR,smp_error_interrupt
909 ENTRY(spurious_interrupt)
910 apicinterrupt SPURIOUS_APIC_VECTOR,smp_spurious_interrupt
911 END(spurious_interrupt)
914 * Exception entry points.
918 PARAVIRT_ADJUST_EXCEPTION_FRAME
919 pushq $0 /* push error code/oldrax */
920 CFI_ADJUST_CFA_OFFSET 8
921 pushq %rax /* push real oldrax to the rdi slot */
922 CFI_ADJUST_CFA_OFFSET 8
929 .macro errorentry sym
931 PARAVIRT_ADJUST_EXCEPTION_FRAME
933 CFI_ADJUST_CFA_OFFSET 8
940 /* error code is on the stack already */
941 /* handle NMI like exceptions that can happen everywhere */
942 .macro paranoidentry sym, ist=0, irqtrace=1
946 movl $MSR_GS_BASE,%ecx
954 movq %gs:pda_data_offset, %rbp
960 movq ORIG_RAX(%rsp),%rsi
961 movq $-1,ORIG_RAX(%rsp)
963 subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
967 addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
969 DISABLE_INTERRUPTS(CLBR_NONE)
976 * "Paranoid" exit path from exception stack.
977 * Paranoid because this is used by NMIs and cannot take
978 * any kernel state for granted.
979 * We don't do kernel preemption checks here, because only
980 * NMI should be common and it does not enable IRQs and
981 * cannot get reschedule ticks.
983 * "trace" is 0 for the NMI handler only, because irq-tracing
984 * is fundamentally NMI-unsafe. (we cannot change the soft and
985 * hard flags at once, atomically)
987 .macro paranoidexit trace=1
988 /* ebx: no swapgs flag */
990 testl %ebx,%ebx /* swapgs needed? */
991 jnz paranoid_restore\trace
993 jnz paranoid_userspace\trace
994 paranoid_swapgs\trace:
999 paranoid_restore\trace:
1002 paranoid_userspace\trace:
1003 GET_THREAD_INFO(%rcx)
1004 movl TI_flags(%rcx),%ebx
1005 andl $_TIF_WORK_MASK,%ebx
1006 jz paranoid_swapgs\trace
1007 movq %rsp,%rdi /* &pt_regs */
1009 movq %rax,%rsp /* switch stack for scheduling */
1010 testl $_TIF_NEED_RESCHED,%ebx
1011 jnz paranoid_schedule\trace
1012 movl %ebx,%edx /* arg3: thread flags */
1016 ENABLE_INTERRUPTS(CLBR_NONE)
1017 xorl %esi,%esi /* arg2: oldset */
1018 movq %rsp,%rdi /* arg1: &pt_regs */
1019 call do_notify_resume
1020 DISABLE_INTERRUPTS(CLBR_NONE)
1024 jmp paranoid_userspace\trace
1025 paranoid_schedule\trace:
1029 ENABLE_INTERRUPTS(CLBR_ANY)
1031 DISABLE_INTERRUPTS(CLBR_ANY)
1035 jmp paranoid_userspace\trace
1040 * Exception entry point. This expects an error code/orig_rax on the stack
1041 * and the exception handler in %rax.
1043 KPROBE_ENTRY(error_entry)
1045 CFI_REL_OFFSET rax,0
1046 /* rdi slot contains rax, oldrax contains error code */
1049 CFI_ADJUST_CFA_OFFSET (14*8)
1050 movq %rsi,13*8(%rsp)
1051 CFI_REL_OFFSET rsi,RSI
1052 movq 14*8(%rsp),%rsi /* load rax from rdi slot */
1053 CFI_REGISTER rax,rsi
1054 movq %rdx,12*8(%rsp)
1055 CFI_REL_OFFSET rdx,RDX
1056 movq %rcx,11*8(%rsp)
1057 CFI_REL_OFFSET rcx,RCX
1058 movq %rsi,10*8(%rsp) /* store rax */
1059 CFI_REL_OFFSET rax,RAX
1061 CFI_REL_OFFSET r8,R8
1063 CFI_REL_OFFSET r9,R9
1065 CFI_REL_OFFSET r10,R10
1067 CFI_REL_OFFSET r11,R11
1069 CFI_REL_OFFSET rbx,RBX
1071 CFI_REL_OFFSET rbp,RBP
1073 CFI_REL_OFFSET r12,R12
1075 CFI_REL_OFFSET r13,R13
1077 CFI_REL_OFFSET r14,R14
1079 CFI_REL_OFFSET r15,R15
1082 je error_kernelspace
1088 CFI_REL_OFFSET rdi,RDI
1090 movq ORIG_RAX(%rsp),%rsi /* get error code */
1091 movq $-1,ORIG_RAX(%rsp)
1093 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
1097 DISABLE_INTERRUPTS(CLBR_NONE)
1099 GET_THREAD_INFO(%rcx)
1102 LOCKDEP_SYS_EXIT_IRQ
1103 movl TI_flags(%rcx),%edx
1104 movl $_TIF_WORK_MASK,%edi
1112 /* There are two places in the kernel that can potentially fault with
1113 usergs. Handle them here. The exception handlers after
1114 iret run with kernel gs again, so don't set the user space flag.
1115 B stepping K8s sometimes report an truncated RIP for IRET
1116 exceptions returning to compat mode. Check for these here too. */
1117 leaq irq_return(%rip),%rcx
1120 movl %ecx,%ecx /* zero extend */
1123 cmpq $gs_change,RIP(%rsp)
1126 KPROBE_END(error_entry)
1128 /* Reload gs selector with exception handling */
1129 /* edi: new selector */
1130 ENTRY(native_load_gs_index)
1133 CFI_ADJUST_CFA_OFFSET 8
1134 DISABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI))
1138 2: mfence /* workaround */
1141 CFI_ADJUST_CFA_OFFSET -8
1144 ENDPROC(native_load_gs_index)
1146 .section __ex_table,"a"
1148 .quad gs_change,bad_gs
1150 .section .fixup,"ax"
1151 /* running with kernelgs */
1153 SWAPGS /* switch back to user gs */
1160 * Create a kernel thread.
1162 * C extern interface:
1163 * extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
1165 * asm input arguments:
1166 * rdi: fn, rsi: arg, rdx: flags
1168 ENTRY(kernel_thread)
1170 FAKE_STACK_FRAME $child_rip
1173 # rdi: flags, rsi: usp, rdx: will be &pt_regs
1175 orq kernel_thread_flags(%rip),%rdi
1188 * It isn't worth to check for reschedule here,
1189 * so internally to the x86_64 port you can rely on kernel_thread()
1190 * not to reschedule the child before returning, this avoids the need
1191 * of hacks for example to fork off the per-CPU idle tasks.
1192 * [Hopefully no generic code relies on the reschedule -AK]
1198 ENDPROC(kernel_thread)
1201 pushq $0 # fake return address
1204 * Here we are in the child and the registers are set as they were
1205 * at kernel_thread() invocation in the parent.
1217 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
1219 * C extern interface:
1220 * extern long execve(char *name, char **argv, char **envp)
1222 * asm input arguments:
1223 * rdi: name, rsi: argv, rdx: envp
1225 * We want to fallback into:
1226 * extern long sys_execve(char *name, char **argv,char **envp, struct pt_regs *regs)
1228 * do_sys_execve asm fallback arguments:
1229 * rdi: name, rsi: argv, rdx: envp, rcx: fake frame on the stack
1231 ENTRY(kernel_execve)
1237 movq %rax, RAX(%rsp)
1240 je int_ret_from_sys_call
1245 ENDPROC(kernel_execve)
1247 KPROBE_ENTRY(page_fault)
1248 errorentry do_page_fault
1249 KPROBE_END(page_fault)
1251 ENTRY(coprocessor_error)
1252 zeroentry do_coprocessor_error
1253 END(coprocessor_error)
1255 ENTRY(simd_coprocessor_error)
1256 zeroentry do_simd_coprocessor_error
1257 END(simd_coprocessor_error)
1259 ENTRY(device_not_available)
1260 zeroentry do_device_not_available
1261 END(device_not_available)
1263 /* runs on exception stack */
1266 PARAVIRT_ADJUST_EXCEPTION_FRAME
1268 CFI_ADJUST_CFA_OFFSET 8
1269 paranoidentry do_debug, DEBUG_STACK
1273 /* runs on exception stack */
1276 PARAVIRT_ADJUST_EXCEPTION_FRAME
1278 CFI_ADJUST_CFA_OFFSET 8
1279 paranoidentry do_nmi, 0, 0
1280 #ifdef CONFIG_TRACE_IRQFLAGS
1290 PARAVIRT_ADJUST_EXCEPTION_FRAME
1292 CFI_ADJUST_CFA_OFFSET 8
1293 paranoidentry do_int3, DEBUG_STACK
1299 zeroentry do_overflow
1307 zeroentry do_invalid_op
1310 ENTRY(coprocessor_segment_overrun)
1311 zeroentry do_coprocessor_segment_overrun
1312 END(coprocessor_segment_overrun)
1314 /* runs on exception stack */
1317 PARAVIRT_ADJUST_EXCEPTION_FRAME
1318 paranoidentry do_double_fault
1324 errorentry do_invalid_TSS
1327 ENTRY(segment_not_present)
1328 errorentry do_segment_not_present
1329 END(segment_not_present)
1331 /* runs on exception stack */
1332 ENTRY(stack_segment)
1334 PARAVIRT_ADJUST_EXCEPTION_FRAME
1335 paranoidentry do_stack_segment
1340 KPROBE_ENTRY(general_protection)
1341 errorentry do_general_protection
1342 KPROBE_END(general_protection)
1344 ENTRY(alignment_check)
1345 errorentry do_alignment_check
1346 END(alignment_check)
1349 zeroentry do_divide_error
1352 ENTRY(spurious_interrupt_bug)
1353 zeroentry do_spurious_interrupt_bug
1354 END(spurious_interrupt_bug)
1356 #ifdef CONFIG_X86_MCE
1357 /* runs on exception stack */
1358 ENTRY(machine_check)
1360 PARAVIRT_ADJUST_EXCEPTION_FRAME
1362 CFI_ADJUST_CFA_OFFSET 8
1363 paranoidentry do_machine_check
1369 /* Call softirq on interrupt stack. Interrupts are off. */
1373 CFI_ADJUST_CFA_OFFSET 8
1374 CFI_REL_OFFSET rbp,0
1376 CFI_DEF_CFA_REGISTER rbp
1377 incl %gs:pda_irqcount
1378 cmove %gs:pda_irqstackptr,%rsp
1379 push %rbp # backlink for old unwinder
1382 CFI_DEF_CFA_REGISTER rsp
1383 CFI_ADJUST_CFA_OFFSET -8
1384 decl %gs:pda_irqcount
1387 ENDPROC(call_softirq)
1389 KPROBE_ENTRY(ignore_sysret)
1394 ENDPROC(ignore_sysret)
1397 ENTRY(xen_hypervisor_callback)
1398 zeroentry xen_do_hypervisor_callback
1399 END(xen_hypervisor_callback)
1402 # A note on the "critical region" in our callback handler.
1403 # We want to avoid stacking callback handlers due to events occurring
1404 # during handling of the last event. To do this, we keep events disabled
1405 # until we've done all processing. HOWEVER, we must enable events before
1406 # popping the stack frame (can't be done atomically) and so it would still
1407 # be possible to get enough handler activations to overflow the stack.
1408 # Although unlikely, bugs of that kind are hard to track down, so we'd
1409 # like to avoid the possibility.
1410 # So, on entry to the handler we detect whether we interrupted an
1411 # existing activation in its critical region -- if so, we pop the current
1412 # activation and restart the handler using the previous one.
1414 ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
1416 /* Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will
1417 see the correct pointer to the pt_regs */
1418 movq %rdi, %rsp # we don't return, adjust the stack frame
1421 11: incl %gs:pda_irqcount
1423 CFI_DEF_CFA_REGISTER rbp
1424 cmovzq %gs:pda_irqstackptr,%rsp
1425 pushq %rbp # backlink for old unwinder
1426 call xen_evtchn_do_upcall
1428 CFI_DEF_CFA_REGISTER rsp
1429 decl %gs:pda_irqcount
1432 END(do_hypervisor_callback)
1435 # Hypervisor uses this for application faults while it executes.
1436 # We get here for two reasons:
1437 # 1. Fault while reloading DS, ES, FS or GS
1438 # 2. Fault while executing IRET
1439 # Category 1 we do not need to fix up as Xen has already reloaded all segment
1440 # registers that could be reloaded and zeroed the others.
1441 # Category 2 we fix up by killing the current process. We cannot use the
1442 # normal Linux return path in this case because if we use the IRET hypercall
1443 # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1444 # We distinguish between categories by comparing each saved segment register
1445 # with its current contents: any discrepancy means we in category 1.
1447 ENTRY(xen_failsafe_callback)
1448 framesz = (RIP-0x30) /* workaround buggy gas */
1450 CFI_REL_OFFSET rcx, 0
1451 CFI_REL_OFFSET r11, 8
1465 /* All segments match their saved values => Category 2 (Bad IRET). */
1471 CFI_ADJUST_CFA_OFFSET -0x30
1473 CFI_ADJUST_CFA_OFFSET 8
1475 CFI_ADJUST_CFA_OFFSET 8
1477 CFI_ADJUST_CFA_OFFSET 8
1478 jmp general_protection
1480 1: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */
1486 CFI_ADJUST_CFA_OFFSET -0x30
1488 CFI_ADJUST_CFA_OFFSET 8
1492 END(xen_failsafe_callback)
1494 #endif /* CONFIG_XEN */