entry_32.S 32 KB

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