entry_32.S 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 1991,1992 Linus Torvalds
  4. *
  5. * entry_32.S contains the system-call and low-level fault and trap handling routines.
  6. *
  7. * Stack layout while running C code:
  8. * ptrace needs to have all registers on the stack.
  9. * If the order here is changed, it needs to be
  10. * updated in fork.c:copy_process(), signal.c:do_signal(),
  11. * ptrace.c and ptrace.h
  12. *
  13. * 0(%esp) - %ebx
  14. * 4(%esp) - %ecx
  15. * 8(%esp) - %edx
  16. * C(%esp) - %esi
  17. * 10(%esp) - %edi
  18. * 14(%esp) - %ebp
  19. * 18(%esp) - %eax
  20. * 1C(%esp) - %ds
  21. * 20(%esp) - %es
  22. * 24(%esp) - %fs
  23. * 28(%esp) - unused -- was %gs on old stackprotector kernels
  24. * 2C(%esp) - orig_eax
  25. * 30(%esp) - %eip
  26. * 34(%esp) - %cs
  27. * 38(%esp) - %eflags
  28. * 3C(%esp) - %oldesp
  29. * 40(%esp) - %oldss
  30. */
  31. #include <linux/linkage.h>
  32. #include <linux/err.h>
  33. #include <asm/thread_info.h>
  34. #include <asm/irqflags.h>
  35. #include <asm/errno.h>
  36. #include <asm/segment.h>
  37. #include <asm/smp.h>
  38. #include <asm/percpu.h>
  39. #include <asm/processor-flags.h>
  40. #include <asm/irq_vectors.h>
  41. #include <asm/cpufeatures.h>
  42. #include <asm/alternative.h>
  43. #include <asm/asm.h>
  44. #include <asm/smap.h>
  45. #include <asm/frame.h>
  46. #include <asm/trapnr.h>
  47. #include <asm/nospec-branch.h>
  48. #include "calling.h"
  49. .section .entry.text, "ax"
  50. #define PTI_SWITCH_MASK (1 << PAGE_SHIFT)
  51. /* Unconditionally switch to user cr3 */
  52. .macro SWITCH_TO_USER_CR3 scratch_reg:req
  53. ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
  54. movl %cr3, \scratch_reg
  55. orl $PTI_SWITCH_MASK, \scratch_reg
  56. movl \scratch_reg, %cr3
  57. .Lend_\@:
  58. .endm
  59. .macro BUG_IF_WRONG_CR3 no_user_check=0
  60. #ifdef CONFIG_DEBUG_ENTRY
  61. ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
  62. .if \no_user_check == 0
  63. /* coming from usermode? */
  64. testl $USER_SEGMENT_RPL_MASK, PT_CS(%esp)
  65. jz .Lend_\@
  66. .endif
  67. /* On user-cr3? */
  68. movl %cr3, %eax
  69. testl $PTI_SWITCH_MASK, %eax
  70. jnz .Lend_\@
  71. /* From userspace with kernel cr3 - BUG */
  72. ud2
  73. .Lend_\@:
  74. #endif
  75. .endm
  76. /*
  77. * Switch to kernel cr3 if not already loaded and return current cr3 in
  78. * \scratch_reg
  79. */
  80. .macro SWITCH_TO_KERNEL_CR3 scratch_reg:req
  81. ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
  82. movl %cr3, \scratch_reg
  83. /* Test if we are already on kernel CR3 */
  84. testl $PTI_SWITCH_MASK, \scratch_reg
  85. jz .Lend_\@
  86. andl $(~PTI_SWITCH_MASK), \scratch_reg
  87. movl \scratch_reg, %cr3
  88. /* Return original CR3 in \scratch_reg */
  89. orl $PTI_SWITCH_MASK, \scratch_reg
  90. .Lend_\@:
  91. .endm
  92. #define CS_FROM_ENTRY_STACK (1 << 31)
  93. #define CS_FROM_USER_CR3 (1 << 30)
  94. #define CS_FROM_KERNEL (1 << 29)
  95. #define CS_FROM_ESPFIX (1 << 28)
  96. .macro FIXUP_FRAME
  97. /*
  98. * The high bits of the CS dword (__csh) are used for CS_FROM_*.
  99. * Clear them in case hardware didn't do this for us.
  100. */
  101. andl $0x0000ffff, 4*4(%esp)
  102. #ifdef CONFIG_VM86
  103. testl $X86_EFLAGS_VM, 5*4(%esp)
  104. jnz .Lfrom_usermode_no_fixup_\@
  105. #endif
  106. testl $USER_SEGMENT_RPL_MASK, 4*4(%esp)
  107. jnz .Lfrom_usermode_no_fixup_\@
  108. orl $CS_FROM_KERNEL, 4*4(%esp)
  109. /*
  110. * When we're here from kernel mode; the (exception) stack looks like:
  111. *
  112. * 6*4(%esp) - <previous context>
  113. * 5*4(%esp) - flags
  114. * 4*4(%esp) - cs
  115. * 3*4(%esp) - ip
  116. * 2*4(%esp) - orig_eax
  117. * 1*4(%esp) - gs / function
  118. * 0*4(%esp) - fs
  119. *
  120. * Lets build a 5 entry IRET frame after that, such that struct pt_regs
  121. * is complete and in particular regs->sp is correct. This gives us
  122. * the original 6 entries as gap:
  123. *
  124. * 14*4(%esp) - <previous context>
  125. * 13*4(%esp) - gap / flags
  126. * 12*4(%esp) - gap / cs
  127. * 11*4(%esp) - gap / ip
  128. * 10*4(%esp) - gap / orig_eax
  129. * 9*4(%esp) - gap / gs / function
  130. * 8*4(%esp) - gap / fs
  131. * 7*4(%esp) - ss
  132. * 6*4(%esp) - sp
  133. * 5*4(%esp) - flags
  134. * 4*4(%esp) - cs
  135. * 3*4(%esp) - ip
  136. * 2*4(%esp) - orig_eax
  137. * 1*4(%esp) - gs / function
  138. * 0*4(%esp) - fs
  139. */
  140. pushl %ss # ss
  141. pushl %esp # sp (points at ss)
  142. addl $7*4, (%esp) # point sp back at the previous context
  143. pushl 7*4(%esp) # flags
  144. pushl 7*4(%esp) # cs
  145. pushl 7*4(%esp) # ip
  146. pushl 7*4(%esp) # orig_eax
  147. pushl 7*4(%esp) # gs / function
  148. pushl 7*4(%esp) # fs
  149. .Lfrom_usermode_no_fixup_\@:
  150. .endm
  151. .macro IRET_FRAME
  152. /*
  153. * We're called with %ds, %es, %fs, and %gs from the interrupted
  154. * frame, so we shouldn't use them. Also, we may be in ESPFIX
  155. * mode and therefore have a nonzero SS base and an offset ESP,
  156. * so any attempt to access the stack needs to use SS. (except for
  157. * accesses through %esp, which automatically use SS.)
  158. */
  159. testl $CS_FROM_KERNEL, 1*4(%esp)
  160. jz .Lfinished_frame_\@
  161. /*
  162. * Reconstruct the 3 entry IRET frame right after the (modified)
  163. * regs->sp without lowering %esp in between, such that an NMI in the
  164. * middle doesn't scribble our stack.
  165. */
  166. pushl %eax
  167. pushl %ecx
  168. movl 5*4(%esp), %eax # (modified) regs->sp
  169. movl 4*4(%esp), %ecx # flags
  170. movl %ecx, %ss:-1*4(%eax)
  171. movl 3*4(%esp), %ecx # cs
  172. andl $0x0000ffff, %ecx
  173. movl %ecx, %ss:-2*4(%eax)
  174. movl 2*4(%esp), %ecx # ip
  175. movl %ecx, %ss:-3*4(%eax)
  176. movl 1*4(%esp), %ecx # eax
  177. movl %ecx, %ss:-4*4(%eax)
  178. popl %ecx
  179. lea -4*4(%eax), %esp
  180. popl %eax
  181. .Lfinished_frame_\@:
  182. .endm
  183. .macro SAVE_ALL pt_regs_ax=%eax switch_stacks=0 skip_gs=0 unwind_espfix=0
  184. cld
  185. .if \skip_gs == 0
  186. pushl $0
  187. .endif
  188. pushl %fs
  189. pushl %eax
  190. movl $(__KERNEL_PERCPU), %eax
  191. movl %eax, %fs
  192. .if \unwind_espfix > 0
  193. UNWIND_ESPFIX_STACK
  194. .endif
  195. popl %eax
  196. FIXUP_FRAME
  197. pushl %es
  198. pushl %ds
  199. pushl \pt_regs_ax
  200. pushl %ebp
  201. pushl %edi
  202. pushl %esi
  203. pushl %edx
  204. pushl %ecx
  205. pushl %ebx
  206. movl $(__USER_DS), %edx
  207. movl %edx, %ds
  208. movl %edx, %es
  209. /* Switch to kernel stack if necessary */
  210. .if \switch_stacks > 0
  211. SWITCH_TO_KERNEL_STACK
  212. .endif
  213. .endm
  214. .macro SAVE_ALL_NMI cr3_reg:req unwind_espfix=0
  215. SAVE_ALL unwind_espfix=\unwind_espfix
  216. BUG_IF_WRONG_CR3
  217. /*
  218. * Now switch the CR3 when PTI is enabled.
  219. *
  220. * We can enter with either user or kernel cr3, the code will
  221. * store the old cr3 in \cr3_reg and switches to the kernel cr3
  222. * if necessary.
  223. */
  224. SWITCH_TO_KERNEL_CR3 scratch_reg=\cr3_reg
  225. .Lend_\@:
  226. .endm
  227. .macro RESTORE_INT_REGS
  228. popl %ebx
  229. popl %ecx
  230. popl %edx
  231. popl %esi
  232. popl %edi
  233. popl %ebp
  234. popl %eax
  235. .endm
  236. .macro RESTORE_REGS pop=0
  237. RESTORE_INT_REGS
  238. 1: popl %ds
  239. 2: popl %es
  240. 3: popl %fs
  241. 4: addl $(4 + \pop), %esp /* pop the unused "gs" slot */
  242. IRET_FRAME
  243. /*
  244. * There is no _ASM_EXTABLE_TYPE_REG() for ASM, however since this is
  245. * ASM the registers are known and we can trivially hard-code them.
  246. */
  247. _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_POP_ZERO|EX_REG_DS)
  248. _ASM_EXTABLE_TYPE(2b, 3b, EX_TYPE_POP_ZERO|EX_REG_ES)
  249. _ASM_EXTABLE_TYPE(3b, 4b, EX_TYPE_POP_ZERO|EX_REG_FS)
  250. .endm
  251. .macro RESTORE_ALL_NMI cr3_reg:req pop=0
  252. /*
  253. * Now switch the CR3 when PTI is enabled.
  254. *
  255. * We enter with kernel cr3 and switch the cr3 to the value
  256. * stored on \cr3_reg, which is either a user or a kernel cr3.
  257. */
  258. ALTERNATIVE "jmp .Lswitched_\@", "", X86_FEATURE_PTI
  259. testl $PTI_SWITCH_MASK, \cr3_reg
  260. jz .Lswitched_\@
  261. /* User cr3 in \cr3_reg - write it to hardware cr3 */
  262. movl \cr3_reg, %cr3
  263. .Lswitched_\@:
  264. BUG_IF_WRONG_CR3
  265. RESTORE_REGS pop=\pop
  266. .endm
  267. .macro CHECK_AND_APPLY_ESPFIX
  268. #ifdef CONFIG_X86_ESPFIX32
  269. #define GDT_ESPFIX_OFFSET (GDT_ENTRY_ESPFIX_SS * 8)
  270. #define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page + GDT_ESPFIX_OFFSET)
  271. ALTERNATIVE "jmp .Lend_\@", "", X86_BUG_ESPFIX
  272. movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
  273. /*
  274. * Warning: PT_OLDSS(%esp) contains the wrong/random values if we
  275. * are returning to the kernel.
  276. * See comments in process.c:copy_thread() for details.
  277. */
  278. movb PT_OLDSS(%esp), %ah
  279. movb PT_CS(%esp), %al
  280. andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
  281. cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
  282. jne .Lend_\@ # returning to user-space with LDT SS
  283. /*
  284. * Setup and switch to ESPFIX stack
  285. *
  286. * We're returning to userspace with a 16 bit stack. The CPU will not
  287. * restore the high word of ESP for us on executing iret... This is an
  288. * "official" bug of all the x86-compatible CPUs, which we can work
  289. * around to make dosemu and wine happy. We do this by preloading the
  290. * high word of ESP with the high word of the userspace ESP while
  291. * compensating for the offset by changing to the ESPFIX segment with
  292. * a base address that matches for the difference.
  293. */
  294. mov %esp, %edx /* load kernel esp */
  295. mov PT_OLDESP(%esp), %eax /* load userspace esp */
  296. mov %dx, %ax /* eax: new kernel esp */
  297. sub %eax, %edx /* offset (low word is 0) */
  298. shr $16, %edx
  299. mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
  300. mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
  301. pushl $__ESPFIX_SS
  302. pushl %eax /* new kernel esp */
  303. /*
  304. * Disable interrupts, but do not irqtrace this section: we
  305. * will soon execute iret and the tracer was already set to
  306. * the irqstate after the IRET:
  307. */
  308. cli
  309. lss (%esp), %esp /* switch to espfix segment */
  310. .Lend_\@:
  311. #endif /* CONFIG_X86_ESPFIX32 */
  312. .endm
  313. /*
  314. * Called with pt_regs fully populated and kernel segments loaded,
  315. * so we can access PER_CPU and use the integer registers.
  316. *
  317. * We need to be very careful here with the %esp switch, because an NMI
  318. * can happen everywhere. If the NMI handler finds itself on the
  319. * entry-stack, it will overwrite the task-stack and everything we
  320. * copied there. So allocate the stack-frame on the task-stack and
  321. * switch to it before we do any copying.
  322. */
  323. .macro SWITCH_TO_KERNEL_STACK
  324. BUG_IF_WRONG_CR3
  325. SWITCH_TO_KERNEL_CR3 scratch_reg=%eax
  326. /*
  327. * %eax now contains the entry cr3 and we carry it forward in
  328. * that register for the time this macro runs
  329. */
  330. /* Are we on the entry stack? Bail out if not! */
  331. movl PER_CPU_VAR(cpu_entry_area), %ecx
  332. addl $CPU_ENTRY_AREA_entry_stack + SIZEOF_entry_stack, %ecx
  333. subl %esp, %ecx /* ecx = (end of entry_stack) - esp */
  334. cmpl $SIZEOF_entry_stack, %ecx
  335. jae .Lend_\@
  336. /* Load stack pointer into %esi and %edi */
  337. movl %esp, %esi
  338. movl %esi, %edi
  339. /* Move %edi to the top of the entry stack */
  340. andl $(MASK_entry_stack), %edi
  341. addl $(SIZEOF_entry_stack), %edi
  342. /* Load top of task-stack into %edi */
  343. movl TSS_entry2task_stack(%edi), %edi
  344. /* Special case - entry from kernel mode via entry stack */
  345. #ifdef CONFIG_VM86
  346. movl PT_EFLAGS(%esp), %ecx # mix EFLAGS and CS
  347. movb PT_CS(%esp), %cl
  348. andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %ecx
  349. #else
  350. movl PT_CS(%esp), %ecx
  351. andl $SEGMENT_RPL_MASK, %ecx
  352. #endif
  353. cmpl $USER_RPL, %ecx
  354. jb .Lentry_from_kernel_\@
  355. /* Bytes to copy */
  356. movl $PTREGS_SIZE, %ecx
  357. #ifdef CONFIG_VM86
  358. testl $X86_EFLAGS_VM, PT_EFLAGS(%esi)
  359. jz .Lcopy_pt_regs_\@
  360. /*
  361. * Stack-frame contains 4 additional segment registers when
  362. * coming from VM86 mode
  363. */
  364. addl $(4 * 4), %ecx
  365. #endif
  366. .Lcopy_pt_regs_\@:
  367. /* Allocate frame on task-stack */
  368. subl %ecx, %edi
  369. /* Switch to task-stack */
  370. movl %edi, %esp
  371. /*
  372. * We are now on the task-stack and can safely copy over the
  373. * stack-frame
  374. */
  375. shrl $2, %ecx
  376. cld
  377. rep movsl
  378. jmp .Lend_\@
  379. .Lentry_from_kernel_\@:
  380. /*
  381. * This handles the case when we enter the kernel from
  382. * kernel-mode and %esp points to the entry-stack. When this
  383. * happens we need to switch to the task-stack to run C code,
  384. * but switch back to the entry-stack again when we approach
  385. * iret and return to the interrupted code-path. This usually
  386. * happens when we hit an exception while restoring user-space
  387. * segment registers on the way back to user-space or when the
  388. * sysenter handler runs with eflags.tf set.
  389. *
  390. * When we switch to the task-stack here, we can't trust the
  391. * contents of the entry-stack anymore, as the exception handler
  392. * might be scheduled out or moved to another CPU. Therefore we
  393. * copy the complete entry-stack to the task-stack and set a
  394. * marker in the iret-frame (bit 31 of the CS dword) to detect
  395. * what we've done on the iret path.
  396. *
  397. * On the iret path we copy everything back and switch to the
  398. * entry-stack, so that the interrupted kernel code-path
  399. * continues on the same stack it was interrupted with.
  400. *
  401. * Be aware that an NMI can happen anytime in this code.
  402. *
  403. * %esi: Entry-Stack pointer (same as %esp)
  404. * %edi: Top of the task stack
  405. * %eax: CR3 on kernel entry
  406. */
  407. /* Calculate number of bytes on the entry stack in %ecx */
  408. movl %esi, %ecx
  409. /* %ecx to the top of entry-stack */
  410. andl $(MASK_entry_stack), %ecx
  411. addl $(SIZEOF_entry_stack), %ecx
  412. /* Number of bytes on the entry stack to %ecx */
  413. sub %esi, %ecx
  414. /* Mark stackframe as coming from entry stack */
  415. orl $CS_FROM_ENTRY_STACK, PT_CS(%esp)
  416. /*
  417. * Test the cr3 used to enter the kernel and add a marker
  418. * so that we can switch back to it before iret.
  419. */
  420. testl $PTI_SWITCH_MASK, %eax
  421. jz .Lcopy_pt_regs_\@
  422. orl $CS_FROM_USER_CR3, PT_CS(%esp)
  423. /*
  424. * %esi and %edi are unchanged, %ecx contains the number of
  425. * bytes to copy. The code at .Lcopy_pt_regs_\@ will allocate
  426. * the stack-frame on task-stack and copy everything over
  427. */
  428. jmp .Lcopy_pt_regs_\@
  429. .Lend_\@:
  430. .endm
  431. /*
  432. * Switch back from the kernel stack to the entry stack.
  433. *
  434. * The %esp register must point to pt_regs on the task stack. It will
  435. * first calculate the size of the stack-frame to copy, depending on
  436. * whether we return to VM86 mode or not. With that it uses 'rep movsl'
  437. * to copy the contents of the stack over to the entry stack.
  438. *
  439. * We must be very careful here, as we can't trust the contents of the
  440. * task-stack once we switched to the entry-stack. When an NMI happens
  441. * while on the entry-stack, the NMI handler will switch back to the top
  442. * of the task stack, overwriting our stack-frame we are about to copy.
  443. * Therefore we switch the stack only after everything is copied over.
  444. */
  445. .macro SWITCH_TO_ENTRY_STACK
  446. /* Bytes to copy */
  447. movl $PTREGS_SIZE, %ecx
  448. #ifdef CONFIG_VM86
  449. testl $(X86_EFLAGS_VM), PT_EFLAGS(%esp)
  450. jz .Lcopy_pt_regs_\@
  451. /* Additional 4 registers to copy when returning to VM86 mode */
  452. addl $(4 * 4), %ecx
  453. .Lcopy_pt_regs_\@:
  454. #endif
  455. /* Initialize source and destination for movsl */
  456. movl PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %edi
  457. subl %ecx, %edi
  458. movl %esp, %esi
  459. /* Save future stack pointer in %ebx */
  460. movl %edi, %ebx
  461. /* Copy over the stack-frame */
  462. shrl $2, %ecx
  463. cld
  464. rep movsl
  465. /*
  466. * Switch to entry-stack - needs to happen after everything is
  467. * copied because the NMI handler will overwrite the task-stack
  468. * when on entry-stack
  469. */
  470. movl %ebx, %esp
  471. .Lend_\@:
  472. .endm
  473. /*
  474. * This macro handles the case when we return to kernel-mode on the iret
  475. * path and have to switch back to the entry stack and/or user-cr3
  476. *
  477. * See the comments below the .Lentry_from_kernel_\@ label in the
  478. * SWITCH_TO_KERNEL_STACK macro for more details.
  479. */
  480. .macro PARANOID_EXIT_TO_KERNEL_MODE
  481. /*
  482. * Test if we entered the kernel with the entry-stack. Most
  483. * likely we did not, because this code only runs on the
  484. * return-to-kernel path.
  485. */
  486. testl $CS_FROM_ENTRY_STACK, PT_CS(%esp)
  487. jz .Lend_\@
  488. /* Unlikely slow-path */
  489. /* Clear marker from stack-frame */
  490. andl $(~CS_FROM_ENTRY_STACK), PT_CS(%esp)
  491. /* Copy the remaining task-stack contents to entry-stack */
  492. movl %esp, %esi
  493. movl PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %edi
  494. /* Bytes on the task-stack to ecx */
  495. movl PER_CPU_VAR(cpu_tss_rw + TSS_sp1), %ecx
  496. subl %esi, %ecx
  497. /* Allocate stack-frame on entry-stack */
  498. subl %ecx, %edi
  499. /*
  500. * Save future stack-pointer, we must not switch until the
  501. * copy is done, otherwise the NMI handler could destroy the
  502. * contents of the task-stack we are about to copy.
  503. */
  504. movl %edi, %ebx
  505. /* Do the copy */
  506. shrl $2, %ecx
  507. cld
  508. rep movsl
  509. /* Safe to switch to entry-stack now */
  510. movl %ebx, %esp
  511. /*
  512. * We came from entry-stack and need to check if we also need to
  513. * switch back to user cr3.
  514. */
  515. testl $CS_FROM_USER_CR3, PT_CS(%esp)
  516. jz .Lend_\@
  517. /* Clear marker from stack-frame */
  518. andl $(~CS_FROM_USER_CR3), PT_CS(%esp)
  519. SWITCH_TO_USER_CR3 scratch_reg=%eax
  520. .Lend_\@:
  521. .endm
  522. /**
  523. * idtentry - Macro to generate entry stubs for simple IDT entries
  524. * @vector: Vector number
  525. * @asmsym: ASM symbol for the entry point
  526. * @cfunc: C function to be called
  527. * @has_error_code: Hardware pushed error code on stack
  528. */
  529. .macro idtentry vector asmsym cfunc has_error_code:req
  530. SYM_CODE_START(\asmsym)
  531. ASM_CLAC
  532. cld
  533. .if \has_error_code == 0
  534. pushl $0 /* Clear the error code */
  535. .endif
  536. /* Push the C-function address into the GS slot */
  537. pushl $\cfunc
  538. /* Invoke the common exception entry */
  539. jmp handle_exception
  540. SYM_CODE_END(\asmsym)
  541. .endm
  542. .macro idtentry_irq vector cfunc
  543. .p2align CONFIG_X86_L1_CACHE_SHIFT
  544. SYM_CODE_START_LOCAL(asm_\cfunc)
  545. ASM_CLAC
  546. SAVE_ALL switch_stacks=1
  547. ENCODE_FRAME_POINTER
  548. movl %esp, %eax
  549. movl PT_ORIG_EAX(%esp), %edx /* get the vector from stack */
  550. movl $-1, PT_ORIG_EAX(%esp) /* no syscall to restart */
  551. call \cfunc
  552. jmp handle_exception_return
  553. SYM_CODE_END(asm_\cfunc)
  554. .endm
  555. /*
  556. * Include the defines which emit the idt entries which are shared
  557. * shared between 32 and 64 bit and emit the __irqentry_text_* markers
  558. * so the stacktrace boundary checks work.
  559. */
  560. .align 16
  561. .globl __irqentry_text_start
  562. __irqentry_text_start:
  563. #include <asm/idtentry.h>
  564. .align 16
  565. .globl __irqentry_text_end
  566. __irqentry_text_end:
  567. /*
  568. * %eax: prev task
  569. * %edx: next task
  570. */
  571. .pushsection .text, "ax"
  572. SYM_CODE_START(__switch_to_asm)
  573. /*
  574. * Save callee-saved registers
  575. * This must match the order in struct inactive_task_frame
  576. */
  577. pushl %ebp
  578. pushl %ebx
  579. pushl %edi
  580. pushl %esi
  581. /*
  582. * Flags are saved to prevent AC leakage. This could go
  583. * away if objtool would have 32bit support to verify
  584. * the STAC/CLAC correctness.
  585. */
  586. pushfl
  587. /* switch stack */
  588. movl %esp, TASK_threadsp(%eax)
  589. movl TASK_threadsp(%edx), %esp
  590. #ifdef CONFIG_STACKPROTECTOR
  591. movl TASK_stack_canary(%edx), %ebx
  592. movl %ebx, PER_CPU_VAR(__stack_chk_guard)
  593. #endif
  594. /*
  595. * When switching from a shallower to a deeper call stack
  596. * the RSB may either underflow or use entries populated
  597. * with userspace addresses. On CPUs where those concerns
  598. * exist, overwrite the RSB with entries which capture
  599. * speculative execution to prevent attack.
  600. */
  601. FILL_RETURN_BUFFER %ebx, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW
  602. /* Restore flags or the incoming task to restore AC state. */
  603. popfl
  604. /* restore callee-saved registers */
  605. popl %esi
  606. popl %edi
  607. popl %ebx
  608. popl %ebp
  609. jmp __switch_to
  610. SYM_CODE_END(__switch_to_asm)
  611. .popsection
  612. /*
  613. * A newly forked process directly context switches into this address.
  614. *
  615. * eax: prev task we switched from
  616. * ebx: kernel thread func (NULL for user thread)
  617. * edi: kernel thread arg
  618. */
  619. .pushsection .text, "ax"
  620. SYM_CODE_START(ret_from_fork_asm)
  621. movl %esp, %edx /* regs */
  622. /* return address for the stack unwinder */
  623. pushl $.Lsyscall_32_done
  624. FRAME_BEGIN
  625. /* prev already in EAX */
  626. movl %ebx, %ecx /* fn */
  627. pushl %edi /* fn_arg */
  628. call ret_from_fork
  629. addl $4, %esp
  630. FRAME_END
  631. RET
  632. SYM_CODE_END(ret_from_fork_asm)
  633. .popsection
  634. SYM_ENTRY(__begin_SYSENTER_singlestep_region, SYM_L_GLOBAL, SYM_A_NONE)
  635. /*
  636. * All code from here through __end_SYSENTER_singlestep_region is subject
  637. * to being single-stepped if a user program sets TF and executes SYSENTER.
  638. * There is absolutely nothing that we can do to prevent this from happening
  639. * (thanks Intel!). To keep our handling of this situation as simple as
  640. * possible, we handle TF just like AC and NT, except that our #DB handler
  641. * will ignore all of the single-step traps generated in this range.
  642. */
  643. /*
  644. * 32-bit SYSENTER entry.
  645. *
  646. * 32-bit system calls through the vDSO's __kernel_vsyscall enter here
  647. * if X86_FEATURE_SEP is available. This is the preferred system call
  648. * entry on 32-bit systems.
  649. *
  650. * The SYSENTER instruction, in principle, should *only* occur in the
  651. * vDSO. In practice, a small number of Android devices were shipped
  652. * with a copy of Bionic that inlined a SYSENTER instruction. This
  653. * never happened in any of Google's Bionic versions -- it only happened
  654. * in a narrow range of Intel-provided versions.
  655. *
  656. * SYSENTER loads SS, ESP, CS, and EIP from previously programmed MSRs.
  657. * IF and VM in RFLAGS are cleared (IOW: interrupts are off).
  658. * SYSENTER does not save anything on the stack,
  659. * and does not save old EIP (!!!), ESP, or EFLAGS.
  660. *
  661. * To avoid losing track of EFLAGS.VM (and thus potentially corrupting
  662. * user and/or vm86 state), we explicitly disable the SYSENTER
  663. * instruction in vm86 mode by reprogramming the MSRs.
  664. *
  665. * Arguments:
  666. * eax system call number
  667. * ebx arg1
  668. * ecx arg2
  669. * edx arg3
  670. * esi arg4
  671. * edi arg5
  672. * ebp user stack
  673. * 0(%ebp) arg6
  674. */
  675. SYM_FUNC_START(entry_SYSENTER_32)
  676. /*
  677. * On entry-stack with all userspace-regs live - save and
  678. * restore eflags and %eax to use it as scratch-reg for the cr3
  679. * switch.
  680. */
  681. pushfl
  682. pushl %eax
  683. BUG_IF_WRONG_CR3 no_user_check=1
  684. SWITCH_TO_KERNEL_CR3 scratch_reg=%eax
  685. popl %eax
  686. popfl
  687. /* Stack empty again, switch to task stack */
  688. movl TSS_entry2task_stack(%esp), %esp
  689. .Lsysenter_past_esp:
  690. pushl $__USER_DS /* pt_regs->ss */
  691. pushl $0 /* pt_regs->sp (placeholder) */
  692. pushfl /* pt_regs->flags (except IF = 0) */
  693. pushl $__USER_CS /* pt_regs->cs */
  694. pushl $0 /* pt_regs->ip = 0 (placeholder) */
  695. pushl %eax /* pt_regs->orig_ax */
  696. SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest, stack already switched */
  697. /*
  698. * SYSENTER doesn't filter flags, so we need to clear NT, AC
  699. * and TF ourselves. To save a few cycles, we can check whether
  700. * either was set instead of doing an unconditional popfq.
  701. * This needs to happen before enabling interrupts so that
  702. * we don't get preempted with NT set.
  703. *
  704. * If TF is set, we will single-step all the way to here -- do_debug
  705. * will ignore all the traps. (Yes, this is slow, but so is
  706. * single-stepping in general. This allows us to avoid having
  707. * a more complicated code to handle the case where a user program
  708. * forces us to single-step through the SYSENTER entry code.)
  709. *
  710. * NB.: .Lsysenter_fix_flags is a label with the code under it moved
  711. * out-of-line as an optimization: NT is unlikely to be set in the
  712. * majority of the cases and instead of polluting the I$ unnecessarily,
  713. * we're keeping that code behind a branch which will predict as
  714. * not-taken and therefore its instructions won't be fetched.
  715. */
  716. testl $X86_EFLAGS_NT|X86_EFLAGS_AC|X86_EFLAGS_TF, PT_EFLAGS(%esp)
  717. jnz .Lsysenter_fix_flags
  718. .Lsysenter_flags_fixed:
  719. movl %esp, %eax
  720. call do_SYSENTER_32
  721. testb %al, %al
  722. jz .Lsyscall_32_done
  723. STACKLEAK_ERASE
  724. /* Opportunistic SYSEXIT */
  725. /*
  726. * Setup entry stack - we keep the pointer in %eax and do the
  727. * switch after almost all user-state is restored.
  728. */
  729. /* Load entry stack pointer and allocate frame for eflags/eax */
  730. movl PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %eax
  731. subl $(2*4), %eax
  732. /* Copy eflags and eax to entry stack */
  733. movl PT_EFLAGS(%esp), %edi
  734. movl PT_EAX(%esp), %esi
  735. movl %edi, (%eax)
  736. movl %esi, 4(%eax)
  737. /* Restore user registers and segments */
  738. movl PT_EIP(%esp), %edx /* pt_regs->ip */
  739. movl PT_OLDESP(%esp), %ecx /* pt_regs->sp */
  740. 1: mov PT_FS(%esp), %fs
  741. popl %ebx /* pt_regs->bx */
  742. addl $2*4, %esp /* skip pt_regs->cx and pt_regs->dx */
  743. popl %esi /* pt_regs->si */
  744. popl %edi /* pt_regs->di */
  745. popl %ebp /* pt_regs->bp */
  746. /* Switch to entry stack */
  747. movl %eax, %esp
  748. /* Now ready to switch the cr3 */
  749. SWITCH_TO_USER_CR3 scratch_reg=%eax
  750. /* Clobbers ZF */
  751. CLEAR_CPU_BUFFERS
  752. /*
  753. * Restore all flags except IF. (We restore IF separately because
  754. * STI gives a one-instruction window in which we won't be interrupted,
  755. * whereas POPF does not.)
  756. */
  757. btrl $X86_EFLAGS_IF_BIT, (%esp)
  758. BUG_IF_WRONG_CR3 no_user_check=1
  759. popfl
  760. popl %eax
  761. /*
  762. * Return back to the vDSO, which will pop ecx and edx.
  763. * Don't bother with DS and ES (they already contain __USER_DS).
  764. */
  765. sti
  766. sysexit
  767. 2: movl $0, PT_FS(%esp)
  768. jmp 1b
  769. _ASM_EXTABLE(1b, 2b)
  770. .Lsysenter_fix_flags:
  771. pushl $X86_EFLAGS_FIXED
  772. popfl
  773. jmp .Lsysenter_flags_fixed
  774. SYM_ENTRY(__end_SYSENTER_singlestep_region, SYM_L_GLOBAL, SYM_A_NONE)
  775. SYM_FUNC_END(entry_SYSENTER_32)
  776. /*
  777. * 32-bit legacy system call entry.
  778. *
  779. * 32-bit x86 Linux system calls traditionally used the INT $0x80
  780. * instruction. INT $0x80 lands here.
  781. *
  782. * This entry point can be used by any 32-bit perform system calls.
  783. * Instances of INT $0x80 can be found inline in various programs and
  784. * libraries. It is also used by the vDSO's __kernel_vsyscall
  785. * fallback for hardware that doesn't support a faster entry method.
  786. * Restarted 32-bit system calls also fall back to INT $0x80
  787. * regardless of what instruction was originally used to do the system
  788. * call. (64-bit programs can use INT $0x80 as well, but they can
  789. * only run on 64-bit kernels and therefore land in
  790. * entry_INT80_compat.)
  791. *
  792. * This is considered a slow path. It is not used by most libc
  793. * implementations on modern hardware except during process startup.
  794. *
  795. * Arguments:
  796. * eax system call number
  797. * ebx arg1
  798. * ecx arg2
  799. * edx arg3
  800. * esi arg4
  801. * edi arg5
  802. * ebp arg6
  803. */
  804. SYM_FUNC_START(entry_INT80_32)
  805. ASM_CLAC
  806. pushl %eax /* pt_regs->orig_ax */
  807. SAVE_ALL pt_regs_ax=$-ENOSYS switch_stacks=1 /* save rest */
  808. movl %esp, %eax
  809. call do_int80_syscall_32
  810. .Lsyscall_32_done:
  811. STACKLEAK_ERASE
  812. restore_all_switch_stack:
  813. SWITCH_TO_ENTRY_STACK
  814. CHECK_AND_APPLY_ESPFIX
  815. /* Switch back to user CR3 */
  816. SWITCH_TO_USER_CR3 scratch_reg=%eax
  817. BUG_IF_WRONG_CR3
  818. /* Restore user state */
  819. RESTORE_REGS pop=4 # skip orig_eax/error_code
  820. CLEAR_CPU_BUFFERS
  821. .Lirq_return:
  822. /*
  823. * ARCH_HAS_MEMBARRIER_SYNC_CORE rely on IRET core serialization
  824. * when returning from IPI handler and when returning from
  825. * scheduler to user-space.
  826. */
  827. iret
  828. .Lasm_iret_error:
  829. pushl $0 # no error code
  830. pushl $iret_error
  831. #ifdef CONFIG_DEBUG_ENTRY
  832. /*
  833. * The stack-frame here is the one that iret faulted on, so its a
  834. * return-to-user frame. We are on kernel-cr3 because we come here from
  835. * the fixup code. This confuses the CR3 checker, so switch to user-cr3
  836. * as the checker expects it.
  837. */
  838. pushl %eax
  839. SWITCH_TO_USER_CR3 scratch_reg=%eax
  840. popl %eax
  841. #endif
  842. jmp handle_exception
  843. _ASM_EXTABLE(.Lirq_return, .Lasm_iret_error)
  844. SYM_FUNC_END(entry_INT80_32)
  845. .macro FIXUP_ESPFIX_STACK
  846. /*
  847. * Switch back for ESPFIX stack to the normal zerobased stack
  848. *
  849. * We can't call C functions using the ESPFIX stack. This code reads
  850. * the high word of the segment base from the GDT and swiches to the
  851. * normal stack and adjusts ESP with the matching offset.
  852. *
  853. * We might be on user CR3 here, so percpu data is not mapped and we can't
  854. * access the GDT through the percpu segment. Instead, use SGDT to find
  855. * the cpu_entry_area alias of the GDT.
  856. */
  857. #ifdef CONFIG_X86_ESPFIX32
  858. /* fixup the stack */
  859. pushl %ecx
  860. subl $2*4, %esp
  861. sgdt (%esp)
  862. movl 2(%esp), %ecx /* GDT address */
  863. /*
  864. * Careful: ECX is a linear pointer, so we need to force base
  865. * zero. %cs is the only known-linear segment we have right now.
  866. */
  867. mov %cs:GDT_ESPFIX_OFFSET + 4(%ecx), %al /* bits 16..23 */
  868. mov %cs:GDT_ESPFIX_OFFSET + 7(%ecx), %ah /* bits 24..31 */
  869. shl $16, %eax
  870. addl $2*4, %esp
  871. popl %ecx
  872. addl %esp, %eax /* the adjusted stack pointer */
  873. pushl $__KERNEL_DS
  874. pushl %eax
  875. lss (%esp), %esp /* switch to the normal stack segment */
  876. #endif
  877. .endm
  878. .macro UNWIND_ESPFIX_STACK
  879. /* It's safe to clobber %eax, all other regs need to be preserved */
  880. #ifdef CONFIG_X86_ESPFIX32
  881. movl %ss, %eax
  882. /* see if on espfix stack */
  883. cmpw $__ESPFIX_SS, %ax
  884. jne .Lno_fixup_\@
  885. /* switch to normal stack */
  886. FIXUP_ESPFIX_STACK
  887. .Lno_fixup_\@:
  888. #endif
  889. .endm
  890. SYM_CODE_START_LOCAL_NOALIGN(handle_exception)
  891. /* the function address is in %gs's slot on the stack */
  892. SAVE_ALL switch_stacks=1 skip_gs=1 unwind_espfix=1
  893. ENCODE_FRAME_POINTER
  894. movl PT_GS(%esp), %edi # get the function address
  895. /* fixup orig %eax */
  896. movl PT_ORIG_EAX(%esp), %edx # get the error code
  897. movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
  898. movl %esp, %eax # pt_regs pointer
  899. CALL_NOSPEC edi
  900. handle_exception_return:
  901. #ifdef CONFIG_VM86
  902. movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
  903. movb PT_CS(%esp), %al
  904. andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
  905. #else
  906. /*
  907. * We can be coming here from child spawned by kernel_thread().
  908. */
  909. movl PT_CS(%esp), %eax
  910. andl $SEGMENT_RPL_MASK, %eax
  911. #endif
  912. cmpl $USER_RPL, %eax # returning to v8086 or userspace ?
  913. jnb ret_to_user
  914. PARANOID_EXIT_TO_KERNEL_MODE
  915. BUG_IF_WRONG_CR3
  916. RESTORE_REGS 4
  917. jmp .Lirq_return
  918. ret_to_user:
  919. movl %esp, %eax
  920. jmp restore_all_switch_stack
  921. SYM_CODE_END(handle_exception)
  922. SYM_CODE_START(asm_exc_double_fault)
  923. 1:
  924. /*
  925. * This is a task gate handler, not an interrupt gate handler.
  926. * The error code is on the stack, but the stack is otherwise
  927. * empty. Interrupts are off. Our state is sane with the following
  928. * exceptions:
  929. *
  930. * - CR0.TS is set. "TS" literally means "task switched".
  931. * - EFLAGS.NT is set because we're a "nested task".
  932. * - The doublefault TSS has back_link set and has been marked busy.
  933. * - TR points to the doublefault TSS and the normal TSS is busy.
  934. * - CR3 is the normal kernel PGD. This would be delightful, except
  935. * that the CPU didn't bother to save the old CR3 anywhere. This
  936. * would make it very awkward to return back to the context we came
  937. * from.
  938. *
  939. * The rest of EFLAGS is sanitized for us, so we don't need to
  940. * worry about AC or DF.
  941. *
  942. * Don't even bother popping the error code. It's always zero,
  943. * and ignoring it makes us a bit more robust against buggy
  944. * hypervisor task gate implementations.
  945. *
  946. * We will manually undo the task switch instead of doing a
  947. * task-switching IRET.
  948. */
  949. clts /* clear CR0.TS */
  950. pushl $X86_EFLAGS_FIXED
  951. popfl /* clear EFLAGS.NT */
  952. call doublefault_shim
  953. /* We don't support returning, so we have no IRET here. */
  954. 1:
  955. hlt
  956. jmp 1b
  957. SYM_CODE_END(asm_exc_double_fault)
  958. /*
  959. * NMI is doubly nasty. It can happen on the first instruction of
  960. * entry_SYSENTER_32 (just like #DB), but it can also interrupt the beginning
  961. * of the #DB handler even if that #DB in turn hit before entry_SYSENTER_32
  962. * switched stacks. We handle both conditions by simply checking whether we
  963. * interrupted kernel code running on the SYSENTER stack.
  964. */
  965. SYM_CODE_START(asm_exc_nmi)
  966. ASM_CLAC
  967. #ifdef CONFIG_X86_ESPFIX32
  968. /*
  969. * ESPFIX_SS is only ever set on the return to user path
  970. * after we've switched to the entry stack.
  971. */
  972. pushl %eax
  973. movl %ss, %eax
  974. cmpw $__ESPFIX_SS, %ax
  975. popl %eax
  976. je .Lnmi_espfix_stack
  977. #endif
  978. pushl %eax # pt_regs->orig_ax
  979. SAVE_ALL_NMI cr3_reg=%edi
  980. ENCODE_FRAME_POINTER
  981. xorl %edx, %edx # zero error code
  982. movl %esp, %eax # pt_regs pointer
  983. /* Are we currently on the SYSENTER stack? */
  984. movl PER_CPU_VAR(cpu_entry_area), %ecx
  985. addl $CPU_ENTRY_AREA_entry_stack + SIZEOF_entry_stack, %ecx
  986. subl %eax, %ecx /* ecx = (end of entry_stack) - esp */
  987. cmpl $SIZEOF_entry_stack, %ecx
  988. jb .Lnmi_from_sysenter_stack
  989. /* Not on SYSENTER stack. */
  990. call exc_nmi
  991. jmp .Lnmi_return
  992. .Lnmi_from_sysenter_stack:
  993. /*
  994. * We're on the SYSENTER stack. Switch off. No one (not even debug)
  995. * is using the thread stack right now, so it's safe for us to use it.
  996. */
  997. movl %esp, %ebx
  998. movl PER_CPU_VAR(pcpu_hot + X86_top_of_stack), %esp
  999. call exc_nmi
  1000. movl %ebx, %esp
  1001. .Lnmi_return:
  1002. #ifdef CONFIG_X86_ESPFIX32
  1003. testl $CS_FROM_ESPFIX, PT_CS(%esp)
  1004. jnz .Lnmi_from_espfix
  1005. #endif
  1006. CHECK_AND_APPLY_ESPFIX
  1007. RESTORE_ALL_NMI cr3_reg=%edi pop=4
  1008. CLEAR_CPU_BUFFERS
  1009. jmp .Lirq_return
  1010. #ifdef CONFIG_X86_ESPFIX32
  1011. .Lnmi_espfix_stack:
  1012. /*
  1013. * Create the pointer to LSS back
  1014. */
  1015. pushl %ss
  1016. pushl %esp
  1017. addl $4, (%esp)
  1018. /* Copy the (short) IRET frame */
  1019. pushl 4*4(%esp) # flags
  1020. pushl 4*4(%esp) # cs
  1021. pushl 4*4(%esp) # ip
  1022. pushl %eax # orig_ax
  1023. SAVE_ALL_NMI cr3_reg=%edi unwind_espfix=1
  1024. ENCODE_FRAME_POINTER
  1025. /* clear CS_FROM_KERNEL, set CS_FROM_ESPFIX */
  1026. xorl $(CS_FROM_ESPFIX | CS_FROM_KERNEL), PT_CS(%esp)
  1027. xorl %edx, %edx # zero error code
  1028. movl %esp, %eax # pt_regs pointer
  1029. jmp .Lnmi_from_sysenter_stack
  1030. .Lnmi_from_espfix:
  1031. RESTORE_ALL_NMI cr3_reg=%edi
  1032. /*
  1033. * Because we cleared CS_FROM_KERNEL, IRET_FRAME 'forgot' to
  1034. * fix up the gap and long frame:
  1035. *
  1036. * 3 - original frame (exception)
  1037. * 2 - ESPFIX block (above)
  1038. * 6 - gap (FIXUP_FRAME)
  1039. * 5 - long frame (FIXUP_FRAME)
  1040. * 1 - orig_ax
  1041. */
  1042. lss (1+5+6)*4(%esp), %esp # back to espfix stack
  1043. CLEAR_CPU_BUFFERS
  1044. jmp .Lirq_return
  1045. #endif
  1046. SYM_CODE_END(asm_exc_nmi)
  1047. .pushsection .text, "ax"
  1048. SYM_CODE_START(rewind_stack_and_make_dead)
  1049. /* Prevent any naive code from trying to unwind to our caller. */
  1050. xorl %ebp, %ebp
  1051. movl PER_CPU_VAR(pcpu_hot + X86_top_of_stack), %esi
  1052. leal -TOP_OF_KERNEL_STACK_PADDING-PTREGS_SIZE(%esi), %esp
  1053. call make_task_dead
  1054. 1: jmp 1b
  1055. SYM_CODE_END(rewind_stack_and_make_dead)
  1056. .popsection