entry_32.S 32 KB

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