entry_64.S 44 KB

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