entry_64.S 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * linux/arch/x86_64/entry.S
  4. *
  5. * Copyright (C) 1991, 1992 Linus Torvalds
  6. * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs
  7. * Copyright (C) 2000 Pavel Machek <pavel@suse.cz>
  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. * A note on terminology:
  14. * - iret frame: Architecture defined interrupt frame from SS to RIP
  15. * at the top of the kernel process stack.
  16. *
  17. * Some macro usage:
  18. * - ENTRY/END: Define functions in the symbol table.
  19. * - TRACE_IRQ_*: Trace hardirq state for lock debugging.
  20. * - idtentry: Define exception entry points.
  21. */
  22. #include <linux/linkage.h>
  23. #include <asm/segment.h>
  24. #include <asm/cache.h>
  25. #include <asm/errno.h>
  26. #include <asm/asm-offsets.h>
  27. #include <asm/msr.h>
  28. #include <asm/unistd.h>
  29. #include <asm/thread_info.h>
  30. #include <asm/hw_irq.h>
  31. #include <asm/page_types.h>
  32. #include <asm/irqflags.h>
  33. #include <asm/paravirt.h>
  34. #include <asm/percpu.h>
  35. #include <asm/asm.h>
  36. #include <asm/smap.h>
  37. #include <asm/pgtable_types.h>
  38. #include <asm/export.h>
  39. #include <asm/frame.h>
  40. #include <asm/nospec-branch.h>
  41. #include <linux/err.h>
  42. #include "calling.h"
  43. .code64
  44. .section .entry.text, "ax"
  45. #ifdef CONFIG_PARAVIRT
  46. ENTRY(native_usergs_sysret64)
  47. UNWIND_HINT_EMPTY
  48. swapgs
  49. sysretq
  50. END(native_usergs_sysret64)
  51. #endif /* CONFIG_PARAVIRT */
  52. .macro TRACE_IRQS_FLAGS flags:req
  53. #ifdef CONFIG_TRACE_IRQFLAGS
  54. btl $9, \flags /* interrupts off? */
  55. jnc 1f
  56. TRACE_IRQS_ON
  57. 1:
  58. #endif
  59. .endm
  60. .macro TRACE_IRQS_IRETQ
  61. TRACE_IRQS_FLAGS EFLAGS(%rsp)
  62. .endm
  63. /*
  64. * When dynamic function tracer is enabled it will add a breakpoint
  65. * to all locations that it is about to modify, sync CPUs, update
  66. * all the code, sync CPUs, then remove the breakpoints. In this time
  67. * if lockdep is enabled, it might jump back into the debug handler
  68. * outside the updating of the IST protection. (TRACE_IRQS_ON/OFF).
  69. *
  70. * We need to change the IDT table before calling TRACE_IRQS_ON/OFF to
  71. * make sure the stack pointer does not get reset back to the top
  72. * of the debug stack, and instead just reuses the current stack.
  73. */
  74. #if defined(CONFIG_DYNAMIC_FTRACE) && defined(CONFIG_TRACE_IRQFLAGS)
  75. .macro TRACE_IRQS_OFF_DEBUG
  76. call debug_stack_set_zero
  77. TRACE_IRQS_OFF
  78. call debug_stack_reset
  79. .endm
  80. .macro TRACE_IRQS_ON_DEBUG
  81. call debug_stack_set_zero
  82. TRACE_IRQS_ON
  83. call debug_stack_reset
  84. .endm
  85. .macro TRACE_IRQS_IRETQ_DEBUG
  86. btl $9, EFLAGS(%rsp) /* interrupts off? */
  87. jnc 1f
  88. TRACE_IRQS_ON_DEBUG
  89. 1:
  90. .endm
  91. #else
  92. # define TRACE_IRQS_OFF_DEBUG TRACE_IRQS_OFF
  93. # define TRACE_IRQS_ON_DEBUG TRACE_IRQS_ON
  94. # define TRACE_IRQS_IRETQ_DEBUG TRACE_IRQS_IRETQ
  95. #endif
  96. /*
  97. * 64-bit SYSCALL instruction entry. Up to 6 arguments in registers.
  98. *
  99. * This is the only entry point used for 64-bit system calls. The
  100. * hardware interface is reasonably well designed and the register to
  101. * argument mapping Linux uses fits well with the registers that are
  102. * available when SYSCALL is used.
  103. *
  104. * SYSCALL instructions can be found inlined in libc implementations as
  105. * well as some other programs and libraries. There are also a handful
  106. * of SYSCALL instructions in the vDSO used, for example, as a
  107. * clock_gettimeofday fallback.
  108. *
  109. * 64-bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11,
  110. * then loads new ss, cs, and rip from previously programmed MSRs.
  111. * rflags gets masked by a value from another MSR (so CLD and CLAC
  112. * are not needed). SYSCALL does not save anything on the stack
  113. * and does not change rsp.
  114. *
  115. * Registers on entry:
  116. * rax system call number
  117. * rcx return address
  118. * r11 saved rflags (note: r11 is callee-clobbered register in C ABI)
  119. * rdi arg0
  120. * rsi arg1
  121. * rdx arg2
  122. * r10 arg3 (needs to be moved to rcx to conform to C ABI)
  123. * r8 arg4
  124. * r9 arg5
  125. * (note: r12-r15, rbp, rbx are callee-preserved in C ABI)
  126. *
  127. * Only called from user space.
  128. *
  129. * When user can change pt_regs->foo always force IRET. That is because
  130. * it deals with uncanonical addresses better. SYSRET has trouble
  131. * with them due to bugs in both AMD and Intel CPUs.
  132. */
  133. .pushsection .entry_trampoline, "ax"
  134. /*
  135. * The code in here gets remapped into cpu_entry_area's trampoline. This means
  136. * that the assembler and linker have the wrong idea as to where this code
  137. * lives (and, in fact, it's mapped more than once, so it's not even at a
  138. * fixed address). So we can't reference any symbols outside the entry
  139. * trampoline and expect it to work.
  140. *
  141. * Instead, we carefully abuse %rip-relative addressing.
  142. * _entry_trampoline(%rip) refers to the start of the remapped) entry
  143. * trampoline. We can thus find cpu_entry_area with this macro:
  144. */
  145. #define CPU_ENTRY_AREA \
  146. _entry_trampoline - CPU_ENTRY_AREA_entry_trampoline(%rip)
  147. /* The top word of the SYSENTER stack is hot and is usable as scratch space. */
  148. #define RSP_SCRATCH CPU_ENTRY_AREA_entry_stack + \
  149. SIZEOF_entry_stack - 8 + CPU_ENTRY_AREA
  150. ENTRY(entry_SYSCALL_64_trampoline)
  151. UNWIND_HINT_EMPTY
  152. swapgs
  153. /* Stash the user RSP. */
  154. movq %rsp, RSP_SCRATCH
  155. /* Note: using %rsp as a scratch reg. */
  156. SWITCH_TO_KERNEL_CR3 scratch_reg=%rsp
  157. /* Load the top of the task stack into RSP */
  158. movq CPU_ENTRY_AREA_tss + TSS_sp1 + CPU_ENTRY_AREA, %rsp
  159. /* Start building the simulated IRET frame. */
  160. pushq $__USER_DS /* pt_regs->ss */
  161. pushq RSP_SCRATCH /* pt_regs->sp */
  162. pushq %r11 /* pt_regs->flags */
  163. pushq $__USER_CS /* pt_regs->cs */
  164. pushq %rcx /* pt_regs->ip */
  165. /*
  166. * x86 lacks a near absolute jump, and we can't jump to the real
  167. * entry text with a relative jump. We could push the target
  168. * address and then use retq, but this destroys the pipeline on
  169. * many CPUs (wasting over 20 cycles on Sandy Bridge). Instead,
  170. * spill RDI and restore it in a second-stage trampoline.
  171. */
  172. pushq %rdi
  173. movq $entry_SYSCALL_64_stage2, %rdi
  174. JMP_NOSPEC %rdi
  175. END(entry_SYSCALL_64_trampoline)
  176. .popsection
  177. ENTRY(entry_SYSCALL_64_stage2)
  178. UNWIND_HINT_EMPTY
  179. popq %rdi
  180. jmp entry_SYSCALL_64_after_hwframe
  181. END(entry_SYSCALL_64_stage2)
  182. ENTRY(entry_SYSCALL_64)
  183. UNWIND_HINT_EMPTY
  184. /*
  185. * Interrupts are off on entry.
  186. * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON,
  187. * it is too small to ever cause noticeable irq latency.
  188. */
  189. swapgs
  190. /*
  191. * This path is only taken when PAGE_TABLE_ISOLATION is disabled so it
  192. * is not required to switch CR3.
  193. */
  194. movq %rsp, PER_CPU_VAR(rsp_scratch)
  195. movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
  196. /* Construct struct pt_regs on stack */
  197. pushq $__USER_DS /* pt_regs->ss */
  198. pushq PER_CPU_VAR(rsp_scratch) /* pt_regs->sp */
  199. pushq %r11 /* pt_regs->flags */
  200. pushq $__USER_CS /* pt_regs->cs */
  201. pushq %rcx /* pt_regs->ip */
  202. GLOBAL(entry_SYSCALL_64_after_hwframe)
  203. pushq %rax /* pt_regs->orig_ax */
  204. PUSH_AND_CLEAR_REGS rax=$-ENOSYS
  205. TRACE_IRQS_OFF
  206. /* IRQs are off. */
  207. movq %rax, %rdi
  208. movq %rsp, %rsi
  209. call do_syscall_64 /* returns with IRQs disabled */
  210. TRACE_IRQS_IRETQ /* we're about to change IF */
  211. /*
  212. * Try to use SYSRET instead of IRET if we're returning to
  213. * a completely clean 64-bit userspace context. If we're not,
  214. * go to the slow exit path.
  215. */
  216. movq RCX(%rsp), %rcx
  217. movq RIP(%rsp), %r11
  218. cmpq %rcx, %r11 /* SYSRET requires RCX == RIP */
  219. jne swapgs_restore_regs_and_return_to_usermode
  220. /*
  221. * On Intel CPUs, SYSRET with non-canonical RCX/RIP will #GP
  222. * in kernel space. This essentially lets the user take over
  223. * the kernel, since userspace controls RSP.
  224. *
  225. * If width of "canonical tail" ever becomes variable, this will need
  226. * to be updated to remain correct on both old and new CPUs.
  227. *
  228. * Change top bits to match most significant bit (47th or 56th bit
  229. * depending on paging mode) in the address.
  230. */
  231. #ifdef CONFIG_X86_5LEVEL
  232. ALTERNATIVE "shl $(64 - 48), %rcx; sar $(64 - 48), %rcx", \
  233. "shl $(64 - 57), %rcx; sar $(64 - 57), %rcx", X86_FEATURE_LA57
  234. #else
  235. shl $(64 - (__VIRTUAL_MASK_SHIFT+1)), %rcx
  236. sar $(64 - (__VIRTUAL_MASK_SHIFT+1)), %rcx
  237. #endif
  238. /* If this changed %rcx, it was not canonical */
  239. cmpq %rcx, %r11
  240. jne swapgs_restore_regs_and_return_to_usermode
  241. cmpq $__USER_CS, CS(%rsp) /* CS must match SYSRET */
  242. jne swapgs_restore_regs_and_return_to_usermode
  243. movq R11(%rsp), %r11
  244. cmpq %r11, EFLAGS(%rsp) /* R11 == RFLAGS */
  245. jne swapgs_restore_regs_and_return_to_usermode
  246. /*
  247. * SYSCALL clears RF when it saves RFLAGS in R11 and SYSRET cannot
  248. * restore RF properly. If the slowpath sets it for whatever reason, we
  249. * need to restore it correctly.
  250. *
  251. * SYSRET can restore TF, but unlike IRET, restoring TF results in a
  252. * trap from userspace immediately after SYSRET. This would cause an
  253. * infinite loop whenever #DB happens with register state that satisfies
  254. * the opportunistic SYSRET conditions. For example, single-stepping
  255. * this user code:
  256. *
  257. * movq $stuck_here, %rcx
  258. * pushfq
  259. * popq %r11
  260. * stuck_here:
  261. *
  262. * would never get past 'stuck_here'.
  263. */
  264. testq $(X86_EFLAGS_RF|X86_EFLAGS_TF), %r11
  265. jnz swapgs_restore_regs_and_return_to_usermode
  266. /* nothing to check for RSP */
  267. cmpq $__USER_DS, SS(%rsp) /* SS must match SYSRET */
  268. jne swapgs_restore_regs_and_return_to_usermode
  269. /*
  270. * We win! This label is here just for ease of understanding
  271. * perf profiles. Nothing jumps here.
  272. */
  273. syscall_return_via_sysret:
  274. /* rcx and r11 are already restored (see code above) */
  275. POP_REGS pop_rdi=0 skip_r11rcx=1
  276. /*
  277. * Now all regs are restored except RSP and RDI.
  278. * Save old stack pointer and switch to trampoline stack.
  279. */
  280. movq %rsp, %rdi
  281. movq PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %rsp
  282. UNWIND_HINT_EMPTY
  283. pushq RSP-RDI(%rdi) /* RSP */
  284. pushq (%rdi) /* RDI */
  285. /*
  286. * We are on the trampoline stack. All regs except RDI are live.
  287. * We can do future final exit work right here.
  288. */
  289. SWITCH_TO_USER_CR3_STACK scratch_reg=%rdi
  290. popq %rdi
  291. popq %rsp
  292. USERGS_SYSRET64
  293. END(entry_SYSCALL_64)
  294. /*
  295. * %rdi: prev task
  296. * %rsi: next task
  297. */
  298. ENTRY(__switch_to_asm)
  299. UNWIND_HINT_FUNC
  300. /*
  301. * Save callee-saved registers
  302. * This must match the order in inactive_task_frame
  303. */
  304. pushq %rbp
  305. pushq %rbx
  306. pushq %r12
  307. pushq %r13
  308. pushq %r14
  309. pushq %r15
  310. pushfq
  311. /* switch stack */
  312. movq %rsp, TASK_threadsp(%rdi)
  313. movq TASK_threadsp(%rsi), %rsp
  314. #ifdef CONFIG_STACKPROTECTOR
  315. movq TASK_stack_canary(%rsi), %rbx
  316. movq %rbx, PER_CPU_VAR(irq_stack_union)+stack_canary_offset
  317. #endif
  318. #ifdef CONFIG_RETPOLINE
  319. /*
  320. * When switching from a shallower to a deeper call stack
  321. * the RSB may either underflow or use entries populated
  322. * with userspace addresses. On CPUs where those concerns
  323. * exist, overwrite the RSB with entries which capture
  324. * speculative execution to prevent attack.
  325. */
  326. FILL_RETURN_BUFFER %r12, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW
  327. #endif
  328. /* restore callee-saved registers */
  329. popfq
  330. popq %r15
  331. popq %r14
  332. popq %r13
  333. popq %r12
  334. popq %rbx
  335. popq %rbp
  336. jmp __switch_to
  337. END(__switch_to_asm)
  338. /*
  339. * A newly forked process directly context switches into this address.
  340. *
  341. * rax: prev task we switched from
  342. * rbx: kernel thread func (NULL for user thread)
  343. * r12: kernel thread arg
  344. */
  345. ENTRY(ret_from_fork)
  346. UNWIND_HINT_EMPTY
  347. movq %rax, %rdi
  348. call schedule_tail /* rdi: 'prev' task parameter */
  349. testq %rbx, %rbx /* from kernel_thread? */
  350. jnz 1f /* kernel threads are uncommon */
  351. 2:
  352. UNWIND_HINT_REGS
  353. movq %rsp, %rdi
  354. call syscall_return_slowpath /* returns with IRQs disabled */
  355. TRACE_IRQS_ON /* user mode is traced as IRQS on */
  356. jmp swapgs_restore_regs_and_return_to_usermode
  357. 1:
  358. /* kernel thread */
  359. UNWIND_HINT_EMPTY
  360. movq %r12, %rdi
  361. CALL_NOSPEC %rbx
  362. /*
  363. * A kernel thread is allowed to return here after successfully
  364. * calling do_execve(). Exit to userspace to complete the execve()
  365. * syscall.
  366. */
  367. movq $0, RAX(%rsp)
  368. jmp 2b
  369. END(ret_from_fork)
  370. /*
  371. * Build the entry stubs with some assembler magic.
  372. * We pack 1 stub into every 8-byte block.
  373. */
  374. .align 8
  375. ENTRY(irq_entries_start)
  376. vector=FIRST_EXTERNAL_VECTOR
  377. .rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR)
  378. UNWIND_HINT_IRET_REGS
  379. pushq $(~vector+0x80) /* Note: always in signed byte range */
  380. jmp common_interrupt
  381. .align 8
  382. vector=vector+1
  383. .endr
  384. END(irq_entries_start)
  385. .align 8
  386. ENTRY(spurious_entries_start)
  387. vector=FIRST_SYSTEM_VECTOR
  388. .rept (NR_VECTORS - FIRST_SYSTEM_VECTOR)
  389. UNWIND_HINT_IRET_REGS
  390. pushq $(~vector+0x80) /* Note: always in signed byte range */
  391. jmp common_spurious
  392. .align 8
  393. vector=vector+1
  394. .endr
  395. END(spurious_entries_start)
  396. .macro DEBUG_ENTRY_ASSERT_IRQS_OFF
  397. #ifdef CONFIG_DEBUG_ENTRY
  398. pushq %rax
  399. SAVE_FLAGS(CLBR_RAX)
  400. testl $X86_EFLAGS_IF, %eax
  401. jz .Lokay_\@
  402. ud2
  403. .Lokay_\@:
  404. popq %rax
  405. #endif
  406. .endm
  407. /*
  408. * Enters the IRQ stack if we're not already using it. NMI-safe. Clobbers
  409. * flags and puts old RSP into old_rsp, and leaves all other GPRs alone.
  410. * Requires kernel GSBASE.
  411. *
  412. * The invariant is that, if irq_count != -1, then the IRQ stack is in use.
  413. */
  414. .macro ENTER_IRQ_STACK regs=1 old_rsp save_ret=0
  415. DEBUG_ENTRY_ASSERT_IRQS_OFF
  416. .if \save_ret
  417. /*
  418. * If save_ret is set, the original stack contains one additional
  419. * entry -- the return address. Therefore, move the address one
  420. * entry below %rsp to \old_rsp.
  421. */
  422. leaq 8(%rsp), \old_rsp
  423. .else
  424. movq %rsp, \old_rsp
  425. .endif
  426. .if \regs
  427. UNWIND_HINT_REGS base=\old_rsp
  428. .endif
  429. incl PER_CPU_VAR(irq_count)
  430. jnz .Lirq_stack_push_old_rsp_\@
  431. /*
  432. * Right now, if we just incremented irq_count to zero, we've
  433. * claimed the IRQ stack but we haven't switched to it yet.
  434. *
  435. * If anything is added that can interrupt us here without using IST,
  436. * it must be *extremely* careful to limit its stack usage. This
  437. * could include kprobes and a hypothetical future IST-less #DB
  438. * handler.
  439. *
  440. * The OOPS unwinder relies on the word at the top of the IRQ
  441. * stack linking back to the previous RSP for the entire time we're
  442. * on the IRQ stack. For this to work reliably, we need to write
  443. * it before we actually move ourselves to the IRQ stack.
  444. */
  445. movq \old_rsp, PER_CPU_VAR(irq_stack_union + IRQ_STACK_SIZE - 8)
  446. movq PER_CPU_VAR(irq_stack_ptr), %rsp
  447. #ifdef CONFIG_DEBUG_ENTRY
  448. /*
  449. * If the first movq above becomes wrong due to IRQ stack layout
  450. * changes, the only way we'll notice is if we try to unwind right
  451. * here. Assert that we set up the stack right to catch this type
  452. * of bug quickly.
  453. */
  454. cmpq -8(%rsp), \old_rsp
  455. je .Lirq_stack_okay\@
  456. ud2
  457. .Lirq_stack_okay\@:
  458. #endif
  459. .Lirq_stack_push_old_rsp_\@:
  460. pushq \old_rsp
  461. .if \regs
  462. UNWIND_HINT_REGS indirect=1
  463. .endif
  464. .if \save_ret
  465. /*
  466. * Push the return address to the stack. This return address can
  467. * be found at the "real" original RSP, which was offset by 8 at
  468. * the beginning of this macro.
  469. */
  470. pushq -8(\old_rsp)
  471. .endif
  472. .endm
  473. /*
  474. * Undoes ENTER_IRQ_STACK.
  475. */
  476. .macro LEAVE_IRQ_STACK regs=1
  477. DEBUG_ENTRY_ASSERT_IRQS_OFF
  478. /* We need to be off the IRQ stack before decrementing irq_count. */
  479. popq %rsp
  480. .if \regs
  481. UNWIND_HINT_REGS
  482. .endif
  483. /*
  484. * As in ENTER_IRQ_STACK, irq_count == 0, we are still claiming
  485. * the irq stack but we're not on it.
  486. */
  487. decl PER_CPU_VAR(irq_count)
  488. .endm
  489. /*
  490. * Interrupt entry helper function.
  491. *
  492. * Entry runs with interrupts off. Stack layout at entry:
  493. * +----------------------------------------------------+
  494. * | regs->ss |
  495. * | regs->rsp |
  496. * | regs->eflags |
  497. * | regs->cs |
  498. * | regs->ip |
  499. * +----------------------------------------------------+
  500. * | regs->orig_ax = ~(interrupt number) |
  501. * +----------------------------------------------------+
  502. * | return address |
  503. * +----------------------------------------------------+
  504. */
  505. ENTRY(interrupt_entry)
  506. UNWIND_HINT_IRET_REGS offset=16
  507. ASM_CLAC
  508. cld
  509. testb $3, CS-ORIG_RAX+8(%rsp)
  510. jz 1f
  511. SWAPGS
  512. FENCE_SWAPGS_USER_ENTRY
  513. /*
  514. * Switch to the thread stack. The IRET frame and orig_ax are
  515. * on the stack, as well as the return address. RDI..R12 are
  516. * not (yet) on the stack and space has not (yet) been
  517. * allocated for them.
  518. */
  519. pushq %rdi
  520. /* Need to switch before accessing the thread stack. */
  521. SWITCH_TO_KERNEL_CR3 scratch_reg=%rdi
  522. movq %rsp, %rdi
  523. movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
  524. /*
  525. * We have RDI, return address, and orig_ax on the stack on
  526. * top of the IRET frame. That means offset=24
  527. */
  528. UNWIND_HINT_IRET_REGS base=%rdi offset=24
  529. pushq 7*8(%rdi) /* regs->ss */
  530. pushq 6*8(%rdi) /* regs->rsp */
  531. pushq 5*8(%rdi) /* regs->eflags */
  532. pushq 4*8(%rdi) /* regs->cs */
  533. pushq 3*8(%rdi) /* regs->ip */
  534. UNWIND_HINT_IRET_REGS
  535. pushq 2*8(%rdi) /* regs->orig_ax */
  536. pushq 8(%rdi) /* return address */
  537. movq (%rdi), %rdi
  538. jmp 2f
  539. 1:
  540. FENCE_SWAPGS_KERNEL_ENTRY
  541. 2:
  542. PUSH_AND_CLEAR_REGS save_ret=1
  543. ENCODE_FRAME_POINTER 8
  544. testb $3, CS+8(%rsp)
  545. jz 1f
  546. /*
  547. * IRQ from user mode.
  548. *
  549. * We need to tell lockdep that IRQs are off. We can't do this until
  550. * we fix gsbase, and we should do it before enter_from_user_mode
  551. * (which can take locks). Since TRACE_IRQS_OFF is idempotent,
  552. * the simplest way to handle it is to just call it twice if
  553. * we enter from user mode. There's no reason to optimize this since
  554. * TRACE_IRQS_OFF is a no-op if lockdep is off.
  555. */
  556. TRACE_IRQS_OFF
  557. CALL_enter_from_user_mode
  558. 1:
  559. ENTER_IRQ_STACK old_rsp=%rdi save_ret=1
  560. /* We entered an interrupt context - irqs are off: */
  561. TRACE_IRQS_OFF
  562. ret
  563. END(interrupt_entry)
  564. _ASM_NOKPROBE(interrupt_entry)
  565. /* Interrupt entry/exit. */
  566. /*
  567. * The interrupt stubs push (~vector+0x80) onto the stack and
  568. * then jump to common_spurious/interrupt.
  569. */
  570. common_spurious:
  571. addq $-0x80, (%rsp) /* Adjust vector to [-256, -1] range */
  572. call interrupt_entry
  573. UNWIND_HINT_REGS indirect=1
  574. call smp_spurious_interrupt /* rdi points to pt_regs */
  575. jmp ret_from_intr
  576. END(common_spurious)
  577. _ASM_NOKPROBE(common_spurious)
  578. /* common_interrupt is a hotpath. Align it */
  579. .p2align CONFIG_X86_L1_CACHE_SHIFT
  580. common_interrupt:
  581. addq $-0x80, (%rsp) /* Adjust vector to [-256, -1] range */
  582. call interrupt_entry
  583. UNWIND_HINT_REGS indirect=1
  584. call do_IRQ /* rdi points to pt_regs */
  585. /* 0(%rsp): old RSP */
  586. ret_from_intr:
  587. DISABLE_INTERRUPTS(CLBR_ANY)
  588. TRACE_IRQS_OFF
  589. LEAVE_IRQ_STACK
  590. testb $3, CS(%rsp)
  591. jz retint_kernel
  592. /* Interrupt came from user space */
  593. GLOBAL(retint_user)
  594. mov %rsp,%rdi
  595. call prepare_exit_to_usermode
  596. TRACE_IRQS_IRETQ
  597. GLOBAL(swapgs_restore_regs_and_return_to_usermode)
  598. #ifdef CONFIG_DEBUG_ENTRY
  599. /* Assert that pt_regs indicates user mode. */
  600. testb $3, CS(%rsp)
  601. jnz 1f
  602. ud2
  603. 1:
  604. #endif
  605. POP_REGS pop_rdi=0
  606. /*
  607. * The stack is now user RDI, orig_ax, RIP, CS, EFLAGS, RSP, SS.
  608. * Save old stack pointer and switch to trampoline stack.
  609. */
  610. movq %rsp, %rdi
  611. movq PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %rsp
  612. UNWIND_HINT_EMPTY
  613. /* Copy the IRET frame to the trampoline stack. */
  614. pushq 6*8(%rdi) /* SS */
  615. pushq 5*8(%rdi) /* RSP */
  616. pushq 4*8(%rdi) /* EFLAGS */
  617. pushq 3*8(%rdi) /* CS */
  618. pushq 2*8(%rdi) /* RIP */
  619. /* Push user RDI on the trampoline stack. */
  620. pushq (%rdi)
  621. /*
  622. * We are on the trampoline stack. All regs except RDI are live.
  623. * We can do future final exit work right here.
  624. */
  625. SWITCH_TO_USER_CR3_STACK scratch_reg=%rdi
  626. /* Restore RDI. */
  627. popq %rdi
  628. SWAPGS
  629. INTERRUPT_RETURN
  630. /* Returning to kernel space */
  631. retint_kernel:
  632. #ifdef CONFIG_PREEMPT
  633. /* Interrupts are off */
  634. /* Check if we need preemption */
  635. btl $9, EFLAGS(%rsp) /* were interrupts off? */
  636. jnc 1f
  637. 0: cmpl $0, PER_CPU_VAR(__preempt_count)
  638. jnz 1f
  639. call preempt_schedule_irq
  640. jmp 0b
  641. 1:
  642. #endif
  643. /*
  644. * The iretq could re-enable interrupts:
  645. */
  646. TRACE_IRQS_IRETQ
  647. GLOBAL(restore_regs_and_return_to_kernel)
  648. #ifdef CONFIG_DEBUG_ENTRY
  649. /* Assert that pt_regs indicates kernel mode. */
  650. testb $3, CS(%rsp)
  651. jz 1f
  652. ud2
  653. 1:
  654. #endif
  655. POP_REGS
  656. addq $8, %rsp /* skip regs->orig_ax */
  657. /*
  658. * ARCH_HAS_MEMBARRIER_SYNC_CORE rely on IRET core serialization
  659. * when returning from IPI handler.
  660. */
  661. INTERRUPT_RETURN
  662. ENTRY(native_iret)
  663. UNWIND_HINT_IRET_REGS
  664. /*
  665. * Are we returning to a stack segment from the LDT? Note: in
  666. * 64-bit mode SS:RSP on the exception stack is always valid.
  667. */
  668. #ifdef CONFIG_X86_ESPFIX64
  669. testb $4, (SS-RIP)(%rsp)
  670. jnz native_irq_return_ldt
  671. #endif
  672. .global native_irq_return_iret
  673. native_irq_return_iret:
  674. /*
  675. * This may fault. Non-paranoid faults on return to userspace are
  676. * handled by fixup_bad_iret. These include #SS, #GP, and #NP.
  677. * Double-faults due to espfix64 are handled in do_double_fault.
  678. * Other faults here are fatal.
  679. */
  680. iretq
  681. #ifdef CONFIG_X86_ESPFIX64
  682. native_irq_return_ldt:
  683. /*
  684. * We are running with user GSBASE. All GPRs contain their user
  685. * values. We have a percpu ESPFIX stack that is eight slots
  686. * long (see ESPFIX_STACK_SIZE). espfix_waddr points to the bottom
  687. * of the ESPFIX stack.
  688. *
  689. * We clobber RAX and RDI in this code. We stash RDI on the
  690. * normal stack and RAX on the ESPFIX stack.
  691. *
  692. * The ESPFIX stack layout we set up looks like this:
  693. *
  694. * --- top of ESPFIX stack ---
  695. * SS
  696. * RSP
  697. * RFLAGS
  698. * CS
  699. * RIP <-- RSP points here when we're done
  700. * RAX <-- espfix_waddr points here
  701. * --- bottom of ESPFIX stack ---
  702. */
  703. pushq %rdi /* Stash user RDI */
  704. SWAPGS /* to kernel GS */
  705. SWITCH_TO_KERNEL_CR3 scratch_reg=%rdi /* to kernel CR3 */
  706. movq PER_CPU_VAR(espfix_waddr), %rdi
  707. movq %rax, (0*8)(%rdi) /* user RAX */
  708. movq (1*8)(%rsp), %rax /* user RIP */
  709. movq %rax, (1*8)(%rdi)
  710. movq (2*8)(%rsp), %rax /* user CS */
  711. movq %rax, (2*8)(%rdi)
  712. movq (3*8)(%rsp), %rax /* user RFLAGS */
  713. movq %rax, (3*8)(%rdi)
  714. movq (5*8)(%rsp), %rax /* user SS */
  715. movq %rax, (5*8)(%rdi)
  716. movq (4*8)(%rsp), %rax /* user RSP */
  717. movq %rax, (4*8)(%rdi)
  718. /* Now RAX == RSP. */
  719. andl $0xffff0000, %eax /* RAX = (RSP & 0xffff0000) */
  720. /*
  721. * espfix_stack[31:16] == 0. The page tables are set up such that
  722. * (espfix_stack | (X & 0xffff0000)) points to a read-only alias of
  723. * espfix_waddr for any X. That is, there are 65536 RO aliases of
  724. * the same page. Set up RSP so that RSP[31:16] contains the
  725. * respective 16 bits of the /userspace/ RSP and RSP nonetheless
  726. * still points to an RO alias of the ESPFIX stack.
  727. */
  728. orq PER_CPU_VAR(espfix_stack), %rax
  729. SWITCH_TO_USER_CR3_STACK scratch_reg=%rdi
  730. SWAPGS /* to user GS */
  731. popq %rdi /* Restore user RDI */
  732. movq %rax, %rsp
  733. UNWIND_HINT_IRET_REGS offset=8
  734. /*
  735. * At this point, we cannot write to the stack any more, but we can
  736. * still read.
  737. */
  738. popq %rax /* Restore user RAX */
  739. /*
  740. * RSP now points to an ordinary IRET frame, except that the page
  741. * is read-only and RSP[31:16] are preloaded with the userspace
  742. * values. We can now IRET back to userspace.
  743. */
  744. jmp native_irq_return_iret
  745. #endif
  746. END(common_interrupt)
  747. _ASM_NOKPROBE(common_interrupt)
  748. /*
  749. * APIC interrupts.
  750. */
  751. .macro apicinterrupt3 num sym do_sym
  752. ENTRY(\sym)
  753. UNWIND_HINT_IRET_REGS
  754. pushq $~(\num)
  755. .Lcommon_\sym:
  756. call interrupt_entry
  757. UNWIND_HINT_REGS indirect=1
  758. call \do_sym /* rdi points to pt_regs */
  759. jmp ret_from_intr
  760. END(\sym)
  761. _ASM_NOKPROBE(\sym)
  762. .endm
  763. /* Make sure APIC interrupt handlers end up in the irqentry section: */
  764. #define PUSH_SECTION_IRQENTRY .pushsection .irqentry.text, "ax"
  765. #define POP_SECTION_IRQENTRY .popsection
  766. .macro apicinterrupt num sym do_sym
  767. PUSH_SECTION_IRQENTRY
  768. apicinterrupt3 \num \sym \do_sym
  769. POP_SECTION_IRQENTRY
  770. .endm
  771. #ifdef CONFIG_SMP
  772. apicinterrupt3 IRQ_MOVE_CLEANUP_VECTOR irq_move_cleanup_interrupt smp_irq_move_cleanup_interrupt
  773. apicinterrupt3 REBOOT_VECTOR reboot_interrupt smp_reboot_interrupt
  774. #endif
  775. #ifdef CONFIG_X86_UV
  776. apicinterrupt3 UV_BAU_MESSAGE uv_bau_message_intr1 uv_bau_message_interrupt
  777. #endif
  778. apicinterrupt LOCAL_TIMER_VECTOR apic_timer_interrupt smp_apic_timer_interrupt
  779. apicinterrupt X86_PLATFORM_IPI_VECTOR x86_platform_ipi smp_x86_platform_ipi
  780. #ifdef CONFIG_HAVE_KVM
  781. apicinterrupt3 POSTED_INTR_VECTOR kvm_posted_intr_ipi smp_kvm_posted_intr_ipi
  782. apicinterrupt3 POSTED_INTR_WAKEUP_VECTOR kvm_posted_intr_wakeup_ipi smp_kvm_posted_intr_wakeup_ipi
  783. apicinterrupt3 POSTED_INTR_NESTED_VECTOR kvm_posted_intr_nested_ipi smp_kvm_posted_intr_nested_ipi
  784. #endif
  785. #ifdef CONFIG_X86_MCE_THRESHOLD
  786. apicinterrupt THRESHOLD_APIC_VECTOR threshold_interrupt smp_threshold_interrupt
  787. #endif
  788. #ifdef CONFIG_X86_MCE_AMD
  789. apicinterrupt DEFERRED_ERROR_VECTOR deferred_error_interrupt smp_deferred_error_interrupt
  790. #endif
  791. #ifdef CONFIG_X86_THERMAL_VECTOR
  792. apicinterrupt THERMAL_APIC_VECTOR thermal_interrupt smp_thermal_interrupt
  793. #endif
  794. #ifdef CONFIG_SMP
  795. apicinterrupt CALL_FUNCTION_SINGLE_VECTOR call_function_single_interrupt smp_call_function_single_interrupt
  796. apicinterrupt CALL_FUNCTION_VECTOR call_function_interrupt smp_call_function_interrupt
  797. apicinterrupt RESCHEDULE_VECTOR reschedule_interrupt smp_reschedule_interrupt
  798. #endif
  799. apicinterrupt ERROR_APIC_VECTOR error_interrupt smp_error_interrupt
  800. apicinterrupt SPURIOUS_APIC_VECTOR spurious_interrupt smp_spurious_interrupt
  801. #ifdef CONFIG_IRQ_WORK
  802. apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt
  803. #endif
  804. /*
  805. * Exception entry points.
  806. */
  807. #define CPU_TSS_IST(x) PER_CPU_VAR(cpu_tss_rw) + (TSS_ist + ((x) - 1) * 8)
  808. .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 create_gap=0
  809. ENTRY(\sym)
  810. UNWIND_HINT_IRET_REGS offset=\has_error_code*8
  811. /* Sanity check */
  812. .if \shift_ist != -1 && \paranoid == 0
  813. .error "using shift_ist requires paranoid=1"
  814. .endif
  815. ASM_CLAC
  816. .if \has_error_code == 0
  817. pushq $-1 /* ORIG_RAX: no syscall to restart */
  818. .endif
  819. .if \paranoid == 1
  820. testb $3, CS-ORIG_RAX(%rsp) /* If coming from userspace, switch stacks */
  821. jnz .Lfrom_usermode_switch_stack_\@
  822. .endif
  823. .if \create_gap == 1
  824. /*
  825. * If coming from kernel space, create a 6-word gap to allow the
  826. * int3 handler to emulate a call instruction.
  827. */
  828. testb $3, CS-ORIG_RAX(%rsp)
  829. jnz .Lfrom_usermode_no_gap_\@
  830. .rept 6
  831. pushq 5*8(%rsp)
  832. .endr
  833. UNWIND_HINT_IRET_REGS offset=8
  834. .Lfrom_usermode_no_gap_\@:
  835. .endif
  836. .if \paranoid
  837. call paranoid_entry
  838. .else
  839. call error_entry
  840. .endif
  841. UNWIND_HINT_REGS
  842. /* returned flag: ebx=0: need swapgs on exit, ebx=1: don't need it */
  843. .if \paranoid
  844. .if \shift_ist != -1
  845. TRACE_IRQS_OFF_DEBUG /* reload IDT in case of recursion */
  846. .else
  847. TRACE_IRQS_OFF
  848. .endif
  849. .endif
  850. movq %rsp, %rdi /* pt_regs pointer */
  851. .if \has_error_code
  852. movq ORIG_RAX(%rsp), %rsi /* get error code */
  853. movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */
  854. .else
  855. xorl %esi, %esi /* no error code */
  856. .endif
  857. .if \shift_ist != -1
  858. subq $EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist)
  859. .endif
  860. call \do_sym
  861. .if \shift_ist != -1
  862. addq $EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist)
  863. .endif
  864. /* these procedures expect "no swapgs" flag in ebx */
  865. .if \paranoid
  866. jmp paranoid_exit
  867. .else
  868. jmp error_exit
  869. .endif
  870. .if \paranoid == 1
  871. /*
  872. * Entry from userspace. Switch stacks and treat it
  873. * as a normal entry. This means that paranoid handlers
  874. * run in real process context if user_mode(regs).
  875. */
  876. .Lfrom_usermode_switch_stack_\@:
  877. call error_entry
  878. movq %rsp, %rdi /* pt_regs pointer */
  879. .if \has_error_code
  880. movq ORIG_RAX(%rsp), %rsi /* get error code */
  881. movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */
  882. .else
  883. xorl %esi, %esi /* no error code */
  884. .endif
  885. call \do_sym
  886. jmp error_exit
  887. .endif
  888. _ASM_NOKPROBE(\sym)
  889. END(\sym)
  890. .endm
  891. idtentry divide_error do_divide_error has_error_code=0
  892. idtentry overflow do_overflow has_error_code=0
  893. idtentry bounds do_bounds has_error_code=0
  894. idtentry invalid_op do_invalid_op has_error_code=0
  895. idtentry device_not_available do_device_not_available has_error_code=0
  896. idtentry double_fault do_double_fault has_error_code=1 paranoid=2
  897. idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0
  898. idtentry invalid_TSS do_invalid_TSS has_error_code=1
  899. idtentry segment_not_present do_segment_not_present has_error_code=1
  900. idtentry spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0
  901. idtentry coprocessor_error do_coprocessor_error has_error_code=0
  902. idtentry alignment_check do_alignment_check has_error_code=1
  903. idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0
  904. /*
  905. * Reload gs selector with exception handling
  906. * edi: new selector
  907. */
  908. ENTRY(native_load_gs_index)
  909. FRAME_BEGIN
  910. pushfq
  911. DISABLE_INTERRUPTS(CLBR_ANY & ~CLBR_RDI)
  912. TRACE_IRQS_OFF
  913. SWAPGS
  914. .Lgs_change:
  915. movl %edi, %gs
  916. 2: ALTERNATIVE "", "mfence", X86_BUG_SWAPGS_FENCE
  917. SWAPGS
  918. TRACE_IRQS_FLAGS (%rsp)
  919. popfq
  920. FRAME_END
  921. ret
  922. ENDPROC(native_load_gs_index)
  923. EXPORT_SYMBOL(native_load_gs_index)
  924. _ASM_EXTABLE(.Lgs_change, bad_gs)
  925. .section .fixup, "ax"
  926. /* running with kernelgs */
  927. bad_gs:
  928. SWAPGS /* switch back to user gs */
  929. .macro ZAP_GS
  930. /* This can't be a string because the preprocessor needs to see it. */
  931. movl $__USER_DS, %eax
  932. movl %eax, %gs
  933. .endm
  934. ALTERNATIVE "", "ZAP_GS", X86_BUG_NULL_SEG
  935. xorl %eax, %eax
  936. movl %eax, %gs
  937. jmp 2b
  938. .previous
  939. /* Call softirq on interrupt stack. Interrupts are off. */
  940. ENTRY(do_softirq_own_stack)
  941. pushq %rbp
  942. mov %rsp, %rbp
  943. ENTER_IRQ_STACK regs=0 old_rsp=%r11
  944. call __do_softirq
  945. LEAVE_IRQ_STACK regs=0
  946. leaveq
  947. ret
  948. ENDPROC(do_softirq_own_stack)
  949. #ifdef CONFIG_XEN
  950. idtentry hypervisor_callback xen_do_hypervisor_callback has_error_code=0
  951. /*
  952. * A note on the "critical region" in our callback handler.
  953. * We want to avoid stacking callback handlers due to events occurring
  954. * during handling of the last event. To do this, we keep events disabled
  955. * until we've done all processing. HOWEVER, we must enable events before
  956. * popping the stack frame (can't be done atomically) and so it would still
  957. * be possible to get enough handler activations to overflow the stack.
  958. * Although unlikely, bugs of that kind are hard to track down, so we'd
  959. * like to avoid the possibility.
  960. * So, on entry to the handler we detect whether we interrupted an
  961. * existing activation in its critical region -- if so, we pop the current
  962. * activation and restart the handler using the previous one.
  963. */
  964. ENTRY(xen_do_hypervisor_callback) /* do_hypervisor_callback(struct *pt_regs) */
  965. /*
  966. * Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will
  967. * see the correct pointer to the pt_regs
  968. */
  969. UNWIND_HINT_FUNC
  970. movq %rdi, %rsp /* we don't return, adjust the stack frame */
  971. UNWIND_HINT_REGS
  972. ENTER_IRQ_STACK old_rsp=%r10
  973. call xen_evtchn_do_upcall
  974. LEAVE_IRQ_STACK
  975. #ifndef CONFIG_PREEMPT
  976. call xen_maybe_preempt_hcall
  977. #endif
  978. jmp error_exit
  979. END(xen_do_hypervisor_callback)
  980. /*
  981. * Hypervisor uses this for application faults while it executes.
  982. * We get here for two reasons:
  983. * 1. Fault while reloading DS, ES, FS or GS
  984. * 2. Fault while executing IRET
  985. * Category 1 we do not need to fix up as Xen has already reloaded all segment
  986. * registers that could be reloaded and zeroed the others.
  987. * Category 2 we fix up by killing the current process. We cannot use the
  988. * normal Linux return path in this case because if we use the IRET hypercall
  989. * to pop the stack frame we end up in an infinite loop of failsafe callbacks.
  990. * We distinguish between categories by comparing each saved segment register
  991. * with its current contents: any discrepancy means we in category 1.
  992. */
  993. ENTRY(xen_failsafe_callback)
  994. UNWIND_HINT_EMPTY
  995. movl %ds, %ecx
  996. cmpw %cx, 0x10(%rsp)
  997. jne 1f
  998. movl %es, %ecx
  999. cmpw %cx, 0x18(%rsp)
  1000. jne 1f
  1001. movl %fs, %ecx
  1002. cmpw %cx, 0x20(%rsp)
  1003. jne 1f
  1004. movl %gs, %ecx
  1005. cmpw %cx, 0x28(%rsp)
  1006. jne 1f
  1007. /* All segments match their saved values => Category 2 (Bad IRET). */
  1008. movq (%rsp), %rcx
  1009. movq 8(%rsp), %r11
  1010. addq $0x30, %rsp
  1011. pushq $0 /* RIP */
  1012. UNWIND_HINT_IRET_REGS offset=8
  1013. jmp general_protection
  1014. 1: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */
  1015. movq (%rsp), %rcx
  1016. movq 8(%rsp), %r11
  1017. addq $0x30, %rsp
  1018. UNWIND_HINT_IRET_REGS
  1019. pushq $-1 /* orig_ax = -1 => not a system call */
  1020. PUSH_AND_CLEAR_REGS
  1021. ENCODE_FRAME_POINTER
  1022. jmp error_exit
  1023. END(xen_failsafe_callback)
  1024. apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
  1025. xen_hvm_callback_vector xen_evtchn_do_upcall
  1026. #endif /* CONFIG_XEN */
  1027. #if IS_ENABLED(CONFIG_HYPERV)
  1028. apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
  1029. hyperv_callback_vector hyperv_vector_handler
  1030. apicinterrupt3 HYPERV_REENLIGHTENMENT_VECTOR \
  1031. hyperv_reenlightenment_vector hyperv_reenlightenment_intr
  1032. apicinterrupt3 HYPERV_STIMER0_VECTOR \
  1033. hv_stimer0_callback_vector hv_stimer0_vector_handler
  1034. #endif /* CONFIG_HYPERV */
  1035. idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
  1036. idtentry int3 do_int3 has_error_code=0 create_gap=1
  1037. idtentry stack_segment do_stack_segment has_error_code=1
  1038. #ifdef CONFIG_XEN
  1039. idtentry xennmi do_nmi has_error_code=0
  1040. idtentry xendebug do_debug has_error_code=0
  1041. #endif
  1042. idtentry general_protection do_general_protection has_error_code=1
  1043. idtentry page_fault do_page_fault has_error_code=1
  1044. #ifdef CONFIG_KVM_GUEST
  1045. idtentry async_page_fault do_async_page_fault has_error_code=1
  1046. #endif
  1047. #ifdef CONFIG_X86_MCE
  1048. idtentry machine_check do_mce has_error_code=0 paranoid=1
  1049. #endif
  1050. /*
  1051. * Save all registers in pt_regs, and switch gs if needed.
  1052. * Use slow, but surefire "are we in kernel?" check.
  1053. * Return: ebx=0: need swapgs on exit, ebx=1: otherwise
  1054. */
  1055. ENTRY(paranoid_entry)
  1056. UNWIND_HINT_FUNC
  1057. cld
  1058. PUSH_AND_CLEAR_REGS save_ret=1
  1059. ENCODE_FRAME_POINTER 8
  1060. movl $1, %ebx
  1061. movl $MSR_GS_BASE, %ecx
  1062. rdmsr
  1063. testl %edx, %edx
  1064. js 1f /* negative -> in kernel */
  1065. SWAPGS
  1066. xorl %ebx, %ebx
  1067. 1:
  1068. /*
  1069. * Always stash CR3 in %r14. This value will be restored,
  1070. * verbatim, at exit. Needed if paranoid_entry interrupted
  1071. * another entry that already switched to the user CR3 value
  1072. * but has not yet returned to userspace.
  1073. *
  1074. * This is also why CS (stashed in the "iret frame" by the
  1075. * hardware at entry) can not be used: this may be a return
  1076. * to kernel code, but with a user CR3 value.
  1077. */
  1078. SAVE_AND_SWITCH_TO_KERNEL_CR3 scratch_reg=%rax save_reg=%r14
  1079. /*
  1080. * The above SAVE_AND_SWITCH_TO_KERNEL_CR3 macro doesn't do an
  1081. * unconditional CR3 write, even in the PTI case. So do an lfence
  1082. * to prevent GS speculation, regardless of whether PTI is enabled.
  1083. */
  1084. FENCE_SWAPGS_KERNEL_ENTRY
  1085. ret
  1086. END(paranoid_entry)
  1087. /*
  1088. * "Paranoid" exit path from exception stack. This is invoked
  1089. * only on return from non-NMI IST interrupts that came
  1090. * from kernel space.
  1091. *
  1092. * We may be returning to very strange contexts (e.g. very early
  1093. * in syscall entry), so checking for preemption here would
  1094. * be complicated. Fortunately, we there's no good reason
  1095. * to try to handle preemption here.
  1096. *
  1097. * On entry, ebx is "no swapgs" flag (1: don't need swapgs, 0: need it)
  1098. */
  1099. ENTRY(paranoid_exit)
  1100. UNWIND_HINT_REGS
  1101. DISABLE_INTERRUPTS(CLBR_ANY)
  1102. TRACE_IRQS_OFF_DEBUG
  1103. testl %ebx, %ebx /* swapgs needed? */
  1104. jnz .Lparanoid_exit_no_swapgs
  1105. TRACE_IRQS_IRETQ
  1106. /* Always restore stashed CR3 value (see paranoid_entry) */
  1107. RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
  1108. SWAPGS_UNSAFE_STACK
  1109. jmp .Lparanoid_exit_restore
  1110. .Lparanoid_exit_no_swapgs:
  1111. TRACE_IRQS_IRETQ_DEBUG
  1112. /* Always restore stashed CR3 value (see paranoid_entry) */
  1113. RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
  1114. .Lparanoid_exit_restore:
  1115. jmp restore_regs_and_return_to_kernel
  1116. END(paranoid_exit)
  1117. /*
  1118. * Save all registers in pt_regs, and switch GS if needed.
  1119. */
  1120. ENTRY(error_entry)
  1121. UNWIND_HINT_FUNC
  1122. cld
  1123. PUSH_AND_CLEAR_REGS save_ret=1
  1124. ENCODE_FRAME_POINTER 8
  1125. testb $3, CS+8(%rsp)
  1126. jz .Lerror_kernelspace
  1127. /*
  1128. * We entered from user mode or we're pretending to have entered
  1129. * from user mode due to an IRET fault.
  1130. */
  1131. SWAPGS
  1132. FENCE_SWAPGS_USER_ENTRY
  1133. /* We have user CR3. Change to kernel CR3. */
  1134. SWITCH_TO_KERNEL_CR3 scratch_reg=%rax
  1135. .Lerror_entry_from_usermode_after_swapgs:
  1136. /* Put us onto the real thread stack. */
  1137. popq %r12 /* save return addr in %12 */
  1138. movq %rsp, %rdi /* arg0 = pt_regs pointer */
  1139. call sync_regs
  1140. movq %rax, %rsp /* switch stack */
  1141. ENCODE_FRAME_POINTER
  1142. pushq %r12
  1143. /*
  1144. * We need to tell lockdep that IRQs are off. We can't do this until
  1145. * we fix gsbase, and we should do it before enter_from_user_mode
  1146. * (which can take locks).
  1147. */
  1148. TRACE_IRQS_OFF
  1149. CALL_enter_from_user_mode
  1150. ret
  1151. .Lerror_entry_done_lfence:
  1152. FENCE_SWAPGS_KERNEL_ENTRY
  1153. .Lerror_entry_done:
  1154. TRACE_IRQS_OFF
  1155. ret
  1156. /*
  1157. * There are two places in the kernel that can potentially fault with
  1158. * usergs. Handle them here. B stepping K8s sometimes report a
  1159. * truncated RIP for IRET exceptions returning to compat mode. Check
  1160. * for these here too.
  1161. */
  1162. .Lerror_kernelspace:
  1163. leaq native_irq_return_iret(%rip), %rcx
  1164. cmpq %rcx, RIP+8(%rsp)
  1165. je .Lerror_bad_iret
  1166. movl %ecx, %eax /* zero extend */
  1167. cmpq %rax, RIP+8(%rsp)
  1168. je .Lbstep_iret
  1169. cmpq $.Lgs_change, RIP+8(%rsp)
  1170. jne .Lerror_entry_done_lfence
  1171. /*
  1172. * hack: .Lgs_change can fail with user gsbase. If this happens, fix up
  1173. * gsbase and proceed. We'll fix up the exception and land in
  1174. * .Lgs_change's error handler with kernel gsbase.
  1175. */
  1176. SWAPGS
  1177. FENCE_SWAPGS_USER_ENTRY
  1178. SWITCH_TO_KERNEL_CR3 scratch_reg=%rax
  1179. jmp .Lerror_entry_done
  1180. .Lbstep_iret:
  1181. /* Fix truncated RIP */
  1182. movq %rcx, RIP+8(%rsp)
  1183. /* fall through */
  1184. .Lerror_bad_iret:
  1185. /*
  1186. * We came from an IRET to user mode, so we have user
  1187. * gsbase and CR3. Switch to kernel gsbase and CR3:
  1188. */
  1189. SWAPGS
  1190. FENCE_SWAPGS_USER_ENTRY
  1191. SWITCH_TO_KERNEL_CR3 scratch_reg=%rax
  1192. /*
  1193. * Pretend that the exception came from user mode: set up pt_regs
  1194. * as if we faulted immediately after IRET.
  1195. */
  1196. mov %rsp, %rdi
  1197. call fixup_bad_iret
  1198. mov %rax, %rsp
  1199. jmp .Lerror_entry_from_usermode_after_swapgs
  1200. END(error_entry)
  1201. ENTRY(error_exit)
  1202. UNWIND_HINT_REGS
  1203. DISABLE_INTERRUPTS(CLBR_ANY)
  1204. TRACE_IRQS_OFF
  1205. testb $3, CS(%rsp)
  1206. jz retint_kernel
  1207. jmp retint_user
  1208. END(error_exit)
  1209. /*
  1210. * Runs on exception stack. Xen PV does not go through this path at all,
  1211. * so we can use real assembly here.
  1212. *
  1213. * Registers:
  1214. * %r14: Used to save/restore the CR3 of the interrupted context
  1215. * when PAGE_TABLE_ISOLATION is in use. Do not clobber.
  1216. */
  1217. ENTRY(nmi)
  1218. UNWIND_HINT_IRET_REGS
  1219. /*
  1220. * We allow breakpoints in NMIs. If a breakpoint occurs, then
  1221. * the iretq it performs will take us out of NMI context.
  1222. * This means that we can have nested NMIs where the next
  1223. * NMI is using the top of the stack of the previous NMI. We
  1224. * can't let it execute because the nested NMI will corrupt the
  1225. * stack of the previous NMI. NMI handlers are not re-entrant
  1226. * anyway.
  1227. *
  1228. * To handle this case we do the following:
  1229. * Check the a special location on the stack that contains
  1230. * a variable that is set when NMIs are executing.
  1231. * The interrupted task's stack is also checked to see if it
  1232. * is an NMI stack.
  1233. * If the variable is not set and the stack is not the NMI
  1234. * stack then:
  1235. * o Set the special variable on the stack
  1236. * o Copy the interrupt frame into an "outermost" location on the
  1237. * stack
  1238. * o Copy the interrupt frame into an "iret" location on the stack
  1239. * o Continue processing the NMI
  1240. * If the variable is set or the previous stack is the NMI stack:
  1241. * o Modify the "iret" location to jump to the repeat_nmi
  1242. * o return back to the first NMI
  1243. *
  1244. * Now on exit of the first NMI, we first clear the stack variable
  1245. * The NMI stack will tell any nested NMIs at that point that it is
  1246. * nested. Then we pop the stack normally with iret, and if there was
  1247. * a nested NMI that updated the copy interrupt stack frame, a
  1248. * jump will be made to the repeat_nmi code that will handle the second
  1249. * NMI.
  1250. *
  1251. * However, espfix prevents us from directly returning to userspace
  1252. * with a single IRET instruction. Similarly, IRET to user mode
  1253. * can fault. We therefore handle NMIs from user space like
  1254. * other IST entries.
  1255. */
  1256. ASM_CLAC
  1257. /* Use %rdx as our temp variable throughout */
  1258. pushq %rdx
  1259. testb $3, CS-RIP+8(%rsp)
  1260. jz .Lnmi_from_kernel
  1261. /*
  1262. * NMI from user mode. We need to run on the thread stack, but we
  1263. * can't go through the normal entry paths: NMIs are masked, and
  1264. * we don't want to enable interrupts, because then we'll end
  1265. * up in an awkward situation in which IRQs are on but NMIs
  1266. * are off.
  1267. *
  1268. * We also must not push anything to the stack before switching
  1269. * stacks lest we corrupt the "NMI executing" variable.
  1270. */
  1271. swapgs
  1272. cld
  1273. FENCE_SWAPGS_USER_ENTRY
  1274. SWITCH_TO_KERNEL_CR3 scratch_reg=%rdx
  1275. movq %rsp, %rdx
  1276. movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
  1277. UNWIND_HINT_IRET_REGS base=%rdx offset=8
  1278. pushq 5*8(%rdx) /* pt_regs->ss */
  1279. pushq 4*8(%rdx) /* pt_regs->rsp */
  1280. pushq 3*8(%rdx) /* pt_regs->flags */
  1281. pushq 2*8(%rdx) /* pt_regs->cs */
  1282. pushq 1*8(%rdx) /* pt_regs->rip */
  1283. UNWIND_HINT_IRET_REGS
  1284. pushq $-1 /* pt_regs->orig_ax */
  1285. PUSH_AND_CLEAR_REGS rdx=(%rdx)
  1286. ENCODE_FRAME_POINTER
  1287. /*
  1288. * At this point we no longer need to worry about stack damage
  1289. * due to nesting -- we're on the normal thread stack and we're
  1290. * done with the NMI stack.
  1291. */
  1292. movq %rsp, %rdi
  1293. movq $-1, %rsi
  1294. call do_nmi
  1295. /*
  1296. * Return back to user mode. We must *not* do the normal exit
  1297. * work, because we don't want to enable interrupts.
  1298. */
  1299. jmp swapgs_restore_regs_and_return_to_usermode
  1300. .Lnmi_from_kernel:
  1301. /*
  1302. * Here's what our stack frame will look like:
  1303. * +---------------------------------------------------------+
  1304. * | original SS |
  1305. * | original Return RSP |
  1306. * | original RFLAGS |
  1307. * | original CS |
  1308. * | original RIP |
  1309. * +---------------------------------------------------------+
  1310. * | temp storage for rdx |
  1311. * +---------------------------------------------------------+
  1312. * | "NMI executing" variable |
  1313. * +---------------------------------------------------------+
  1314. * | iret SS } Copied from "outermost" frame |
  1315. * | iret Return RSP } on each loop iteration; overwritten |
  1316. * | iret RFLAGS } by a nested NMI to force another |
  1317. * | iret CS } iteration if needed. |
  1318. * | iret RIP } |
  1319. * +---------------------------------------------------------+
  1320. * | outermost SS } initialized in first_nmi; |
  1321. * | outermost Return RSP } will not be changed before |
  1322. * | outermost RFLAGS } NMI processing is done. |
  1323. * | outermost CS } Copied to "iret" frame on each |
  1324. * | outermost RIP } iteration. |
  1325. * +---------------------------------------------------------+
  1326. * | pt_regs |
  1327. * +---------------------------------------------------------+
  1328. *
  1329. * The "original" frame is used by hardware. Before re-enabling
  1330. * NMIs, we need to be done with it, and we need to leave enough
  1331. * space for the asm code here.
  1332. *
  1333. * We return by executing IRET while RSP points to the "iret" frame.
  1334. * That will either return for real or it will loop back into NMI
  1335. * processing.
  1336. *
  1337. * The "outermost" frame is copied to the "iret" frame on each
  1338. * iteration of the loop, so each iteration starts with the "iret"
  1339. * frame pointing to the final return target.
  1340. */
  1341. /*
  1342. * Determine whether we're a nested NMI.
  1343. *
  1344. * If we interrupted kernel code between repeat_nmi and
  1345. * end_repeat_nmi, then we are a nested NMI. We must not
  1346. * modify the "iret" frame because it's being written by
  1347. * the outer NMI. That's okay; the outer NMI handler is
  1348. * about to about to call do_nmi anyway, so we can just
  1349. * resume the outer NMI.
  1350. */
  1351. movq $repeat_nmi, %rdx
  1352. cmpq 8(%rsp), %rdx
  1353. ja 1f
  1354. movq $end_repeat_nmi, %rdx
  1355. cmpq 8(%rsp), %rdx
  1356. ja nested_nmi_out
  1357. 1:
  1358. /*
  1359. * Now check "NMI executing". If it's set, then we're nested.
  1360. * This will not detect if we interrupted an outer NMI just
  1361. * before IRET.
  1362. */
  1363. cmpl $1, -8(%rsp)
  1364. je nested_nmi
  1365. /*
  1366. * Now test if the previous stack was an NMI stack. This covers
  1367. * the case where we interrupt an outer NMI after it clears
  1368. * "NMI executing" but before IRET. We need to be careful, though:
  1369. * there is one case in which RSP could point to the NMI stack
  1370. * despite there being no NMI active: naughty userspace controls
  1371. * RSP at the very beginning of the SYSCALL targets. We can
  1372. * pull a fast one on naughty userspace, though: we program
  1373. * SYSCALL to mask DF, so userspace cannot cause DF to be set
  1374. * if it controls the kernel's RSP. We set DF before we clear
  1375. * "NMI executing".
  1376. */
  1377. lea 6*8(%rsp), %rdx
  1378. /* Compare the NMI stack (rdx) with the stack we came from (4*8(%rsp)) */
  1379. cmpq %rdx, 4*8(%rsp)
  1380. /* If the stack pointer is above the NMI stack, this is a normal NMI */
  1381. ja first_nmi
  1382. subq $EXCEPTION_STKSZ, %rdx
  1383. cmpq %rdx, 4*8(%rsp)
  1384. /* If it is below the NMI stack, it is a normal NMI */
  1385. jb first_nmi
  1386. /* Ah, it is within the NMI stack. */
  1387. testb $(X86_EFLAGS_DF >> 8), (3*8 + 1)(%rsp)
  1388. jz first_nmi /* RSP was user controlled. */
  1389. /* This is a nested NMI. */
  1390. nested_nmi:
  1391. /*
  1392. * Modify the "iret" frame to point to repeat_nmi, forcing another
  1393. * iteration of NMI handling.
  1394. */
  1395. subq $8, %rsp
  1396. leaq -10*8(%rsp), %rdx
  1397. pushq $__KERNEL_DS
  1398. pushq %rdx
  1399. pushfq
  1400. pushq $__KERNEL_CS
  1401. pushq $repeat_nmi
  1402. /* Put stack back */
  1403. addq $(6*8), %rsp
  1404. nested_nmi_out:
  1405. popq %rdx
  1406. /* We are returning to kernel mode, so this cannot result in a fault. */
  1407. iretq
  1408. first_nmi:
  1409. /* Restore rdx. */
  1410. movq (%rsp), %rdx
  1411. /* Make room for "NMI executing". */
  1412. pushq $0
  1413. /* Leave room for the "iret" frame */
  1414. subq $(5*8), %rsp
  1415. /* Copy the "original" frame to the "outermost" frame */
  1416. .rept 5
  1417. pushq 11*8(%rsp)
  1418. .endr
  1419. UNWIND_HINT_IRET_REGS
  1420. /* Everything up to here is safe from nested NMIs */
  1421. #ifdef CONFIG_DEBUG_ENTRY
  1422. /*
  1423. * For ease of testing, unmask NMIs right away. Disabled by
  1424. * default because IRET is very expensive.
  1425. */
  1426. pushq $0 /* SS */
  1427. pushq %rsp /* RSP (minus 8 because of the previous push) */
  1428. addq $8, (%rsp) /* Fix up RSP */
  1429. pushfq /* RFLAGS */
  1430. pushq $__KERNEL_CS /* CS */
  1431. pushq $1f /* RIP */
  1432. iretq /* continues at repeat_nmi below */
  1433. UNWIND_HINT_IRET_REGS
  1434. 1:
  1435. #endif
  1436. repeat_nmi:
  1437. /*
  1438. * If there was a nested NMI, the first NMI's iret will return
  1439. * here. But NMIs are still enabled and we can take another
  1440. * nested NMI. The nested NMI checks the interrupted RIP to see
  1441. * if it is between repeat_nmi and end_repeat_nmi, and if so
  1442. * it will just return, as we are about to repeat an NMI anyway.
  1443. * This makes it safe to copy to the stack frame that a nested
  1444. * NMI will update.
  1445. *
  1446. * RSP is pointing to "outermost RIP". gsbase is unknown, but, if
  1447. * we're repeating an NMI, gsbase has the same value that it had on
  1448. * the first iteration. paranoid_entry will load the kernel
  1449. * gsbase if needed before we call do_nmi. "NMI executing"
  1450. * is zero.
  1451. */
  1452. movq $1, 10*8(%rsp) /* Set "NMI executing". */
  1453. /*
  1454. * Copy the "outermost" frame to the "iret" frame. NMIs that nest
  1455. * here must not modify the "iret" frame while we're writing to
  1456. * it or it will end up containing garbage.
  1457. */
  1458. addq $(10*8), %rsp
  1459. .rept 5
  1460. pushq -6*8(%rsp)
  1461. .endr
  1462. subq $(5*8), %rsp
  1463. end_repeat_nmi:
  1464. /*
  1465. * Everything below this point can be preempted by a nested NMI.
  1466. * If this happens, then the inner NMI will change the "iret"
  1467. * frame to point back to repeat_nmi.
  1468. */
  1469. pushq $-1 /* ORIG_RAX: no syscall to restart */
  1470. /*
  1471. * Use paranoid_entry to handle SWAPGS, but no need to use paranoid_exit
  1472. * as we should not be calling schedule in NMI context.
  1473. * Even with normal interrupts enabled. An NMI should not be
  1474. * setting NEED_RESCHED or anything that normal interrupts and
  1475. * exceptions might do.
  1476. */
  1477. call paranoid_entry
  1478. UNWIND_HINT_REGS
  1479. /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
  1480. movq %rsp, %rdi
  1481. movq $-1, %rsi
  1482. call do_nmi
  1483. /* Always restore stashed CR3 value (see paranoid_entry) */
  1484. RESTORE_CR3 scratch_reg=%r15 save_reg=%r14
  1485. testl %ebx, %ebx /* swapgs needed? */
  1486. jnz nmi_restore
  1487. nmi_swapgs:
  1488. SWAPGS_UNSAFE_STACK
  1489. nmi_restore:
  1490. POP_REGS
  1491. /*
  1492. * Skip orig_ax and the "outermost" frame to point RSP at the "iret"
  1493. * at the "iret" frame.
  1494. */
  1495. addq $6*8, %rsp
  1496. /*
  1497. * Clear "NMI executing". Set DF first so that we can easily
  1498. * distinguish the remaining code between here and IRET from
  1499. * the SYSCALL entry and exit paths.
  1500. *
  1501. * We arguably should just inspect RIP instead, but I (Andy) wrote
  1502. * this code when I had the misapprehension that Xen PV supported
  1503. * NMIs, and Xen PV would break that approach.
  1504. */
  1505. std
  1506. movq $0, 5*8(%rsp) /* clear "NMI executing" */
  1507. /*
  1508. * iretq reads the "iret" frame and exits the NMI stack in a
  1509. * single instruction. We are returning to kernel mode, so this
  1510. * cannot result in a fault. Similarly, we don't need to worry
  1511. * about espfix64 on the way back to kernel mode.
  1512. */
  1513. iretq
  1514. END(nmi)
  1515. ENTRY(ignore_sysret)
  1516. UNWIND_HINT_EMPTY
  1517. mov $-ENOSYS, %eax
  1518. sysret
  1519. END(ignore_sysret)
  1520. ENTRY(rewind_stack_do_exit)
  1521. UNWIND_HINT_FUNC
  1522. /* Prevent any naive code from trying to unwind to our caller. */
  1523. xorl %ebp, %ebp
  1524. movq PER_CPU_VAR(cpu_current_top_of_stack), %rax
  1525. leaq -PTREGS_SIZE(%rax), %rsp
  1526. UNWIND_HINT_REGS
  1527. call do_exit
  1528. END(rewind_stack_do_exit)