entry_32.S 32 KB

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