entry_32.S 32 KB

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