entry_32.S 33 KB

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