entry_32.S 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401
  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: TI_sysenter_return
  368. * is relative to thread_info, which is at the bottom of the
  369. * kernel stack page. 4*4 means the 4 words pushed above;
  370. * TOP_OF_KERNEL_STACK_PADDING takes us to the top of the stack;
  371. * and THREAD_SIZE takes us to the bottom.
  372. */
  373. pushl_cfi ((TI_sysenter_return) - THREAD_SIZE + TOP_OF_KERNEL_STACK_PADDING + 4*4)(%esp)
  374. CFI_REL_OFFSET eip, 0
  375. pushl_cfi %eax
  376. SAVE_ALL
  377. ENABLE_INTERRUPTS(CLBR_NONE)
  378. /*
  379. * Load the potential sixth argument from user stack.
  380. * Careful about security.
  381. */
  382. cmpl $__PAGE_OFFSET-3,%ebp
  383. jae syscall_fault
  384. ASM_STAC
  385. 1: movl (%ebp),%ebp
  386. ASM_CLAC
  387. movl %ebp,PT_EBP(%esp)
  388. _ASM_EXTABLE(1b,syscall_fault)
  389. GET_THREAD_INFO(%ebp)
  390. testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
  391. jnz sysenter_audit
  392. sysenter_do_call:
  393. cmpl $(NR_syscalls), %eax
  394. jae sysenter_badsys
  395. call *sys_call_table(,%eax,4)
  396. sysenter_after_call:
  397. movl %eax,PT_EAX(%esp)
  398. LOCKDEP_SYS_EXIT
  399. DISABLE_INTERRUPTS(CLBR_ANY)
  400. TRACE_IRQS_OFF
  401. movl TI_flags(%ebp), %ecx
  402. testl $_TIF_ALLWORK_MASK, %ecx
  403. jnz sysexit_audit
  404. sysenter_exit:
  405. /* if something modifies registers it must also disable sysexit */
  406. movl PT_EIP(%esp), %edx
  407. movl PT_OLDESP(%esp), %ecx
  408. xorl %ebp,%ebp
  409. TRACE_IRQS_ON
  410. 1: mov PT_FS(%esp), %fs
  411. PTGS_TO_GS
  412. ENABLE_INTERRUPTS_SYSEXIT
  413. #ifdef CONFIG_AUDITSYSCALL
  414. sysenter_audit:
  415. testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
  416. jnz syscall_trace_entry
  417. /* movl PT_EAX(%esp), %eax already set, syscall number: 1st arg to audit */
  418. movl PT_EBX(%esp), %edx /* ebx/a0: 2nd arg to audit */
  419. /* movl PT_ECX(%esp), %ecx already set, a1: 3nd arg to audit */
  420. pushl_cfi PT_ESI(%esp) /* a3: 5th arg */
  421. pushl_cfi PT_EDX+4(%esp) /* a2: 4th arg */
  422. call __audit_syscall_entry
  423. popl_cfi %ecx /* get that remapped edx off the stack */
  424. popl_cfi %ecx /* get that remapped esi off the stack */
  425. movl PT_EAX(%esp),%eax /* reload syscall number */
  426. jmp sysenter_do_call
  427. sysexit_audit:
  428. testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
  429. jnz syscall_exit_work
  430. TRACE_IRQS_ON
  431. ENABLE_INTERRUPTS(CLBR_ANY)
  432. movl %eax,%edx /* second arg, syscall return value */
  433. cmpl $-MAX_ERRNO,%eax /* is it an error ? */
  434. setbe %al /* 1 if so, 0 if not */
  435. movzbl %al,%eax /* zero-extend that */
  436. call __audit_syscall_exit
  437. DISABLE_INTERRUPTS(CLBR_ANY)
  438. TRACE_IRQS_OFF
  439. movl TI_flags(%ebp), %ecx
  440. testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
  441. jnz syscall_exit_work
  442. movl PT_EAX(%esp),%eax /* reload syscall return value */
  443. jmp sysenter_exit
  444. #endif
  445. CFI_ENDPROC
  446. .pushsection .fixup,"ax"
  447. 2: movl $0,PT_FS(%esp)
  448. jmp 1b
  449. .popsection
  450. _ASM_EXTABLE(1b,2b)
  451. PTGS_TO_GS_EX
  452. ENDPROC(ia32_sysenter_target)
  453. # system call handler stub
  454. ENTRY(system_call)
  455. RING0_INT_FRAME # can't unwind into user space anyway
  456. ASM_CLAC
  457. pushl_cfi %eax # save orig_eax
  458. SAVE_ALL
  459. GET_THREAD_INFO(%ebp)
  460. # system call tracing in operation / emulation
  461. testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
  462. jnz syscall_trace_entry
  463. cmpl $(NR_syscalls), %eax
  464. jae syscall_badsys
  465. syscall_call:
  466. call *sys_call_table(,%eax,4)
  467. syscall_after_call:
  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. jnz syscall_exit_work
  478. restore_all:
  479. TRACE_IRQS_IRET
  480. restore_all_notrace:
  481. #ifdef CONFIG_X86_ESPFIX32
  482. movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
  483. # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
  484. # are returning to the kernel.
  485. # See comments in process.c:copy_thread() for details.
  486. movb PT_OLDSS(%esp), %ah
  487. movb PT_CS(%esp), %al
  488. andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
  489. cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
  490. CFI_REMEMBER_STATE
  491. je ldt_ss # returning to user-space with LDT SS
  492. #endif
  493. restore_nocheck:
  494. RESTORE_REGS 4 # skip orig_eax/error_code
  495. irq_return:
  496. INTERRUPT_RETURN
  497. .section .fixup,"ax"
  498. ENTRY(iret_exc)
  499. pushl $0 # no error code
  500. pushl $do_iret_error
  501. jmp error_code
  502. .previous
  503. _ASM_EXTABLE(irq_return,iret_exc)
  504. #ifdef CONFIG_X86_ESPFIX32
  505. CFI_RESTORE_STATE
  506. ldt_ss:
  507. #ifdef CONFIG_PARAVIRT
  508. /*
  509. * The kernel can't run on a non-flat stack if paravirt mode
  510. * is active. Rather than try to fixup the high bits of
  511. * ESP, bypass this code entirely. This may break DOSemu
  512. * and/or Wine support in a paravirt VM, although the option
  513. * is still available to implement the setting of the high
  514. * 16-bits in the INTERRUPT_RETURN paravirt-op.
  515. */
  516. cmpl $0, pv_info+PARAVIRT_enabled
  517. jne restore_nocheck
  518. #endif
  519. /*
  520. * Setup and switch to ESPFIX stack
  521. *
  522. * We're returning to userspace with a 16 bit stack. The CPU will not
  523. * restore the high word of ESP for us on executing iret... This is an
  524. * "official" bug of all the x86-compatible CPUs, which we can work
  525. * around to make dosemu and wine happy. We do this by preloading the
  526. * high word of ESP with the high word of the userspace ESP while
  527. * compensating for the offset by changing to the ESPFIX segment with
  528. * a base address that matches for the difference.
  529. */
  530. #define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
  531. mov %esp, %edx /* load kernel esp */
  532. mov PT_OLDESP(%esp), %eax /* load userspace esp */
  533. mov %dx, %ax /* eax: new kernel esp */
  534. sub %eax, %edx /* offset (low word is 0) */
  535. shr $16, %edx
  536. mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
  537. mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
  538. pushl_cfi $__ESPFIX_SS
  539. pushl_cfi %eax /* new kernel esp */
  540. /* Disable interrupts, but do not irqtrace this section: we
  541. * will soon execute iret and the tracer was already set to
  542. * the irqstate after the iret */
  543. DISABLE_INTERRUPTS(CLBR_EAX)
  544. lss (%esp), %esp /* switch to espfix segment */
  545. CFI_ADJUST_CFA_OFFSET -8
  546. jmp restore_nocheck
  547. #endif
  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. jnz 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. ASM_CLAC
  626. GET_THREAD_INFO(%ebp)
  627. movl $-EFAULT,PT_EAX(%esp)
  628. jmp resume_userspace
  629. END(syscall_fault)
  630. syscall_badsys:
  631. movl $-ENOSYS,%eax
  632. jmp syscall_after_call
  633. END(syscall_badsys)
  634. sysenter_badsys:
  635. movl $-ENOSYS,%eax
  636. jmp sysenter_after_call
  637. END(sysenter_badsys)
  638. CFI_ENDPROC
  639. .macro FIXUP_ESPFIX_STACK
  640. /*
  641. * Switch back for ESPFIX stack to the normal zerobased stack
  642. *
  643. * We can't call C functions using the ESPFIX stack. This code reads
  644. * the high word of the segment base from the GDT and swiches to the
  645. * normal stack and adjusts ESP with the matching offset.
  646. */
  647. #ifdef CONFIG_X86_ESPFIX32
  648. /* fixup the stack */
  649. mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
  650. mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
  651. shl $16, %eax
  652. addl %esp, %eax /* the adjusted stack pointer */
  653. pushl_cfi $__KERNEL_DS
  654. pushl_cfi %eax
  655. lss (%esp), %esp /* switch to the normal stack segment */
  656. CFI_ADJUST_CFA_OFFSET -8
  657. #endif
  658. .endm
  659. .macro UNWIND_ESPFIX_STACK
  660. #ifdef CONFIG_X86_ESPFIX32
  661. movl %ss, %eax
  662. /* see if on espfix stack */
  663. cmpw $__ESPFIX_SS, %ax
  664. jne 27f
  665. movl $__KERNEL_DS, %eax
  666. movl %eax, %ds
  667. movl %eax, %es
  668. /* switch to normal stack */
  669. FIXUP_ESPFIX_STACK
  670. 27:
  671. #endif
  672. .endm
  673. /*
  674. * Build the entry stubs with some assembler magic.
  675. * We pack 1 stub into every 8-byte block.
  676. */
  677. .align 8
  678. ENTRY(irq_entries_start)
  679. RING0_INT_FRAME
  680. vector=FIRST_EXTERNAL_VECTOR
  681. .rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR)
  682. pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
  683. vector=vector+1
  684. jmp common_interrupt
  685. CFI_ADJUST_CFA_OFFSET -4
  686. .align 8
  687. .endr
  688. END(irq_entries_start)
  689. /*
  690. * the CPU automatically disables interrupts when executing an IRQ vector,
  691. * so IRQ-flags tracing has to follow that:
  692. */
  693. .p2align CONFIG_X86_L1_CACHE_SHIFT
  694. common_interrupt:
  695. ASM_CLAC
  696. addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
  697. SAVE_ALL
  698. TRACE_IRQS_OFF
  699. movl %esp,%eax
  700. call do_IRQ
  701. jmp ret_from_intr
  702. ENDPROC(common_interrupt)
  703. CFI_ENDPROC
  704. #define BUILD_INTERRUPT3(name, nr, fn) \
  705. ENTRY(name) \
  706. RING0_INT_FRAME; \
  707. ASM_CLAC; \
  708. pushl_cfi $~(nr); \
  709. SAVE_ALL; \
  710. TRACE_IRQS_OFF \
  711. movl %esp,%eax; \
  712. call fn; \
  713. jmp ret_from_intr; \
  714. CFI_ENDPROC; \
  715. ENDPROC(name)
  716. #ifdef CONFIG_TRACING
  717. #define TRACE_BUILD_INTERRUPT(name, nr) \
  718. BUILD_INTERRUPT3(trace_##name, nr, smp_trace_##name)
  719. #else
  720. #define TRACE_BUILD_INTERRUPT(name, nr)
  721. #endif
  722. #define BUILD_INTERRUPT(name, nr) \
  723. BUILD_INTERRUPT3(name, nr, smp_##name); \
  724. TRACE_BUILD_INTERRUPT(name, nr)
  725. /* The include is where all of the SMP etc. interrupts come from */
  726. #include <asm/entry_arch.h>
  727. ENTRY(coprocessor_error)
  728. RING0_INT_FRAME
  729. ASM_CLAC
  730. pushl_cfi $0
  731. pushl_cfi $do_coprocessor_error
  732. jmp error_code
  733. CFI_ENDPROC
  734. END(coprocessor_error)
  735. ENTRY(simd_coprocessor_error)
  736. RING0_INT_FRAME
  737. ASM_CLAC
  738. pushl_cfi $0
  739. #ifdef CONFIG_X86_INVD_BUG
  740. /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
  741. ALTERNATIVE "pushl_cfi $do_general_protection", \
  742. "pushl $do_simd_coprocessor_error", \
  743. X86_FEATURE_XMM
  744. #else
  745. pushl_cfi $do_simd_coprocessor_error
  746. #endif
  747. jmp error_code
  748. CFI_ENDPROC
  749. END(simd_coprocessor_error)
  750. ENTRY(device_not_available)
  751. RING0_INT_FRAME
  752. ASM_CLAC
  753. pushl_cfi $-1 # mark this as an int
  754. pushl_cfi $do_device_not_available
  755. jmp error_code
  756. CFI_ENDPROC
  757. END(device_not_available)
  758. #ifdef CONFIG_PARAVIRT
  759. ENTRY(native_iret)
  760. iret
  761. _ASM_EXTABLE(native_iret, iret_exc)
  762. END(native_iret)
  763. ENTRY(native_irq_enable_sysexit)
  764. sti
  765. sysexit
  766. END(native_irq_enable_sysexit)
  767. #endif
  768. ENTRY(overflow)
  769. RING0_INT_FRAME
  770. ASM_CLAC
  771. pushl_cfi $0
  772. pushl_cfi $do_overflow
  773. jmp error_code
  774. CFI_ENDPROC
  775. END(overflow)
  776. ENTRY(bounds)
  777. RING0_INT_FRAME
  778. ASM_CLAC
  779. pushl_cfi $0
  780. pushl_cfi $do_bounds
  781. jmp error_code
  782. CFI_ENDPROC
  783. END(bounds)
  784. ENTRY(invalid_op)
  785. RING0_INT_FRAME
  786. ASM_CLAC
  787. pushl_cfi $0
  788. pushl_cfi $do_invalid_op
  789. jmp error_code
  790. CFI_ENDPROC
  791. END(invalid_op)
  792. ENTRY(coprocessor_segment_overrun)
  793. RING0_INT_FRAME
  794. ASM_CLAC
  795. pushl_cfi $0
  796. pushl_cfi $do_coprocessor_segment_overrun
  797. jmp error_code
  798. CFI_ENDPROC
  799. END(coprocessor_segment_overrun)
  800. ENTRY(invalid_TSS)
  801. RING0_EC_FRAME
  802. ASM_CLAC
  803. pushl_cfi $do_invalid_TSS
  804. jmp error_code
  805. CFI_ENDPROC
  806. END(invalid_TSS)
  807. ENTRY(segment_not_present)
  808. RING0_EC_FRAME
  809. ASM_CLAC
  810. pushl_cfi $do_segment_not_present
  811. jmp error_code
  812. CFI_ENDPROC
  813. END(segment_not_present)
  814. ENTRY(stack_segment)
  815. RING0_EC_FRAME
  816. ASM_CLAC
  817. pushl_cfi $do_stack_segment
  818. jmp error_code
  819. CFI_ENDPROC
  820. END(stack_segment)
  821. ENTRY(alignment_check)
  822. RING0_EC_FRAME
  823. ASM_CLAC
  824. pushl_cfi $do_alignment_check
  825. jmp error_code
  826. CFI_ENDPROC
  827. END(alignment_check)
  828. ENTRY(divide_error)
  829. RING0_INT_FRAME
  830. ASM_CLAC
  831. pushl_cfi $0 # no error code
  832. pushl_cfi $do_divide_error
  833. jmp error_code
  834. CFI_ENDPROC
  835. END(divide_error)
  836. #ifdef CONFIG_X86_MCE
  837. ENTRY(machine_check)
  838. RING0_INT_FRAME
  839. ASM_CLAC
  840. pushl_cfi $0
  841. pushl_cfi machine_check_vector
  842. jmp error_code
  843. CFI_ENDPROC
  844. END(machine_check)
  845. #endif
  846. ENTRY(spurious_interrupt_bug)
  847. RING0_INT_FRAME
  848. ASM_CLAC
  849. pushl_cfi $0
  850. pushl_cfi $do_spurious_interrupt_bug
  851. jmp error_code
  852. CFI_ENDPROC
  853. END(spurious_interrupt_bug)
  854. #ifdef CONFIG_XEN
  855. /* Xen doesn't set %esp to be precisely what the normal sysenter
  856. entrypoint expects, so fix it up before using the normal path. */
  857. ENTRY(xen_sysenter_target)
  858. RING0_INT_FRAME
  859. addl $5*4, %esp /* remove xen-provided frame */
  860. CFI_ADJUST_CFA_OFFSET -5*4
  861. jmp sysenter_past_esp
  862. CFI_ENDPROC
  863. ENTRY(xen_hypervisor_callback)
  864. CFI_STARTPROC
  865. pushl_cfi $-1 /* orig_ax = -1 => not a system call */
  866. SAVE_ALL
  867. TRACE_IRQS_OFF
  868. /* Check to see if we got the event in the critical
  869. region in xen_iret_direct, after we've reenabled
  870. events and checked for pending events. This simulates
  871. iret instruction's behaviour where it delivers a
  872. pending interrupt when enabling interrupts. */
  873. movl PT_EIP(%esp),%eax
  874. cmpl $xen_iret_start_crit,%eax
  875. jb 1f
  876. cmpl $xen_iret_end_crit,%eax
  877. jae 1f
  878. jmp xen_iret_crit_fixup
  879. ENTRY(xen_do_upcall)
  880. 1: mov %esp, %eax
  881. call xen_evtchn_do_upcall
  882. #ifndef CONFIG_PREEMPT
  883. call xen_maybe_preempt_hcall
  884. #endif
  885. jmp ret_from_intr
  886. CFI_ENDPROC
  887. ENDPROC(xen_hypervisor_callback)
  888. # Hypervisor uses this for application faults while it executes.
  889. # We get here for two reasons:
  890. # 1. Fault while reloading DS, ES, FS or GS
  891. # 2. Fault while executing IRET
  892. # Category 1 we fix up by reattempting the load, and zeroing the segment
  893. # register if the load fails.
  894. # Category 2 we fix up by jumping to do_iret_error. We cannot use the
  895. # normal Linux return path in this case because if we use the IRET hypercall
  896. # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
  897. # We distinguish between categories by maintaining a status value in EAX.
  898. ENTRY(xen_failsafe_callback)
  899. CFI_STARTPROC
  900. pushl_cfi %eax
  901. movl $1,%eax
  902. 1: mov 4(%esp),%ds
  903. 2: mov 8(%esp),%es
  904. 3: mov 12(%esp),%fs
  905. 4: mov 16(%esp),%gs
  906. /* EAX == 0 => Category 1 (Bad segment)
  907. EAX != 0 => Category 2 (Bad IRET) */
  908. testl %eax,%eax
  909. popl_cfi %eax
  910. lea 16(%esp),%esp
  911. CFI_ADJUST_CFA_OFFSET -16
  912. jz 5f
  913. jmp iret_exc
  914. 5: pushl_cfi $-1 /* orig_ax = -1 => not a system call */
  915. SAVE_ALL
  916. jmp ret_from_exception
  917. CFI_ENDPROC
  918. .section .fixup,"ax"
  919. 6: xorl %eax,%eax
  920. movl %eax,4(%esp)
  921. jmp 1b
  922. 7: xorl %eax,%eax
  923. movl %eax,8(%esp)
  924. jmp 2b
  925. 8: xorl %eax,%eax
  926. movl %eax,12(%esp)
  927. jmp 3b
  928. 9: xorl %eax,%eax
  929. movl %eax,16(%esp)
  930. jmp 4b
  931. .previous
  932. _ASM_EXTABLE(1b,6b)
  933. _ASM_EXTABLE(2b,7b)
  934. _ASM_EXTABLE(3b,8b)
  935. _ASM_EXTABLE(4b,9b)
  936. ENDPROC(xen_failsafe_callback)
  937. BUILD_INTERRUPT3(xen_hvm_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
  938. xen_evtchn_do_upcall)
  939. #endif /* CONFIG_XEN */
  940. #if IS_ENABLED(CONFIG_HYPERV)
  941. BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
  942. hyperv_vector_handler)
  943. #endif /* CONFIG_HYPERV */
  944. #ifdef CONFIG_FUNCTION_TRACER
  945. #ifdef CONFIG_DYNAMIC_FTRACE
  946. ENTRY(mcount)
  947. ret
  948. END(mcount)
  949. ENTRY(ftrace_caller)
  950. pushl %eax
  951. pushl %ecx
  952. pushl %edx
  953. pushl $0 /* Pass NULL as regs pointer */
  954. movl 4*4(%esp), %eax
  955. movl 0x4(%ebp), %edx
  956. movl function_trace_op, %ecx
  957. subl $MCOUNT_INSN_SIZE, %eax
  958. .globl ftrace_call
  959. ftrace_call:
  960. call ftrace_stub
  961. addl $4,%esp /* skip NULL pointer */
  962. popl %edx
  963. popl %ecx
  964. popl %eax
  965. ftrace_ret:
  966. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  967. .globl ftrace_graph_call
  968. ftrace_graph_call:
  969. jmp ftrace_stub
  970. #endif
  971. .globl ftrace_stub
  972. ftrace_stub:
  973. ret
  974. END(ftrace_caller)
  975. ENTRY(ftrace_regs_caller)
  976. pushf /* push flags before compare (in cs location) */
  977. /*
  978. * i386 does not save SS and ESP when coming from kernel.
  979. * Instead, to get sp, &regs->sp is used (see ptrace.h).
  980. * Unfortunately, that means eflags must be at the same location
  981. * as the current return ip is. We move the return ip into the
  982. * ip location, and move flags into the return ip location.
  983. */
  984. pushl 4(%esp) /* save return ip into ip slot */
  985. pushl $0 /* Load 0 into orig_ax */
  986. pushl %gs
  987. pushl %fs
  988. pushl %es
  989. pushl %ds
  990. pushl %eax
  991. pushl %ebp
  992. pushl %edi
  993. pushl %esi
  994. pushl %edx
  995. pushl %ecx
  996. pushl %ebx
  997. movl 13*4(%esp), %eax /* Get the saved flags */
  998. movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */
  999. /* clobbering return ip */
  1000. movl $__KERNEL_CS,13*4(%esp)
  1001. movl 12*4(%esp), %eax /* Load ip (1st parameter) */
  1002. subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
  1003. movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
  1004. movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
  1005. pushl %esp /* Save pt_regs as 4th parameter */
  1006. GLOBAL(ftrace_regs_call)
  1007. call ftrace_stub
  1008. addl $4, %esp /* Skip pt_regs */
  1009. movl 14*4(%esp), %eax /* Move flags back into cs */
  1010. movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */
  1011. movl 12*4(%esp), %eax /* Get return ip from regs->ip */
  1012. movl %eax, 14*4(%esp) /* Put return ip back for ret */
  1013. popl %ebx
  1014. popl %ecx
  1015. popl %edx
  1016. popl %esi
  1017. popl %edi
  1018. popl %ebp
  1019. popl %eax
  1020. popl %ds
  1021. popl %es
  1022. popl %fs
  1023. popl %gs
  1024. addl $8, %esp /* Skip orig_ax and ip */
  1025. popf /* Pop flags at end (no addl to corrupt flags) */
  1026. jmp ftrace_ret
  1027. popf
  1028. jmp ftrace_stub
  1029. #else /* ! CONFIG_DYNAMIC_FTRACE */
  1030. ENTRY(mcount)
  1031. cmpl $__PAGE_OFFSET, %esp
  1032. jb ftrace_stub /* Paging not enabled yet? */
  1033. cmpl $ftrace_stub, ftrace_trace_function
  1034. jnz trace
  1035. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1036. cmpl $ftrace_stub, ftrace_graph_return
  1037. jnz ftrace_graph_caller
  1038. cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
  1039. jnz ftrace_graph_caller
  1040. #endif
  1041. .globl ftrace_stub
  1042. ftrace_stub:
  1043. ret
  1044. /* taken from glibc */
  1045. trace:
  1046. pushl %eax
  1047. pushl %ecx
  1048. pushl %edx
  1049. movl 0xc(%esp), %eax
  1050. movl 0x4(%ebp), %edx
  1051. subl $MCOUNT_INSN_SIZE, %eax
  1052. call *ftrace_trace_function
  1053. popl %edx
  1054. popl %ecx
  1055. popl %eax
  1056. jmp ftrace_stub
  1057. END(mcount)
  1058. #endif /* CONFIG_DYNAMIC_FTRACE */
  1059. #endif /* CONFIG_FUNCTION_TRACER */
  1060. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1061. ENTRY(ftrace_graph_caller)
  1062. pushl %eax
  1063. pushl %ecx
  1064. pushl %edx
  1065. movl 0xc(%esp), %eax
  1066. lea 0x4(%ebp), %edx
  1067. movl (%ebp), %ecx
  1068. subl $MCOUNT_INSN_SIZE, %eax
  1069. call prepare_ftrace_return
  1070. popl %edx
  1071. popl %ecx
  1072. popl %eax
  1073. ret
  1074. END(ftrace_graph_caller)
  1075. .globl return_to_handler
  1076. return_to_handler:
  1077. pushl %eax
  1078. pushl %edx
  1079. movl %ebp, %eax
  1080. call ftrace_return_to_handler
  1081. movl %eax, %ecx
  1082. popl %edx
  1083. popl %eax
  1084. jmp *%ecx
  1085. #endif
  1086. #ifdef CONFIG_TRACING
  1087. ENTRY(trace_page_fault)
  1088. RING0_EC_FRAME
  1089. ASM_CLAC
  1090. pushl_cfi $trace_do_page_fault
  1091. jmp error_code
  1092. CFI_ENDPROC
  1093. END(trace_page_fault)
  1094. #endif
  1095. ENTRY(page_fault)
  1096. RING0_EC_FRAME
  1097. ASM_CLAC
  1098. pushl_cfi $do_page_fault
  1099. ALIGN
  1100. error_code:
  1101. /* the function address is in %gs's slot on the stack */
  1102. pushl_cfi %fs
  1103. /*CFI_REL_OFFSET fs, 0*/
  1104. pushl_cfi %es
  1105. /*CFI_REL_OFFSET es, 0*/
  1106. pushl_cfi %ds
  1107. /*CFI_REL_OFFSET ds, 0*/
  1108. pushl_cfi_reg eax
  1109. pushl_cfi_reg ebp
  1110. pushl_cfi_reg edi
  1111. pushl_cfi_reg esi
  1112. pushl_cfi_reg edx
  1113. pushl_cfi_reg ecx
  1114. pushl_cfi_reg ebx
  1115. cld
  1116. movl $(__KERNEL_PERCPU), %ecx
  1117. movl %ecx, %fs
  1118. UNWIND_ESPFIX_STACK
  1119. GS_TO_REG %ecx
  1120. movl PT_GS(%esp), %edi # get the function address
  1121. movl PT_ORIG_EAX(%esp), %edx # get the error code
  1122. movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
  1123. REG_TO_PTGS %ecx
  1124. SET_KERNEL_GS %ecx
  1125. movl $(__USER_DS), %ecx
  1126. movl %ecx, %ds
  1127. movl %ecx, %es
  1128. TRACE_IRQS_OFF
  1129. movl %esp,%eax # pt_regs pointer
  1130. call *%edi
  1131. jmp ret_from_exception
  1132. CFI_ENDPROC
  1133. END(page_fault)
  1134. /*
  1135. * Debug traps and NMI can happen at the one SYSENTER instruction
  1136. * that sets up the real kernel stack. Check here, since we can't
  1137. * allow the wrong stack to be used.
  1138. *
  1139. * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
  1140. * already pushed 3 words if it hits on the sysenter instruction:
  1141. * eflags, cs and eip.
  1142. *
  1143. * We just load the right stack, and push the three (known) values
  1144. * by hand onto the new stack - while updating the return eip past
  1145. * the instruction that would have done it for sysenter.
  1146. */
  1147. .macro FIX_STACK offset ok label
  1148. cmpw $__KERNEL_CS, 4(%esp)
  1149. jne \ok
  1150. \label:
  1151. movl TSS_sysenter_sp0 + \offset(%esp), %esp
  1152. CFI_DEF_CFA esp, 0
  1153. CFI_UNDEFINED eip
  1154. pushfl_cfi
  1155. pushl_cfi $__KERNEL_CS
  1156. pushl_cfi $sysenter_past_esp
  1157. CFI_REL_OFFSET eip, 0
  1158. .endm
  1159. ENTRY(debug)
  1160. RING0_INT_FRAME
  1161. ASM_CLAC
  1162. cmpl $ia32_sysenter_target,(%esp)
  1163. jne debug_stack_correct
  1164. FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
  1165. debug_stack_correct:
  1166. pushl_cfi $-1 # mark this as an int
  1167. SAVE_ALL
  1168. TRACE_IRQS_OFF
  1169. xorl %edx,%edx # error code 0
  1170. movl %esp,%eax # pt_regs pointer
  1171. call do_debug
  1172. jmp ret_from_exception
  1173. CFI_ENDPROC
  1174. END(debug)
  1175. /*
  1176. * NMI is doubly nasty. It can happen _while_ we're handling
  1177. * a debug fault, and the debug fault hasn't yet been able to
  1178. * clear up the stack. So we first check whether we got an
  1179. * NMI on the sysenter entry path, but after that we need to
  1180. * check whether we got an NMI on the debug path where the debug
  1181. * fault happened on the sysenter path.
  1182. */
  1183. ENTRY(nmi)
  1184. RING0_INT_FRAME
  1185. ASM_CLAC
  1186. #ifdef CONFIG_X86_ESPFIX32
  1187. pushl_cfi %eax
  1188. movl %ss, %eax
  1189. cmpw $__ESPFIX_SS, %ax
  1190. popl_cfi %eax
  1191. je nmi_espfix_stack
  1192. #endif
  1193. cmpl $ia32_sysenter_target,(%esp)
  1194. je nmi_stack_fixup
  1195. pushl_cfi %eax
  1196. movl %esp,%eax
  1197. /* Do not access memory above the end of our stack page,
  1198. * it might not exist.
  1199. */
  1200. andl $(THREAD_SIZE-1),%eax
  1201. cmpl $(THREAD_SIZE-20),%eax
  1202. popl_cfi %eax
  1203. jae nmi_stack_correct
  1204. cmpl $ia32_sysenter_target,12(%esp)
  1205. je nmi_debug_stack_check
  1206. nmi_stack_correct:
  1207. /* We have a RING0_INT_FRAME here */
  1208. pushl_cfi %eax
  1209. SAVE_ALL
  1210. xorl %edx,%edx # zero error code
  1211. movl %esp,%eax # pt_regs pointer
  1212. call do_nmi
  1213. jmp restore_all_notrace
  1214. CFI_ENDPROC
  1215. nmi_stack_fixup:
  1216. RING0_INT_FRAME
  1217. FIX_STACK 12, nmi_stack_correct, 1
  1218. jmp nmi_stack_correct
  1219. nmi_debug_stack_check:
  1220. /* We have a RING0_INT_FRAME here */
  1221. cmpw $__KERNEL_CS,16(%esp)
  1222. jne nmi_stack_correct
  1223. cmpl $debug,(%esp)
  1224. jb nmi_stack_correct
  1225. cmpl $debug_esp_fix_insn,(%esp)
  1226. ja nmi_stack_correct
  1227. FIX_STACK 24, nmi_stack_correct, 1
  1228. jmp nmi_stack_correct
  1229. #ifdef CONFIG_X86_ESPFIX32
  1230. nmi_espfix_stack:
  1231. /* We have a RING0_INT_FRAME here.
  1232. *
  1233. * create the pointer to lss back
  1234. */
  1235. pushl_cfi %ss
  1236. pushl_cfi %esp
  1237. addl $4, (%esp)
  1238. /* copy the iret frame of 12 bytes */
  1239. .rept 3
  1240. pushl_cfi 16(%esp)
  1241. .endr
  1242. pushl_cfi %eax
  1243. SAVE_ALL
  1244. FIXUP_ESPFIX_STACK # %eax == %esp
  1245. xorl %edx,%edx # zero error code
  1246. call do_nmi
  1247. RESTORE_REGS
  1248. lss 12+4(%esp), %esp # back to espfix stack
  1249. CFI_ADJUST_CFA_OFFSET -24
  1250. jmp irq_return
  1251. #endif
  1252. CFI_ENDPROC
  1253. END(nmi)
  1254. ENTRY(int3)
  1255. RING0_INT_FRAME
  1256. ASM_CLAC
  1257. pushl_cfi $-1 # mark this as an int
  1258. SAVE_ALL
  1259. TRACE_IRQS_OFF
  1260. xorl %edx,%edx # zero error code
  1261. movl %esp,%eax # pt_regs pointer
  1262. call do_int3
  1263. jmp ret_from_exception
  1264. CFI_ENDPROC
  1265. END(int3)
  1266. ENTRY(general_protection)
  1267. RING0_EC_FRAME
  1268. pushl_cfi $do_general_protection
  1269. jmp error_code
  1270. CFI_ENDPROC
  1271. END(general_protection)
  1272. #ifdef CONFIG_KVM_GUEST
  1273. ENTRY(async_page_fault)
  1274. RING0_EC_FRAME
  1275. ASM_CLAC
  1276. pushl_cfi $do_async_page_fault
  1277. jmp error_code
  1278. CFI_ENDPROC
  1279. END(async_page_fault)
  1280. #endif