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. UNWIND_HINT_EMPTY
  276. POP_REGS pop_rdi=0 skip_r11rcx=1
  277. /*
  278. * Now all regs are restored except RSP and RDI.
  279. * Save old stack pointer and switch to trampoline stack.
  280. */
  281. movq %rsp, %rdi
  282. movq PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %rsp
  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_FUNC
  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. pushq 2*8(%rdi) /* regs->orig_ax */
  535. pushq 8(%rdi) /* return address */
  536. UNWIND_HINT_FUNC
  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. /* Copy the IRET frame to the trampoline stack. */
  613. pushq 6*8(%rdi) /* SS */
  614. pushq 5*8(%rdi) /* RSP */
  615. pushq 4*8(%rdi) /* EFLAGS */
  616. pushq 3*8(%rdi) /* CS */
  617. pushq 2*8(%rdi) /* RIP */
  618. /* Push user RDI on the trampoline stack. */
  619. pushq (%rdi)
  620. /*
  621. * We are on the trampoline stack. All regs except RDI are live.
  622. * We can do future final exit work right here.
  623. */
  624. SWITCH_TO_USER_CR3_STACK scratch_reg=%rdi
  625. /* Restore RDI. */
  626. popq %rdi
  627. SWAPGS
  628. INTERRUPT_RETURN
  629. /* Returning to kernel space */
  630. retint_kernel:
  631. #ifdef CONFIG_PREEMPT
  632. /* Interrupts are off */
  633. /* Check if we need preemption */
  634. btl $9, EFLAGS(%rsp) /* were interrupts off? */
  635. jnc 1f
  636. 0: cmpl $0, PER_CPU_VAR(__preempt_count)
  637. jnz 1f
  638. call preempt_schedule_irq
  639. jmp 0b
  640. 1:
  641. #endif
  642. /*
  643. * The iretq could re-enable interrupts:
  644. */
  645. TRACE_IRQS_IRETQ
  646. GLOBAL(restore_regs_and_return_to_kernel)
  647. #ifdef CONFIG_DEBUG_ENTRY
  648. /* Assert that pt_regs indicates kernel mode. */
  649. testb $3, CS(%rsp)
  650. jz 1f
  651. ud2
  652. 1:
  653. #endif
  654. POP_REGS
  655. addq $8, %rsp /* skip regs->orig_ax */
  656. /*
  657. * ARCH_HAS_MEMBARRIER_SYNC_CORE rely on IRET core serialization
  658. * when returning from IPI handler.
  659. */
  660. INTERRUPT_RETURN
  661. ENTRY(native_iret)
  662. UNWIND_HINT_IRET_REGS
  663. /*
  664. * Are we returning to a stack segment from the LDT? Note: in
  665. * 64-bit mode SS:RSP on the exception stack is always valid.
  666. */
  667. #ifdef CONFIG_X86_ESPFIX64
  668. testb $4, (SS-RIP)(%rsp)
  669. jnz native_irq_return_ldt
  670. #endif
  671. .global native_irq_return_iret
  672. native_irq_return_iret:
  673. /*
  674. * This may fault. Non-paranoid faults on return to userspace are
  675. * handled by fixup_bad_iret. These include #SS, #GP, and #NP.
  676. * Double-faults due to espfix64 are handled in do_double_fault.
  677. * Other faults here are fatal.
  678. */
  679. iretq
  680. #ifdef CONFIG_X86_ESPFIX64
  681. native_irq_return_ldt:
  682. /*
  683. * We are running with user GSBASE. All GPRs contain their user
  684. * values. We have a percpu ESPFIX stack that is eight slots
  685. * long (see ESPFIX_STACK_SIZE). espfix_waddr points to the bottom
  686. * of the ESPFIX stack.
  687. *
  688. * We clobber RAX and RDI in this code. We stash RDI on the
  689. * normal stack and RAX on the ESPFIX stack.
  690. *
  691. * The ESPFIX stack layout we set up looks like this:
  692. *
  693. * --- top of ESPFIX stack ---
  694. * SS
  695. * RSP
  696. * RFLAGS
  697. * CS
  698. * RIP <-- RSP points here when we're done
  699. * RAX <-- espfix_waddr points here
  700. * --- bottom of ESPFIX stack ---
  701. */
  702. pushq %rdi /* Stash user RDI */
  703. SWAPGS /* to kernel GS */
  704. SWITCH_TO_KERNEL_CR3 scratch_reg=%rdi /* to kernel CR3 */
  705. movq PER_CPU_VAR(espfix_waddr), %rdi
  706. movq %rax, (0*8)(%rdi) /* user RAX */
  707. movq (1*8)(%rsp), %rax /* user RIP */
  708. movq %rax, (1*8)(%rdi)
  709. movq (2*8)(%rsp), %rax /* user CS */
  710. movq %rax, (2*8)(%rdi)
  711. movq (3*8)(%rsp), %rax /* user RFLAGS */
  712. movq %rax, (3*8)(%rdi)
  713. movq (5*8)(%rsp), %rax /* user SS */
  714. movq %rax, (5*8)(%rdi)
  715. movq (4*8)(%rsp), %rax /* user RSP */
  716. movq %rax, (4*8)(%rdi)
  717. /* Now RAX == RSP. */
  718. andl $0xffff0000, %eax /* RAX = (RSP & 0xffff0000) */
  719. /*
  720. * espfix_stack[31:16] == 0. The page tables are set up such that
  721. * (espfix_stack | (X & 0xffff0000)) points to a read-only alias of
  722. * espfix_waddr for any X. That is, there are 65536 RO aliases of
  723. * the same page. Set up RSP so that RSP[31:16] contains the
  724. * respective 16 bits of the /userspace/ RSP and RSP nonetheless
  725. * still points to an RO alias of the ESPFIX stack.
  726. */
  727. orq PER_CPU_VAR(espfix_stack), %rax
  728. SWITCH_TO_USER_CR3_STACK scratch_reg=%rdi
  729. SWAPGS /* to user GS */
  730. popq %rdi /* Restore user RDI */
  731. movq %rax, %rsp
  732. UNWIND_HINT_IRET_REGS offset=8
  733. /*
  734. * At this point, we cannot write to the stack any more, but we can
  735. * still read.
  736. */
  737. popq %rax /* Restore user RAX */
  738. /*
  739. * RSP now points to an ordinary IRET frame, except that the page
  740. * is read-only and RSP[31:16] are preloaded with the userspace
  741. * values. We can now IRET back to userspace.
  742. */
  743. jmp native_irq_return_iret
  744. #endif
  745. END(common_interrupt)
  746. _ASM_NOKPROBE(common_interrupt)
  747. /*
  748. * APIC interrupts.
  749. */
  750. .macro apicinterrupt3 num sym do_sym
  751. ENTRY(\sym)
  752. UNWIND_HINT_IRET_REGS
  753. pushq $~(\num)
  754. .Lcommon_\sym:
  755. call interrupt_entry
  756. UNWIND_HINT_REGS indirect=1
  757. call \do_sym /* rdi points to pt_regs */
  758. jmp ret_from_intr
  759. END(\sym)
  760. _ASM_NOKPROBE(\sym)
  761. .endm
  762. /* Make sure APIC interrupt handlers end up in the irqentry section: */
  763. #define PUSH_SECTION_IRQENTRY .pushsection .irqentry.text, "ax"
  764. #define POP_SECTION_IRQENTRY .popsection
  765. .macro apicinterrupt num sym do_sym
  766. PUSH_SECTION_IRQENTRY
  767. apicinterrupt3 \num \sym \do_sym
  768. POP_SECTION_IRQENTRY
  769. .endm
  770. #ifdef CONFIG_SMP
  771. apicinterrupt3 IRQ_MOVE_CLEANUP_VECTOR irq_move_cleanup_interrupt smp_irq_move_cleanup_interrupt
  772. apicinterrupt3 REBOOT_VECTOR reboot_interrupt smp_reboot_interrupt
  773. #endif
  774. #ifdef CONFIG_X86_UV
  775. apicinterrupt3 UV_BAU_MESSAGE uv_bau_message_intr1 uv_bau_message_interrupt
  776. #endif
  777. apicinterrupt LOCAL_TIMER_VECTOR apic_timer_interrupt smp_apic_timer_interrupt
  778. apicinterrupt X86_PLATFORM_IPI_VECTOR x86_platform_ipi smp_x86_platform_ipi
  779. #ifdef CONFIG_HAVE_KVM
  780. apicinterrupt3 POSTED_INTR_VECTOR kvm_posted_intr_ipi smp_kvm_posted_intr_ipi
  781. apicinterrupt3 POSTED_INTR_WAKEUP_VECTOR kvm_posted_intr_wakeup_ipi smp_kvm_posted_intr_wakeup_ipi
  782. apicinterrupt3 POSTED_INTR_NESTED_VECTOR kvm_posted_intr_nested_ipi smp_kvm_posted_intr_nested_ipi
  783. #endif
  784. #ifdef CONFIG_X86_MCE_THRESHOLD
  785. apicinterrupt THRESHOLD_APIC_VECTOR threshold_interrupt smp_threshold_interrupt
  786. #endif
  787. #ifdef CONFIG_X86_MCE_AMD
  788. apicinterrupt DEFERRED_ERROR_VECTOR deferred_error_interrupt smp_deferred_error_interrupt
  789. #endif
  790. #ifdef CONFIG_X86_THERMAL_VECTOR
  791. apicinterrupt THERMAL_APIC_VECTOR thermal_interrupt smp_thermal_interrupt
  792. #endif
  793. #ifdef CONFIG_SMP
  794. apicinterrupt CALL_FUNCTION_SINGLE_VECTOR call_function_single_interrupt smp_call_function_single_interrupt
  795. apicinterrupt CALL_FUNCTION_VECTOR call_function_interrupt smp_call_function_interrupt
  796. apicinterrupt RESCHEDULE_VECTOR reschedule_interrupt smp_reschedule_interrupt
  797. #endif
  798. apicinterrupt ERROR_APIC_VECTOR error_interrupt smp_error_interrupt
  799. apicinterrupt SPURIOUS_APIC_VECTOR spurious_interrupt smp_spurious_interrupt
  800. #ifdef CONFIG_IRQ_WORK
  801. apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt
  802. #endif
  803. /*
  804. * Exception entry points.
  805. */
  806. #define CPU_TSS_IST(x) PER_CPU_VAR(cpu_tss_rw) + (TSS_ist + ((x) - 1) * 8)
  807. .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 create_gap=0
  808. ENTRY(\sym)
  809. UNWIND_HINT_IRET_REGS offset=\has_error_code*8
  810. /* Sanity check */
  811. .if \shift_ist != -1 && \paranoid == 0
  812. .error "using shift_ist requires paranoid=1"
  813. .endif
  814. ASM_CLAC
  815. .if \has_error_code == 0
  816. pushq $-1 /* ORIG_RAX: no syscall to restart */
  817. .endif
  818. .if \paranoid == 1
  819. testb $3, CS-ORIG_RAX(%rsp) /* If coming from userspace, switch stacks */
  820. jnz .Lfrom_usermode_switch_stack_\@
  821. .endif
  822. .if \create_gap == 1
  823. /*
  824. * If coming from kernel space, create a 6-word gap to allow the
  825. * int3 handler to emulate a call instruction.
  826. */
  827. testb $3, CS-ORIG_RAX(%rsp)
  828. jnz .Lfrom_usermode_no_gap_\@
  829. .rept 6
  830. pushq 5*8(%rsp)
  831. .endr
  832. UNWIND_HINT_IRET_REGS offset=8
  833. .Lfrom_usermode_no_gap_\@:
  834. .endif
  835. .if \paranoid
  836. call paranoid_entry
  837. .else
  838. call error_entry
  839. .endif
  840. UNWIND_HINT_REGS
  841. /* returned flag: ebx=0: need swapgs on exit, ebx=1: don't need it */
  842. .if \paranoid
  843. .if \shift_ist != -1
  844. TRACE_IRQS_OFF_DEBUG /* reload IDT in case of recursion */
  845. .else
  846. TRACE_IRQS_OFF
  847. .endif
  848. .endif
  849. movq %rsp, %rdi /* pt_regs pointer */
  850. .if \has_error_code
  851. movq ORIG_RAX(%rsp), %rsi /* get error code */
  852. movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */
  853. .else
  854. xorl %esi, %esi /* no error code */
  855. .endif
  856. .if \shift_ist != -1
  857. subq $EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist)
  858. .endif
  859. call \do_sym
  860. .if \shift_ist != -1
  861. addq $EXCEPTION_STKSZ, CPU_TSS_IST(\shift_ist)
  862. .endif
  863. /* these procedures expect "no swapgs" flag in ebx */
  864. .if \paranoid
  865. jmp paranoid_exit
  866. .else
  867. jmp error_exit
  868. .endif
  869. .if \paranoid == 1
  870. /*
  871. * Entry from userspace. Switch stacks and treat it
  872. * as a normal entry. This means that paranoid handlers
  873. * run in real process context if user_mode(regs).
  874. */
  875. .Lfrom_usermode_switch_stack_\@:
  876. call error_entry
  877. movq %rsp, %rdi /* pt_regs pointer */
  878. .if \has_error_code
  879. movq ORIG_RAX(%rsp), %rsi /* get error code */
  880. movq $-1, ORIG_RAX(%rsp) /* no syscall to restart */
  881. .else
  882. xorl %esi, %esi /* no error code */
  883. .endif
  884. call \do_sym
  885. jmp error_exit
  886. .endif
  887. _ASM_NOKPROBE(\sym)
  888. END(\sym)
  889. .endm
  890. idtentry divide_error do_divide_error has_error_code=0
  891. idtentry overflow do_overflow has_error_code=0
  892. idtentry bounds do_bounds has_error_code=0
  893. idtentry invalid_op do_invalid_op has_error_code=0
  894. idtentry device_not_available do_device_not_available has_error_code=0
  895. idtentry double_fault do_double_fault has_error_code=1 paranoid=2
  896. idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0
  897. idtentry invalid_TSS do_invalid_TSS has_error_code=1
  898. idtentry segment_not_present do_segment_not_present has_error_code=1
  899. idtentry spurious_interrupt_bug do_spurious_interrupt_bug has_error_code=0
  900. idtentry coprocessor_error do_coprocessor_error has_error_code=0
  901. idtentry alignment_check do_alignment_check has_error_code=1
  902. idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0
  903. /*
  904. * Reload gs selector with exception handling
  905. * edi: new selector
  906. */
  907. ENTRY(native_load_gs_index)
  908. FRAME_BEGIN
  909. pushfq
  910. DISABLE_INTERRUPTS(CLBR_ANY & ~CLBR_RDI)
  911. TRACE_IRQS_OFF
  912. SWAPGS
  913. .Lgs_change:
  914. movl %edi, %gs
  915. 2: ALTERNATIVE "", "mfence", X86_BUG_SWAPGS_FENCE
  916. SWAPGS
  917. TRACE_IRQS_FLAGS (%rsp)
  918. popfq
  919. FRAME_END
  920. ret
  921. ENDPROC(native_load_gs_index)
  922. EXPORT_SYMBOL(native_load_gs_index)
  923. _ASM_EXTABLE(.Lgs_change, bad_gs)
  924. .section .fixup, "ax"
  925. /* running with kernelgs */
  926. bad_gs:
  927. SWAPGS /* switch back to user gs */
  928. .macro ZAP_GS
  929. /* This can't be a string because the preprocessor needs to see it. */
  930. movl $__USER_DS, %eax
  931. movl %eax, %gs
  932. .endm
  933. ALTERNATIVE "", "ZAP_GS", X86_BUG_NULL_SEG
  934. xorl %eax, %eax
  935. movl %eax, %gs
  936. jmp 2b
  937. .previous
  938. /* Call softirq on interrupt stack. Interrupts are off. */
  939. ENTRY(do_softirq_own_stack)
  940. pushq %rbp
  941. mov %rsp, %rbp
  942. ENTER_IRQ_STACK regs=0 old_rsp=%r11
  943. call __do_softirq
  944. LEAVE_IRQ_STACK regs=0
  945. leaveq
  946. ret
  947. ENDPROC(do_softirq_own_stack)
  948. #ifdef CONFIG_XEN
  949. idtentry hypervisor_callback xen_do_hypervisor_callback has_error_code=0
  950. /*
  951. * A note on the "critical region" in our callback handler.
  952. * We want to avoid stacking callback handlers due to events occurring
  953. * during handling of the last event. To do this, we keep events disabled
  954. * until we've done all processing. HOWEVER, we must enable events before
  955. * popping the stack frame (can't be done atomically) and so it would still
  956. * be possible to get enough handler activations to overflow the stack.
  957. * Although unlikely, bugs of that kind are hard to track down, so we'd
  958. * like to avoid the possibility.
  959. * So, on entry to the handler we detect whether we interrupted an
  960. * existing activation in its critical region -- if so, we pop the current
  961. * activation and restart the handler using the previous one.
  962. */
  963. ENTRY(xen_do_hypervisor_callback) /* do_hypervisor_callback(struct *pt_regs) */
  964. /*
  965. * Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will
  966. * see the correct pointer to the pt_regs
  967. */
  968. UNWIND_HINT_FUNC
  969. movq %rdi, %rsp /* we don't return, adjust the stack frame */
  970. UNWIND_HINT_REGS
  971. ENTER_IRQ_STACK old_rsp=%r10
  972. call xen_evtchn_do_upcall
  973. LEAVE_IRQ_STACK
  974. #ifndef CONFIG_PREEMPT
  975. call xen_maybe_preempt_hcall
  976. #endif
  977. jmp error_exit
  978. END(xen_do_hypervisor_callback)
  979. /*
  980. * Hypervisor uses this for application faults while it executes.
  981. * We get here for two reasons:
  982. * 1. Fault while reloading DS, ES, FS or GS
  983. * 2. Fault while executing IRET
  984. * Category 1 we do not need to fix up as Xen has already reloaded all segment
  985. * registers that could be reloaded and zeroed the others.
  986. * Category 2 we fix up by killing the current process. We cannot use the
  987. * normal Linux return path in this case because if we use the IRET hypercall
  988. * to pop the stack frame we end up in an infinite loop of failsafe callbacks.
  989. * We distinguish between categories by comparing each saved segment register
  990. * with its current contents: any discrepancy means we in category 1.
  991. */
  992. ENTRY(xen_failsafe_callback)
  993. UNWIND_HINT_EMPTY
  994. movl %ds, %ecx
  995. cmpw %cx, 0x10(%rsp)
  996. jne 1f
  997. movl %es, %ecx
  998. cmpw %cx, 0x18(%rsp)
  999. jne 1f
  1000. movl %fs, %ecx
  1001. cmpw %cx, 0x20(%rsp)
  1002. jne 1f
  1003. movl %gs, %ecx
  1004. cmpw %cx, 0x28(%rsp)
  1005. jne 1f
  1006. /* All segments match their saved values => Category 2 (Bad IRET). */
  1007. movq (%rsp), %rcx
  1008. movq 8(%rsp), %r11
  1009. addq $0x30, %rsp
  1010. pushq $0 /* RIP */
  1011. UNWIND_HINT_IRET_REGS offset=8
  1012. jmp general_protection
  1013. 1: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */
  1014. movq (%rsp), %rcx
  1015. movq 8(%rsp), %r11
  1016. addq $0x30, %rsp
  1017. UNWIND_HINT_IRET_REGS
  1018. pushq $-1 /* orig_ax = -1 => not a system call */
  1019. PUSH_AND_CLEAR_REGS
  1020. ENCODE_FRAME_POINTER
  1021. jmp error_exit
  1022. END(xen_failsafe_callback)
  1023. apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
  1024. xen_hvm_callback_vector xen_evtchn_do_upcall
  1025. #endif /* CONFIG_XEN */
  1026. #if IS_ENABLED(CONFIG_HYPERV)
  1027. apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
  1028. hyperv_callback_vector hyperv_vector_handler
  1029. apicinterrupt3 HYPERV_REENLIGHTENMENT_VECTOR \
  1030. hyperv_reenlightenment_vector hyperv_reenlightenment_intr
  1031. apicinterrupt3 HYPERV_STIMER0_VECTOR \
  1032. hv_stimer0_callback_vector hv_stimer0_vector_handler
  1033. #endif /* CONFIG_HYPERV */
  1034. idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
  1035. idtentry int3 do_int3 has_error_code=0 create_gap=1
  1036. idtentry stack_segment do_stack_segment has_error_code=1
  1037. #ifdef CONFIG_XEN
  1038. idtentry xennmi do_nmi has_error_code=0
  1039. idtentry xendebug do_debug has_error_code=0
  1040. #endif
  1041. idtentry general_protection do_general_protection has_error_code=1
  1042. idtentry page_fault do_page_fault has_error_code=1
  1043. #ifdef CONFIG_KVM_GUEST
  1044. idtentry async_page_fault do_async_page_fault has_error_code=1
  1045. #endif
  1046. #ifdef CONFIG_X86_MCE
  1047. idtentry machine_check do_mce has_error_code=0 paranoid=1
  1048. #endif
  1049. /*
  1050. * Save all registers in pt_regs, and switch gs if needed.
  1051. * Use slow, but surefire "are we in kernel?" check.
  1052. * Return: ebx=0: need swapgs on exit, ebx=1: otherwise
  1053. */
  1054. ENTRY(paranoid_entry)
  1055. UNWIND_HINT_FUNC
  1056. cld
  1057. PUSH_AND_CLEAR_REGS save_ret=1
  1058. ENCODE_FRAME_POINTER 8
  1059. movl $1, %ebx
  1060. movl $MSR_GS_BASE, %ecx
  1061. rdmsr
  1062. testl %edx, %edx
  1063. js 1f /* negative -> in kernel */
  1064. SWAPGS
  1065. xorl %ebx, %ebx
  1066. 1:
  1067. /*
  1068. * Always stash CR3 in %r14. This value will be restored,
  1069. * verbatim, at exit. Needed if paranoid_entry interrupted
  1070. * another entry that already switched to the user CR3 value
  1071. * but has not yet returned to userspace.
  1072. *
  1073. * This is also why CS (stashed in the "iret frame" by the
  1074. * hardware at entry) can not be used: this may be a return
  1075. * to kernel code, but with a user CR3 value.
  1076. */
  1077. SAVE_AND_SWITCH_TO_KERNEL_CR3 scratch_reg=%rax save_reg=%r14
  1078. /*
  1079. * The above SAVE_AND_SWITCH_TO_KERNEL_CR3 macro doesn't do an
  1080. * unconditional CR3 write, even in the PTI case. So do an lfence
  1081. * to prevent GS speculation, regardless of whether PTI is enabled.
  1082. */
  1083. FENCE_SWAPGS_KERNEL_ENTRY
  1084. ret
  1085. END(paranoid_entry)
  1086. /*
  1087. * "Paranoid" exit path from exception stack. This is invoked
  1088. * only on return from non-NMI IST interrupts that came
  1089. * from kernel space.
  1090. *
  1091. * We may be returning to very strange contexts (e.g. very early
  1092. * in syscall entry), so checking for preemption here would
  1093. * be complicated. Fortunately, we there's no good reason
  1094. * to try to handle preemption here.
  1095. *
  1096. * On entry, ebx is "no swapgs" flag (1: don't need swapgs, 0: need it)
  1097. */
  1098. ENTRY(paranoid_exit)
  1099. UNWIND_HINT_REGS
  1100. DISABLE_INTERRUPTS(CLBR_ANY)
  1101. TRACE_IRQS_OFF_DEBUG
  1102. testl %ebx, %ebx /* swapgs needed? */
  1103. jnz .Lparanoid_exit_no_swapgs
  1104. TRACE_IRQS_IRETQ
  1105. /* Always restore stashed CR3 value (see paranoid_entry) */
  1106. RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
  1107. SWAPGS_UNSAFE_STACK
  1108. jmp .Lparanoid_exit_restore
  1109. .Lparanoid_exit_no_swapgs:
  1110. TRACE_IRQS_IRETQ_DEBUG
  1111. /* Always restore stashed CR3 value (see paranoid_entry) */
  1112. RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
  1113. .Lparanoid_exit_restore:
  1114. jmp restore_regs_and_return_to_kernel
  1115. END(paranoid_exit)
  1116. /*
  1117. * Save all registers in pt_regs, and switch GS if needed.
  1118. */
  1119. ENTRY(error_entry)
  1120. UNWIND_HINT_FUNC
  1121. cld
  1122. PUSH_AND_CLEAR_REGS save_ret=1
  1123. ENCODE_FRAME_POINTER 8
  1124. testb $3, CS+8(%rsp)
  1125. jz .Lerror_kernelspace
  1126. /*
  1127. * We entered from user mode or we're pretending to have entered
  1128. * from user mode due to an IRET fault.
  1129. */
  1130. SWAPGS
  1131. FENCE_SWAPGS_USER_ENTRY
  1132. /* We have user CR3. Change to kernel CR3. */
  1133. SWITCH_TO_KERNEL_CR3 scratch_reg=%rax
  1134. .Lerror_entry_from_usermode_after_swapgs:
  1135. /* Put us onto the real thread stack. */
  1136. popq %r12 /* save return addr in %12 */
  1137. movq %rsp, %rdi /* arg0 = pt_regs pointer */
  1138. call sync_regs
  1139. movq %rax, %rsp /* switch stack */
  1140. ENCODE_FRAME_POINTER
  1141. pushq %r12
  1142. /*
  1143. * We need to tell lockdep that IRQs are off. We can't do this until
  1144. * we fix gsbase, and we should do it before enter_from_user_mode
  1145. * (which can take locks).
  1146. */
  1147. TRACE_IRQS_OFF
  1148. CALL_enter_from_user_mode
  1149. ret
  1150. .Lerror_entry_done_lfence:
  1151. FENCE_SWAPGS_KERNEL_ENTRY
  1152. .Lerror_entry_done:
  1153. TRACE_IRQS_OFF
  1154. ret
  1155. /*
  1156. * There are two places in the kernel that can potentially fault with
  1157. * usergs. Handle them here. B stepping K8s sometimes report a
  1158. * truncated RIP for IRET exceptions returning to compat mode. Check
  1159. * for these here too.
  1160. */
  1161. .Lerror_kernelspace:
  1162. leaq native_irq_return_iret(%rip), %rcx
  1163. cmpq %rcx, RIP+8(%rsp)
  1164. je .Lerror_bad_iret
  1165. movl %ecx, %eax /* zero extend */
  1166. cmpq %rax, RIP+8(%rsp)
  1167. je .Lbstep_iret
  1168. cmpq $.Lgs_change, RIP+8(%rsp)
  1169. jne .Lerror_entry_done_lfence
  1170. /*
  1171. * hack: .Lgs_change can fail with user gsbase. If this happens, fix up
  1172. * gsbase and proceed. We'll fix up the exception and land in
  1173. * .Lgs_change's error handler with kernel gsbase.
  1174. */
  1175. SWAPGS
  1176. FENCE_SWAPGS_USER_ENTRY
  1177. SWITCH_TO_KERNEL_CR3 scratch_reg=%rax
  1178. jmp .Lerror_entry_done
  1179. .Lbstep_iret:
  1180. /* Fix truncated RIP */
  1181. movq %rcx, RIP+8(%rsp)
  1182. /* fall through */
  1183. .Lerror_bad_iret:
  1184. /*
  1185. * We came from an IRET to user mode, so we have user
  1186. * gsbase and CR3. Switch to kernel gsbase and CR3:
  1187. */
  1188. SWAPGS
  1189. FENCE_SWAPGS_USER_ENTRY
  1190. SWITCH_TO_KERNEL_CR3 scratch_reg=%rax
  1191. /*
  1192. * Pretend that the exception came from user mode: set up pt_regs
  1193. * as if we faulted immediately after IRET.
  1194. */
  1195. mov %rsp, %rdi
  1196. call fixup_bad_iret
  1197. mov %rax, %rsp
  1198. jmp .Lerror_entry_from_usermode_after_swapgs
  1199. END(error_entry)
  1200. ENTRY(error_exit)
  1201. UNWIND_HINT_REGS
  1202. DISABLE_INTERRUPTS(CLBR_ANY)
  1203. TRACE_IRQS_OFF
  1204. testb $3, CS(%rsp)
  1205. jz retint_kernel
  1206. jmp retint_user
  1207. END(error_exit)
  1208. /*
  1209. * Runs on exception stack. Xen PV does not go through this path at all,
  1210. * so we can use real assembly here.
  1211. *
  1212. * Registers:
  1213. * %r14: Used to save/restore the CR3 of the interrupted context
  1214. * when PAGE_TABLE_ISOLATION is in use. Do not clobber.
  1215. */
  1216. ENTRY(nmi)
  1217. UNWIND_HINT_IRET_REGS
  1218. /*
  1219. * We allow breakpoints in NMIs. If a breakpoint occurs, then
  1220. * the iretq it performs will take us out of NMI context.
  1221. * This means that we can have nested NMIs where the next
  1222. * NMI is using the top of the stack of the previous NMI. We
  1223. * can't let it execute because the nested NMI will corrupt the
  1224. * stack of the previous NMI. NMI handlers are not re-entrant
  1225. * anyway.
  1226. *
  1227. * To handle this case we do the following:
  1228. * Check the a special location on the stack that contains
  1229. * a variable that is set when NMIs are executing.
  1230. * The interrupted task's stack is also checked to see if it
  1231. * is an NMI stack.
  1232. * If the variable is not set and the stack is not the NMI
  1233. * stack then:
  1234. * o Set the special variable on the stack
  1235. * o Copy the interrupt frame into an "outermost" location on the
  1236. * stack
  1237. * o Copy the interrupt frame into an "iret" location on the stack
  1238. * o Continue processing the NMI
  1239. * If the variable is set or the previous stack is the NMI stack:
  1240. * o Modify the "iret" location to jump to the repeat_nmi
  1241. * o return back to the first NMI
  1242. *
  1243. * Now on exit of the first NMI, we first clear the stack variable
  1244. * The NMI stack will tell any nested NMIs at that point that it is
  1245. * nested. Then we pop the stack normally with iret, and if there was
  1246. * a nested NMI that updated the copy interrupt stack frame, a
  1247. * jump will be made to the repeat_nmi code that will handle the second
  1248. * NMI.
  1249. *
  1250. * However, espfix prevents us from directly returning to userspace
  1251. * with a single IRET instruction. Similarly, IRET to user mode
  1252. * can fault. We therefore handle NMIs from user space like
  1253. * other IST entries.
  1254. */
  1255. ASM_CLAC
  1256. /* Use %rdx as our temp variable throughout */
  1257. pushq %rdx
  1258. testb $3, CS-RIP+8(%rsp)
  1259. jz .Lnmi_from_kernel
  1260. /*
  1261. * NMI from user mode. We need to run on the thread stack, but we
  1262. * can't go through the normal entry paths: NMIs are masked, and
  1263. * we don't want to enable interrupts, because then we'll end
  1264. * up in an awkward situation in which IRQs are on but NMIs
  1265. * are off.
  1266. *
  1267. * We also must not push anything to the stack before switching
  1268. * stacks lest we corrupt the "NMI executing" variable.
  1269. */
  1270. swapgs
  1271. cld
  1272. FENCE_SWAPGS_USER_ENTRY
  1273. SWITCH_TO_KERNEL_CR3 scratch_reg=%rdx
  1274. movq %rsp, %rdx
  1275. movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
  1276. UNWIND_HINT_IRET_REGS base=%rdx offset=8
  1277. pushq 5*8(%rdx) /* pt_regs->ss */
  1278. pushq 4*8(%rdx) /* pt_regs->rsp */
  1279. pushq 3*8(%rdx) /* pt_regs->flags */
  1280. pushq 2*8(%rdx) /* pt_regs->cs */
  1281. pushq 1*8(%rdx) /* pt_regs->rip */
  1282. UNWIND_HINT_IRET_REGS
  1283. pushq $-1 /* pt_regs->orig_ax */
  1284. PUSH_AND_CLEAR_REGS rdx=(%rdx)
  1285. ENCODE_FRAME_POINTER
  1286. /*
  1287. * At this point we no longer need to worry about stack damage
  1288. * due to nesting -- we're on the normal thread stack and we're
  1289. * done with the NMI stack.
  1290. */
  1291. movq %rsp, %rdi
  1292. movq $-1, %rsi
  1293. call do_nmi
  1294. /*
  1295. * Return back to user mode. We must *not* do the normal exit
  1296. * work, because we don't want to enable interrupts.
  1297. */
  1298. jmp swapgs_restore_regs_and_return_to_usermode
  1299. .Lnmi_from_kernel:
  1300. /*
  1301. * Here's what our stack frame will look like:
  1302. * +---------------------------------------------------------+
  1303. * | original SS |
  1304. * | original Return RSP |
  1305. * | original RFLAGS |
  1306. * | original CS |
  1307. * | original RIP |
  1308. * +---------------------------------------------------------+
  1309. * | temp storage for rdx |
  1310. * +---------------------------------------------------------+
  1311. * | "NMI executing" variable |
  1312. * +---------------------------------------------------------+
  1313. * | iret SS } Copied from "outermost" frame |
  1314. * | iret Return RSP } on each loop iteration; overwritten |
  1315. * | iret RFLAGS } by a nested NMI to force another |
  1316. * | iret CS } iteration if needed. |
  1317. * | iret RIP } |
  1318. * +---------------------------------------------------------+
  1319. * | outermost SS } initialized in first_nmi; |
  1320. * | outermost Return RSP } will not be changed before |
  1321. * | outermost RFLAGS } NMI processing is done. |
  1322. * | outermost CS } Copied to "iret" frame on each |
  1323. * | outermost RIP } iteration. |
  1324. * +---------------------------------------------------------+
  1325. * | pt_regs |
  1326. * +---------------------------------------------------------+
  1327. *
  1328. * The "original" frame is used by hardware. Before re-enabling
  1329. * NMIs, we need to be done with it, and we need to leave enough
  1330. * space for the asm code here.
  1331. *
  1332. * We return by executing IRET while RSP points to the "iret" frame.
  1333. * That will either return for real or it will loop back into NMI
  1334. * processing.
  1335. *
  1336. * The "outermost" frame is copied to the "iret" frame on each
  1337. * iteration of the loop, so each iteration starts with the "iret"
  1338. * frame pointing to the final return target.
  1339. */
  1340. /*
  1341. * Determine whether we're a nested NMI.
  1342. *
  1343. * If we interrupted kernel code between repeat_nmi and
  1344. * end_repeat_nmi, then we are a nested NMI. We must not
  1345. * modify the "iret" frame because it's being written by
  1346. * the outer NMI. That's okay; the outer NMI handler is
  1347. * about to about to call do_nmi anyway, so we can just
  1348. * resume the outer NMI.
  1349. */
  1350. movq $repeat_nmi, %rdx
  1351. cmpq 8(%rsp), %rdx
  1352. ja 1f
  1353. movq $end_repeat_nmi, %rdx
  1354. cmpq 8(%rsp), %rdx
  1355. ja nested_nmi_out
  1356. 1:
  1357. /*
  1358. * Now check "NMI executing". If it's set, then we're nested.
  1359. * This will not detect if we interrupted an outer NMI just
  1360. * before IRET.
  1361. */
  1362. cmpl $1, -8(%rsp)
  1363. je nested_nmi
  1364. /*
  1365. * Now test if the previous stack was an NMI stack. This covers
  1366. * the case where we interrupt an outer NMI after it clears
  1367. * "NMI executing" but before IRET. We need to be careful, though:
  1368. * there is one case in which RSP could point to the NMI stack
  1369. * despite there being no NMI active: naughty userspace controls
  1370. * RSP at the very beginning of the SYSCALL targets. We can
  1371. * pull a fast one on naughty userspace, though: we program
  1372. * SYSCALL to mask DF, so userspace cannot cause DF to be set
  1373. * if it controls the kernel's RSP. We set DF before we clear
  1374. * "NMI executing".
  1375. */
  1376. lea 6*8(%rsp), %rdx
  1377. /* Compare the NMI stack (rdx) with the stack we came from (4*8(%rsp)) */
  1378. cmpq %rdx, 4*8(%rsp)
  1379. /* If the stack pointer is above the NMI stack, this is a normal NMI */
  1380. ja first_nmi
  1381. subq $EXCEPTION_STKSZ, %rdx
  1382. cmpq %rdx, 4*8(%rsp)
  1383. /* If it is below the NMI stack, it is a normal NMI */
  1384. jb first_nmi
  1385. /* Ah, it is within the NMI stack. */
  1386. testb $(X86_EFLAGS_DF >> 8), (3*8 + 1)(%rsp)
  1387. jz first_nmi /* RSP was user controlled. */
  1388. /* This is a nested NMI. */
  1389. nested_nmi:
  1390. /*
  1391. * Modify the "iret" frame to point to repeat_nmi, forcing another
  1392. * iteration of NMI handling.
  1393. */
  1394. subq $8, %rsp
  1395. leaq -10*8(%rsp), %rdx
  1396. pushq $__KERNEL_DS
  1397. pushq %rdx
  1398. pushfq
  1399. pushq $__KERNEL_CS
  1400. pushq $repeat_nmi
  1401. /* Put stack back */
  1402. addq $(6*8), %rsp
  1403. nested_nmi_out:
  1404. popq %rdx
  1405. /* We are returning to kernel mode, so this cannot result in a fault. */
  1406. iretq
  1407. first_nmi:
  1408. /* Restore rdx. */
  1409. movq (%rsp), %rdx
  1410. /* Make room for "NMI executing". */
  1411. pushq $0
  1412. /* Leave room for the "iret" frame */
  1413. subq $(5*8), %rsp
  1414. /* Copy the "original" frame to the "outermost" frame */
  1415. .rept 5
  1416. pushq 11*8(%rsp)
  1417. .endr
  1418. UNWIND_HINT_IRET_REGS
  1419. /* Everything up to here is safe from nested NMIs */
  1420. #ifdef CONFIG_DEBUG_ENTRY
  1421. /*
  1422. * For ease of testing, unmask NMIs right away. Disabled by
  1423. * default because IRET is very expensive.
  1424. */
  1425. pushq $0 /* SS */
  1426. pushq %rsp /* RSP (minus 8 because of the previous push) */
  1427. addq $8, (%rsp) /* Fix up RSP */
  1428. pushfq /* RFLAGS */
  1429. pushq $__KERNEL_CS /* CS */
  1430. pushq $1f /* RIP */
  1431. iretq /* continues at repeat_nmi below */
  1432. UNWIND_HINT_IRET_REGS
  1433. 1:
  1434. #endif
  1435. repeat_nmi:
  1436. /*
  1437. * If there was a nested NMI, the first NMI's iret will return
  1438. * here. But NMIs are still enabled and we can take another
  1439. * nested NMI. The nested NMI checks the interrupted RIP to see
  1440. * if it is between repeat_nmi and end_repeat_nmi, and if so
  1441. * it will just return, as we are about to repeat an NMI anyway.
  1442. * This makes it safe to copy to the stack frame that a nested
  1443. * NMI will update.
  1444. *
  1445. * RSP is pointing to "outermost RIP". gsbase is unknown, but, if
  1446. * we're repeating an NMI, gsbase has the same value that it had on
  1447. * the first iteration. paranoid_entry will load the kernel
  1448. * gsbase if needed before we call do_nmi. "NMI executing"
  1449. * is zero.
  1450. */
  1451. movq $1, 10*8(%rsp) /* Set "NMI executing". */
  1452. /*
  1453. * Copy the "outermost" frame to the "iret" frame. NMIs that nest
  1454. * here must not modify the "iret" frame while we're writing to
  1455. * it or it will end up containing garbage.
  1456. */
  1457. addq $(10*8), %rsp
  1458. .rept 5
  1459. pushq -6*8(%rsp)
  1460. .endr
  1461. subq $(5*8), %rsp
  1462. end_repeat_nmi:
  1463. /*
  1464. * Everything below this point can be preempted by a nested NMI.
  1465. * If this happens, then the inner NMI will change the "iret"
  1466. * frame to point back to repeat_nmi.
  1467. */
  1468. pushq $-1 /* ORIG_RAX: no syscall to restart */
  1469. /*
  1470. * Use paranoid_entry to handle SWAPGS, but no need to use paranoid_exit
  1471. * as we should not be calling schedule in NMI context.
  1472. * Even with normal interrupts enabled. An NMI should not be
  1473. * setting NEED_RESCHED or anything that normal interrupts and
  1474. * exceptions might do.
  1475. */
  1476. call paranoid_entry
  1477. UNWIND_HINT_REGS
  1478. /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
  1479. movq %rsp, %rdi
  1480. movq $-1, %rsi
  1481. call do_nmi
  1482. /* Always restore stashed CR3 value (see paranoid_entry) */
  1483. RESTORE_CR3 scratch_reg=%r15 save_reg=%r14
  1484. testl %ebx, %ebx /* swapgs needed? */
  1485. jnz nmi_restore
  1486. nmi_swapgs:
  1487. SWAPGS_UNSAFE_STACK
  1488. nmi_restore:
  1489. POP_REGS
  1490. /*
  1491. * Skip orig_ax and the "outermost" frame to point RSP at the "iret"
  1492. * at the "iret" frame.
  1493. */
  1494. addq $6*8, %rsp
  1495. /*
  1496. * Clear "NMI executing". Set DF first so that we can easily
  1497. * distinguish the remaining code between here and IRET from
  1498. * the SYSCALL entry and exit paths.
  1499. *
  1500. * We arguably should just inspect RIP instead, but I (Andy) wrote
  1501. * this code when I had the misapprehension that Xen PV supported
  1502. * NMIs, and Xen PV would break that approach.
  1503. */
  1504. std
  1505. movq $0, 5*8(%rsp) /* clear "NMI executing" */
  1506. /*
  1507. * iretq reads the "iret" frame and exits the NMI stack in a
  1508. * single instruction. We are returning to kernel mode, so this
  1509. * cannot result in a fault. Similarly, we don't need to worry
  1510. * about espfix64 on the way back to kernel mode.
  1511. */
  1512. iretq
  1513. END(nmi)
  1514. ENTRY(ignore_sysret)
  1515. UNWIND_HINT_EMPTY
  1516. mov $-ENOSYS, %eax
  1517. sysret
  1518. END(ignore_sysret)
  1519. ENTRY(rewind_stack_do_exit)
  1520. UNWIND_HINT_FUNC
  1521. /* Prevent any naive code from trying to unwind to our caller. */
  1522. xorl %ebp, %ebp
  1523. movq PER_CPU_VAR(cpu_current_top_of_stack), %rax
  1524. leaq -PTREGS_SIZE(%rax), %rsp
  1525. UNWIND_HINT_FUNC sp_offset=PTREGS_SIZE
  1526. call do_exit
  1527. END(rewind_stack_do_exit)