blob: edd7aadfacfa7fb10deb546c37a134b0d05288c6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Ingo Molnara49976d2015-06-08 09:49:11 +02002 * Copyright (C) 1991,1992 Linus Torvalds
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Ingo Molnara49976d2015-06-08 09:49:11 +02004 * entry_32.S contains the system-call and low-level fault and trap handling routines.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Andi Kleen889f21c2007-05-02 19:27:19 +02006 * Stack layout in 'syscall_exit':
Ingo Molnara49976d2015-06-08 09:49:11 +02007 * ptrace needs to have all registers on the stack.
8 * If the order here is changed, it needs to be
9 * updated in fork.c:copy_process(), signal.c:do_signal(),
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * ptrace.c and ptrace.h
11 *
12 * 0(%esp) - %ebx
13 * 4(%esp) - %ecx
14 * 8(%esp) - %edx
15 * C(%esp) - %esi
16 * 10(%esp) - %edi
17 * 14(%esp) - %ebp
18 * 18(%esp) - %eax
19 * 1C(%esp) - %ds
20 * 20(%esp) - %es
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010021 * 24(%esp) - %fs
Tejun Heoccbeed32009-02-09 22:17:40 +090022 * 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
23 * 2C(%esp) - orig_eax
24 * 30(%esp) - %eip
25 * 34(%esp) - %cs
26 * 38(%esp) - %eflags
27 * 3C(%esp) - %oldesp
28 * 40(%esp) - %oldss
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 */
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/linkage.h>
Eric Parisd7e75282012-01-03 14:23:06 -050032#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/thread_info.h>
Ingo Molnar55f327f2006-07-03 00:24:43 -070034#include <asm/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/errno.h>
36#include <asm/segment.h>
37#include <asm/smp.h>
Jeremy Fitzhardinge0341c142009-02-13 11:14:01 -080038#include <asm/page_types.h>
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010039#include <asm/percpu.h>
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030040#include <asm/processor-flags.h>
Abhishek Sagar395a59d2008-06-21 23:47:27 +053041#include <asm/ftrace.h>
Thomas Gleixner9b7dc562008-05-02 20:10:09 +020042#include <asm/irq_vectors.h>
Brian Gerst40d2e762010-03-21 09:00:43 -040043#include <asm/cpufeature.h>
Andy Lutomirskib4ca46e2011-08-25 16:10:33 -040044#include <asm/alternative-asm.h>
H. Peter Anvin6837a542012-04-20 12:19:50 -070045#include <asm/asm.h>
H. Peter Anvine59d1b02012-09-21 13:58:10 -070046#include <asm/smap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Roland McGrathaf0575b2008-06-24 04:16:52 -070048/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
49#include <linux/elf-em.h>
50#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
Ingo Molnara49976d2015-06-08 09:49:11 +020051#define __AUDIT_ARCH_LE 0x40000000
Roland McGrathaf0575b2008-06-24 04:16:52 -070052
53#ifndef CONFIG_AUDITSYSCALL
Ingo Molnara49976d2015-06-08 09:49:11 +020054# define sysenter_audit syscall_trace_entry
55# define sysexit_audit syscall_exit_work
Roland McGrathaf0575b2008-06-24 04:16:52 -070056#endif
57
Jiri Olsaea714542011-03-07 19:10:39 +010058 .section .entry.text, "ax"
59
Rusty Russell139ec7c2006-12-07 02:14:08 +010060/*
61 * We use macros for low-level operations which need to be overridden
62 * for paravirtualization. The following will never clobber any registers:
63 * INTERRUPT_RETURN (aka. "iret")
64 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -040065 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
Rusty Russell139ec7c2006-12-07 02:14:08 +010066 *
67 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
68 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
69 * Allowing a register to be clobbered can shrink the paravirt replacement
70 * enough to patch inline, increasing performance.
71 */
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#ifdef CONFIG_PREEMPT
Ingo Molnara49976d2015-06-08 09:49:11 +020074# define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#else
Ingo Molnara49976d2015-06-08 09:49:11 +020076# define preempt_stop(clobbers)
77# define resume_kernel restore_all
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#endif
79
Ingo Molnar55f327f2006-07-03 00:24:43 -070080.macro TRACE_IRQS_IRET
81#ifdef CONFIG_TRACE_IRQFLAGS
Ingo Molnara49976d2015-06-08 09:49:11 +020082 testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off?
83 jz 1f
Ingo Molnar55f327f2006-07-03 00:24:43 -070084 TRACE_IRQS_ON
851:
86#endif
87.endm
88
Tejun Heoccbeed32009-02-09 22:17:40 +090089/*
90 * User gs save/restore
91 *
92 * %gs is used for userland TLS and kernel only uses it for stack
93 * canary which is required to be at %gs:20 by gcc. Read the comment
94 * at the top of stackprotector.h for more info.
95 *
96 * Local labels 98 and 99 are used.
97 */
98#ifdef CONFIG_X86_32_LAZY_GS
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Tejun Heoccbeed32009-02-09 22:17:40 +0900100 /* unfortunately push/pop can't be no-op */
101.macro PUSH_GS
Ingo Molnara49976d2015-06-08 09:49:11 +0200102 pushl $0
Tejun Heoccbeed32009-02-09 22:17:40 +0900103.endm
104.macro POP_GS pop=0
Ingo Molnara49976d2015-06-08 09:49:11 +0200105 addl $(4 + \pop), %esp
Tejun Heoccbeed32009-02-09 22:17:40 +0900106.endm
107.macro POP_GS_EX
108.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Tejun Heoccbeed32009-02-09 22:17:40 +0900110 /* all the rest are no-op */
111.macro PTGS_TO_GS
112.endm
113.macro PTGS_TO_GS_EX
114.endm
115.macro GS_TO_REG reg
116.endm
117.macro REG_TO_PTGS reg
118.endm
119.macro SET_KERNEL_GS reg
120.endm
121
122#else /* CONFIG_X86_32_LAZY_GS */
123
124.macro PUSH_GS
Ingo Molnara49976d2015-06-08 09:49:11 +0200125 pushl %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900126.endm
127
128.macro POP_GS pop=0
Ingo Molnara49976d2015-06-08 09:49:11 +020012998: popl %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900130 .if \pop <> 0
131 add $\pop, %esp
Tejun Heoccbeed32009-02-09 22:17:40 +0900132 .endif
133.endm
134.macro POP_GS_EX
135.pushsection .fixup, "ax"
Ingo Molnara49976d2015-06-08 09:49:11 +020013699: movl $0, (%esp)
137 jmp 98b
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100138.popsection
Ingo Molnara49976d2015-06-08 09:49:11 +0200139 _ASM_EXTABLE(98b, 99b)
Tejun Heoccbeed32009-02-09 22:17:40 +0900140.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Tejun Heoccbeed32009-02-09 22:17:40 +0900142.macro PTGS_TO_GS
Ingo Molnara49976d2015-06-08 09:49:11 +020014398: mov PT_GS(%esp), %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900144.endm
145.macro PTGS_TO_GS_EX
146.pushsection .fixup, "ax"
Ingo Molnara49976d2015-06-08 09:49:11 +020014799: movl $0, PT_GS(%esp)
148 jmp 98b
Tejun Heoccbeed32009-02-09 22:17:40 +0900149.popsection
Ingo Molnara49976d2015-06-08 09:49:11 +0200150 _ASM_EXTABLE(98b, 99b)
Tejun Heoccbeed32009-02-09 22:17:40 +0900151.endm
152
153.macro GS_TO_REG reg
Ingo Molnara49976d2015-06-08 09:49:11 +0200154 movl %gs, \reg
Tejun Heoccbeed32009-02-09 22:17:40 +0900155.endm
156.macro REG_TO_PTGS reg
Ingo Molnara49976d2015-06-08 09:49:11 +0200157 movl \reg, PT_GS(%esp)
Tejun Heoccbeed32009-02-09 22:17:40 +0900158.endm
159.macro SET_KERNEL_GS reg
Ingo Molnara49976d2015-06-08 09:49:11 +0200160 movl $(__KERNEL_STACK_CANARY), \reg
161 movl \reg, %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900162.endm
163
Ingo Molnara49976d2015-06-08 09:49:11 +0200164#endif /* CONFIG_X86_32_LAZY_GS */
Tejun Heoccbeed32009-02-09 22:17:40 +0900165
Tejun Heof0d96112009-02-09 22:17:40 +0900166.macro SAVE_ALL
167 cld
Tejun Heoccbeed32009-02-09 22:17:40 +0900168 PUSH_GS
Ingo Molnara49976d2015-06-08 09:49:11 +0200169 pushl %fs
170 pushl %es
171 pushl %ds
172 pushl %eax
173 pushl %ebp
174 pushl %edi
175 pushl %esi
176 pushl %edx
177 pushl %ecx
178 pushl %ebx
179 movl $(__USER_DS), %edx
180 movl %edx, %ds
181 movl %edx, %es
182 movl $(__KERNEL_PERCPU), %edx
183 movl %edx, %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900184 SET_KERNEL_GS %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900185.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Tejun Heof0d96112009-02-09 22:17:40 +0900187.macro RESTORE_INT_REGS
Ingo Molnara49976d2015-06-08 09:49:11 +0200188 popl %ebx
189 popl %ecx
190 popl %edx
191 popl %esi
192 popl %edi
193 popl %ebp
194 popl %eax
Tejun Heof0d96112009-02-09 22:17:40 +0900195.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Tejun Heoccbeed32009-02-09 22:17:40 +0900197.macro RESTORE_REGS pop=0
Tejun Heof0d96112009-02-09 22:17:40 +0900198 RESTORE_INT_REGS
Ingo Molnara49976d2015-06-08 09:49:11 +02001991: popl %ds
2002: popl %es
2013: popl %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900202 POP_GS \pop
Tejun Heof0d96112009-02-09 22:17:40 +0900203.pushsection .fixup, "ax"
Ingo Molnara49976d2015-06-08 09:49:11 +02002044: movl $0, (%esp)
205 jmp 1b
2065: movl $0, (%esp)
207 jmp 2b
2086: movl $0, (%esp)
209 jmp 3b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210.popsection
Ingo Molnara49976d2015-06-08 09:49:11 +0200211 _ASM_EXTABLE(1b, 4b)
212 _ASM_EXTABLE(2b, 5b)
213 _ASM_EXTABLE(3b, 6b)
Tejun Heoccbeed32009-02-09 22:17:40 +0900214 POP_GS_EX
Tejun Heof0d96112009-02-09 22:17:40 +0900215.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217ENTRY(ret_from_fork)
Ingo Molnara49976d2015-06-08 09:49:11 +0200218 pushl %eax
219 call schedule_tail
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 GET_THREAD_INFO(%ebp)
Ingo Molnara49976d2015-06-08 09:49:11 +0200221 popl %eax
222 pushl $0x0202 # Reset kernel eflags
Ingo Molnar131484c2015-05-28 12:21:47 +0200223 popfl
Ingo Molnara49976d2015-06-08 09:49:11 +0200224 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100225END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Al Viro22e2430d2012-10-10 21:35:42 -0400227ENTRY(ret_from_kernel_thread)
Ingo Molnara49976d2015-06-08 09:49:11 +0200228 pushl %eax
229 call schedule_tail
Al Viro6783eaa2012-08-02 23:05:11 +0400230 GET_THREAD_INFO(%ebp)
Ingo Molnara49976d2015-06-08 09:49:11 +0200231 popl %eax
232 pushl $0x0202 # Reset kernel eflags
Ingo Molnar131484c2015-05-28 12:21:47 +0200233 popfl
Ingo Molnara49976d2015-06-08 09:49:11 +0200234 movl PT_EBP(%esp), %eax
235 call *PT_EBX(%esp)
236 movl $0, PT_EAX(%esp)
237 jmp syscall_exit
Al Viro22e2430d2012-10-10 21:35:42 -0400238ENDPROC(ret_from_kernel_thread)
Al Viro6783eaa2012-08-02 23:05:11 +0400239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/*
241 * Return to user mode is not as complex as all this looks,
242 * but we want the default path for a system call return to
243 * go as quickly as possible which is why some of this is
244 * less clear than it otherwise should be.
245 */
246
247 # userspace resumption stub bypassing syscall exit tracing
248 ALIGN
249ret_from_exception:
Rusty Russell139ec7c2006-12-07 02:14:08 +0100250 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251ret_from_intr:
252 GET_THREAD_INFO(%ebp)
Dmitry Adamushko29a2e282012-03-22 21:39:25 +0100253#ifdef CONFIG_VM86
Ingo Molnara49976d2015-06-08 09:49:11 +0200254 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
255 movb PT_CS(%esp), %al
256 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
Dmitry Adamushko29a2e282012-03-22 21:39:25 +0100257#else
258 /*
Al Viro6783eaa2012-08-02 23:05:11 +0400259 * We can be coming here from child spawned by kernel_thread().
Dmitry Adamushko29a2e282012-03-22 21:39:25 +0100260 */
Ingo Molnara49976d2015-06-08 09:49:11 +0200261 movl PT_CS(%esp), %eax
262 andl $SEGMENT_RPL_MASK, %eax
Dmitry Adamushko29a2e282012-03-22 21:39:25 +0100263#endif
Ingo Molnara49976d2015-06-08 09:49:11 +0200264 cmpl $USER_RPL, %eax
265 jb resume_kernel # not returning to v8086 or userspace
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267ENTRY(resume_userspace)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200268 LOCKDEP_SYS_EXIT
Ingo Molnara49976d2015-06-08 09:49:11 +0200269 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
270 # setting need_resched or sigpending
271 # between sampling and the iret
Peter Zijlstrae32e58a2008-06-06 10:14:08 +0200272 TRACE_IRQS_OFF
Ingo Molnara49976d2015-06-08 09:49:11 +0200273 movl TI_flags(%ebp), %ecx
274 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
275 # int/exception return?
276 jne work_pending
277 jmp restore_all
Jan Beulich47a55cd2007-02-13 13:26:24 +0100278END(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280#ifdef CONFIG_PREEMPT
281ENTRY(resume_kernel)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100282 DISABLE_INTERRUPTS(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283need_resched:
Ingo Molnara49976d2015-06-08 09:49:11 +0200284 cmpl $0, PER_CPU_VAR(__preempt_count)
285 jnz restore_all
286 testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off (exception path) ?
287 jz restore_all
288 call preempt_schedule_irq
289 jmp need_resched
Jan Beulich47a55cd2007-02-13 13:26:24 +0100290END(resume_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291#endif
292
Ingo Molnara49976d2015-06-08 09:49:11 +0200293/*
294 * SYSENTER_RETURN points to after the SYSENTER instruction
295 * in the vsyscall page. See vsyscall-sysentry.S, which defines
296 * the symbol.
297 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Ingo Molnara49976d2015-06-08 09:49:11 +0200299 # SYSENTER call handler stub
Ingo Molnar4c8cd0c2015-06-08 08:33:56 +0200300ENTRY(entry_SYSENTER_32)
Ingo Molnara49976d2015-06-08 09:49:11 +0200301 movl TSS_sysenter_sp0(%esp), %esp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700303 /*
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700304 * Interrupts are disabled here, but we can't trace it until
305 * enough kernel state to call TRACE_IRQS_OFF can be called - but
306 * we immediately enable interrupts at that point anyway.
Ingo Molnar55f327f2006-07-03 00:24:43 -0700307 */
Ingo Molnara49976d2015-06-08 09:49:11 +0200308 pushl $__USER_DS
309 pushl %ebp
Ingo Molnar131484c2015-05-28 12:21:47 +0200310 pushfl
Ingo Molnara49976d2015-06-08 09:49:11 +0200311 orl $X86_EFLAGS_IF, (%esp)
312 pushl $__USER_CS
Ingo Molnare6e54942006-06-27 02:53:50 -0700313 /*
314 * Push current_thread_info()->sysenter_return to the stack.
Andy Lutomirskiff8287f2015-04-02 12:41:44 -0700315 * A tiny bit of offset fixup is necessary: TI_sysenter_return
316 * is relative to thread_info, which is at the bottom of the
317 * kernel stack page. 4*4 means the 4 words pushed above;
318 * TOP_OF_KERNEL_STACK_PADDING takes us to the top of the stack;
319 * and THREAD_SIZE takes us to the bottom.
Ingo Molnare6e54942006-06-27 02:53:50 -0700320 */
Ingo Molnara49976d2015-06-08 09:49:11 +0200321 pushl ((TI_sysenter_return) - THREAD_SIZE + TOP_OF_KERNEL_STACK_PADDING + 4*4)(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Ingo Molnara49976d2015-06-08 09:49:11 +0200323 pushl %eax
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700324 SAVE_ALL
325 ENABLE_INTERRUPTS(CLBR_NONE)
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327/*
328 * Load the potential sixth argument from user stack.
329 * Careful about security.
330 */
Ingo Molnara49976d2015-06-08 09:49:11 +0200331 cmpl $__PAGE_OFFSET-3, %ebp
332 jae syscall_fault
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700333 ASM_STAC
Ingo Molnara49976d2015-06-08 09:49:11 +02003341: movl (%ebp), %ebp
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700335 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200336 movl %ebp, PT_EBP(%esp)
337 _ASM_EXTABLE(1b, syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 GET_THREAD_INFO(%ebp)
340
Ingo Molnara49976d2015-06-08 09:49:11 +0200341 testl $_TIF_WORK_SYSCALL_ENTRY, TI_flags(%ebp)
342 jnz sysenter_audit
Roland McGrathaf0575b2008-06-24 04:16:52 -0700343sysenter_do_call:
Ingo Molnara49976d2015-06-08 09:49:11 +0200344 cmpl $(NR_syscalls), %eax
345 jae sysenter_badsys
346 call *sys_call_table(, %eax, 4)
Andy Lutomirski554086d2014-06-23 14:22:15 -0700347sysenter_after_call:
Ingo Molnara49976d2015-06-08 09:49:11 +0200348 movl %eax, PT_EAX(%esp)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200349 LOCKDEP_SYS_EXIT
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200350 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700351 TRACE_IRQS_OFF
Ingo Molnara49976d2015-06-08 09:49:11 +0200352 movl TI_flags(%ebp), %ecx
353 testl $_TIF_ALLWORK_MASK, %ecx
354 jnz sysexit_audit
Roland McGrathaf0575b2008-06-24 04:16:52 -0700355sysenter_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356/* if something modifies registers it must also disable sysexit */
Ingo Molnara49976d2015-06-08 09:49:11 +0200357 movl PT_EIP(%esp), %edx
358 movl PT_OLDESP(%esp), %ecx
359 xorl %ebp, %ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700360 TRACE_IRQS_ON
Ingo Molnara49976d2015-06-08 09:49:11 +02003611: mov PT_FS(%esp), %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900362 PTGS_TO_GS
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400363 ENABLE_INTERRUPTS_SYSEXIT
Roland McGrathaf0575b2008-06-24 04:16:52 -0700364
365#ifdef CONFIG_AUDITSYSCALL
366sysenter_audit:
Ingo Molnara49976d2015-06-08 09:49:11 +0200367 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), TI_flags(%ebp)
368 jnz syscall_trace_entry
369 /* movl PT_EAX(%esp), %eax already set, syscall number: 1st arg to audit */
370 movl PT_EBX(%esp), %edx /* ebx/a0: 2nd arg to audit */
371 /* movl PT_ECX(%esp), %ecx already set, a1: 3nd arg to audit */
372 pushl PT_ESI(%esp) /* a3: 5th arg */
373 pushl PT_EDX+4(%esp) /* a2: 4th arg */
374 call __audit_syscall_entry
375 popl %ecx /* get that remapped edx off the stack */
376 popl %ecx /* get that remapped esi off the stack */
377 movl PT_EAX(%esp), %eax /* reload syscall number */
378 jmp sysenter_do_call
Roland McGrathaf0575b2008-06-24 04:16:52 -0700379
380sysexit_audit:
Ingo Molnara49976d2015-06-08 09:49:11 +0200381 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
382 jnz syscall_exit_work
Roland McGrathaf0575b2008-06-24 04:16:52 -0700383 TRACE_IRQS_ON
384 ENABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnara49976d2015-06-08 09:49:11 +0200385 movl %eax, %edx /* second arg, syscall return value */
386 cmpl $-MAX_ERRNO, %eax /* is it an error ? */
387 setbe %al /* 1 if so, 0 if not */
388 movzbl %al, %eax /* zero-extend that */
389 call __audit_syscall_exit
Roland McGrathaf0575b2008-06-24 04:16:52 -0700390 DISABLE_INTERRUPTS(CLBR_ANY)
391 TRACE_IRQS_OFF
Ingo Molnara49976d2015-06-08 09:49:11 +0200392 movl TI_flags(%ebp), %ecx
393 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
394 jnz syscall_exit_work
395 movl PT_EAX(%esp), %eax /* reload syscall return value */
396 jmp sysenter_exit
Roland McGrathaf0575b2008-06-24 04:16:52 -0700397#endif
398
Ingo Molnara49976d2015-06-08 09:49:11 +0200399.pushsection .fixup, "ax"
4002: movl $0, PT_FS(%esp)
401 jmp 1b
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100402.popsection
Ingo Molnara49976d2015-06-08 09:49:11 +0200403 _ASM_EXTABLE(1b, 2b)
Tejun Heoccbeed32009-02-09 22:17:40 +0900404 PTGS_TO_GS_EX
Ingo Molnar4c8cd0c2015-06-08 08:33:56 +0200405ENDPROC(entry_SYSENTER_32)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407 # system call handler stub
Ingo Molnarb2502b42015-06-08 08:42:03 +0200408ENTRY(entry_INT80_32)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700409 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200410 pushl %eax # save orig_eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 SAVE_ALL
412 GET_THREAD_INFO(%ebp)
Ingo Molnara49976d2015-06-08 09:49:11 +0200413 # system call tracing in operation / emulation
414 testl $_TIF_WORK_SYSCALL_ENTRY, TI_flags(%ebp)
415 jnz syscall_trace_entry
416 cmpl $(NR_syscalls), %eax
417 jae syscall_badsys
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418syscall_call:
Ingo Molnara49976d2015-06-08 09:49:11 +0200419 call *sys_call_table(, %eax, 4)
Sven Wegener8142b212014-07-22 10:26:06 +0200420syscall_after_call:
Ingo Molnara49976d2015-06-08 09:49:11 +0200421 movl %eax, PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422syscall_exit:
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200423 LOCKDEP_SYS_EXIT
Ingo Molnara49976d2015-06-08 09:49:11 +0200424 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
425 # setting need_resched or sigpending
426 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700427 TRACE_IRQS_OFF
Ingo Molnara49976d2015-06-08 09:49:11 +0200428 movl TI_flags(%ebp), %ecx
429 testl $_TIF_ALLWORK_MASK, %ecx # current->work
430 jnz syscall_exit_work
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432restore_all:
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200433 TRACE_IRQS_IRET
434restore_all_notrace:
H. Peter Anvin34273f42014-05-04 10:36:22 -0700435#ifdef CONFIG_X86_ESPFIX32
Ingo Molnara49976d2015-06-08 09:49:11 +0200436 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
437 /*
438 * Warning: PT_OLDSS(%esp) contains the wrong/random values if we
439 * are returning to the kernel.
440 * See comments in process.c:copy_thread() for details.
441 */
442 movb PT_OLDSS(%esp), %ah
443 movb PT_CS(%esp), %al
444 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
445 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
446 je ldt_ss # returning to user-space with LDT SS
H. Peter Anvin34273f42014-05-04 10:36:22 -0700447#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448restore_nocheck:
Ingo Molnara49976d2015-06-08 09:49:11 +0200449 RESTORE_REGS 4 # skip orig_eax/error_code
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200450irq_return:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100451 INTERRUPT_RETURN
Ingo Molnara49976d2015-06-08 09:49:11 +0200452.section .fixup, "ax"
453ENTRY(iret_exc )
454 pushl $0 # no error code
455 pushl $do_iret_error
456 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457.previous
Ingo Molnara49976d2015-06-08 09:49:11 +0200458 _ASM_EXTABLE(irq_return, iret_exc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
H. Peter Anvin34273f42014-05-04 10:36:22 -0700460#ifdef CONFIG_X86_ESPFIX32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461ldt_ss:
Rusty Russelld3561b72006-12-07 02:14:07 +0100462#ifdef CONFIG_PARAVIRT
463 /*
464 * The kernel can't run on a non-flat stack if paravirt mode
465 * is active. Rather than try to fixup the high bits of
466 * ESP, bypass this code entirely. This may break DOSemu
467 * and/or Wine support in a paravirt VM, although the option
468 * is still available to implement the setting of the high
469 * 16-bits in the INTERRUPT_RETURN paravirt-op.
470 */
Ingo Molnara49976d2015-06-08 09:49:11 +0200471 cmpl $0, pv_info+PARAVIRT_enabled
472 jne restore_nocheck
Rusty Russelld3561b72006-12-07 02:14:07 +0100473#endif
474
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200475/*
476 * Setup and switch to ESPFIX stack
477 *
478 * We're returning to userspace with a 16 bit stack. The CPU will not
479 * restore the high word of ESP for us on executing iret... This is an
480 * "official" bug of all the x86-compatible CPUs, which we can work
481 * around to make dosemu and wine happy. We do this by preloading the
482 * high word of ESP with the high word of the userspace ESP while
483 * compensating for the offset by changing to the ESPFIX segment with
484 * a base address that matches for the difference.
485 */
Brian Gerst72c511d2010-07-31 12:48:23 -0400486#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
Ingo Molnara49976d2015-06-08 09:49:11 +0200487 mov %esp, %edx /* load kernel esp */
488 mov PT_OLDESP(%esp), %eax /* load userspace esp */
489 mov %dx, %ax /* eax: new kernel esp */
490 sub %eax, %edx /* offset (low word is 0) */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200491 shr $16, %edx
Ingo Molnara49976d2015-06-08 09:49:11 +0200492 mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
493 mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
494 pushl $__ESPFIX_SS
495 pushl %eax /* new kernel esp */
496 /*
497 * Disable interrupts, but do not irqtrace this section: we
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200498 * will soon execute iret and the tracer was already set to
Ingo Molnara49976d2015-06-08 09:49:11 +0200499 * the irqstate after the IRET:
500 */
Rusty Russell139ec7c2006-12-07 02:14:08 +0100501 DISABLE_INTERRUPTS(CLBR_EAX)
Ingo Molnara49976d2015-06-08 09:49:11 +0200502 lss (%esp), %esp /* switch to espfix segment */
503 jmp restore_nocheck
H. Peter Anvin34273f42014-05-04 10:36:22 -0700504#endif
Ingo Molnarb2502b42015-06-08 08:42:03 +0200505ENDPROC(entry_INT80_32)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 # perform work that needs to be done immediately before resumption
508 ALIGN
509work_pending:
510 testb $_TIF_NEED_RESCHED, %cl
Ingo Molnara49976d2015-06-08 09:49:11 +0200511 jz work_notifysig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512work_resched:
Ingo Molnara49976d2015-06-08 09:49:11 +0200513 call schedule
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200514 LOCKDEP_SYS_EXIT
Ingo Molnara49976d2015-06-08 09:49:11 +0200515 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
516 # setting need_resched or sigpending
517 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700518 TRACE_IRQS_OFF
Ingo Molnara49976d2015-06-08 09:49:11 +0200519 movl TI_flags(%ebp), %ecx
520 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
521 # than syscall tracing?
522 jz restore_all
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 testb $_TIF_NEED_RESCHED, %cl
Ingo Molnara49976d2015-06-08 09:49:11 +0200524 jnz work_resched
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Ingo Molnara49976d2015-06-08 09:49:11 +0200526work_notifysig: # deal with pending signals and
527 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100528#ifdef CONFIG_VM86
Ingo Molnara49976d2015-06-08 09:49:11 +0200529 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
530 movl %esp, %eax
531 jnz work_notifysig_v86 # returning to kernel-space or
532 # vm86-space
Al Viro969ae0b2012-05-26 01:07:39 -04005331:
Joe Korty74b47a72006-12-07 02:14:04 +0100534#else
Ingo Molnara49976d2015-06-08 09:49:11 +0200535 movl %esp, %eax
Joe Korty74b47a72006-12-07 02:14:04 +0100536#endif
Srikar Dronamraju3596ff42011-10-25 19:48:12 +0530537 TRACE_IRQS_ON
538 ENABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnara49976d2015-06-08 09:49:11 +0200539 movb PT_CS(%esp), %bl
Al Viro44fbbb32012-04-30 18:24:46 -0400540 andb $SEGMENT_RPL_MASK, %bl
541 cmpb $USER_RPL, %bl
Ingo Molnara49976d2015-06-08 09:49:11 +0200542 jb resume_kernel
543 xorl %edx, %edx
544 call do_notify_resume
545 jmp resume_userspace
Al Viro969ae0b2012-05-26 01:07:39 -0400546
547#ifdef CONFIG_VM86
548 ALIGN
549work_notifysig_v86:
Ingo Molnara49976d2015-06-08 09:49:11 +0200550 pushl %ecx # save ti_flags for do_notify_resume
551 call save_v86_state # %eax contains pt_regs pointer
552 popl %ecx
553 movl %eax, %esp
554 jmp 1b
Al Viro969ae0b2012-05-26 01:07:39 -0400555#endif
Jan Beulich47a55cd2007-02-13 13:26:24 +0100556END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 # perform syscall exit tracing
559 ALIGN
560syscall_trace_entry:
Ingo Molnara49976d2015-06-08 09:49:11 +0200561 movl $-ENOSYS, PT_EAX(%esp)
562 movl %esp, %eax
563 call syscall_trace_enter
Roland McGrathd4d67152008-07-09 02:38:07 -0700564 /* What it returned is what we'll actually use. */
Ingo Molnara49976d2015-06-08 09:49:11 +0200565 cmpl $(NR_syscalls), %eax
566 jnae syscall_call
567 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100568END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 # perform syscall exit tracing
571 ALIGN
572syscall_exit_work:
Ingo Molnara49976d2015-06-08 09:49:11 +0200573 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
574 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700575 TRACE_IRQS_ON
Ingo Molnara49976d2015-06-08 09:49:11 +0200576 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
577 # schedule() instead
578 movl %esp, %eax
579 call syscall_trace_leave
580 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100581END(syscall_exit_work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583syscall_fault:
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700584 ASM_CLAC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 GET_THREAD_INFO(%ebp)
Ingo Molnara49976d2015-06-08 09:49:11 +0200586 movl $-EFAULT, PT_EAX(%esp)
587 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100588END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590syscall_badsys:
Ingo Molnara49976d2015-06-08 09:49:11 +0200591 movl $-ENOSYS, %eax
592 jmp syscall_after_call
Andy Lutomirski554086d2014-06-23 14:22:15 -0700593END(syscall_badsys)
594
595sysenter_badsys:
Ingo Molnara49976d2015-06-08 09:49:11 +0200596 movl $-ENOSYS, %eax
597 jmp sysenter_after_call
Stefan Baderfb21b842014-08-15 10:57:46 +0200598END(sysenter_badsys)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Tejun Heof0d96112009-02-09 22:17:40 +0900600.macro FIXUP_ESPFIX_STACK
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200601/*
602 * Switch back for ESPFIX stack to the normal zerobased stack
603 *
604 * We can't call C functions using the ESPFIX stack. This code reads
605 * the high word of the segment base from the GDT and swiches to the
606 * normal stack and adjusts ESP with the matching offset.
607 */
H. Peter Anvin34273f42014-05-04 10:36:22 -0700608#ifdef CONFIG_X86_ESPFIX32
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200609 /* fixup the stack */
Ingo Molnara49976d2015-06-08 09:49:11 +0200610 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
611 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200612 shl $16, %eax
Ingo Molnara49976d2015-06-08 09:49:11 +0200613 addl %esp, %eax /* the adjusted stack pointer */
614 pushl $__KERNEL_DS
615 pushl %eax
616 lss (%esp), %esp /* switch to the normal stack segment */
H. Peter Anvin34273f42014-05-04 10:36:22 -0700617#endif
Tejun Heof0d96112009-02-09 22:17:40 +0900618.endm
619.macro UNWIND_ESPFIX_STACK
H. Peter Anvin34273f42014-05-04 10:36:22 -0700620#ifdef CONFIG_X86_ESPFIX32
Ingo Molnara49976d2015-06-08 09:49:11 +0200621 movl %ss, %eax
Tejun Heof0d96112009-02-09 22:17:40 +0900622 /* see if on espfix stack */
Ingo Molnara49976d2015-06-08 09:49:11 +0200623 cmpw $__ESPFIX_SS, %ax
624 jne 27f
625 movl $__KERNEL_DS, %eax
626 movl %eax, %ds
627 movl %eax, %es
Tejun Heof0d96112009-02-09 22:17:40 +0900628 /* switch to normal stack */
629 FIXUP_ESPFIX_STACK
63027:
H. Peter Anvin34273f42014-05-04 10:36:22 -0700631#endif
Tejun Heof0d96112009-02-09 22:17:40 +0900632.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634/*
Denys Vlasenko3304c9c2015-04-03 21:49:13 +0200635 * Build the entry stubs with some assembler magic.
636 * We pack 1 stub into every 8-byte block.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 */
Denys Vlasenko3304c9c2015-04-03 21:49:13 +0200638 .align 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639ENTRY(irq_entries_start)
Denys Vlasenko3304c9c2015-04-03 21:49:13 +0200640 vector=FIRST_EXTERNAL_VECTOR
641 .rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR)
Ingo Molnara49976d2015-06-08 09:49:11 +0200642 pushl $(~vector+0x80) /* Note: always in signed byte range */
Denys Vlasenko3304c9c2015-04-03 21:49:13 +0200643 vector=vector+1
644 jmp common_interrupt
Denys Vlasenko3304c9c2015-04-03 21:49:13 +0200645 .align 8
646 .endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100647END(irq_entries_start)
648
Ingo Molnar55f327f2006-07-03 00:24:43 -0700649/*
650 * the CPU automatically disables interrupts when executing an IRQ vector,
651 * so IRQ-flags tracing has to follow that:
652 */
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800653 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654common_interrupt:
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700655 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200656 addl $-0x80, (%esp) /* Adjust vector into the [-256, -1] range */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700658 TRACE_IRQS_OFF
Ingo Molnara49976d2015-06-08 09:49:11 +0200659 movl %esp, %eax
660 call do_IRQ
661 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100662ENDPROC(common_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Tejun Heo02cf94c2009-01-21 17:26:06 +0900664#define BUILD_INTERRUPT3(name, nr, fn) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665ENTRY(name) \
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700666 ASM_CLAC; \
Ingo Molnara49976d2015-06-08 09:49:11 +0200667 pushl $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200668 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700669 TRACE_IRQS_OFF \
Ingo Molnara49976d2015-06-08 09:49:11 +0200670 movl %esp, %eax; \
671 call fn; \
672 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100673ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Seiji Aguchicf910e82013-06-20 11:46:53 -0400675
676#ifdef CONFIG_TRACING
Ingo Molnara49976d2015-06-08 09:49:11 +0200677# define TRACE_BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(trace_##name, nr, smp_trace_##name)
Seiji Aguchicf910e82013-06-20 11:46:53 -0400678#else
Ingo Molnara49976d2015-06-08 09:49:11 +0200679# define TRACE_BUILD_INTERRUPT(name, nr)
Seiji Aguchicf910e82013-06-20 11:46:53 -0400680#endif
681
Ingo Molnara49976d2015-06-08 09:49:11 +0200682#define BUILD_INTERRUPT(name, nr) \
683 BUILD_INTERRUPT3(name, nr, smp_##name); \
Seiji Aguchicf910e82013-06-20 11:46:53 -0400684 TRACE_BUILD_INTERRUPT(name, nr)
Tejun Heo02cf94c2009-01-21 17:26:06 +0900685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686/* The include is where all of the SMP etc. interrupts come from */
Ingo Molnar1164dd02009-01-28 19:34:09 +0100687#include <asm/entry_arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689ENTRY(coprocessor_error)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700690 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200691 pushl $0
692 pushl $do_coprocessor_error
693 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100694END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696ENTRY(simd_coprocessor_error)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700697 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200698 pushl $0
Brian Gerst40d2e762010-03-21 09:00:43 -0400699#ifdef CONFIG_X86_INVD_BUG
700 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
Ingo Molnara49976d2015-06-08 09:49:11 +0200701 ALTERNATIVE "pushl $do_general_protection", \
702 "pushl $do_simd_coprocessor_error", \
Borislav Petkov8e65f6e2015-01-18 12:35:55 +0100703 X86_FEATURE_XMM
Brian Gerst40d2e762010-03-21 09:00:43 -0400704#else
Ingo Molnara49976d2015-06-08 09:49:11 +0200705 pushl $do_simd_coprocessor_error
Brian Gerst40d2e762010-03-21 09:00:43 -0400706#endif
Ingo Molnara49976d2015-06-08 09:49:11 +0200707 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100708END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710ENTRY(device_not_available)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700711 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200712 pushl $-1 # mark this as an int
713 pushl $do_device_not_available
714 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100715END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Rusty Russelld3561b72006-12-07 02:14:07 +0100717#ifdef CONFIG_PARAVIRT
718ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100719 iret
H. Peter Anvin6837a542012-04-20 12:19:50 -0700720 _ASM_EXTABLE(native_iret, iret_exc)
Jan Beulich47a55cd2007-02-13 13:26:24 +0100721END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100722
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400723ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100724 sti
725 sysexit
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400726END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100727#endif
728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729ENTRY(overflow)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700730 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200731 pushl $0
732 pushl $do_overflow
733 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100734END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736ENTRY(bounds)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700737 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200738 pushl $0
739 pushl $do_bounds
740 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100741END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743ENTRY(invalid_op)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700744 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200745 pushl $0
746 pushl $do_invalid_op
747 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100748END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750ENTRY(coprocessor_segment_overrun)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700751 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200752 pushl $0
753 pushl $do_coprocessor_segment_overrun
754 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100755END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757ENTRY(invalid_TSS)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700758 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200759 pushl $do_invalid_TSS
760 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100761END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763ENTRY(segment_not_present)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700764 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200765 pushl $do_segment_not_present
766 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100767END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769ENTRY(stack_segment)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700770 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200771 pushl $do_stack_segment
772 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100773END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775ENTRY(alignment_check)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700776 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200777 pushl $do_alignment_check
778 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100779END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200781ENTRY(divide_error)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700782 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200783 pushl $0 # no error code
784 pushl $do_divide_error
785 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100786END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788#ifdef CONFIG_X86_MCE
789ENTRY(machine_check)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700790 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200791 pushl $0
792 pushl machine_check_vector
793 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100794END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795#endif
796
797ENTRY(spurious_interrupt_bug)
H. Peter Anvine59d1b02012-09-21 13:58:10 -0700798 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +0200799 pushl $0
800 pushl $do_spurious_interrupt_bug
801 jmp error_code
Jan Beulich47a55cd2007-02-13 13:26:24 +0100802END(spurious_interrupt_bug)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700804#ifdef CONFIG_XEN
Ingo Molnara49976d2015-06-08 09:49:11 +0200805/*
806 * Xen doesn't set %esp to be precisely what the normal SYSENTER
807 * entry point expects, so fix it up before using the normal path.
808 */
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700809ENTRY(xen_sysenter_target)
Ingo Molnara49976d2015-06-08 09:49:11 +0200810 addl $5*4, %esp /* remove xen-provided frame */
811 jmp sysenter_past_esp
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700812
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700813ENTRY(xen_hypervisor_callback)
Ingo Molnara49976d2015-06-08 09:49:11 +0200814 pushl $-1 /* orig_ax = -1 => not a system call */
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700815 SAVE_ALL
816 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -0700817
Ingo Molnara49976d2015-06-08 09:49:11 +0200818 /*
819 * Check to see if we got the event in the critical
820 * region in xen_iret_direct, after we've reenabled
821 * events and checked for pending events. This simulates
822 * iret instruction's behaviour where it delivers a
823 * pending interrupt when enabling interrupts:
824 */
825 movl PT_EIP(%esp), %eax
826 cmpl $xen_iret_start_crit, %eax
827 jb 1f
828 cmpl $xen_iret_end_crit, %eax
829 jae 1f
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -0700830
Ingo Molnara49976d2015-06-08 09:49:11 +0200831 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -0700832
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700833ENTRY(xen_do_upcall)
Ingo Molnara49976d2015-06-08 09:49:11 +02008341: mov %esp, %eax
835 call xen_evtchn_do_upcall
David Vrabelfdfd8112015-02-19 15:23:17 +0000836#ifndef CONFIG_PREEMPT
Ingo Molnara49976d2015-06-08 09:49:11 +0200837 call xen_maybe_preempt_hcall
David Vrabelfdfd8112015-02-19 15:23:17 +0000838#endif
Ingo Molnara49976d2015-06-08 09:49:11 +0200839 jmp ret_from_intr
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700840ENDPROC(xen_hypervisor_callback)
841
Ingo Molnara49976d2015-06-08 09:49:11 +0200842/*
843 * Hypervisor uses this for application faults while it executes.
844 * We get here for two reasons:
845 * 1. Fault while reloading DS, ES, FS or GS
846 * 2. Fault while executing IRET
847 * Category 1 we fix up by reattempting the load, and zeroing the segment
848 * register if the load fails.
849 * Category 2 we fix up by jumping to do_iret_error. We cannot use the
850 * normal Linux return path in this case because if we use the IRET hypercall
851 * to pop the stack frame we end up in an infinite loop of failsafe callbacks.
852 * We distinguish between categories by maintaining a status value in EAX.
853 */
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700854ENTRY(xen_failsafe_callback)
Ingo Molnara49976d2015-06-08 09:49:11 +0200855 pushl %eax
856 movl $1, %eax
8571: mov 4(%esp), %ds
8582: mov 8(%esp), %es
8593: mov 12(%esp), %fs
8604: mov 16(%esp), %gs
David Vrabela349e23d12012-10-19 17:29:07 +0100861 /* EAX == 0 => Category 1 (Bad segment)
862 EAX != 0 => Category 2 (Bad IRET) */
Ingo Molnara49976d2015-06-08 09:49:11 +0200863 testl %eax, %eax
864 popl %eax
865 lea 16(%esp), %esp
866 jz 5f
867 jmp iret_exc
8685: pushl $-1 /* orig_ax = -1 => not a system call */
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700869 SAVE_ALL
Ingo Molnara49976d2015-06-08 09:49:11 +0200870 jmp ret_from_exception
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700871
Ingo Molnara49976d2015-06-08 09:49:11 +0200872.section .fixup, "ax"
8736: xorl %eax, %eax
874 movl %eax, 4(%esp)
875 jmp 1b
8767: xorl %eax, %eax
877 movl %eax, 8(%esp)
878 jmp 2b
8798: xorl %eax, %eax
880 movl %eax, 12(%esp)
881 jmp 3b
8829: xorl %eax, %eax
883 movl %eax, 16(%esp)
884 jmp 4b
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700885.previous
Ingo Molnara49976d2015-06-08 09:49:11 +0200886 _ASM_EXTABLE(1b, 6b)
887 _ASM_EXTABLE(2b, 7b)
888 _ASM_EXTABLE(3b, 8b)
889 _ASM_EXTABLE(4b, 9b)
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700890ENDPROC(xen_failsafe_callback)
891
K. Y. Srinivasanbc2b0332013-02-03 17:22:39 -0800892BUILD_INTERRUPT3(xen_hvm_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
Sheng Yang38e20b02010-05-14 12:40:51 +0100893 xen_evtchn_do_upcall)
894
Ingo Molnara49976d2015-06-08 09:49:11 +0200895#endif /* CONFIG_XEN */
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700896
K. Y. Srinivasanbc2b0332013-02-03 17:22:39 -0800897#if IS_ENABLED(CONFIG_HYPERV)
898
899BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
900 hyperv_vector_handler)
901
902#endif /* CONFIG_HYPERV */
903
Steven Rostedt606576c2008-10-06 19:06:12 -0400904#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200905#ifdef CONFIG_DYNAMIC_FTRACE
906
907ENTRY(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200908 ret
909END(mcount)
910
911ENTRY(ftrace_caller)
Ingo Molnara49976d2015-06-08 09:49:11 +0200912 pushl %eax
913 pushl %ecx
914 pushl %edx
915 pushl $0 /* Pass NULL as regs pointer */
916 movl 4*4(%esp), %eax
917 movl 0x4(%ebp), %edx
918 movl function_trace_op, %ecx
919 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200920
921.globl ftrace_call
922ftrace_call:
Ingo Molnara49976d2015-06-08 09:49:11 +0200923 call ftrace_stub
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200924
Ingo Molnara49976d2015-06-08 09:49:11 +0200925 addl $4, %esp /* skip NULL pointer */
926 popl %edx
927 popl %ecx
928 popl %eax
Steven Rostedt4de72392012-06-05 20:00:11 -0400929ftrace_ret:
Steven Rostedt5a45cfe2008-11-26 00:16:24 -0500930#ifdef CONFIG_FUNCTION_GRAPH_TRACER
931.globl ftrace_graph_call
932ftrace_graph_call:
Ingo Molnara49976d2015-06-08 09:49:11 +0200933 jmp ftrace_stub
Steven Rostedt5a45cfe2008-11-26 00:16:24 -0500934#endif
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200935
936.globl ftrace_stub
937ftrace_stub:
938 ret
939END(ftrace_caller)
940
Steven Rostedt4de72392012-06-05 20:00:11 -0400941ENTRY(ftrace_regs_caller)
942 pushf /* push flags before compare (in cs location) */
Steven Rostedt4de72392012-06-05 20:00:11 -0400943
944 /*
945 * i386 does not save SS and ESP when coming from kernel.
946 * Instead, to get sp, &regs->sp is used (see ptrace.h).
947 * Unfortunately, that means eflags must be at the same location
948 * as the current return ip is. We move the return ip into the
949 * ip location, and move flags into the return ip location.
950 */
Ingo Molnara49976d2015-06-08 09:49:11 +0200951 pushl 4(%esp) /* save return ip into ip slot */
Steven Rostedt4de72392012-06-05 20:00:11 -0400952
Ingo Molnara49976d2015-06-08 09:49:11 +0200953 pushl $0 /* Load 0 into orig_ax */
954 pushl %gs
955 pushl %fs
956 pushl %es
957 pushl %ds
958 pushl %eax
959 pushl %ebp
960 pushl %edi
961 pushl %esi
962 pushl %edx
963 pushl %ecx
964 pushl %ebx
Steven Rostedt4de72392012-06-05 20:00:11 -0400965
Ingo Molnara49976d2015-06-08 09:49:11 +0200966 movl 13*4(%esp), %eax /* Get the saved flags */
967 movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */
968 /* clobbering return ip */
969 movl $__KERNEL_CS, 13*4(%esp)
Steven Rostedt4de72392012-06-05 20:00:11 -0400970
Ingo Molnara49976d2015-06-08 09:49:11 +0200971 movl 12*4(%esp), %eax /* Load ip (1st parameter) */
972 subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
973 movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
974 movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
975 pushl %esp /* Save pt_regs as 4th parameter */
Steven Rostedt4de72392012-06-05 20:00:11 -0400976
977GLOBAL(ftrace_regs_call)
Ingo Molnara49976d2015-06-08 09:49:11 +0200978 call ftrace_stub
Steven Rostedt4de72392012-06-05 20:00:11 -0400979
Ingo Molnara49976d2015-06-08 09:49:11 +0200980 addl $4, %esp /* Skip pt_regs */
981 movl 14*4(%esp), %eax /* Move flags back into cs */
982 movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */
983 movl 12*4(%esp), %eax /* Get return ip from regs->ip */
984 movl %eax, 14*4(%esp) /* Put return ip back for ret */
Steven Rostedt4de72392012-06-05 20:00:11 -0400985
Ingo Molnara49976d2015-06-08 09:49:11 +0200986 popl %ebx
987 popl %ecx
988 popl %edx
989 popl %esi
990 popl %edi
991 popl %ebp
992 popl %eax
993 popl %ds
994 popl %es
995 popl %fs
996 popl %gs
997 addl $8, %esp /* Skip orig_ax and ip */
998 popf /* Pop flags at end (no addl to corrupt flags) */
999 jmp ftrace_ret
Steven Rostedt4de72392012-06-05 20:00:11 -04001000
Steven Rostedt4de72392012-06-05 20:00:11 -04001001 popf
Ingo Molnara49976d2015-06-08 09:49:11 +02001002 jmp ftrace_stub
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001003#else /* ! CONFIG_DYNAMIC_FTRACE */
1004
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001005ENTRY(mcount)
Ingo Molnara49976d2015-06-08 09:49:11 +02001006 cmpl $__PAGE_OFFSET, %esp
1007 jb ftrace_stub /* Paging not enabled yet? */
H. Peter Anvinaf058ab2013-08-30 17:29:29 -07001008
Ingo Molnara49976d2015-06-08 09:49:11 +02001009 cmpl $ftrace_stub, ftrace_trace_function
1010 jnz trace
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001011#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Ingo Molnara49976d2015-06-08 09:49:11 +02001012 cmpl $ftrace_stub, ftrace_graph_return
1013 jnz ftrace_graph_caller
Steven Rostedte49dc192008-12-02 23:50:05 -05001014
Ingo Molnara49976d2015-06-08 09:49:11 +02001015 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1016 jnz ftrace_graph_caller
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001017#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001018.globl ftrace_stub
1019ftrace_stub:
1020 ret
1021
1022 /* taken from glibc */
1023trace:
Ingo Molnara49976d2015-06-08 09:49:11 +02001024 pushl %eax
1025 pushl %ecx
1026 pushl %edx
1027 movl 0xc(%esp), %eax
1028 movl 0x4(%ebp), %edx
1029 subl $MCOUNT_INSN_SIZE, %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001030
Ingo Molnara49976d2015-06-08 09:49:11 +02001031 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001032
Ingo Molnara49976d2015-06-08 09:49:11 +02001033 popl %edx
1034 popl %ecx
1035 popl %eax
1036 jmp ftrace_stub
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001037END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001038#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt606576c2008-10-06 19:06:12 -04001039#endif /* CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001040
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001041#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1042ENTRY(ftrace_graph_caller)
Ingo Molnara49976d2015-06-08 09:49:11 +02001043 pushl %eax
1044 pushl %ecx
1045 pushl %edx
1046 movl 0xc(%esp), %eax
1047 lea 0x4(%ebp), %edx
1048 movl (%ebp), %ecx
1049 subl $MCOUNT_INSN_SIZE, %eax
1050 call prepare_ftrace_return
1051 popl %edx
1052 popl %ecx
1053 popl %eax
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001054 ret
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001055END(ftrace_graph_caller)
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001056
1057.globl return_to_handler
1058return_to_handler:
Ingo Molnara49976d2015-06-08 09:49:11 +02001059 pushl %eax
1060 pushl %edx
1061 movl %ebp, %eax
1062 call ftrace_return_to_handler
1063 movl %eax, %ecx
1064 popl %edx
1065 popl %eax
1066 jmp *%ecx
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001067#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Seiji Aguchi25c74b12013-10-30 16:37:00 -04001069#ifdef CONFIG_TRACING
1070ENTRY(trace_page_fault)
Seiji Aguchi25c74b12013-10-30 16:37:00 -04001071 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +02001072 pushl $trace_do_page_fault
1073 jmp error_code
Seiji Aguchi25c74b12013-10-30 16:37:00 -04001074END(trace_page_fault)
1075#endif
1076
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001077ENTRY(page_fault)
H. Peter Anvine59d1b02012-09-21 13:58:10 -07001078 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +02001079 pushl $do_page_fault
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001080 ALIGN
1081error_code:
Tejun Heoccbeed32009-02-09 22:17:40 +09001082 /* the function address is in %gs's slot on the stack */
Ingo Molnara49976d2015-06-08 09:49:11 +02001083 pushl %fs
1084 pushl %es
1085 pushl %ds
1086 pushl %eax
1087 pushl %ebp
1088 pushl %edi
1089 pushl %esi
1090 pushl %edx
1091 pushl %ecx
1092 pushl %ebx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001093 cld
Ingo Molnara49976d2015-06-08 09:49:11 +02001094 movl $(__KERNEL_PERCPU), %ecx
1095 movl %ecx, %fs
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001096 UNWIND_ESPFIX_STACK
Tejun Heoccbeed32009-02-09 22:17:40 +09001097 GS_TO_REG %ecx
Ingo Molnara49976d2015-06-08 09:49:11 +02001098 movl PT_GS(%esp), %edi # get the function address
1099 movl PT_ORIG_EAX(%esp), %edx # get the error code
1100 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Tejun Heoccbeed32009-02-09 22:17:40 +09001101 REG_TO_PTGS %ecx
1102 SET_KERNEL_GS %ecx
Ingo Molnara49976d2015-06-08 09:49:11 +02001103 movl $(__USER_DS), %ecx
1104 movl %ecx, %ds
1105 movl %ecx, %es
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001106 TRACE_IRQS_OFF
Ingo Molnara49976d2015-06-08 09:49:11 +02001107 movl %esp, %eax # pt_regs pointer
1108 call *%edi
1109 jmp ret_from_exception
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001110END(page_fault)
1111
1112/*
1113 * Debug traps and NMI can happen at the one SYSENTER instruction
1114 * that sets up the real kernel stack. Check here, since we can't
1115 * allow the wrong stack to be used.
1116 *
1117 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1118 * already pushed 3 words if it hits on the sysenter instruction:
1119 * eflags, cs and eip.
1120 *
1121 * We just load the right stack, and push the three (known) values
1122 * by hand onto the new stack - while updating the return eip past
1123 * the instruction that would have done it for sysenter.
1124 */
Tejun Heof0d96112009-02-09 22:17:40 +09001125.macro FIX_STACK offset ok label
Ingo Molnara49976d2015-06-08 09:49:11 +02001126 cmpw $__KERNEL_CS, 4(%esp)
1127 jne \ok
Tejun Heof0d96112009-02-09 22:17:40 +09001128\label:
Ingo Molnara49976d2015-06-08 09:49:11 +02001129 movl TSS_sysenter_sp0 + \offset(%esp), %esp
Ingo Molnar131484c2015-05-28 12:21:47 +02001130 pushfl
Ingo Molnara49976d2015-06-08 09:49:11 +02001131 pushl $__KERNEL_CS
1132 pushl $sysenter_past_esp
Tejun Heof0d96112009-02-09 22:17:40 +09001133.endm
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001134
1135ENTRY(debug)
H. Peter Anvine59d1b02012-09-21 13:58:10 -07001136 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +02001137 cmpl $entry_SYSENTER_32, (%esp)
1138 jne debug_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001139 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001140debug_stack_correct:
Ingo Molnara49976d2015-06-08 09:49:11 +02001141 pushl $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001142 SAVE_ALL
1143 TRACE_IRQS_OFF
Ingo Molnara49976d2015-06-08 09:49:11 +02001144 xorl %edx, %edx # error code 0
1145 movl %esp, %eax # pt_regs pointer
1146 call do_debug
1147 jmp ret_from_exception
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001148END(debug)
1149
1150/*
1151 * NMI is doubly nasty. It can happen _while_ we're handling
1152 * a debug fault, and the debug fault hasn't yet been able to
1153 * clear up the stack. So we first check whether we got an
1154 * NMI on the sysenter entry path, but after that we need to
1155 * check whether we got an NMI on the debug path where the debug
1156 * fault happened on the sysenter path.
1157 */
1158ENTRY(nmi)
H. Peter Anvine59d1b02012-09-21 13:58:10 -07001159 ASM_CLAC
H. Peter Anvin34273f42014-05-04 10:36:22 -07001160#ifdef CONFIG_X86_ESPFIX32
Ingo Molnara49976d2015-06-08 09:49:11 +02001161 pushl %eax
1162 movl %ss, %eax
1163 cmpw $__ESPFIX_SS, %ax
1164 popl %eax
1165 je nmi_espfix_stack
H. Peter Anvin34273f42014-05-04 10:36:22 -07001166#endif
Ingo Molnara49976d2015-06-08 09:49:11 +02001167 cmpl $entry_SYSENTER_32, (%esp)
1168 je nmi_stack_fixup
1169 pushl %eax
1170 movl %esp, %eax
1171 /*
1172 * Do not access memory above the end of our stack page,
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001173 * it might not exist.
1174 */
Ingo Molnara49976d2015-06-08 09:49:11 +02001175 andl $(THREAD_SIZE-1), %eax
1176 cmpl $(THREAD_SIZE-20), %eax
1177 popl %eax
1178 jae nmi_stack_correct
1179 cmpl $entry_SYSENTER_32, 12(%esp)
1180 je nmi_debug_stack_check
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001181nmi_stack_correct:
Ingo Molnara49976d2015-06-08 09:49:11 +02001182 pushl %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001183 SAVE_ALL
Ingo Molnara49976d2015-06-08 09:49:11 +02001184 xorl %edx, %edx # zero error code
1185 movl %esp, %eax # pt_regs pointer
1186 call do_nmi
1187 jmp restore_all_notrace
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001188
1189nmi_stack_fixup:
Tejun Heof0d96112009-02-09 22:17:40 +09001190 FIX_STACK 12, nmi_stack_correct, 1
Ingo Molnara49976d2015-06-08 09:49:11 +02001191 jmp nmi_stack_correct
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001192
1193nmi_debug_stack_check:
Ingo Molnara49976d2015-06-08 09:49:11 +02001194 cmpw $__KERNEL_CS, 16(%esp)
1195 jne nmi_stack_correct
1196 cmpl $debug, (%esp)
1197 jb nmi_stack_correct
1198 cmpl $debug_esp_fix_insn, (%esp)
1199 ja nmi_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001200 FIX_STACK 24, nmi_stack_correct, 1
Ingo Molnara49976d2015-06-08 09:49:11 +02001201 jmp nmi_stack_correct
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001202
H. Peter Anvin34273f42014-05-04 10:36:22 -07001203#ifdef CONFIG_X86_ESPFIX32
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001204nmi_espfix_stack:
Ingo Molnar131484c2015-05-28 12:21:47 +02001205 /*
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001206 * create the pointer to lss back
1207 */
Ingo Molnara49976d2015-06-08 09:49:11 +02001208 pushl %ss
1209 pushl %esp
1210 addl $4, (%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001211 /* copy the iret frame of 12 bytes */
1212 .rept 3
Ingo Molnara49976d2015-06-08 09:49:11 +02001213 pushl 16(%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001214 .endr
Ingo Molnara49976d2015-06-08 09:49:11 +02001215 pushl %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001216 SAVE_ALL
Ingo Molnara49976d2015-06-08 09:49:11 +02001217 FIXUP_ESPFIX_STACK # %eax == %esp
1218 xorl %edx, %edx # zero error code
1219 call do_nmi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001220 RESTORE_REGS
Ingo Molnara49976d2015-06-08 09:49:11 +02001221 lss 12+4(%esp), %esp # back to espfix stack
1222 jmp irq_return
H. Peter Anvin34273f42014-05-04 10:36:22 -07001223#endif
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001224END(nmi)
1225
1226ENTRY(int3)
H. Peter Anvine59d1b02012-09-21 13:58:10 -07001227 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +02001228 pushl $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001229 SAVE_ALL
1230 TRACE_IRQS_OFF
Ingo Molnara49976d2015-06-08 09:49:11 +02001231 xorl %edx, %edx # zero error code
1232 movl %esp, %eax # pt_regs pointer
1233 call do_int3
1234 jmp ret_from_exception
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001235END(int3)
1236
1237ENTRY(general_protection)
Ingo Molnara49976d2015-06-08 09:49:11 +02001238 pushl $do_general_protection
1239 jmp error_code
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001240END(general_protection)
1241
Gleb Natapov631bc482010-10-14 11:22:52 +02001242#ifdef CONFIG_KVM_GUEST
1243ENTRY(async_page_fault)
H. Peter Anvine59d1b02012-09-21 13:58:10 -07001244 ASM_CLAC
Ingo Molnara49976d2015-06-08 09:49:11 +02001245 pushl $do_async_page_fault
1246 jmp error_code
Sedat Dilek2ae9d292011-03-08 22:39:24 +01001247END(async_page_fault)
Gleb Natapov631bc482010-10-14 11:22:52 +02001248#endif