x86/asm/entry/64: Rename THREAD_INFO() to ASM_THREAD_INFO()
[deliverable/linux.git] / arch / x86 / kernel / entry_64.S
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/x86_64/entry.S
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs
6 * Copyright (C) 2000 Pavel Machek <pavel@suse.cz>
1da177e4
LT
7 */
8
9/*
10 * entry.S contains the system-call and fault low-level handling routines.
11 *
8b4777a4
AL
12 * Some of this is documented in Documentation/x86/entry_64.txt
13 *
1da177e4
LT
14 * NOTE: This code handles signal-recognition, which happens every time
15 * after an interrupt and after each system call.
0bd7b798 16 *
0bd7b798 17 * A note on terminology:
7fcb3bc3 18 * - iret frame: Architecture defined interrupt frame from SS to RIP
0bd7b798 19 * at the top of the kernel process stack.
2e91a17b
AK
20 *
21 * Some macro usage:
22 * - CFI macros are used to generate dwarf2 unwind information for better
23 * backtraces. They don't change any code.
2e91a17b 24 * - ENTRY/END Define functions in the symbol table.
2e91a17b 25 * - TRACE_IRQ_* - Trace hard interrupt state for lock debugging.
cb5dd2c5 26 * - idtentry - Define exception entry points.
1da177e4
LT
27 */
28
1da177e4
LT
29#include <linux/linkage.h>
30#include <asm/segment.h>
1da177e4
LT
31#include <asm/cache.h>
32#include <asm/errno.h>
33#include <asm/dwarf2.h>
34#include <asm/calling.h>
e2d5df93 35#include <asm/asm-offsets.h>
1da177e4
LT
36#include <asm/msr.h>
37#include <asm/unistd.h>
38#include <asm/thread_info.h>
39#include <asm/hw_irq.h>
0341c14d 40#include <asm/page_types.h>
2601e64d 41#include <asm/irqflags.h>
72fe4858 42#include <asm/paravirt.h>
9939ddaf 43#include <asm/percpu.h>
d7abc0fa 44#include <asm/asm.h>
91d1aa43 45#include <asm/context_tracking.h>
63bcff2a 46#include <asm/smap.h>
3891a04a 47#include <asm/pgtable_types.h>
d7e7528b 48#include <linux/err.h>
1da177e4 49
86a1c34a
RM
50/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
51#include <linux/elf-em.h>
52#define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
53#define __AUDIT_ARCH_64BIT 0x80000000
54#define __AUDIT_ARCH_LE 0x40000000
55
1da177e4 56 .code64
ea714547
JO
57 .section .entry.text, "ax"
58
16444a8a 59
dc37db4d 60#ifndef CONFIG_PREEMPT
1da177e4 61#define retint_kernel retint_restore_args
0bd7b798 62#endif
2601e64d 63
72fe4858 64#ifdef CONFIG_PARAVIRT
2be29982 65ENTRY(native_usergs_sysret64)
72fe4858
GOC
66 swapgs
67 sysretq
b3baaa13 68ENDPROC(native_usergs_sysret64)
72fe4858
GOC
69#endif /* CONFIG_PARAVIRT */
70
2601e64d 71
f2db9382 72.macro TRACE_IRQS_IRETQ
2601e64d 73#ifdef CONFIG_TRACE_IRQFLAGS
f2db9382 74 bt $9,EFLAGS(%rsp) /* interrupts off? */
2601e64d
IM
75 jnc 1f
76 TRACE_IRQS_ON
771:
78#endif
79.endm
80
5963e317
SR
81/*
82 * When dynamic function tracer is enabled it will add a breakpoint
83 * to all locations that it is about to modify, sync CPUs, update
84 * all the code, sync CPUs, then remove the breakpoints. In this time
85 * if lockdep is enabled, it might jump back into the debug handler
86 * outside the updating of the IST protection. (TRACE_IRQS_ON/OFF).
87 *
88 * We need to change the IDT table before calling TRACE_IRQS_ON/OFF to
89 * make sure the stack pointer does not get reset back to the top
90 * of the debug stack, and instead just reuses the current stack.
91 */
92#if defined(CONFIG_DYNAMIC_FTRACE) && defined(CONFIG_TRACE_IRQFLAGS)
93
94.macro TRACE_IRQS_OFF_DEBUG
95 call debug_stack_set_zero
96 TRACE_IRQS_OFF
97 call debug_stack_reset
98.endm
99
100.macro TRACE_IRQS_ON_DEBUG
101 call debug_stack_set_zero
102 TRACE_IRQS_ON
103 call debug_stack_reset
104.endm
105
f2db9382
DV
106.macro TRACE_IRQS_IRETQ_DEBUG
107 bt $9,EFLAGS(%rsp) /* interrupts off? */
5963e317
SR
108 jnc 1f
109 TRACE_IRQS_ON_DEBUG
1101:
111.endm
112
113#else
114# define TRACE_IRQS_OFF_DEBUG TRACE_IRQS_OFF
115# define TRACE_IRQS_ON_DEBUG TRACE_IRQS_ON
116# define TRACE_IRQS_IRETQ_DEBUG TRACE_IRQS_IRETQ
117#endif
118
dcd072e2 119/*
e90e147c 120 * empty frame
dcd072e2
AH
121 */
122 .macro EMPTY_FRAME start=1 offset=0
7effaa88 123 .if \start
dcd072e2 124 CFI_STARTPROC simple
adf14236 125 CFI_SIGNAL_FRAME
dcd072e2 126 CFI_DEF_CFA rsp,8+\offset
7effaa88 127 .else
dcd072e2 128 CFI_DEF_CFA_OFFSET 8+\offset
7effaa88 129 .endif
1da177e4 130 .endm
d99015b1
AH
131
132/*
dcd072e2 133 * initial frame state for interrupts (and exceptions without error code)
d99015b1 134 */
dcd072e2 135 .macro INTR_FRAME start=1 offset=0
911d2bb5
DV
136 EMPTY_FRAME \start, 5*8+\offset
137 /*CFI_REL_OFFSET ss, 4*8+\offset*/
138 CFI_REL_OFFSET rsp, 3*8+\offset
139 /*CFI_REL_OFFSET rflags, 2*8+\offset*/
140 /*CFI_REL_OFFSET cs, 1*8+\offset*/
141 CFI_REL_OFFSET rip, 0*8+\offset
d99015b1
AH
142 .endm
143
d99015b1
AH
144/*
145 * initial frame state for exceptions with error code (and interrupts
146 * with vector already pushed)
147 */
dcd072e2 148 .macro XCPT_FRAME start=1 offset=0
911d2bb5 149 INTR_FRAME \start, 1*8+\offset
dcd072e2
AH
150 .endm
151
152/*
76f5df43 153 * frame that enables passing a complete pt_regs to a C function.
dcd072e2 154 */
76f5df43 155 .macro DEFAULT_FRAME start=1 offset=0
f2db9382
DV
156 XCPT_FRAME \start, ORIG_RAX+\offset
157 CFI_REL_OFFSET rdi, RDI+\offset
158 CFI_REL_OFFSET rsi, RSI+\offset
159 CFI_REL_OFFSET rdx, RDX+\offset
160 CFI_REL_OFFSET rcx, RCX+\offset
161 CFI_REL_OFFSET rax, RAX+\offset
162 CFI_REL_OFFSET r8, R8+\offset
163 CFI_REL_OFFSET r9, R9+\offset
164 CFI_REL_OFFSET r10, R10+\offset
165 CFI_REL_OFFSET r11, R11+\offset
dcd072e2
AH
166 CFI_REL_OFFSET rbx, RBX+\offset
167 CFI_REL_OFFSET rbp, RBP+\offset
168 CFI_REL_OFFSET r12, R12+\offset
169 CFI_REL_OFFSET r13, R13+\offset
170 CFI_REL_OFFSET r14, R14+\offset
171 CFI_REL_OFFSET r15, R15+\offset
172 .endm
d99015b1 173
1da177e4 174/*
b87cf63e 175 * 64bit SYSCALL instruction entry. Up to 6 arguments in registers.
1da177e4 176 *
b87cf63e
DV
177 * 64bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11,
178 * then loads new ss, cs, and rip from previously programmed MSRs.
179 * rflags gets masked by a value from another MSR (so CLD and CLAC
180 * are not needed). SYSCALL does not save anything on the stack
181 * and does not change rsp.
182 *
183 * Registers on entry:
1da177e4 184 * rax system call number
b87cf63e
DV
185 * rcx return address
186 * r11 saved rflags (note: r11 is callee-clobbered register in C ABI)
1da177e4 187 * rdi arg0
1da177e4 188 * rsi arg1
0bd7b798 189 * rdx arg2
b87cf63e 190 * r10 arg3 (needs to be moved to rcx to conform to C ABI)
1da177e4
LT
191 * r8 arg4
192 * r9 arg5
b87cf63e 193 * (note: r12-r15,rbp,rbx are callee-preserved in C ABI)
0bd7b798 194 *
1da177e4
LT
195 * Only called from user space.
196 *
7fcb3bc3 197 * When user can change pt_regs->foo always force IRET. That is because
7bf36bbc
AK
198 * it deals with uncanonical addresses better. SYSRET has trouble
199 * with them due to bugs in both AMD and Intel CPUs.
0bd7b798 200 */
1da177e4
LT
201
202ENTRY(system_call)
7effaa88 203 CFI_STARTPROC simple
adf14236 204 CFI_SIGNAL_FRAME
ef593260 205 CFI_DEF_CFA rsp,0
7effaa88
JB
206 CFI_REGISTER rip,rcx
207 /*CFI_REGISTER rflags,r11*/
9ed8e7d8
DV
208
209 /*
210 * Interrupts are off on entry.
211 * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON,
212 * it is too small to ever cause noticeable irq latency.
213 */
72fe4858
GOC
214 SWAPGS_UNSAFE_STACK
215 /*
216 * A hypervisor implementation might want to use a label
217 * after the swapgs, so that it can do the swapgs
218 * for the guest and jump here on syscall.
219 */
f6b2bc84 220GLOBAL(system_call_after_swapgs)
72fe4858 221
c38e5038 222 movq %rsp,PER_CPU_VAR(rsp_scratch)
9af45651 223 movq PER_CPU_VAR(kernel_stack),%rsp
9ed8e7d8
DV
224
225 /* Construct struct pt_regs on stack */
226 pushq_cfi $__USER_DS /* pt_regs->ss */
227 pushq_cfi PER_CPU_VAR(rsp_scratch) /* pt_regs->sp */
33db1fd4 228 /*
9ed8e7d8
DV
229 * Re-enable interrupts.
230 * We use 'rsp_scratch' as a scratch space, hence irq-off block above
231 * must execute atomically in the face of possible interrupt-driven
232 * task preemption. We must enable interrupts only after we're done
233 * with using rsp_scratch:
33db1fd4
DV
234 */
235 ENABLE_INTERRUPTS(CLBR_NONE)
9ed8e7d8
DV
236 pushq_cfi %r11 /* pt_regs->flags */
237 pushq_cfi $__USER_CS /* pt_regs->cs */
238 pushq_cfi %rcx /* pt_regs->ip */
239 CFI_REL_OFFSET rip,0
240 pushq_cfi_reg rax /* pt_regs->orig_ax */
241 pushq_cfi_reg rdi /* pt_regs->di */
242 pushq_cfi_reg rsi /* pt_regs->si */
243 pushq_cfi_reg rdx /* pt_regs->dx */
244 pushq_cfi_reg rcx /* pt_regs->cx */
245 pushq_cfi $-ENOSYS /* pt_regs->ax */
246 pushq_cfi_reg r8 /* pt_regs->r8 */
247 pushq_cfi_reg r9 /* pt_regs->r9 */
248 pushq_cfi_reg r10 /* pt_regs->r10 */
a71ffdd7
DV
249 pushq_cfi_reg r11 /* pt_regs->r11 */
250 sub $(6*8),%rsp /* pt_regs->bp,bx,r12-15 not saved */
9ed8e7d8 251
dca5b52a 252 testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
1da177e4 253 jnz tracesys
86a1c34a 254system_call_fastpath:
fca460f9 255#if __SYSCALL_MASK == ~0
1da177e4 256 cmpq $__NR_syscall_max,%rax
fca460f9
PA
257#else
258 andl $__SYSCALL_MASK,%eax
259 cmpl $__NR_syscall_max,%eax
260#endif
54eea995 261 ja ret_from_sys_call /* and return regs->ax */
1da177e4
LT
262 movq %r10,%rcx
263 call *sys_call_table(,%rax,8) # XXX: rip relative
f2db9382 264 movq %rax,RAX(%rsp)
1da177e4
LT
265/*
266 * Syscall return path ending with SYSRET (fast path)
29722cd4 267 * Has incompletely filled pt_regs, iret frame is also incomplete.
0bd7b798 268 */
1da177e4 269ret_from_sys_call:
dca5b52a 270 testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
65c23774 271 jnz int_ret_from_sys_call /* Go the slow path */
96b6352c 272
10cd706d 273 LOCKDEP_SYS_EXIT
72fe4858 274 DISABLE_INTERRUPTS(CLBR_NONE)
2601e64d 275 TRACE_IRQS_OFF
bcddc015 276 CFI_REMEMBER_STATE
2601e64d
IM
277 /*
278 * sysretq will re-enable interrupts:
279 */
280 TRACE_IRQS_ON
29722cd4
DV
281 RESTORE_C_REGS_EXCEPT_RCX_R11
282 movq RIP(%rsp),%rcx
7effaa88 283 CFI_REGISTER rip,rcx
29722cd4 284 movq EFLAGS(%rsp),%r11
7effaa88 285 /*CFI_REGISTER rflags,r11*/
263042e4 286 movq RSP(%rsp),%rsp
b87cf63e
DV
287 /*
288 * 64bit SYSRET restores rip from rcx,
289 * rflags from r11 (but RF and VM bits are forced to 0),
290 * cs and ss are loaded from MSRs.
291 */
2be29982 292 USERGS_SYSRET64
1da177e4 293
bcddc015 294 CFI_RESTORE_STATE
1da177e4 295
7fcb3bc3 296 /* Do syscall entry tracing */
0bd7b798 297tracesys:
76f5df43 298 movq %rsp, %rdi
1dcf74f6
AL
299 movq $AUDIT_ARCH_X86_64, %rsi
300 call syscall_trace_enter_phase1
301 test %rax, %rax
302 jnz tracesys_phase2 /* if needed, run the slow path */
76f5df43 303 RESTORE_C_REGS_EXCEPT_RAX /* else restore clobbered regs */
f2db9382 304 movq ORIG_RAX(%rsp), %rax
1dcf74f6
AL
305 jmp system_call_fastpath /* and return to the fast path */
306
307tracesys_phase2:
76f5df43 308 SAVE_EXTRA_REGS
1dcf74f6
AL
309 movq %rsp, %rdi
310 movq $AUDIT_ARCH_X86_64, %rsi
311 movq %rax,%rdx
312 call syscall_trace_enter_phase2
313
d4d67150 314 /*
e90e147c 315 * Reload registers from stack in case ptrace changed them.
1dcf74f6 316 * We don't reload %rax because syscall_trace_entry_phase2() returned
d4d67150
RM
317 * the value it wants us to use in the table lookup.
318 */
76f5df43
DV
319 RESTORE_C_REGS_EXCEPT_RAX
320 RESTORE_EXTRA_REGS
fca460f9 321#if __SYSCALL_MASK == ~0
1da177e4 322 cmpq $__NR_syscall_max,%rax
fca460f9
PA
323#else
324 andl $__SYSCALL_MASK,%eax
325 cmpl $__NR_syscall_max,%eax
326#endif
54eea995 327 ja int_ret_from_sys_call /* RAX(%rsp) is already set */
1da177e4
LT
328 movq %r10,%rcx /* fixup for C */
329 call *sys_call_table(,%rax,8)
f2db9382 330 movq %rax,RAX(%rsp)
7fcb3bc3 331 /* Use IRET because user could have changed pt_regs->foo */
0bd7b798
AH
332
333/*
1da177e4 334 * Syscall return path ending with IRET.
7fcb3bc3 335 * Has correct iret frame.
bcddc015 336 */
bc8b2b92 337GLOBAL(int_ret_from_sys_call)
72fe4858 338 DISABLE_INTERRUPTS(CLBR_NONE)
2601e64d 339 TRACE_IRQS_OFF
1da177e4
LT
340 movl $_TIF_ALLWORK_MASK,%edi
341 /* edi: mask to check */
bc8b2b92 342GLOBAL(int_with_check)
10cd706d 343 LOCKDEP_SYS_EXIT_IRQ
1da177e4 344 GET_THREAD_INFO(%rcx)
26ccb8a7 345 movl TI_flags(%rcx),%edx
1da177e4
LT
346 andl %edi,%edx
347 jnz int_careful
26ccb8a7 348 andl $~TS_COMPAT,TI_status(%rcx)
1da177e4
LT
349 jmp retint_swapgs
350
351 /* Either reschedule or signal or syscall exit tracking needed. */
352 /* First do a reschedule test. */
353 /* edx: work, edi: workmask */
354int_careful:
355 bt $TIF_NEED_RESCHED,%edx
356 jnc int_very_careful
2601e64d 357 TRACE_IRQS_ON
72fe4858 358 ENABLE_INTERRUPTS(CLBR_NONE)
df5d1874 359 pushq_cfi %rdi
0430499c 360 SCHEDULE_USER
df5d1874 361 popq_cfi %rdi
72fe4858 362 DISABLE_INTERRUPTS(CLBR_NONE)
2601e64d 363 TRACE_IRQS_OFF
1da177e4
LT
364 jmp int_with_check
365
7fcb3bc3 366 /* handle signals and tracing -- both require a full pt_regs */
1da177e4 367int_very_careful:
2601e64d 368 TRACE_IRQS_ON
72fe4858 369 ENABLE_INTERRUPTS(CLBR_NONE)
76f5df43 370 SAVE_EXTRA_REGS
0bd7b798 371 /* Check for syscall exit trace */
d4d67150 372 testl $_TIF_WORK_SYSCALL_EXIT,%edx
1da177e4 373 jz int_signal
df5d1874 374 pushq_cfi %rdi
0bd7b798 375 leaq 8(%rsp),%rdi # &ptregs -> arg1
1da177e4 376 call syscall_trace_leave
df5d1874 377 popq_cfi %rdi
d4d67150 378 andl $~(_TIF_WORK_SYSCALL_EXIT|_TIF_SYSCALL_EMU),%edi
1da177e4 379 jmp int_restore_rest
0bd7b798 380
1da177e4 381int_signal:
8f4d37ec 382 testl $_TIF_DO_NOTIFY_MASK,%edx
1da177e4
LT
383 jz 1f
384 movq %rsp,%rdi # &ptregs -> arg1
385 xorl %esi,%esi # oldset -> arg2
386 call do_notify_resume
eca91e78 3871: movl $_TIF_WORK_MASK,%edi
1da177e4 388int_restore_rest:
76f5df43 389 RESTORE_EXTRA_REGS
72fe4858 390 DISABLE_INTERRUPTS(CLBR_NONE)
2601e64d 391 TRACE_IRQS_OFF
1da177e4
LT
392 jmp int_with_check
393 CFI_ENDPROC
bcddc015 394END(system_call)
0bd7b798 395
1d4b4b29
AV
396 .macro FORK_LIKE func
397ENTRY(stub_\func)
398 CFI_STARTPROC
76f5df43
DV
399 DEFAULT_FRAME 0, 8 /* offset 8: return address */
400 SAVE_EXTRA_REGS 8
1d4b4b29 401 call sys_\func
76f5df43 402 ret
1d4b4b29
AV
403 CFI_ENDPROC
404END(stub_\func)
405 .endm
406
407 FORK_LIKE clone
408 FORK_LIKE fork
409 FORK_LIKE vfork
1da177e4 410
1da177e4
LT
411ENTRY(stub_execve)
412 CFI_STARTPROC
e6b04b6b 413 addq $8, %rsp
76f5df43
DV
414 DEFAULT_FRAME 0
415 SAVE_EXTRA_REGS
1da177e4 416 call sys_execve
1da177e4 417 movq %rax,RAX(%rsp)
76f5df43 418 RESTORE_EXTRA_REGS
1da177e4
LT
419 jmp int_ret_from_sys_call
420 CFI_ENDPROC
4b787e0b 421END(stub_execve)
0bd7b798 422
27d6ec7a
DD
423ENTRY(stub_execveat)
424 CFI_STARTPROC
425 addq $8, %rsp
76f5df43
DV
426 DEFAULT_FRAME 0
427 SAVE_EXTRA_REGS
27d6ec7a 428 call sys_execveat
27d6ec7a 429 movq %rax,RAX(%rsp)
76f5df43 430 RESTORE_EXTRA_REGS
27d6ec7a
DD
431 jmp int_ret_from_sys_call
432 CFI_ENDPROC
433END(stub_execveat)
434
1da177e4
LT
435/*
436 * sigreturn is special because it needs to restore all registers on return.
437 * This cannot be done with SYSRET, so use the IRET return path instead.
0bd7b798 438 */
1da177e4
LT
439ENTRY(stub_rt_sigreturn)
440 CFI_STARTPROC
7effaa88 441 addq $8, %rsp
76f5df43
DV
442 DEFAULT_FRAME 0
443 SAVE_EXTRA_REGS
1da177e4
LT
444 call sys_rt_sigreturn
445 movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
76f5df43 446 RESTORE_EXTRA_REGS
1da177e4
LT
447 jmp int_ret_from_sys_call
448 CFI_ENDPROC
4b787e0b 449END(stub_rt_sigreturn)
1da177e4 450
c5a37394 451#ifdef CONFIG_X86_X32_ABI
c5a37394
PA
452ENTRY(stub_x32_rt_sigreturn)
453 CFI_STARTPROC
454 addq $8, %rsp
76f5df43
DV
455 DEFAULT_FRAME 0
456 SAVE_EXTRA_REGS
c5a37394
PA
457 call sys32_x32_rt_sigreturn
458 movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
76f5df43 459 RESTORE_EXTRA_REGS
c5a37394
PA
460 jmp int_ret_from_sys_call
461 CFI_ENDPROC
462END(stub_x32_rt_sigreturn)
463
d1a797f3
PA
464ENTRY(stub_x32_execve)
465 CFI_STARTPROC
466 addq $8, %rsp
76f5df43
DV
467 DEFAULT_FRAME 0
468 SAVE_EXTRA_REGS
6783eaa2 469 call compat_sys_execve
d1a797f3 470 movq %rax,RAX(%rsp)
76f5df43 471 RESTORE_EXTRA_REGS
d1a797f3
PA
472 jmp int_ret_from_sys_call
473 CFI_ENDPROC
474END(stub_x32_execve)
475
27d6ec7a
DD
476ENTRY(stub_x32_execveat)
477 CFI_STARTPROC
478 addq $8, %rsp
76f5df43
DV
479 DEFAULT_FRAME 0
480 SAVE_EXTRA_REGS
27d6ec7a 481 call compat_sys_execveat
27d6ec7a 482 movq %rax,RAX(%rsp)
76f5df43 483 RESTORE_EXTRA_REGS
27d6ec7a
DD
484 jmp int_ret_from_sys_call
485 CFI_ENDPROC
486END(stub_x32_execveat)
487
c5a37394
PA
488#endif
489
1eeb207f
DV
490/*
491 * A newly forked process directly context switches into this address.
492 *
493 * rdi: prev task we switched from
494 */
495ENTRY(ret_from_fork)
496 DEFAULT_FRAME
497
498 LOCK ; btr $TIF_FORK,TI_flags(%r8)
499
500 pushq_cfi $0x0002
501 popfq_cfi # reset kernel eflags
502
503 call schedule_tail # rdi: 'prev' task parameter
504
505 GET_THREAD_INFO(%rcx)
506
507 RESTORE_EXTRA_REGS
508
509 testl $3,CS(%rsp) # from kernel_thread?
510 jz 1f
511
1e3fbb8a
AL
512 /*
513 * By the time we get here, we have no idea whether our pt_regs,
514 * ti flags, and ti status came from the 64-bit SYSCALL fast path,
515 * the slow path, or one of the ia32entry paths.
516 * Use int_ret_from_sys_call to return, since it can safely handle
517 * all of the above.
518 */
519 jmp int_ret_from_sys_call
1eeb207f
DV
520
5211:
522 movq %rbp, %rdi
523 call *%rbx
524 movl $0, RAX(%rsp)
525 RESTORE_EXTRA_REGS
526 jmp int_ret_from_sys_call
527 CFI_ENDPROC
528END(ret_from_fork)
529
939b7871
PA
530/*
531 * Build the entry stubs and pointer table with some assembler magic.
532 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
533 * single cache line on all modern x86 implementations.
534 */
535 .section .init.rodata,"a"
536ENTRY(interrupt)
ea714547 537 .section .entry.text
939b7871
PA
538 .p2align 5
539 .p2align CONFIG_X86_L1_CACHE_SHIFT
540ENTRY(irq_entries_start)
541 INTR_FRAME
542vector=FIRST_EXTERNAL_VECTOR
2414e021 543.rept (FIRST_SYSTEM_VECTOR-FIRST_EXTERNAL_VECTOR+6)/7
939b7871
PA
544 .balign 32
545 .rept 7
2414e021 546 .if vector < FIRST_SYSTEM_VECTOR
8665596e 547 .if vector <> FIRST_EXTERNAL_VECTOR
939b7871
PA
548 CFI_ADJUST_CFA_OFFSET -8
549 .endif
df5d1874 5501: pushq_cfi $(~vector+0x80) /* Note: always in signed byte range */
8665596e 551 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
939b7871
PA
552 jmp 2f
553 .endif
554 .previous
555 .quad 1b
ea714547 556 .section .entry.text
939b7871
PA
557vector=vector+1
558 .endif
559 .endr
5602: jmp common_interrupt
561.endr
562 CFI_ENDPROC
563END(irq_entries_start)
564
565.previous
566END(interrupt)
567.previous
568
d99015b1 569/*
1da177e4
LT
570 * Interrupt entry/exit.
571 *
572 * Interrupt entry points save only callee clobbered registers in fast path.
d99015b1
AH
573 *
574 * Entry runs with interrupts off.
575 */
1da177e4 576
722024db 577/* 0(%rsp): ~(interrupt number) */
1da177e4 578 .macro interrupt func
f6f64681 579 cld
e90e147c
DV
580 /*
581 * Since nothing in interrupt handling code touches r12...r15 members
582 * of "struct pt_regs", and since interrupts can nest, we can save
583 * four stack slots and simultaneously provide
584 * an unwind-friendly stack layout by saving "truncated" pt_regs
585 * exactly up to rbp slot, without these members.
586 */
76f5df43
DV
587 ALLOC_PT_GPREGS_ON_STACK -RBP
588 SAVE_C_REGS -RBP
589 /* this goes to 0(%rsp) for unwinder, not for saving the value: */
590 SAVE_EXTRA_REGS_RBP -RBP
591
592 leaq -RBP(%rsp),%rdi /* arg1 for \func (pointer to pt_regs) */
f6f64681 593
76f5df43 594 testl $3, CS-RBP(%rsp)
f6f64681
DV
595 je 1f
596 SWAPGS
76f5df43 5971:
f6f64681 598 /*
e90e147c 599 * Save previous stack pointer, optionally switch to interrupt stack.
f6f64681
DV
600 * irq_count is used to check if a CPU is already on an interrupt stack
601 * or not. While this is essentially redundant with preempt_count it is
602 * a little cheaper to use a separate counter in the PDA (short of
603 * moving irq_enter into assembly, which would be too much work)
604 */
76f5df43
DV
605 movq %rsp, %rsi
606 incl PER_CPU_VAR(irq_count)
f6f64681
DV
607 cmovzq PER_CPU_VAR(irq_stack_ptr),%rsp
608 CFI_DEF_CFA_REGISTER rsi
f6f64681 609 pushq %rsi
911d2bb5
DV
610 /*
611 * For debugger:
612 * "CFA (Current Frame Address) is the value on stack + offset"
613 */
f6f64681 614 CFI_ESCAPE 0x0f /* DW_CFA_def_cfa_expression */, 6, \
911d2bb5 615 0x77 /* DW_OP_breg7 (rsp) */, 0, \
f6f64681 616 0x06 /* DW_OP_deref */, \
911d2bb5 617 0x08 /* DW_OP_const1u */, SIZEOF_PTREGS-RBP, \
f6f64681
DV
618 0x22 /* DW_OP_plus */
619 /* We entered an interrupt context - irqs are off: */
620 TRACE_IRQS_OFF
621
1da177e4
LT
622 call \func
623 .endm
624
722024db
AH
625 /*
626 * The interrupt stubs push (~vector+0x80) onto the stack and
627 * then jump to common_interrupt.
628 */
939b7871
PA
629 .p2align CONFIG_X86_L1_CACHE_SHIFT
630common_interrupt:
7effaa88 631 XCPT_FRAME
ee4eb87b 632 ASM_CLAC
722024db 633 addq $-0x80,(%rsp) /* Adjust vector to [-256,-1] range */
1da177e4 634 interrupt do_IRQ
34061f13 635 /* 0(%rsp): old RSP */
7effaa88 636ret_from_intr:
72fe4858 637 DISABLE_INTERRUPTS(CLBR_NONE)
2601e64d 638 TRACE_IRQS_OFF
56895530 639 decl PER_CPU_VAR(irq_count)
625dbc3b 640
a2bbe750
FW
641 /* Restore saved previous stack */
642 popq %rsi
911d2bb5 643 CFI_DEF_CFA rsi,SIZEOF_PTREGS-RBP /* reg/off reset after def_cfa_expr */
e90e147c 644 /* return code expects complete pt_regs - adjust rsp accordingly: */
f2db9382 645 leaq -RBP(%rsi),%rsp
7effaa88 646 CFI_DEF_CFA_REGISTER rsp
f2db9382 647 CFI_ADJUST_CFA_OFFSET RBP
625dbc3b 648
7effaa88 649exit_intr:
1da177e4 650 GET_THREAD_INFO(%rcx)
f2db9382 651 testl $3,CS(%rsp)
1da177e4 652 je retint_kernel
0bd7b798 653
1da177e4
LT
654 /* Interrupt came from user space */
655 /*
e90e147c 656 * Has a correct top of stack.
1da177e4 657 * %rcx: thread info. Interrupts off.
0bd7b798 658 */
1da177e4
LT
659retint_with_reschedule:
660 movl $_TIF_WORK_MASK,%edi
7effaa88 661retint_check:
10cd706d 662 LOCKDEP_SYS_EXIT_IRQ
26ccb8a7 663 movl TI_flags(%rcx),%edx
1da177e4 664 andl %edi,%edx
7effaa88 665 CFI_REMEMBER_STATE
1da177e4 666 jnz retint_careful
10cd706d
PZ
667
668retint_swapgs: /* return to user-space */
2601e64d
IM
669 /*
670 * The iretq could re-enable interrupts:
671 */
72fe4858 672 DISABLE_INTERRUPTS(CLBR_ANY)
2601e64d 673 TRACE_IRQS_IRETQ
2a23c6b8
AL
674
675 /*
676 * Try to use SYSRET instead of IRET if we're returning to
677 * a completely clean 64-bit userspace context.
678 */
f2db9382
DV
679 movq RCX(%rsp),%rcx
680 cmpq %rcx,RIP(%rsp) /* RCX == RIP */
2a23c6b8
AL
681 jne opportunistic_sysret_failed
682
683 /*
684 * On Intel CPUs, sysret with non-canonical RCX/RIP will #GP
685 * in kernel space. This essentially lets the user take over
686 * the kernel, since userspace controls RSP. It's not worth
687 * testing for canonicalness exactly -- this check detects any
688 * of the 17 high bits set, which is true for non-canonical
689 * or kernel addresses. (This will pessimize vsyscall=native.
690 * Big deal.)
691 *
692 * If virtual addresses ever become wider, this will need
693 * to be updated to remain correct on both old and new CPUs.
694 */
695 .ifne __VIRTUAL_MASK_SHIFT - 47
696 .error "virtual address width changed -- sysret checks need update"
697 .endif
698 shr $__VIRTUAL_MASK_SHIFT, %rcx
699 jnz opportunistic_sysret_failed
700
f2db9382 701 cmpq $__USER_CS,CS(%rsp) /* CS must match SYSRET */
2a23c6b8
AL
702 jne opportunistic_sysret_failed
703
f2db9382
DV
704 movq R11(%rsp),%r11
705 cmpq %r11,EFLAGS(%rsp) /* R11 == RFLAGS */
2a23c6b8
AL
706 jne opportunistic_sysret_failed
707
f2db9382 708 testq $X86_EFLAGS_RF,%r11 /* sysret can't restore RF */
2a23c6b8
AL
709 jnz opportunistic_sysret_failed
710
711 /* nothing to check for RSP */
712
f2db9382 713 cmpq $__USER_DS,SS(%rsp) /* SS must match SYSRET */
2a23c6b8
AL
714 jne opportunistic_sysret_failed
715
716 /*
717 * We win! This label is here just for ease of understanding
718 * perf profiles. Nothing jumps here.
719 */
720irq_return_via_sysret:
721 CFI_REMEMBER_STATE
d441c1f2
DV
722 /* r11 is already restored (see code above) */
723 RESTORE_C_REGS_EXCEPT_R11
724 movq RSP(%rsp),%rsp
2a23c6b8
AL
725 USERGS_SYSRET64
726 CFI_RESTORE_STATE
727
728opportunistic_sysret_failed:
72fe4858 729 SWAPGS
2601e64d
IM
730 jmp restore_args
731
10cd706d 732retint_restore_args: /* return to kernel space */
72fe4858 733 DISABLE_INTERRUPTS(CLBR_ANY)
2601e64d
IM
734 /*
735 * The iretq could re-enable interrupts:
736 */
737 TRACE_IRQS_IRETQ
738restore_args:
76f5df43
DV
739 RESTORE_C_REGS
740 REMOVE_PT_GPREGS_FROM_STACK 8
3701d863 741
f7f3d791 742irq_return:
7209a75d
AL
743 INTERRUPT_RETURN
744
745ENTRY(native_iret)
3891a04a
PA
746 /*
747 * Are we returning to a stack segment from the LDT? Note: in
748 * 64-bit mode SS:RSP on the exception stack is always valid.
749 */
34273f41 750#ifdef CONFIG_X86_ESPFIX64
3891a04a 751 testb $4,(SS-RIP)(%rsp)
7209a75d 752 jnz native_irq_return_ldt
34273f41 753#endif
3891a04a 754
af726f21 755.global native_irq_return_iret
7209a75d 756native_irq_return_iret:
b645af2d
AL
757 /*
758 * This may fault. Non-paranoid faults on return to userspace are
759 * handled by fixup_bad_iret. These include #SS, #GP, and #NP.
760 * Double-faults due to espfix64 are handled in do_double_fault.
761 * Other faults here are fatal.
762 */
1da177e4 763 iretq
3701d863 764
34273f41 765#ifdef CONFIG_X86_ESPFIX64
7209a75d 766native_irq_return_ldt:
3891a04a
PA
767 pushq_cfi %rax
768 pushq_cfi %rdi
769 SWAPGS
770 movq PER_CPU_VAR(espfix_waddr),%rdi
771 movq %rax,(0*8)(%rdi) /* RAX */
772 movq (2*8)(%rsp),%rax /* RIP */
773 movq %rax,(1*8)(%rdi)
774 movq (3*8)(%rsp),%rax /* CS */
775 movq %rax,(2*8)(%rdi)
776 movq (4*8)(%rsp),%rax /* RFLAGS */
777 movq %rax,(3*8)(%rdi)
778 movq (6*8)(%rsp),%rax /* SS */
779 movq %rax,(5*8)(%rdi)
780 movq (5*8)(%rsp),%rax /* RSP */
781 movq %rax,(4*8)(%rdi)
782 andl $0xffff0000,%eax
783 popq_cfi %rdi
784 orq PER_CPU_VAR(espfix_stack),%rax
785 SWAPGS
786 movq %rax,%rsp
787 popq_cfi %rax
7209a75d 788 jmp native_irq_return_iret
34273f41 789#endif
3891a04a 790
7effaa88 791 /* edi: workmask, edx: work */
1da177e4 792retint_careful:
7effaa88 793 CFI_RESTORE_STATE
1da177e4
LT
794 bt $TIF_NEED_RESCHED,%edx
795 jnc retint_signal
2601e64d 796 TRACE_IRQS_ON
72fe4858 797 ENABLE_INTERRUPTS(CLBR_NONE)
df5d1874 798 pushq_cfi %rdi
0430499c 799 SCHEDULE_USER
df5d1874 800 popq_cfi %rdi
1da177e4 801 GET_THREAD_INFO(%rcx)
72fe4858 802 DISABLE_INTERRUPTS(CLBR_NONE)
2601e64d 803 TRACE_IRQS_OFF
1da177e4 804 jmp retint_check
0bd7b798 805
1da177e4 806retint_signal:
8f4d37ec 807 testl $_TIF_DO_NOTIFY_MASK,%edx
10ffdbb8 808 jz retint_swapgs
2601e64d 809 TRACE_IRQS_ON
72fe4858 810 ENABLE_INTERRUPTS(CLBR_NONE)
76f5df43 811 SAVE_EXTRA_REGS
0bd7b798 812 movq $-1,ORIG_RAX(%rsp)
3829ee6b 813 xorl %esi,%esi # oldset
1da177e4
LT
814 movq %rsp,%rdi # &pt_regs
815 call do_notify_resume
76f5df43 816 RESTORE_EXTRA_REGS
72fe4858 817 DISABLE_INTERRUPTS(CLBR_NONE)
2601e64d 818 TRACE_IRQS_OFF
be9e6870 819 GET_THREAD_INFO(%rcx)
eca91e78 820 jmp retint_with_reschedule
1da177e4
LT
821
822#ifdef CONFIG_PREEMPT
823 /* Returning to kernel space. Check if we need preemption */
824 /* rcx: threadinfo. interrupts off. */
b06babac 825ENTRY(retint_kernel)
c2daa3be 826 cmpl $0,PER_CPU_VAR(__preempt_count)
1da177e4 827 jnz retint_restore_args
f2db9382 828 bt $9,EFLAGS(%rsp) /* interrupts off? */
1da177e4
LT
829 jnc retint_restore_args
830 call preempt_schedule_irq
831 jmp exit_intr
0bd7b798 832#endif
1da177e4 833 CFI_ENDPROC
4b787e0b 834END(common_interrupt)
3891a04a 835
1da177e4
LT
836/*
837 * APIC interrupts.
0bd7b798 838 */
cf910e83 839.macro apicinterrupt3 num sym do_sym
322648d1 840ENTRY(\sym)
7effaa88 841 INTR_FRAME
ee4eb87b 842 ASM_CLAC
df5d1874 843 pushq_cfi $~(\num)
39e95433 844.Lcommon_\sym:
322648d1 845 interrupt \do_sym
1da177e4
LT
846 jmp ret_from_intr
847 CFI_ENDPROC
322648d1
AH
848END(\sym)
849.endm
1da177e4 850
cf910e83
SA
851#ifdef CONFIG_TRACING
852#define trace(sym) trace_##sym
853#define smp_trace(sym) smp_trace_##sym
854
855.macro trace_apicinterrupt num sym
856apicinterrupt3 \num trace(\sym) smp_trace(\sym)
857.endm
858#else
859.macro trace_apicinterrupt num sym do_sym
860.endm
861#endif
862
863.macro apicinterrupt num sym do_sym
864apicinterrupt3 \num \sym \do_sym
865trace_apicinterrupt \num \sym
866.endm
867
322648d1 868#ifdef CONFIG_SMP
cf910e83 869apicinterrupt3 IRQ_MOVE_CLEANUP_VECTOR \
322648d1 870 irq_move_cleanup_interrupt smp_irq_move_cleanup_interrupt
cf910e83 871apicinterrupt3 REBOOT_VECTOR \
4ef702c1 872 reboot_interrupt smp_reboot_interrupt
322648d1 873#endif
1da177e4 874
03b48632 875#ifdef CONFIG_X86_UV
cf910e83 876apicinterrupt3 UV_BAU_MESSAGE \
322648d1 877 uv_bau_message_intr1 uv_bau_message_interrupt
03b48632 878#endif
322648d1
AH
879apicinterrupt LOCAL_TIMER_VECTOR \
880 apic_timer_interrupt smp_apic_timer_interrupt
4a4de9c7
DS
881apicinterrupt X86_PLATFORM_IPI_VECTOR \
882 x86_platform_ipi smp_x86_platform_ipi
89b831ef 883
d78f2664 884#ifdef CONFIG_HAVE_KVM
cf910e83 885apicinterrupt3 POSTED_INTR_VECTOR \
d78f2664
YZ
886 kvm_posted_intr_ipi smp_kvm_posted_intr_ipi
887#endif
888
33e5ff63 889#ifdef CONFIG_X86_MCE_THRESHOLD
322648d1 890apicinterrupt THRESHOLD_APIC_VECTOR \
7856f6cc 891 threshold_interrupt smp_threshold_interrupt
33e5ff63
SA
892#endif
893
894#ifdef CONFIG_X86_THERMAL_VECTOR
322648d1
AH
895apicinterrupt THERMAL_APIC_VECTOR \
896 thermal_interrupt smp_thermal_interrupt
33e5ff63 897#endif
1812924b 898
322648d1
AH
899#ifdef CONFIG_SMP
900apicinterrupt CALL_FUNCTION_SINGLE_VECTOR \
901 call_function_single_interrupt smp_call_function_single_interrupt
902apicinterrupt CALL_FUNCTION_VECTOR \
903 call_function_interrupt smp_call_function_interrupt
904apicinterrupt RESCHEDULE_VECTOR \
905 reschedule_interrupt smp_reschedule_interrupt
906#endif
1da177e4 907
322648d1
AH
908apicinterrupt ERROR_APIC_VECTOR \
909 error_interrupt smp_error_interrupt
910apicinterrupt SPURIOUS_APIC_VECTOR \
911 spurious_interrupt smp_spurious_interrupt
0bd7b798 912
e360adbe
PZ
913#ifdef CONFIG_IRQ_WORK
914apicinterrupt IRQ_WORK_VECTOR \
915 irq_work_interrupt smp_irq_work_interrupt
241771ef
IM
916#endif
917
1da177e4
LT
918/*
919 * Exception entry points.
0bd7b798 920 */
9b476688 921#define CPU_TSS_IST(x) PER_CPU_VAR(cpu_tss) + (TSS_ist + ((x) - 1) * 8)
577ed45e
AL
922
923.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
322648d1 924ENTRY(\sym)
577ed45e
AL
925 /* Sanity check */
926 .if \shift_ist != -1 && \paranoid == 0
927 .error "using shift_ist requires paranoid=1"
928 .endif
929
cb5dd2c5
AL
930 .if \has_error_code
931 XCPT_FRAME
932 .else
7effaa88 933 INTR_FRAME
cb5dd2c5 934 .endif
1da177e4 935
ee4eb87b 936 ASM_CLAC
b8b1d08b 937 PARAVIRT_ADJUST_EXCEPTION_FRAME
cb5dd2c5
AL
938
939 .ifeq \has_error_code
940 pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */
941 .endif
942
76f5df43 943 ALLOC_PT_GPREGS_ON_STACK
cb5dd2c5
AL
944
945 .if \paranoid
48e08d0f
AL
946 .if \paranoid == 1
947 CFI_REMEMBER_STATE
948 testl $3, CS(%rsp) /* If coming from userspace, switch */
949 jnz 1f /* stacks. */
950 .endif
ebfc453e 951 call paranoid_entry
cb5dd2c5
AL
952 .else
953 call error_entry
954 .endif
ebfc453e 955 /* returned flag: ebx=0: need swapgs on exit, ebx=1: don't need it */
cb5dd2c5 956
1bd24efc 957 DEFAULT_FRAME 0
cb5dd2c5
AL
958
959 .if \paranoid
577ed45e
AL
960 .if \shift_ist != -1
961 TRACE_IRQS_OFF_DEBUG /* reload IDT in case of recursion */
962 .else
b8b1d08b 963 TRACE_IRQS_OFF
cb5dd2c5 964 .endif
577ed45e 965 .endif
cb5dd2c5
AL
966
967 movq %rsp,%rdi /* pt_regs pointer */
968
969 .if \has_error_code
970 movq ORIG_RAX(%rsp),%rsi /* get error code */
971 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
972 .else
973 xorl %esi,%esi /* no error code */
974 .endif
975
577ed45e 976 .if \shift_ist != -1
9b476688 977 subq $EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist)
577ed45e
AL
978 .endif
979
322648d1 980 call \do_sym
cb5dd2c5 981
577ed45e 982 .if \shift_ist != -1
9b476688 983 addq $EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist)
577ed45e
AL
984 .endif
985
ebfc453e 986 /* these procedures expect "no swapgs" flag in ebx */
cb5dd2c5 987 .if \paranoid
ebfc453e 988 jmp paranoid_exit
cb5dd2c5 989 .else
ebfc453e 990 jmp error_exit
cb5dd2c5
AL
991 .endif
992
48e08d0f
AL
993 .if \paranoid == 1
994 CFI_RESTORE_STATE
995 /*
996 * Paranoid entry from userspace. Switch stacks and treat it
997 * as a normal entry. This means that paranoid handlers
998 * run in real process context if user_mode(regs).
999 */
10001:
1001 call error_entry
1002
1003 DEFAULT_FRAME 0
1004
1005 movq %rsp,%rdi /* pt_regs pointer */
1006 call sync_regs
1007 movq %rax,%rsp /* switch stack */
1008
1009 movq %rsp,%rdi /* pt_regs pointer */
1010
1011 .if \has_error_code
1012 movq ORIG_RAX(%rsp),%rsi /* get error code */
1013 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
1014 .else
1015 xorl %esi,%esi /* no error code */
1016 .endif
1017
1018 call \do_sym
1019
1020 jmp error_exit /* %ebx: no swapgs flag */
1021 .endif
1022
b8b1d08b 1023 CFI_ENDPROC
ddeb8f21 1024END(\sym)
322648d1 1025.endm
b8b1d08b 1026
25c74b10 1027#ifdef CONFIG_TRACING
cb5dd2c5
AL
1028.macro trace_idtentry sym do_sym has_error_code:req
1029idtentry trace(\sym) trace(\do_sym) has_error_code=\has_error_code
1030idtentry \sym \do_sym has_error_code=\has_error_code
25c74b10
SA
1031.endm
1032#else
cb5dd2c5
AL
1033.macro trace_idtentry sym do_sym has_error_code:req
1034idtentry \sym \do_sym has_error_code=\has_error_code
25c74b10
SA
1035.endm
1036#endif
1037
cb5dd2c5
AL
1038idtentry divide_error do_divide_error has_error_code=0
1039idtentry overflow do_overflow has_error_code=0
1040idtentry bounds do_bounds has_error_code=0
1041idtentry invalid_op do_invalid_op has_error_code=0
1042idtentry device_not_available do_device_not_available has_error_code=0
48e08d0f 1043idtentry double_fault do_double_fault has_error_code=1 paranoid=2
cb5dd2c5
AL
1044idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0
1045idtentry invalid_TSS do_invalid_TSS has_error_code=1
1046idtentry segment_not_present do_segment_not_present has_error_code=1
1047idtentry spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0
1048idtentry coprocessor_error do_coprocessor_error has_error_code=0
1049idtentry alignment_check do_alignment_check has_error_code=1
1050idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0
5cec93c2 1051
2601e64d 1052
9f1e87ea
CG
1053 /* Reload gs selector with exception handling */
1054 /* edi: new selector */
9f9d489a 1055ENTRY(native_load_gs_index)
7effaa88 1056 CFI_STARTPROC
df5d1874 1057 pushfq_cfi
b8aa287f 1058 DISABLE_INTERRUPTS(CLBR_ANY & ~CLBR_RDI)
9f1e87ea 1059 SWAPGS
0bd7b798 1060gs_change:
9f1e87ea 1061 movl %edi,%gs
1da177e4 10622: mfence /* workaround */
72fe4858 1063 SWAPGS
df5d1874 1064 popfq_cfi
9f1e87ea 1065 ret
7effaa88 1066 CFI_ENDPROC
6efdcfaf 1067END(native_load_gs_index)
0bd7b798 1068
d7abc0fa 1069 _ASM_EXTABLE(gs_change,bad_gs)
9f1e87ea 1070 .section .fixup,"ax"
1da177e4 1071 /* running with kernelgs */
0bd7b798 1072bad_gs:
72fe4858 1073 SWAPGS /* switch back to user gs */
1da177e4 1074 xorl %eax,%eax
9f1e87ea
CG
1075 movl %eax,%gs
1076 jmp 2b
1077 .previous
0bd7b798 1078
2699500b 1079/* Call softirq on interrupt stack. Interrupts are off. */
7d65f4a6 1080ENTRY(do_softirq_own_stack)
7effaa88 1081 CFI_STARTPROC
df5d1874 1082 pushq_cfi %rbp
2699500b
AK
1083 CFI_REL_OFFSET rbp,0
1084 mov %rsp,%rbp
1085 CFI_DEF_CFA_REGISTER rbp
56895530 1086 incl PER_CPU_VAR(irq_count)
26f80bd6 1087 cmove PER_CPU_VAR(irq_stack_ptr),%rsp
2699500b 1088 push %rbp # backlink for old unwinder
ed6b676c 1089 call __do_softirq
2699500b 1090 leaveq
df5d1874 1091 CFI_RESTORE rbp
7effaa88 1092 CFI_DEF_CFA_REGISTER rsp
2699500b 1093 CFI_ADJUST_CFA_OFFSET -8
56895530 1094 decl PER_CPU_VAR(irq_count)
ed6b676c 1095 ret
7effaa88 1096 CFI_ENDPROC
7d65f4a6 1097END(do_softirq_own_stack)
75154f40 1098
3d75e1b8 1099#ifdef CONFIG_XEN
cb5dd2c5 1100idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
3d75e1b8
JF
1101
1102/*
9f1e87ea
CG
1103 * A note on the "critical region" in our callback handler.
1104 * We want to avoid stacking callback handlers due to events occurring
1105 * during handling of the last event. To do this, we keep events disabled
1106 * until we've done all processing. HOWEVER, we must enable events before
1107 * popping the stack frame (can't be done atomically) and so it would still
1108 * be possible to get enough handler activations to overflow the stack.
1109 * Although unlikely, bugs of that kind are hard to track down, so we'd
1110 * like to avoid the possibility.
1111 * So, on entry to the handler we detect whether we interrupted an
1112 * existing activation in its critical region -- if so, we pop the current
1113 * activation and restart the handler using the previous one.
1114 */
3d75e1b8
JF
1115ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
1116 CFI_STARTPROC
9f1e87ea
CG
1117/*
1118 * Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will
1119 * see the correct pointer to the pt_regs
1120 */
3d75e1b8
JF
1121 movq %rdi, %rsp # we don't return, adjust the stack frame
1122 CFI_ENDPROC
dcd072e2 1123 DEFAULT_FRAME
56895530 112411: incl PER_CPU_VAR(irq_count)
3d75e1b8
JF
1125 movq %rsp,%rbp
1126 CFI_DEF_CFA_REGISTER rbp
26f80bd6 1127 cmovzq PER_CPU_VAR(irq_stack_ptr),%rsp
3d75e1b8
JF
1128 pushq %rbp # backlink for old unwinder
1129 call xen_evtchn_do_upcall
1130 popq %rsp
1131 CFI_DEF_CFA_REGISTER rsp
56895530 1132 decl PER_CPU_VAR(irq_count)
fdfd811d
DV
1133#ifndef CONFIG_PREEMPT
1134 call xen_maybe_preempt_hcall
1135#endif
3d75e1b8
JF
1136 jmp error_exit
1137 CFI_ENDPROC
371c394a 1138END(xen_do_hypervisor_callback)
3d75e1b8
JF
1139
1140/*
9f1e87ea
CG
1141 * Hypervisor uses this for application faults while it executes.
1142 * We get here for two reasons:
1143 * 1. Fault while reloading DS, ES, FS or GS
1144 * 2. Fault while executing IRET
1145 * Category 1 we do not need to fix up as Xen has already reloaded all segment
1146 * registers that could be reloaded and zeroed the others.
1147 * Category 2 we fix up by killing the current process. We cannot use the
1148 * normal Linux return path in this case because if we use the IRET hypercall
1149 * to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1150 * We distinguish between categories by comparing each saved segment register
1151 * with its current contents: any discrepancy means we in category 1.
1152 */
3d75e1b8 1153ENTRY(xen_failsafe_callback)
dcd072e2
AH
1154 INTR_FRAME 1 (6*8)
1155 /*CFI_REL_OFFSET gs,GS*/
1156 /*CFI_REL_OFFSET fs,FS*/
1157 /*CFI_REL_OFFSET es,ES*/
1158 /*CFI_REL_OFFSET ds,DS*/
1159 CFI_REL_OFFSET r11,8
1160 CFI_REL_OFFSET rcx,0
3d75e1b8
JF
1161 movw %ds,%cx
1162 cmpw %cx,0x10(%rsp)
1163 CFI_REMEMBER_STATE
1164 jne 1f
1165 movw %es,%cx
1166 cmpw %cx,0x18(%rsp)
1167 jne 1f
1168 movw %fs,%cx
1169 cmpw %cx,0x20(%rsp)
1170 jne 1f
1171 movw %gs,%cx
1172 cmpw %cx,0x28(%rsp)
1173 jne 1f
1174 /* All segments match their saved values => Category 2 (Bad IRET). */
1175 movq (%rsp),%rcx
1176 CFI_RESTORE rcx
1177 movq 8(%rsp),%r11
1178 CFI_RESTORE r11
1179 addq $0x30,%rsp
1180 CFI_ADJUST_CFA_OFFSET -0x30
14ae22ba
IM
1181 pushq_cfi $0 /* RIP */
1182 pushq_cfi %r11
1183 pushq_cfi %rcx
4a5c3e77 1184 jmp general_protection
3d75e1b8
JF
1185 CFI_RESTORE_STATE
11861: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */
1187 movq (%rsp),%rcx
1188 CFI_RESTORE rcx
1189 movq 8(%rsp),%r11
1190 CFI_RESTORE r11
1191 addq $0x30,%rsp
1192 CFI_ADJUST_CFA_OFFSET -0x30
a349e23d 1193 pushq_cfi $-1 /* orig_ax = -1 => not a system call */
76f5df43
DV
1194 ALLOC_PT_GPREGS_ON_STACK
1195 SAVE_C_REGS
1196 SAVE_EXTRA_REGS
3d75e1b8
JF
1197 jmp error_exit
1198 CFI_ENDPROC
3d75e1b8
JF
1199END(xen_failsafe_callback)
1200
cf910e83 1201apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
38e20b07
SY
1202 xen_hvm_callback_vector xen_evtchn_do_upcall
1203
3d75e1b8 1204#endif /* CONFIG_XEN */
ddeb8f21 1205
bc2b0331 1206#if IS_ENABLED(CONFIG_HYPERV)
cf910e83 1207apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
bc2b0331
S
1208 hyperv_callback_vector hyperv_vector_handler
1209#endif /* CONFIG_HYPERV */
1210
577ed45e
AL
1211idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
1212idtentry int3 do_int3 has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
6f442be2 1213idtentry stack_segment do_stack_segment has_error_code=1
6cac5a92 1214#ifdef CONFIG_XEN
cb5dd2c5
AL
1215idtentry xen_debug do_debug has_error_code=0
1216idtentry xen_int3 do_int3 has_error_code=0
1217idtentry xen_stack_segment do_stack_segment has_error_code=1
6cac5a92 1218#endif
cb5dd2c5
AL
1219idtentry general_protection do_general_protection has_error_code=1
1220trace_idtentry page_fault do_page_fault has_error_code=1
631bc487 1221#ifdef CONFIG_KVM_GUEST
cb5dd2c5 1222idtentry async_page_fault do_async_page_fault has_error_code=1
631bc487 1223#endif
ddeb8f21 1224#ifdef CONFIG_X86_MCE
cb5dd2c5 1225idtentry machine_check has_error_code=0 paranoid=1 do_sym=*machine_check_vector(%rip)
ddeb8f21
AH
1226#endif
1227
ebfc453e
DV
1228/*
1229 * Save all registers in pt_regs, and switch gs if needed.
1230 * Use slow, but surefire "are we in kernel?" check.
1231 * Return: ebx=0: need swapgs on exit, ebx=1: otherwise
1232 */
1233ENTRY(paranoid_entry)
1234 XCPT_FRAME 1 15*8
1eeb207f
DV
1235 cld
1236 SAVE_C_REGS 8
1237 SAVE_EXTRA_REGS 8
1238 movl $1,%ebx
1239 movl $MSR_GS_BASE,%ecx
1240 rdmsr
1241 testl %edx,%edx
1242 js 1f /* negative -> in kernel */
1243 SWAPGS
1244 xorl %ebx,%ebx
12451: ret
1246 CFI_ENDPROC
ebfc453e 1247END(paranoid_entry)
ddeb8f21 1248
ebfc453e
DV
1249/*
1250 * "Paranoid" exit path from exception stack. This is invoked
1251 * only on return from non-NMI IST interrupts that came
1252 * from kernel space.
1253 *
1254 * We may be returning to very strange contexts (e.g. very early
1255 * in syscall entry), so checking for preemption here would
1256 * be complicated. Fortunately, we there's no good reason
1257 * to try to handle preemption here.
1258 */
1259/* On entry, ebx is "no swapgs" flag (1: don't need swapgs, 0: need it) */
ddeb8f21 1260ENTRY(paranoid_exit)
1f130a78 1261 DEFAULT_FRAME
ddeb8f21 1262 DISABLE_INTERRUPTS(CLBR_NONE)
5963e317 1263 TRACE_IRQS_OFF_DEBUG
ddeb8f21 1264 testl %ebx,%ebx /* swapgs needed? */
0d550836 1265 jnz paranoid_exit_no_swapgs
f2db9382 1266 TRACE_IRQS_IRETQ
ddeb8f21 1267 SWAPGS_UNSAFE_STACK
0d550836
DV
1268 jmp paranoid_exit_restore
1269paranoid_exit_no_swapgs:
f2db9382 1270 TRACE_IRQS_IRETQ_DEBUG
0d550836 1271paranoid_exit_restore:
76f5df43
DV
1272 RESTORE_EXTRA_REGS
1273 RESTORE_C_REGS
1274 REMOVE_PT_GPREGS_FROM_STACK 8
48e08d0f 1275 INTERRUPT_RETURN
ddeb8f21
AH
1276 CFI_ENDPROC
1277END(paranoid_exit)
1278
1279/*
ebfc453e
DV
1280 * Save all registers in pt_regs, and switch gs if needed.
1281 * Return: ebx=0: need swapgs on exit, ebx=1: otherwise
ddeb8f21
AH
1282 */
1283ENTRY(error_entry)
ebfc453e 1284 XCPT_FRAME 1 15*8
ddeb8f21 1285 cld
76f5df43
DV
1286 SAVE_C_REGS 8
1287 SAVE_EXTRA_REGS 8
ddeb8f21
AH
1288 xorl %ebx,%ebx
1289 testl $3,CS+8(%rsp)
1290 je error_kernelspace
1291error_swapgs:
1292 SWAPGS
1293error_sti:
1294 TRACE_IRQS_OFF
1295 ret
ddeb8f21 1296
ebfc453e
DV
1297 /*
1298 * There are two places in the kernel that can potentially fault with
1299 * usergs. Handle them here. B stepping K8s sometimes report a
1300 * truncated RIP for IRET exceptions returning to compat mode. Check
1301 * for these here too.
1302 */
ddeb8f21 1303error_kernelspace:
3bab13b0 1304 CFI_REL_OFFSET rcx, RCX+8
ddeb8f21 1305 incl %ebx
7209a75d 1306 leaq native_irq_return_iret(%rip),%rcx
ddeb8f21 1307 cmpq %rcx,RIP+8(%rsp)
b645af2d 1308 je error_bad_iret
ae24ffe5
BG
1309 movl %ecx,%eax /* zero extend */
1310 cmpq %rax,RIP+8(%rsp)
1311 je bstep_iret
ddeb8f21 1312 cmpq $gs_change,RIP+8(%rsp)
9f1e87ea 1313 je error_swapgs
ddeb8f21 1314 jmp error_sti
ae24ffe5
BG
1315
1316bstep_iret:
1317 /* Fix truncated RIP */
1318 movq %rcx,RIP+8(%rsp)
b645af2d
AL
1319 /* fall through */
1320
1321error_bad_iret:
1322 SWAPGS
1323 mov %rsp,%rdi
1324 call fixup_bad_iret
1325 mov %rax,%rsp
1326 decl %ebx /* Return to usergs */
1327 jmp error_sti
e6b04b6b 1328 CFI_ENDPROC
ddeb8f21
AH
1329END(error_entry)
1330
1331
ebfc453e 1332/* On entry, ebx is "no swapgs" flag (1: don't need swapgs, 0: need it) */
ddeb8f21
AH
1333ENTRY(error_exit)
1334 DEFAULT_FRAME
1335 movl %ebx,%eax
76f5df43 1336 RESTORE_EXTRA_REGS
ddeb8f21
AH
1337 DISABLE_INTERRUPTS(CLBR_NONE)
1338 TRACE_IRQS_OFF
1339 GET_THREAD_INFO(%rcx)
1340 testl %eax,%eax
1341 jne retint_kernel
1342 LOCKDEP_SYS_EXIT_IRQ
1343 movl TI_flags(%rcx),%edx
1344 movl $_TIF_WORK_MASK,%edi
1345 andl %edi,%edx
1346 jnz retint_careful
1347 jmp retint_swapgs
1348 CFI_ENDPROC
1349END(error_exit)
1350
3f3c8b8c
SR
1351/*
1352 * Test if a given stack is an NMI stack or not.
1353 */
1354 .macro test_in_nmi reg stack nmi_ret normal_ret
1355 cmpq %\reg, \stack
1356 ja \normal_ret
1357 subq $EXCEPTION_STKSZ, %\reg
1358 cmpq %\reg, \stack
1359 jb \normal_ret
1360 jmp \nmi_ret
1361 .endm
ddeb8f21
AH
1362
1363 /* runs on exception stack */
1364ENTRY(nmi)
1365 INTR_FRAME
1366 PARAVIRT_ADJUST_EXCEPTION_FRAME
3f3c8b8c
SR
1367 /*
1368 * We allow breakpoints in NMIs. If a breakpoint occurs, then
1369 * the iretq it performs will take us out of NMI context.
1370 * This means that we can have nested NMIs where the next
1371 * NMI is using the top of the stack of the previous NMI. We
1372 * can't let it execute because the nested NMI will corrupt the
1373 * stack of the previous NMI. NMI handlers are not re-entrant
1374 * anyway.
1375 *
1376 * To handle this case we do the following:
1377 * Check the a special location on the stack that contains
1378 * a variable that is set when NMIs are executing.
1379 * The interrupted task's stack is also checked to see if it
1380 * is an NMI stack.
1381 * If the variable is not set and the stack is not the NMI
1382 * stack then:
1383 * o Set the special variable on the stack
1384 * o Copy the interrupt frame into a "saved" location on the stack
1385 * o Copy the interrupt frame into a "copy" location on the stack
1386 * o Continue processing the NMI
1387 * If the variable is set or the previous stack is the NMI stack:
1388 * o Modify the "copy" location to jump to the repeate_nmi
1389 * o return back to the first NMI
1390 *
1391 * Now on exit of the first NMI, we first clear the stack variable
1392 * The NMI stack will tell any nested NMIs at that point that it is
1393 * nested. Then we pop the stack normally with iret, and if there was
1394 * a nested NMI that updated the copy interrupt stack frame, a
1395 * jump will be made to the repeat_nmi code that will handle the second
1396 * NMI.
1397 */
1398
1399 /* Use %rdx as out temp variable throughout */
1400 pushq_cfi %rdx
62610913 1401 CFI_REL_OFFSET rdx, 0
3f3c8b8c 1402
45d5a168
SR
1403 /*
1404 * If %cs was not the kernel segment, then the NMI triggered in user
1405 * space, which means it is definitely not nested.
1406 */
a38449ef 1407 cmpl $__KERNEL_CS, 16(%rsp)
45d5a168
SR
1408 jne first_nmi
1409
3f3c8b8c
SR
1410 /*
1411 * Check the special variable on the stack to see if NMIs are
1412 * executing.
1413 */
a38449ef 1414 cmpl $1, -8(%rsp)
3f3c8b8c
SR
1415 je nested_nmi
1416
1417 /*
1418 * Now test if the previous stack was an NMI stack.
1419 * We need the double check. We check the NMI stack to satisfy the
1420 * race when the first NMI clears the variable before returning.
1421 * We check the variable because the first NMI could be in a
1422 * breakpoint routine using a breakpoint stack.
1423 */
1424 lea 6*8(%rsp), %rdx
1425 test_in_nmi rdx, 4*8(%rsp), nested_nmi, first_nmi
62610913 1426 CFI_REMEMBER_STATE
3f3c8b8c
SR
1427
1428nested_nmi:
1429 /*
1430 * Do nothing if we interrupted the fixup in repeat_nmi.
1431 * It's about to repeat the NMI handler, so we are fine
1432 * with ignoring this one.
1433 */
1434 movq $repeat_nmi, %rdx
1435 cmpq 8(%rsp), %rdx
1436 ja 1f
1437 movq $end_repeat_nmi, %rdx
1438 cmpq 8(%rsp), %rdx
1439 ja nested_nmi_out
1440
14411:
1442 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
28696f43 1443 leaq -1*8(%rsp), %rdx
3f3c8b8c 1444 movq %rdx, %rsp
28696f43
SQ
1445 CFI_ADJUST_CFA_OFFSET 1*8
1446 leaq -10*8(%rsp), %rdx
3f3c8b8c
SR
1447 pushq_cfi $__KERNEL_DS
1448 pushq_cfi %rdx
1449 pushfq_cfi
1450 pushq_cfi $__KERNEL_CS
1451 pushq_cfi $repeat_nmi
1452
1453 /* Put stack back */
28696f43
SQ
1454 addq $(6*8), %rsp
1455 CFI_ADJUST_CFA_OFFSET -6*8
3f3c8b8c
SR
1456
1457nested_nmi_out:
1458 popq_cfi %rdx
62610913 1459 CFI_RESTORE rdx
3f3c8b8c
SR
1460
1461 /* No need to check faults here */
1462 INTERRUPT_RETURN
1463
62610913 1464 CFI_RESTORE_STATE
3f3c8b8c
SR
1465first_nmi:
1466 /*
1467 * Because nested NMIs will use the pushed location that we
1468 * stored in rdx, we must keep that space available.
1469 * Here's what our stack frame will look like:
1470 * +-------------------------+
1471 * | original SS |
1472 * | original Return RSP |
1473 * | original RFLAGS |
1474 * | original CS |
1475 * | original RIP |
1476 * +-------------------------+
1477 * | temp storage for rdx |
1478 * +-------------------------+
1479 * | NMI executing variable |
1480 * +-------------------------+
3f3c8b8c
SR
1481 * | copied SS |
1482 * | copied Return RSP |
1483 * | copied RFLAGS |
1484 * | copied CS |
1485 * | copied RIP |
1486 * +-------------------------+
28696f43
SQ
1487 * | Saved SS |
1488 * | Saved Return RSP |
1489 * | Saved RFLAGS |
1490 * | Saved CS |
1491 * | Saved RIP |
1492 * +-------------------------+
3f3c8b8c
SR
1493 * | pt_regs |
1494 * +-------------------------+
1495 *
79fb4ad6
SR
1496 * The saved stack frame is used to fix up the copied stack frame
1497 * that a nested NMI may change to make the interrupted NMI iret jump
1498 * to the repeat_nmi. The original stack frame and the temp storage
3f3c8b8c
SR
1499 * is also used by nested NMIs and can not be trusted on exit.
1500 */
79fb4ad6 1501 /* Do not pop rdx, nested NMIs will corrupt that part of the stack */
62610913
JB
1502 movq (%rsp), %rdx
1503 CFI_RESTORE rdx
1504
3f3c8b8c
SR
1505 /* Set the NMI executing variable on the stack. */
1506 pushq_cfi $1
1507
28696f43
SQ
1508 /*
1509 * Leave room for the "copied" frame
1510 */
1511 subq $(5*8), %rsp
444723dc 1512 CFI_ADJUST_CFA_OFFSET 5*8
28696f43 1513
3f3c8b8c
SR
1514 /* Copy the stack frame to the Saved frame */
1515 .rept 5
28696f43 1516 pushq_cfi 11*8(%rsp)
3f3c8b8c 1517 .endr
911d2bb5 1518 CFI_DEF_CFA_OFFSET 5*8
62610913 1519
79fb4ad6
SR
1520 /* Everything up to here is safe from nested NMIs */
1521
62610913
JB
1522 /*
1523 * If there was a nested NMI, the first NMI's iret will return
1524 * here. But NMIs are still enabled and we can take another
1525 * nested NMI. The nested NMI checks the interrupted RIP to see
1526 * if it is between repeat_nmi and end_repeat_nmi, and if so
1527 * it will just return, as we are about to repeat an NMI anyway.
1528 * This makes it safe to copy to the stack frame that a nested
1529 * NMI will update.
1530 */
1531repeat_nmi:
1532 /*
1533 * Update the stack variable to say we are still in NMI (the update
1534 * is benign for the non-repeat case, where 1 was pushed just above
1535 * to this very stack slot).
1536 */
28696f43 1537 movq $1, 10*8(%rsp)
3f3c8b8c
SR
1538
1539 /* Make another copy, this one may be modified by nested NMIs */
28696f43
SQ
1540 addq $(10*8), %rsp
1541 CFI_ADJUST_CFA_OFFSET -10*8
3f3c8b8c 1542 .rept 5
28696f43 1543 pushq_cfi -6*8(%rsp)
3f3c8b8c 1544 .endr
28696f43 1545 subq $(5*8), %rsp
911d2bb5 1546 CFI_DEF_CFA_OFFSET 5*8
62610913 1547end_repeat_nmi:
3f3c8b8c
SR
1548
1549 /*
1550 * Everything below this point can be preempted by a nested
79fb4ad6
SR
1551 * NMI if the first NMI took an exception and reset our iret stack
1552 * so that we repeat another NMI.
3f3c8b8c 1553 */
1fd466ef 1554 pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */
76f5df43
DV
1555 ALLOC_PT_GPREGS_ON_STACK
1556
1fd466ef 1557 /*
ebfc453e 1558 * Use paranoid_entry to handle SWAPGS, but no need to use paranoid_exit
1fd466ef
SR
1559 * as we should not be calling schedule in NMI context.
1560 * Even with normal interrupts enabled. An NMI should not be
1561 * setting NEED_RESCHED or anything that normal interrupts and
1562 * exceptions might do.
1563 */
ebfc453e 1564 call paranoid_entry
ddeb8f21 1565 DEFAULT_FRAME 0
7fbb98c5
SR
1566
1567 /*
1568 * Save off the CR2 register. If we take a page fault in the NMI then
1569 * it could corrupt the CR2 value. If the NMI preempts a page fault
1570 * handler before it was able to read the CR2 register, and then the
1571 * NMI itself takes a page fault, the page fault that was preempted
1572 * will read the information from the NMI page fault and not the
1573 * origin fault. Save it off and restore it if it changes.
1574 * Use the r12 callee-saved register.
1575 */
1576 movq %cr2, %r12
1577
ddeb8f21
AH
1578 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
1579 movq %rsp,%rdi
1580 movq $-1,%rsi
1581 call do_nmi
7fbb98c5
SR
1582
1583 /* Did the NMI take a page fault? Restore cr2 if it did */
1584 movq %cr2, %rcx
1585 cmpq %rcx, %r12
1586 je 1f
1587 movq %r12, %cr2
15881:
1589
ddeb8f21
AH
1590 testl %ebx,%ebx /* swapgs needed? */
1591 jnz nmi_restore
ddeb8f21
AH
1592nmi_swapgs:
1593 SWAPGS_UNSAFE_STACK
1594nmi_restore:
76f5df43
DV
1595 RESTORE_EXTRA_REGS
1596 RESTORE_C_REGS
444723dc 1597 /* Pop the extra iret frame at once */
76f5df43 1598 REMOVE_PT_GPREGS_FROM_STACK 6*8
28696f43 1599
3f3c8b8c 1600 /* Clear the NMI executing stack variable */
28696f43 1601 movq $0, 5*8(%rsp)
ddeb8f21 1602 jmp irq_return
9f1e87ea 1603 CFI_ENDPROC
ddeb8f21
AH
1604END(nmi)
1605
1606ENTRY(ignore_sysret)
1607 CFI_STARTPROC
1608 mov $-ENOSYS,%eax
1609 sysret
1610 CFI_ENDPROC
1611END(ignore_sysret)
1612
This page took 0.921234 seconds and 5 git commands to generate.