entry_32.S 32 KB

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