entry_32.S 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. /*
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. */
  5. /*
  6. * entry.S contains the system-call and fault low-level handling routines.
  7. * This also contains the timer-interrupt handler, as well as all interrupts
  8. * and faults that can result in a task-switch.
  9. *
  10. * NOTE: This code handles signal-recognition, which happens every time
  11. * after a timer-interrupt and after each system call.
  12. *
  13. * I changed all the .align's to 4 (16 byte alignment), as that's faster
  14. * on a 486.
  15. *
  16. * Stack layout in 'syscall_exit':
  17. * ptrace needs to have all regs on the stack.
  18. * if the order here is changed, it needs to be
  19. * updated in fork.c:copy_process, signal.c:do_signal,
  20. * ptrace.c and ptrace.h
  21. *
  22. * 0(%esp) - %ebx
  23. * 4(%esp) - %ecx
  24. * 8(%esp) - %edx
  25. * C(%esp) - %esi
  26. * 10(%esp) - %edi
  27. * 14(%esp) - %ebp
  28. * 18(%esp) - %eax
  29. * 1C(%esp) - %ds
  30. * 20(%esp) - %es
  31. * 24(%esp) - %fs
  32. * 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
  33. * 2C(%esp) - orig_eax
  34. * 30(%esp) - %eip
  35. * 34(%esp) - %cs
  36. * 38(%esp) - %eflags
  37. * 3C(%esp) - %oldesp
  38. * 40(%esp) - %oldss
  39. *
  40. * "current" is in register %ebx during any slow entries.
  41. */
  42. #include <linux/linkage.h>
  43. #include <linux/err.h>
  44. #include <asm/thread_info.h>
  45. #include <asm/irqflags.h>
  46. #include <asm/errno.h>
  47. #include <asm/segment.h>
  48. #include <asm/smp.h>
  49. #include <asm/page_types.h>
  50. #include <asm/percpu.h>
  51. #include <asm/dwarf2.h>
  52. #include <asm/processor-flags.h>
  53. #include <asm/ftrace.h>
  54. #include <asm/irq_vectors.h>
  55. #include <asm/cpufeature.h>
  56. #include <asm/alternative-asm.h>
  57. #include <asm/asm.h>
  58. /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
  59. #include <linux/elf-em.h>
  60. #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
  61. #define __AUDIT_ARCH_LE 0x40000000
  62. #ifndef CONFIG_AUDITSYSCALL
  63. #define sysenter_audit syscall_trace_entry
  64. #define sysexit_audit syscall_exit_work
  65. #endif
  66. .section .entry.text, "ax"
  67. /*
  68. * We use macros for low-level operations which need to be overridden
  69. * for paravirtualization. The following will never clobber any registers:
  70. * INTERRUPT_RETURN (aka. "iret")
  71. * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
  72. * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
  73. *
  74. * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
  75. * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
  76. * Allowing a register to be clobbered can shrink the paravirt replacement
  77. * enough to patch inline, increasing performance.
  78. */
  79. #ifdef CONFIG_PREEMPT
  80. #define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
  81. #else
  82. #define preempt_stop(clobbers)
  83. #define resume_kernel restore_all
  84. #endif
  85. .macro TRACE_IRQS_IRET
  86. #ifdef CONFIG_TRACE_IRQFLAGS
  87. testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
  88. jz 1f
  89. TRACE_IRQS_ON
  90. 1:
  91. #endif
  92. .endm
  93. /*
  94. * User gs save/restore
  95. *
  96. * %gs is used for userland TLS and kernel only uses it for stack
  97. * canary which is required to be at %gs:20 by gcc. Read the comment
  98. * at the top of stackprotector.h for more info.
  99. *
  100. * Local labels 98 and 99 are used.
  101. */
  102. #ifdef CONFIG_X86_32_LAZY_GS
  103. /* unfortunately push/pop can't be no-op */
  104. .macro PUSH_GS
  105. pushl_cfi $0
  106. .endm
  107. .macro POP_GS pop=0
  108. addl $(4 + \pop), %esp
  109. CFI_ADJUST_CFA_OFFSET -(4 + \pop)
  110. .endm
  111. .macro POP_GS_EX
  112. .endm
  113. /* all the rest are no-op */
  114. .macro PTGS_TO_GS
  115. .endm
  116. .macro PTGS_TO_GS_EX
  117. .endm
  118. .macro GS_TO_REG reg
  119. .endm
  120. .macro REG_TO_PTGS reg
  121. .endm
  122. .macro SET_KERNEL_GS reg
  123. .endm
  124. #else /* CONFIG_X86_32_LAZY_GS */
  125. .macro PUSH_GS
  126. pushl_cfi %gs
  127. /*CFI_REL_OFFSET gs, 0*/
  128. .endm
  129. .macro POP_GS pop=0
  130. 98: popl_cfi %gs
  131. /*CFI_RESTORE gs*/
  132. .if \pop <> 0
  133. add $\pop, %esp
  134. CFI_ADJUST_CFA_OFFSET -\pop
  135. .endif
  136. .endm
  137. .macro POP_GS_EX
  138. .pushsection .fixup, "ax"
  139. 99: movl $0, (%esp)
  140. jmp 98b
  141. .popsection
  142. _ASM_EXTABLE(98b,99b)
  143. .endm
  144. .macro PTGS_TO_GS
  145. 98: mov PT_GS(%esp), %gs
  146. .endm
  147. .macro PTGS_TO_GS_EX
  148. .pushsection .fixup, "ax"
  149. 99: movl $0, PT_GS(%esp)
  150. jmp 98b
  151. .popsection
  152. _ASM_EXTABLE(98b,99b)
  153. .endm
  154. .macro GS_TO_REG reg
  155. movl %gs, \reg
  156. /*CFI_REGISTER gs, \reg*/
  157. .endm
  158. .macro REG_TO_PTGS reg
  159. movl \reg, PT_GS(%esp)
  160. /*CFI_REL_OFFSET gs, PT_GS*/
  161. .endm
  162. .macro SET_KERNEL_GS reg
  163. movl $(__KERNEL_STACK_CANARY), \reg
  164. movl \reg, %gs
  165. .endm
  166. #endif /* CONFIG_X86_32_LAZY_GS */
  167. .macro SAVE_ALL
  168. cld
  169. PUSH_GS
  170. pushl_cfi %fs
  171. /*CFI_REL_OFFSET fs, 0;*/
  172. pushl_cfi %es
  173. /*CFI_REL_OFFSET es, 0;*/
  174. pushl_cfi %ds
  175. /*CFI_REL_OFFSET ds, 0;*/
  176. pushl_cfi %eax
  177. CFI_REL_OFFSET eax, 0
  178. pushl_cfi %ebp
  179. CFI_REL_OFFSET ebp, 0
  180. pushl_cfi %edi
  181. CFI_REL_OFFSET edi, 0
  182. pushl_cfi %esi
  183. CFI_REL_OFFSET esi, 0
  184. pushl_cfi %edx
  185. CFI_REL_OFFSET edx, 0
  186. pushl_cfi %ecx
  187. CFI_REL_OFFSET ecx, 0
  188. pushl_cfi %ebx
  189. CFI_REL_OFFSET ebx, 0
  190. movl $(__USER_DS), %edx
  191. movl %edx, %ds
  192. movl %edx, %es
  193. movl $(__KERNEL_PERCPU), %edx
  194. movl %edx, %fs
  195. SET_KERNEL_GS %edx
  196. .endm
  197. .macro RESTORE_INT_REGS
  198. popl_cfi %ebx
  199. CFI_RESTORE ebx
  200. popl_cfi %ecx
  201. CFI_RESTORE ecx
  202. popl_cfi %edx
  203. CFI_RESTORE edx
  204. popl_cfi %esi
  205. CFI_RESTORE esi
  206. popl_cfi %edi
  207. CFI_RESTORE edi
  208. popl_cfi %ebp
  209. CFI_RESTORE ebp
  210. popl_cfi %eax
  211. CFI_RESTORE eax
  212. .endm
  213. .macro RESTORE_REGS pop=0
  214. RESTORE_INT_REGS
  215. 1: popl_cfi %ds
  216. /*CFI_RESTORE ds;*/
  217. 2: popl_cfi %es
  218. /*CFI_RESTORE es;*/
  219. 3: popl_cfi %fs
  220. /*CFI_RESTORE fs;*/
  221. POP_GS \pop
  222. .pushsection .fixup, "ax"
  223. 4: movl $0, (%esp)
  224. jmp 1b
  225. 5: movl $0, (%esp)
  226. jmp 2b
  227. 6: movl $0, (%esp)
  228. jmp 3b
  229. .popsection
  230. _ASM_EXTABLE(1b,4b)
  231. _ASM_EXTABLE(2b,5b)
  232. _ASM_EXTABLE(3b,6b)
  233. POP_GS_EX
  234. .endm
  235. .macro RING0_INT_FRAME
  236. CFI_STARTPROC simple
  237. CFI_SIGNAL_FRAME
  238. CFI_DEF_CFA esp, 3*4
  239. /*CFI_OFFSET cs, -2*4;*/
  240. CFI_OFFSET eip, -3*4
  241. .endm
  242. .macro RING0_EC_FRAME
  243. CFI_STARTPROC simple
  244. CFI_SIGNAL_FRAME
  245. CFI_DEF_CFA esp, 4*4
  246. /*CFI_OFFSET cs, -2*4;*/
  247. CFI_OFFSET eip, -3*4
  248. .endm
  249. .macro RING0_PTREGS_FRAME
  250. CFI_STARTPROC simple
  251. CFI_SIGNAL_FRAME
  252. CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
  253. /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
  254. CFI_OFFSET eip, PT_EIP-PT_OLDESP
  255. /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
  256. /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
  257. CFI_OFFSET eax, PT_EAX-PT_OLDESP
  258. CFI_OFFSET ebp, PT_EBP-PT_OLDESP
  259. CFI_OFFSET edi, PT_EDI-PT_OLDESP
  260. CFI_OFFSET esi, PT_ESI-PT_OLDESP
  261. CFI_OFFSET edx, PT_EDX-PT_OLDESP
  262. CFI_OFFSET ecx, PT_ECX-PT_OLDESP
  263. CFI_OFFSET ebx, PT_EBX-PT_OLDESP
  264. .endm
  265. ENTRY(ret_from_fork)
  266. CFI_STARTPROC
  267. pushl_cfi %eax
  268. call schedule_tail
  269. GET_THREAD_INFO(%ebp)
  270. popl_cfi %eax
  271. pushl_cfi $0x0202 # Reset kernel eflags
  272. popfl_cfi
  273. jmp syscall_exit
  274. CFI_ENDPROC
  275. END(ret_from_fork)
  276. ENTRY(ret_from_kernel_thread)
  277. CFI_STARTPROC
  278. pushl_cfi %eax
  279. call schedule_tail
  280. GET_THREAD_INFO(%ebp)
  281. popl_cfi %eax
  282. pushl_cfi $0x0202 # Reset kernel eflags
  283. popfl_cfi
  284. movl PT_EBP(%esp),%eax
  285. call *PT_EBX(%esp)
  286. movl $0,PT_EAX(%esp)
  287. jmp syscall_exit
  288. CFI_ENDPROC
  289. ENDPROC(ret_from_kernel_thread)
  290. /*
  291. * Interrupt exit functions should be protected against kprobes
  292. */
  293. .pushsection .kprobes.text, "ax"
  294. /*
  295. * Return to user mode is not as complex as all this looks,
  296. * but we want the default path for a system call return to
  297. * go as quickly as possible which is why some of this is
  298. * less clear than it otherwise should be.
  299. */
  300. # userspace resumption stub bypassing syscall exit tracing
  301. ALIGN
  302. RING0_PTREGS_FRAME
  303. ret_from_exception:
  304. preempt_stop(CLBR_ANY)
  305. ret_from_intr:
  306. GET_THREAD_INFO(%ebp)
  307. #ifdef CONFIG_VM86
  308. movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
  309. movb PT_CS(%esp), %al
  310. andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
  311. #else
  312. /*
  313. * We can be coming here from child spawned by kernel_thread().
  314. */
  315. movl PT_CS(%esp), %eax
  316. andl $SEGMENT_RPL_MASK, %eax
  317. #endif
  318. cmpl $USER_RPL, %eax
  319. jb resume_kernel # not returning to v8086 or userspace
  320. ENTRY(resume_userspace)
  321. LOCKDEP_SYS_EXIT
  322. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  323. # setting need_resched or sigpending
  324. # between sampling and the iret
  325. TRACE_IRQS_OFF
  326. movl TI_flags(%ebp), %ecx
  327. andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
  328. # int/exception return?
  329. jne work_pending
  330. jmp restore_all
  331. END(ret_from_exception)
  332. #ifdef CONFIG_PREEMPT
  333. ENTRY(resume_kernel)
  334. DISABLE_INTERRUPTS(CLBR_ANY)
  335. cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
  336. jnz restore_all
  337. need_resched:
  338. movl TI_flags(%ebp), %ecx # need_resched set ?
  339. testb $_TIF_NEED_RESCHED, %cl
  340. jz restore_all
  341. testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
  342. jz restore_all
  343. call preempt_schedule_irq
  344. jmp need_resched
  345. END(resume_kernel)
  346. #endif
  347. CFI_ENDPROC
  348. /*
  349. * End of kprobes section
  350. */
  351. .popsection
  352. /* SYSENTER_RETURN points to after the "sysenter" instruction in
  353. the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
  354. # sysenter call handler stub
  355. ENTRY(ia32_sysenter_target)
  356. CFI_STARTPROC simple
  357. CFI_SIGNAL_FRAME
  358. CFI_DEF_CFA esp, 0
  359. CFI_REGISTER esp, ebp
  360. movl TSS_sysenter_sp0(%esp),%esp
  361. sysenter_past_esp:
  362. /*
  363. * Interrupts are disabled here, but we can't trace it until
  364. * enough kernel state to call TRACE_IRQS_OFF can be called - but
  365. * we immediately enable interrupts at that point anyway.
  366. */
  367. pushl_cfi $__USER_DS
  368. /*CFI_REL_OFFSET ss, 0*/
  369. pushl_cfi %ebp
  370. CFI_REL_OFFSET esp, 0
  371. pushfl_cfi
  372. orl $X86_EFLAGS_IF, (%esp)
  373. pushl_cfi $__USER_CS
  374. /*CFI_REL_OFFSET cs, 0*/
  375. /*
  376. * Push current_thread_info()->sysenter_return to the stack.
  377. * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
  378. * pushed above; +8 corresponds to copy_thread's esp0 setting.
  379. */
  380. pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
  381. CFI_REL_OFFSET eip, 0
  382. pushl_cfi %eax
  383. SAVE_ALL
  384. ENABLE_INTERRUPTS(CLBR_NONE)
  385. /*
  386. * Load the potential sixth argument from user stack.
  387. * Careful about security.
  388. */
  389. cmpl $__PAGE_OFFSET-3,%ebp
  390. jae syscall_fault
  391. 1: movl (%ebp),%ebp
  392. movl %ebp,PT_EBP(%esp)
  393. _ASM_EXTABLE(1b,syscall_fault)
  394. GET_THREAD_INFO(%ebp)
  395. testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
  396. jnz sysenter_audit
  397. sysenter_do_call:
  398. cmpl $(NR_syscalls), %eax
  399. jae syscall_badsys
  400. call *sys_call_table(,%eax,4)
  401. movl %eax,PT_EAX(%esp)
  402. LOCKDEP_SYS_EXIT
  403. DISABLE_INTERRUPTS(CLBR_ANY)
  404. TRACE_IRQS_OFF
  405. movl TI_flags(%ebp), %ecx
  406. testl $_TIF_ALLWORK_MASK, %ecx
  407. jne sysexit_audit
  408. sysenter_exit:
  409. /* if something modifies registers it must also disable sysexit */
  410. movl PT_EIP(%esp), %edx
  411. movl PT_OLDESP(%esp), %ecx
  412. xorl %ebp,%ebp
  413. TRACE_IRQS_ON
  414. 1: mov PT_FS(%esp), %fs
  415. PTGS_TO_GS
  416. ENABLE_INTERRUPTS_SYSEXIT
  417. #ifdef CONFIG_AUDITSYSCALL
  418. sysenter_audit:
  419. testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
  420. jnz syscall_trace_entry
  421. addl $4,%esp
  422. CFI_ADJUST_CFA_OFFSET -4
  423. /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
  424. /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
  425. /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
  426. movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
  427. movl %eax,%edx /* 2nd arg: syscall number */
  428. movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
  429. call __audit_syscall_entry
  430. pushl_cfi %ebx
  431. movl PT_EAX(%esp),%eax /* reload syscall number */
  432. jmp sysenter_do_call
  433. sysexit_audit:
  434. testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
  435. jne syscall_exit_work
  436. TRACE_IRQS_ON
  437. ENABLE_INTERRUPTS(CLBR_ANY)
  438. movl %eax,%edx /* second arg, syscall return value */
  439. cmpl $-MAX_ERRNO,%eax /* is it an error ? */
  440. setbe %al /* 1 if so, 0 if not */
  441. movzbl %al,%eax /* zero-extend that */
  442. call __audit_syscall_exit
  443. DISABLE_INTERRUPTS(CLBR_ANY)
  444. TRACE_IRQS_OFF
  445. movl TI_flags(%ebp), %ecx
  446. testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
  447. jne syscall_exit_work
  448. movl PT_EAX(%esp),%eax /* reload syscall return value */
  449. jmp sysenter_exit
  450. #endif
  451. CFI_ENDPROC
  452. .pushsection .fixup,"ax"
  453. 2: movl $0,PT_FS(%esp)
  454. jmp 1b
  455. .popsection
  456. _ASM_EXTABLE(1b,2b)
  457. PTGS_TO_GS_EX
  458. ENDPROC(ia32_sysenter_target)
  459. /*
  460. * syscall stub including irq exit should be protected against kprobes
  461. */
  462. .pushsection .kprobes.text, "ax"
  463. # system call handler stub
  464. ENTRY(system_call)
  465. RING0_INT_FRAME # can't unwind into user space anyway
  466. pushl_cfi %eax # save orig_eax
  467. SAVE_ALL
  468. GET_THREAD_INFO(%ebp)
  469. # system call tracing in operation / emulation
  470. testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
  471. jnz syscall_trace_entry
  472. cmpl $(NR_syscalls), %eax
  473. jae syscall_badsys
  474. syscall_call:
  475. call *sys_call_table(,%eax,4)
  476. movl %eax,PT_EAX(%esp) # store the return value
  477. syscall_exit:
  478. LOCKDEP_SYS_EXIT
  479. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  480. # setting need_resched or sigpending
  481. # between sampling and the iret
  482. TRACE_IRQS_OFF
  483. movl TI_flags(%ebp), %ecx
  484. testl $_TIF_ALLWORK_MASK, %ecx # current->work
  485. jne syscall_exit_work
  486. restore_all:
  487. TRACE_IRQS_IRET
  488. restore_all_notrace:
  489. movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
  490. # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
  491. # are returning to the kernel.
  492. # See comments in process.c:copy_thread() for details.
  493. movb PT_OLDSS(%esp), %ah
  494. movb PT_CS(%esp), %al
  495. andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
  496. cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
  497. CFI_REMEMBER_STATE
  498. je ldt_ss # returning to user-space with LDT SS
  499. restore_nocheck:
  500. RESTORE_REGS 4 # skip orig_eax/error_code
  501. irq_return:
  502. INTERRUPT_RETURN
  503. .section .fixup,"ax"
  504. ENTRY(iret_exc)
  505. pushl $0 # no error code
  506. pushl $do_iret_error
  507. jmp error_code
  508. .previous
  509. _ASM_EXTABLE(irq_return,iret_exc)
  510. CFI_RESTORE_STATE
  511. ldt_ss:
  512. larl PT_OLDSS(%esp), %eax
  513. jnz restore_nocheck
  514. testl $0x00400000, %eax # returning to 32bit stack?
  515. jnz restore_nocheck # allright, normal return
  516. #ifdef CONFIG_PARAVIRT
  517. /*
  518. * The kernel can't run on a non-flat stack if paravirt mode
  519. * is active. Rather than try to fixup the high bits of
  520. * ESP, bypass this code entirely. This may break DOSemu
  521. * and/or Wine support in a paravirt VM, although the option
  522. * is still available to implement the setting of the high
  523. * 16-bits in the INTERRUPT_RETURN paravirt-op.
  524. */
  525. cmpl $0, pv_info+PARAVIRT_enabled
  526. jne restore_nocheck
  527. #endif
  528. /*
  529. * Setup and switch to ESPFIX stack
  530. *
  531. * We're returning to userspace with a 16 bit stack. The CPU will not
  532. * restore the high word of ESP for us on executing iret... This is an
  533. * "official" bug of all the x86-compatible CPUs, which we can work
  534. * around to make dosemu and wine happy. We do this by preloading the
  535. * high word of ESP with the high word of the userspace ESP while
  536. * compensating for the offset by changing to the ESPFIX segment with
  537. * a base address that matches for the difference.
  538. */
  539. #define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
  540. mov %esp, %edx /* load kernel esp */
  541. mov PT_OLDESP(%esp), %eax /* load userspace esp */
  542. mov %dx, %ax /* eax: new kernel esp */
  543. sub %eax, %edx /* offset (low word is 0) */
  544. shr $16, %edx
  545. mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
  546. mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
  547. pushl_cfi $__ESPFIX_SS
  548. pushl_cfi %eax /* new kernel esp */
  549. /* Disable interrupts, but do not irqtrace this section: we
  550. * will soon execute iret and the tracer was already set to
  551. * the irqstate after the iret */
  552. DISABLE_INTERRUPTS(CLBR_EAX)
  553. lss (%esp), %esp /* switch to espfix segment */
  554. CFI_ADJUST_CFA_OFFSET -8
  555. jmp restore_nocheck
  556. CFI_ENDPROC
  557. ENDPROC(system_call)
  558. # perform work that needs to be done immediately before resumption
  559. ALIGN
  560. RING0_PTREGS_FRAME # can't unwind into user space anyway
  561. work_pending:
  562. testb $_TIF_NEED_RESCHED, %cl
  563. jz work_notifysig
  564. work_resched:
  565. call schedule
  566. LOCKDEP_SYS_EXIT
  567. DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
  568. # setting need_resched or sigpending
  569. # between sampling and the iret
  570. TRACE_IRQS_OFF
  571. movl TI_flags(%ebp), %ecx
  572. andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
  573. # than syscall tracing?
  574. jz restore_all
  575. testb $_TIF_NEED_RESCHED, %cl
  576. jnz work_resched
  577. work_notifysig: # deal with pending signals and
  578. # notify-resume requests
  579. #ifdef CONFIG_VM86
  580. testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
  581. movl %esp, %eax
  582. jne work_notifysig_v86 # returning to kernel-space or
  583. # vm86-space
  584. 1:
  585. #else
  586. movl %esp, %eax
  587. #endif
  588. TRACE_IRQS_ON
  589. ENABLE_INTERRUPTS(CLBR_NONE)
  590. movb PT_CS(%esp), %bl
  591. andb $SEGMENT_RPL_MASK, %bl
  592. cmpb $USER_RPL, %bl
  593. jb resume_kernel
  594. xorl %edx, %edx
  595. call do_notify_resume
  596. jmp resume_userspace
  597. #ifdef CONFIG_VM86
  598. ALIGN
  599. work_notifysig_v86:
  600. pushl_cfi %ecx # save ti_flags for do_notify_resume
  601. call save_v86_state # %eax contains pt_regs pointer
  602. popl_cfi %ecx
  603. movl %eax, %esp
  604. jmp 1b
  605. #endif
  606. END(work_pending)
  607. # perform syscall exit tracing
  608. ALIGN
  609. syscall_trace_entry:
  610. movl $-ENOSYS,PT_EAX(%esp)
  611. movl %esp, %eax
  612. call syscall_trace_enter
  613. /* What it returned is what we'll actually use. */
  614. cmpl $(NR_syscalls), %eax
  615. jnae syscall_call
  616. jmp syscall_exit
  617. END(syscall_trace_entry)
  618. # perform syscall exit tracing
  619. ALIGN
  620. syscall_exit_work:
  621. testl $_TIF_WORK_SYSCALL_EXIT, %ecx
  622. jz work_pending
  623. TRACE_IRQS_ON
  624. ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
  625. # schedule() instead
  626. movl %esp, %eax
  627. call syscall_trace_leave
  628. jmp resume_userspace
  629. END(syscall_exit_work)
  630. CFI_ENDPROC
  631. RING0_INT_FRAME # can't unwind into user space anyway
  632. syscall_fault:
  633. GET_THREAD_INFO(%ebp)
  634. movl $-EFAULT,PT_EAX(%esp)
  635. jmp resume_userspace
  636. END(syscall_fault)
  637. syscall_badsys:
  638. movl $-ENOSYS,PT_EAX(%esp)
  639. jmp resume_userspace
  640. END(syscall_badsys)
  641. CFI_ENDPROC
  642. /*
  643. * End of kprobes section
  644. */
  645. .popsection
  646. /*
  647. * System calls that need a pt_regs pointer.
  648. */
  649. #define PTREGSCALL0(name) \
  650. ENTRY(ptregs_##name) ; \
  651. leal 4(%esp),%eax; \
  652. jmp sys_##name; \
  653. ENDPROC(ptregs_##name)
  654. #define PTREGSCALL1(name) \
  655. ENTRY(ptregs_##name) ; \
  656. leal 4(%esp),%edx; \
  657. movl (PT_EBX+4)(%esp),%eax; \
  658. jmp sys_##name; \
  659. ENDPROC(ptregs_##name)
  660. #define PTREGSCALL2(name) \
  661. ENTRY(ptregs_##name) ; \
  662. leal 4(%esp),%ecx; \
  663. movl (PT_ECX+4)(%esp),%edx; \
  664. movl (PT_EBX+4)(%esp),%eax; \
  665. jmp sys_##name; \
  666. ENDPROC(ptregs_##name)
  667. #define PTREGSCALL3(name) \
  668. ENTRY(ptregs_##name) ; \
  669. CFI_STARTPROC; \
  670. leal 4(%esp),%eax; \
  671. pushl_cfi %eax; \
  672. movl PT_EDX(%eax),%ecx; \
  673. movl PT_ECX(%eax),%edx; \
  674. movl PT_EBX(%eax),%eax; \
  675. call sys_##name; \
  676. addl $4,%esp; \
  677. CFI_ADJUST_CFA_OFFSET -4; \
  678. ret; \
  679. CFI_ENDPROC; \
  680. ENDPROC(ptregs_##name)
  681. PTREGSCALL1(iopl)
  682. PTREGSCALL0(fork)
  683. PTREGSCALL0(vfork)
  684. PTREGSCALL2(sigaltstack)
  685. PTREGSCALL0(sigreturn)
  686. PTREGSCALL0(rt_sigreturn)
  687. PTREGSCALL2(vm86)
  688. PTREGSCALL1(vm86old)
  689. /* Clone is an oddball. The 4th arg is in %edi */
  690. ENTRY(ptregs_clone)
  691. CFI_STARTPROC
  692. leal 4(%esp),%eax
  693. pushl_cfi %eax
  694. pushl_cfi PT_EDI(%eax)
  695. movl PT_EDX(%eax),%ecx
  696. movl PT_ECX(%eax),%edx
  697. movl PT_EBX(%eax),%eax
  698. call sys_clone
  699. addl $8,%esp
  700. CFI_ADJUST_CFA_OFFSET -8
  701. ret
  702. CFI_ENDPROC
  703. ENDPROC(ptregs_clone)
  704. .macro FIXUP_ESPFIX_STACK
  705. /*
  706. * Switch back for ESPFIX stack to the normal zerobased stack
  707. *
  708. * We can't call C functions using the ESPFIX stack. This code reads
  709. * the high word of the segment base from the GDT and swiches to the
  710. * normal stack and adjusts ESP with the matching offset.
  711. */
  712. /* fixup the stack */
  713. mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
  714. mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
  715. shl $16, %eax
  716. addl %esp, %eax /* the adjusted stack pointer */
  717. pushl_cfi $__KERNEL_DS
  718. pushl_cfi %eax
  719. lss (%esp), %esp /* switch to the normal stack segment */
  720. CFI_ADJUST_CFA_OFFSET -8
  721. .endm
  722. .macro UNWIND_ESPFIX_STACK
  723. movl %ss, %eax
  724. /* see if on espfix stack */
  725. cmpw $__ESPFIX_SS, %ax
  726. jne 27f
  727. movl $__KERNEL_DS, %eax
  728. movl %eax, %ds
  729. movl %eax, %es
  730. /* switch to normal stack */
  731. FIXUP_ESPFIX_STACK
  732. 27:
  733. .endm
  734. /*
  735. * Build the entry stubs and pointer table with some assembler magic.
  736. * We pack 7 stubs into a single 32-byte chunk, which will fit in a
  737. * single cache line on all modern x86 implementations.
  738. */
  739. .section .init.rodata,"a"
  740. ENTRY(interrupt)
  741. .section .entry.text, "ax"
  742. .p2align 5
  743. .p2align CONFIG_X86_L1_CACHE_SHIFT
  744. ENTRY(irq_entries_start)
  745. RING0_INT_FRAME
  746. vector=FIRST_EXTERNAL_VECTOR
  747. .rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
  748. .balign 32
  749. .rept 7
  750. .if vector < NR_VECTORS
  751. .if vector <> FIRST_EXTERNAL_VECTOR
  752. CFI_ADJUST_CFA_OFFSET -4
  753. .endif
  754. 1: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
  755. .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
  756. jmp 2f
  757. .endif
  758. .previous
  759. .long 1b
  760. .section .entry.text, "ax"
  761. vector=vector+1
  762. .endif
  763. .endr
  764. 2: jmp common_interrupt
  765. .endr
  766. END(irq_entries_start)
  767. .previous
  768. END(interrupt)
  769. .previous
  770. /*
  771. * the CPU automatically disables interrupts when executing an IRQ vector,
  772. * so IRQ-flags tracing has to follow that:
  773. */
  774. .p2align CONFIG_X86_L1_CACHE_SHIFT
  775. common_interrupt:
  776. addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
  777. SAVE_ALL
  778. TRACE_IRQS_OFF
  779. movl %esp,%eax
  780. call do_IRQ
  781. jmp ret_from_intr
  782. ENDPROC(common_interrupt)
  783. CFI_ENDPROC
  784. /*
  785. * Irq entries should be protected against kprobes
  786. */
  787. .pushsection .kprobes.text, "ax"
  788. #define BUILD_INTERRUPT3(name, nr, fn) \
  789. ENTRY(name) \
  790. RING0_INT_FRAME; \
  791. pushl_cfi $~(nr); \
  792. SAVE_ALL; \
  793. TRACE_IRQS_OFF \
  794. movl %esp,%eax; \
  795. call fn; \
  796. jmp ret_from_intr; \
  797. CFI_ENDPROC; \
  798. ENDPROC(name)
  799. #define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
  800. /* The include is where all of the SMP etc. interrupts come from */
  801. #include <asm/entry_arch.h>
  802. ENTRY(coprocessor_error)
  803. RING0_INT_FRAME
  804. pushl_cfi $0
  805. pushl_cfi $do_coprocessor_error
  806. jmp error_code
  807. CFI_ENDPROC
  808. END(coprocessor_error)
  809. ENTRY(simd_coprocessor_error)
  810. RING0_INT_FRAME
  811. pushl_cfi $0
  812. #ifdef CONFIG_X86_INVD_BUG
  813. /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
  814. 661: pushl_cfi $do_general_protection
  815. 662:
  816. .section .altinstructions,"a"
  817. altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
  818. .previous
  819. .section .altinstr_replacement,"ax"
  820. 663: pushl $do_simd_coprocessor_error
  821. 664:
  822. .previous
  823. #else
  824. pushl_cfi $do_simd_coprocessor_error
  825. #endif
  826. jmp error_code
  827. CFI_ENDPROC
  828. END(simd_coprocessor_error)
  829. ENTRY(device_not_available)
  830. RING0_INT_FRAME
  831. pushl_cfi $-1 # mark this as an int
  832. pushl_cfi $do_device_not_available
  833. jmp error_code
  834. CFI_ENDPROC
  835. END(device_not_available)
  836. #ifdef CONFIG_PARAVIRT
  837. ENTRY(native_iret)
  838. iret
  839. _ASM_EXTABLE(native_iret, iret_exc)
  840. END(native_iret)
  841. ENTRY(native_irq_enable_sysexit)
  842. sti
  843. sysexit
  844. END(native_irq_enable_sysexit)
  845. #endif
  846. ENTRY(overflow)
  847. RING0_INT_FRAME
  848. pushl_cfi $0
  849. pushl_cfi $do_overflow
  850. jmp error_code
  851. CFI_ENDPROC
  852. END(overflow)
  853. ENTRY(bounds)
  854. RING0_INT_FRAME
  855. pushl_cfi $0
  856. pushl_cfi $do_bounds
  857. jmp error_code
  858. CFI_ENDPROC
  859. END(bounds)
  860. ENTRY(invalid_op)
  861. RING0_INT_FRAME
  862. pushl_cfi $0
  863. pushl_cfi $do_invalid_op
  864. jmp error_code
  865. CFI_ENDPROC
  866. END(invalid_op)
  867. ENTRY(coprocessor_segment_overrun)
  868. RING0_INT_FRAME
  869. pushl_cfi $0
  870. pushl_cfi $do_coprocessor_segment_overrun
  871. jmp error_code
  872. CFI_ENDPROC
  873. END(coprocessor_segment_overrun)
  874. ENTRY(invalid_TSS)
  875. RING0_EC_FRAME
  876. pushl_cfi $do_invalid_TSS
  877. jmp error_code
  878. CFI_ENDPROC
  879. END(invalid_TSS)
  880. ENTRY(segment_not_present)
  881. RING0_EC_FRAME
  882. pushl_cfi $do_segment_not_present
  883. jmp error_code
  884. CFI_ENDPROC
  885. END(segment_not_present)
  886. ENTRY(stack_segment)
  887. RING0_EC_FRAME
  888. pushl_cfi $do_stack_segment
  889. jmp error_code
  890. CFI_ENDPROC
  891. END(stack_segment)
  892. ENTRY(alignment_check)
  893. RING0_EC_FRAME
  894. pushl_cfi $do_alignment_check
  895. jmp error_code
  896. CFI_ENDPROC
  897. END(alignment_check)
  898. ENTRY(divide_error)
  899. RING0_INT_FRAME
  900. pushl_cfi $0 # no error code
  901. pushl_cfi $do_divide_error
  902. jmp error_code
  903. CFI_ENDPROC
  904. END(divide_error)
  905. #ifdef CONFIG_X86_MCE
  906. ENTRY(machine_check)
  907. RING0_INT_FRAME
  908. pushl_cfi $0
  909. pushl_cfi machine_check_vector
  910. jmp error_code
  911. CFI_ENDPROC
  912. END(machine_check)
  913. #endif
  914. ENTRY(spurious_interrupt_bug)
  915. RING0_INT_FRAME
  916. pushl_cfi $0
  917. pushl_cfi $do_spurious_interrupt_bug
  918. jmp error_code
  919. CFI_ENDPROC
  920. END(spurious_interrupt_bug)
  921. /*
  922. * End of kprobes section
  923. */
  924. .popsection
  925. #ifdef CONFIG_XEN
  926. /* Xen doesn't set %esp to be precisely what the normal sysenter
  927. entrypoint expects, so fix it up before using the normal path. */
  928. ENTRY(xen_sysenter_target)
  929. RING0_INT_FRAME
  930. addl $5*4, %esp /* remove xen-provided frame */
  931. CFI_ADJUST_CFA_OFFSET -5*4
  932. jmp sysenter_past_esp
  933. CFI_ENDPROC
  934. ENTRY(xen_hypervisor_callback)
  935. CFI_STARTPROC
  936. pushl_cfi $0
  937. SAVE_ALL
  938. TRACE_IRQS_OFF
  939. /* Check to see if we got the event in the critical
  940. region in xen_iret_direct, after we've reenabled
  941. events and checked for pending events. This simulates
  942. iret instruction's behaviour where it delivers a
  943. pending interrupt when enabling interrupts. */
  944. movl PT_EIP(%esp),%eax
  945. cmpl $xen_iret_start_crit,%eax
  946. jb 1f
  947. cmpl $xen_iret_end_crit,%eax
  948. jae 1f
  949. jmp xen_iret_crit_fixup
  950. ENTRY(xen_do_upcall)
  951. 1: mov %esp, %eax
  952. call xen_evtchn_do_upcall
  953. jmp ret_from_intr
  954. CFI_ENDPROC
  955. ENDPROC(xen_hypervisor_callback)
  956. # Hypervisor uses this for application faults while it executes.
  957. # We get here for two reasons:
  958. # 1. Fault while reloading DS, ES, FS or GS
  959. # 2. Fault while executing IRET
  960. # Category 1 we fix up by reattempting the load, and zeroing the segment
  961. # register if the load fails.
  962. # Category 2 we fix up by jumping to do_iret_error. We cannot use the
  963. # normal Linux return path in this case because if we use the IRET hypercall
  964. # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
  965. # We distinguish between categories by maintaining a status value in EAX.
  966. ENTRY(xen_failsafe_callback)
  967. CFI_STARTPROC
  968. pushl_cfi %eax
  969. movl $1,%eax
  970. 1: mov 4(%esp),%ds
  971. 2: mov 8(%esp),%es
  972. 3: mov 12(%esp),%fs
  973. 4: mov 16(%esp),%gs
  974. testl %eax,%eax
  975. popl_cfi %eax
  976. lea 16(%esp),%esp
  977. CFI_ADJUST_CFA_OFFSET -16
  978. jz 5f
  979. addl $16,%esp
  980. jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
  981. 5: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
  982. SAVE_ALL
  983. jmp ret_from_exception
  984. CFI_ENDPROC
  985. .section .fixup,"ax"
  986. 6: xorl %eax,%eax
  987. movl %eax,4(%esp)
  988. jmp 1b
  989. 7: xorl %eax,%eax
  990. movl %eax,8(%esp)
  991. jmp 2b
  992. 8: xorl %eax,%eax
  993. movl %eax,12(%esp)
  994. jmp 3b
  995. 9: xorl %eax,%eax
  996. movl %eax,16(%esp)
  997. jmp 4b
  998. .previous
  999. _ASM_EXTABLE(1b,6b)
  1000. _ASM_EXTABLE(2b,7b)
  1001. _ASM_EXTABLE(3b,8b)
  1002. _ASM_EXTABLE(4b,9b)
  1003. ENDPROC(xen_failsafe_callback)
  1004. BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
  1005. xen_evtchn_do_upcall)
  1006. #endif /* CONFIG_XEN */
  1007. #ifdef CONFIG_FUNCTION_TRACER
  1008. #ifdef CONFIG_DYNAMIC_FTRACE
  1009. ENTRY(mcount)
  1010. ret
  1011. END(mcount)
  1012. ENTRY(ftrace_caller)
  1013. cmpl $0, function_trace_stop
  1014. jne ftrace_stub
  1015. pushl %eax
  1016. pushl %ecx
  1017. pushl %edx
  1018. movl 0xc(%esp), %eax
  1019. movl 0x4(%ebp), %edx
  1020. subl $MCOUNT_INSN_SIZE, %eax
  1021. .globl ftrace_call
  1022. ftrace_call:
  1023. call ftrace_stub
  1024. popl %edx
  1025. popl %ecx
  1026. popl %eax
  1027. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1028. .globl ftrace_graph_call
  1029. ftrace_graph_call:
  1030. jmp ftrace_stub
  1031. #endif
  1032. .globl ftrace_stub
  1033. ftrace_stub:
  1034. ret
  1035. END(ftrace_caller)
  1036. #else /* ! CONFIG_DYNAMIC_FTRACE */
  1037. ENTRY(mcount)
  1038. cmpl $0, function_trace_stop
  1039. jne ftrace_stub
  1040. cmpl $ftrace_stub, ftrace_trace_function
  1041. jnz trace
  1042. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1043. cmpl $ftrace_stub, ftrace_graph_return
  1044. jnz ftrace_graph_caller
  1045. cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
  1046. jnz ftrace_graph_caller
  1047. #endif
  1048. .globl ftrace_stub
  1049. ftrace_stub:
  1050. ret
  1051. /* taken from glibc */
  1052. trace:
  1053. pushl %eax
  1054. pushl %ecx
  1055. pushl %edx
  1056. movl 0xc(%esp), %eax
  1057. movl 0x4(%ebp), %edx
  1058. subl $MCOUNT_INSN_SIZE, %eax
  1059. call *ftrace_trace_function
  1060. popl %edx
  1061. popl %ecx
  1062. popl %eax
  1063. jmp ftrace_stub
  1064. END(mcount)
  1065. #endif /* CONFIG_DYNAMIC_FTRACE */
  1066. #endif /* CONFIG_FUNCTION_TRACER */
  1067. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1068. ENTRY(ftrace_graph_caller)
  1069. cmpl $0, function_trace_stop
  1070. jne ftrace_stub
  1071. pushl %eax
  1072. pushl %ecx
  1073. pushl %edx
  1074. movl 0xc(%esp), %edx
  1075. lea 0x4(%ebp), %eax
  1076. movl (%ebp), %ecx
  1077. subl $MCOUNT_INSN_SIZE, %edx
  1078. call prepare_ftrace_return
  1079. popl %edx
  1080. popl %ecx
  1081. popl %eax
  1082. ret
  1083. END(ftrace_graph_caller)
  1084. .globl return_to_handler
  1085. return_to_handler:
  1086. pushl %eax
  1087. pushl %edx
  1088. movl %ebp, %eax
  1089. call ftrace_return_to_handler
  1090. movl %eax, %ecx
  1091. popl %edx
  1092. popl %eax
  1093. jmp *%ecx
  1094. #endif
  1095. /*
  1096. * Some functions should be protected against kprobes
  1097. */
  1098. .pushsection .kprobes.text, "ax"
  1099. ENTRY(page_fault)
  1100. RING0_EC_FRAME
  1101. pushl_cfi $do_page_fault
  1102. ALIGN
  1103. error_code:
  1104. /* the function address is in %gs's slot on the stack */
  1105. pushl_cfi %fs
  1106. /*CFI_REL_OFFSET fs, 0*/
  1107. pushl_cfi %es
  1108. /*CFI_REL_OFFSET es, 0*/
  1109. pushl_cfi %ds
  1110. /*CFI_REL_OFFSET ds, 0*/
  1111. pushl_cfi %eax
  1112. CFI_REL_OFFSET eax, 0
  1113. pushl_cfi %ebp
  1114. CFI_REL_OFFSET ebp, 0
  1115. pushl_cfi %edi
  1116. CFI_REL_OFFSET edi, 0
  1117. pushl_cfi %esi
  1118. CFI_REL_OFFSET esi, 0
  1119. pushl_cfi %edx
  1120. CFI_REL_OFFSET edx, 0
  1121. pushl_cfi %ecx
  1122. CFI_REL_OFFSET ecx, 0
  1123. pushl_cfi %ebx
  1124. CFI_REL_OFFSET ebx, 0
  1125. cld
  1126. movl $(__KERNEL_PERCPU), %ecx
  1127. movl %ecx, %fs
  1128. UNWIND_ESPFIX_STACK
  1129. GS_TO_REG %ecx
  1130. movl PT_GS(%esp), %edi # get the function address
  1131. movl PT_ORIG_EAX(%esp), %edx # get the error code
  1132. movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
  1133. REG_TO_PTGS %ecx
  1134. SET_KERNEL_GS %ecx
  1135. movl $(__USER_DS), %ecx
  1136. movl %ecx, %ds
  1137. movl %ecx, %es
  1138. TRACE_IRQS_OFF
  1139. movl %esp,%eax # pt_regs pointer
  1140. call *%edi
  1141. jmp ret_from_exception
  1142. CFI_ENDPROC
  1143. END(page_fault)
  1144. /*
  1145. * Debug traps and NMI can happen at the one SYSENTER instruction
  1146. * that sets up the real kernel stack. Check here, since we can't
  1147. * allow the wrong stack to be used.
  1148. *
  1149. * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
  1150. * already pushed 3 words if it hits on the sysenter instruction:
  1151. * eflags, cs and eip.
  1152. *
  1153. * We just load the right stack, and push the three (known) values
  1154. * by hand onto the new stack - while updating the return eip past
  1155. * the instruction that would have done it for sysenter.
  1156. */
  1157. .macro FIX_STACK offset ok label
  1158. cmpw $__KERNEL_CS, 4(%esp)
  1159. jne \ok
  1160. \label:
  1161. movl TSS_sysenter_sp0 + \offset(%esp), %esp
  1162. CFI_DEF_CFA esp, 0
  1163. CFI_UNDEFINED eip
  1164. pushfl_cfi
  1165. pushl_cfi $__KERNEL_CS
  1166. pushl_cfi $sysenter_past_esp
  1167. CFI_REL_OFFSET eip, 0
  1168. .endm
  1169. ENTRY(debug)
  1170. RING0_INT_FRAME
  1171. cmpl $ia32_sysenter_target,(%esp)
  1172. jne debug_stack_correct
  1173. FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
  1174. debug_stack_correct:
  1175. pushl_cfi $-1 # mark this as an int
  1176. SAVE_ALL
  1177. TRACE_IRQS_OFF
  1178. xorl %edx,%edx # error code 0
  1179. movl %esp,%eax # pt_regs pointer
  1180. call do_debug
  1181. jmp ret_from_exception
  1182. CFI_ENDPROC
  1183. END(debug)
  1184. /*
  1185. * NMI is doubly nasty. It can happen _while_ we're handling
  1186. * a debug fault, and the debug fault hasn't yet been able to
  1187. * clear up the stack. So we first check whether we got an
  1188. * NMI on the sysenter entry path, but after that we need to
  1189. * check whether we got an NMI on the debug path where the debug
  1190. * fault happened on the sysenter path.
  1191. */
  1192. ENTRY(nmi)
  1193. RING0_INT_FRAME
  1194. pushl_cfi %eax
  1195. movl %ss, %eax
  1196. cmpw $__ESPFIX_SS, %ax
  1197. popl_cfi %eax
  1198. je nmi_espfix_stack
  1199. cmpl $ia32_sysenter_target,(%esp)
  1200. je nmi_stack_fixup
  1201. pushl_cfi %eax
  1202. movl %esp,%eax
  1203. /* Do not access memory above the end of our stack page,
  1204. * it might not exist.
  1205. */
  1206. andl $(THREAD_SIZE-1),%eax
  1207. cmpl $(THREAD_SIZE-20),%eax
  1208. popl_cfi %eax
  1209. jae nmi_stack_correct
  1210. cmpl $ia32_sysenter_target,12(%esp)
  1211. je nmi_debug_stack_check
  1212. nmi_stack_correct:
  1213. /* We have a RING0_INT_FRAME here */
  1214. pushl_cfi %eax
  1215. SAVE_ALL
  1216. xorl %edx,%edx # zero error code
  1217. movl %esp,%eax # pt_regs pointer
  1218. call do_nmi
  1219. jmp restore_all_notrace
  1220. CFI_ENDPROC
  1221. nmi_stack_fixup:
  1222. RING0_INT_FRAME
  1223. FIX_STACK 12, nmi_stack_correct, 1
  1224. jmp nmi_stack_correct
  1225. nmi_debug_stack_check:
  1226. /* We have a RING0_INT_FRAME here */
  1227. cmpw $__KERNEL_CS,16(%esp)
  1228. jne nmi_stack_correct
  1229. cmpl $debug,(%esp)
  1230. jb nmi_stack_correct
  1231. cmpl $debug_esp_fix_insn,(%esp)
  1232. ja nmi_stack_correct
  1233. FIX_STACK 24, nmi_stack_correct, 1
  1234. jmp nmi_stack_correct
  1235. nmi_espfix_stack:
  1236. /* We have a RING0_INT_FRAME here.
  1237. *
  1238. * create the pointer to lss back
  1239. */
  1240. pushl_cfi %ss
  1241. pushl_cfi %esp
  1242. addl $4, (%esp)
  1243. /* copy the iret frame of 12 bytes */
  1244. .rept 3
  1245. pushl_cfi 16(%esp)
  1246. .endr
  1247. pushl_cfi %eax
  1248. SAVE_ALL
  1249. FIXUP_ESPFIX_STACK # %eax == %esp
  1250. xorl %edx,%edx # zero error code
  1251. call do_nmi
  1252. RESTORE_REGS
  1253. lss 12+4(%esp), %esp # back to espfix stack
  1254. CFI_ADJUST_CFA_OFFSET -24
  1255. jmp irq_return
  1256. CFI_ENDPROC
  1257. END(nmi)
  1258. ENTRY(int3)
  1259. RING0_INT_FRAME
  1260. pushl_cfi $-1 # mark this as an int
  1261. SAVE_ALL
  1262. TRACE_IRQS_OFF
  1263. xorl %edx,%edx # zero error code
  1264. movl %esp,%eax # pt_regs pointer
  1265. call do_int3
  1266. jmp ret_from_exception
  1267. CFI_ENDPROC
  1268. END(int3)
  1269. ENTRY(general_protection)
  1270. RING0_EC_FRAME
  1271. pushl_cfi $do_general_protection
  1272. jmp error_code
  1273. CFI_ENDPROC
  1274. END(general_protection)
  1275. #ifdef CONFIG_KVM_GUEST
  1276. ENTRY(async_page_fault)
  1277. RING0_EC_FRAME
  1278. pushl_cfi $do_async_page_fault
  1279. jmp error_code
  1280. CFI_ENDPROC
  1281. END(async_page_fault)
  1282. #endif
  1283. /*
  1284. * End of kprobes section
  1285. */
  1286. .popsection