process.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/sched.h>
  15. #include <linux/preempt.h>
  16. #include <linux/module.h>
  17. #include <linux/fs.h>
  18. #include <linux/kprobes.h>
  19. #include <linux/elfcore.h>
  20. #include <linux/tick.h>
  21. #include <linux/init.h>
  22. #include <linux/mm.h>
  23. #include <linux/compat.h>
  24. #include <linux/hardirq.h>
  25. #include <linux/syscalls.h>
  26. #include <linux/kernel.h>
  27. #include <linux/tracehook.h>
  28. #include <linux/signal.h>
  29. #include <asm/stack.h>
  30. #include <asm/switch_to.h>
  31. #include <asm/homecache.h>
  32. #include <asm/syscalls.h>
  33. #include <asm/traps.h>
  34. #include <asm/setup.h>
  35. #ifdef CONFIG_HARDWALL
  36. #include <asm/hardwall.h>
  37. #endif
  38. #include <arch/chip.h>
  39. #include <arch/abi.h>
  40. #include <arch/sim_def.h>
  41. /*
  42. * Use the (x86) "idle=poll" option to prefer low latency when leaving the
  43. * idle loop over low power while in the idle loop, e.g. if we have
  44. * one thread per core and we want to get threads out of futex waits fast.
  45. */
  46. static int no_idle_nap;
  47. static int __init idle_setup(char *str)
  48. {
  49. if (!str)
  50. return -EINVAL;
  51. if (!strcmp(str, "poll")) {
  52. pr_info("using polling idle threads.\n");
  53. no_idle_nap = 1;
  54. } else if (!strcmp(str, "halt"))
  55. no_idle_nap = 0;
  56. else
  57. return -1;
  58. return 0;
  59. }
  60. early_param("idle", idle_setup);
  61. /*
  62. * The idle thread. There's no useful work to be
  63. * done, so just try to conserve power and have a
  64. * low exit latency (ie sit in a loop waiting for
  65. * somebody to say that they'd like to reschedule)
  66. */
  67. void cpu_idle(void)
  68. {
  69. int cpu = smp_processor_id();
  70. current_thread_info()->status |= TS_POLLING;
  71. if (no_idle_nap) {
  72. while (1) {
  73. while (!need_resched())
  74. cpu_relax();
  75. schedule();
  76. }
  77. }
  78. /* endless idle loop with no priority at all */
  79. while (1) {
  80. tick_nohz_idle_enter();
  81. rcu_idle_enter();
  82. while (!need_resched()) {
  83. if (cpu_is_offline(cpu))
  84. BUG(); /* no HOTPLUG_CPU */
  85. local_irq_disable();
  86. __get_cpu_var(irq_stat).idle_timestamp = jiffies;
  87. current_thread_info()->status &= ~TS_POLLING;
  88. /*
  89. * TS_POLLING-cleared state must be visible before we
  90. * test NEED_RESCHED:
  91. */
  92. smp_mb();
  93. if (!need_resched())
  94. _cpu_idle();
  95. else
  96. local_irq_enable();
  97. current_thread_info()->status |= TS_POLLING;
  98. }
  99. rcu_idle_exit();
  100. tick_nohz_idle_exit();
  101. schedule_preempt_disabled();
  102. }
  103. }
  104. /*
  105. * Release a thread_info structure
  106. */
  107. void arch_release_thread_info(struct thread_info *info)
  108. {
  109. struct single_step_state *step_state = info->step_state;
  110. #ifdef CONFIG_HARDWALL
  111. /*
  112. * We free a thread_info from the context of the task that has
  113. * been scheduled next, so the original task is already dead.
  114. * Calling deactivate here just frees up the data structures.
  115. * If the task we're freeing held the last reference to a
  116. * hardwall fd, it would have been released prior to this point
  117. * anyway via exit_files(), and the hardwall_task.info pointers
  118. * would be NULL by now.
  119. */
  120. hardwall_deactivate_all(info->task);
  121. #endif
  122. if (step_state) {
  123. /*
  124. * FIXME: we don't munmap step_state->buffer
  125. * because the mm_struct for this process (info->task->mm)
  126. * has already been zeroed in exit_mm(). Keeping a
  127. * reference to it here seems like a bad move, so this
  128. * means we can't munmap() the buffer, and therefore if we
  129. * ptrace multiple threads in a process, we will slowly
  130. * leak user memory. (Note that as soon as the last
  131. * thread in a process dies, we will reclaim all user
  132. * memory including single-step buffers in the usual way.)
  133. * We should either assign a kernel VA to this buffer
  134. * somehow, or we should associate the buffer(s) with the
  135. * mm itself so we can clean them up that way.
  136. */
  137. kfree(step_state);
  138. }
  139. }
  140. static void save_arch_state(struct thread_struct *t);
  141. int copy_thread(unsigned long clone_flags, unsigned long sp,
  142. unsigned long arg, struct task_struct *p)
  143. {
  144. struct pt_regs *childregs = task_pt_regs(p);
  145. unsigned long ksp;
  146. unsigned long *callee_regs;
  147. /*
  148. * Set up the stack and stack pointer appropriately for the
  149. * new child to find itself woken up in __switch_to().
  150. * The callee-saved registers must be on the stack to be read;
  151. * the new task will then jump to assembly support to handle
  152. * calling schedule_tail(), etc., and (for userspace tasks)
  153. * returning to the context set up in the pt_regs.
  154. */
  155. ksp = (unsigned long) childregs;
  156. ksp -= C_ABI_SAVE_AREA_SIZE; /* interrupt-entry save area */
  157. ((long *)ksp)[0] = ((long *)ksp)[1] = 0;
  158. ksp -= CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long);
  159. callee_regs = (unsigned long *)ksp;
  160. ksp -= C_ABI_SAVE_AREA_SIZE; /* __switch_to() save area */
  161. ((long *)ksp)[0] = ((long *)ksp)[1] = 0;
  162. p->thread.ksp = ksp;
  163. /* Record the pid of the task that created this one. */
  164. p->thread.creator_pid = current->pid;
  165. if (unlikely(p->flags & PF_KTHREAD)) {
  166. /* kernel thread */
  167. memset(childregs, 0, sizeof(struct pt_regs));
  168. memset(&callee_regs[2], 0,
  169. (CALLEE_SAVED_REGS_COUNT - 2) * sizeof(unsigned long));
  170. callee_regs[0] = sp; /* r30 = function */
  171. callee_regs[1] = arg; /* r31 = arg */
  172. childregs->ex1 = PL_ICS_EX1(KERNEL_PL, 0);
  173. p->thread.pc = (unsigned long) ret_from_kernel_thread;
  174. return 0;
  175. }
  176. /*
  177. * Start new thread in ret_from_fork so it schedules properly
  178. * and then return from interrupt like the parent.
  179. */
  180. p->thread.pc = (unsigned long) ret_from_fork;
  181. /*
  182. * Do not clone step state from the parent; each thread
  183. * must make its own lazily.
  184. */
  185. task_thread_info(p)->step_state = NULL;
  186. /*
  187. * Copy the registers onto the kernel stack so the
  188. * return-from-interrupt code will reload it into registers.
  189. */
  190. *childregs = *current_pt_regs();
  191. childregs->regs[0] = 0; /* return value is zero */
  192. if (sp)
  193. childregs->sp = sp; /* override with new user stack pointer */
  194. memcpy(callee_regs, &childregs->regs[CALLEE_SAVED_FIRST_REG],
  195. CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long));
  196. /* Save user stack top pointer so we can ID the stack vm area later. */
  197. p->thread.usp0 = childregs->sp;
  198. /*
  199. * If CLONE_SETTLS is set, set "tp" in the new task to "r4",
  200. * which is passed in as arg #5 to sys_clone().
  201. */
  202. if (clone_flags & CLONE_SETTLS)
  203. childregs->tp = childregs->regs[4];
  204. #if CHIP_HAS_TILE_DMA()
  205. /*
  206. * No DMA in the new thread. We model this on the fact that
  207. * fork() clears the pending signals, alarms, and aio for the child.
  208. */
  209. memset(&p->thread.tile_dma_state, 0, sizeof(struct tile_dma_state));
  210. memset(&p->thread.dma_async_tlb, 0, sizeof(struct async_tlb));
  211. #endif
  212. #if CHIP_HAS_SN_PROC()
  213. /* Likewise, the new thread is not running static processor code. */
  214. p->thread.sn_proc_running = 0;
  215. memset(&p->thread.sn_async_tlb, 0, sizeof(struct async_tlb));
  216. #endif
  217. #if CHIP_HAS_PROC_STATUS_SPR()
  218. /* New thread has its miscellaneous processor state bits clear. */
  219. p->thread.proc_status = 0;
  220. #endif
  221. #ifdef CONFIG_HARDWALL
  222. /* New thread does not own any networks. */
  223. memset(&p->thread.hardwall[0], 0,
  224. sizeof(struct hardwall_task) * HARDWALL_TYPES);
  225. #endif
  226. /*
  227. * Start the new thread with the current architecture state
  228. * (user interrupt masks, etc.).
  229. */
  230. save_arch_state(&p->thread);
  231. return 0;
  232. }
  233. /*
  234. * Return "current" if it looks plausible, or else a pointer to a dummy.
  235. * This can be helpful if we are just trying to emit a clean panic.
  236. */
  237. struct task_struct *validate_current(void)
  238. {
  239. static struct task_struct corrupt = { .comm = "<corrupt>" };
  240. struct task_struct *tsk = current;
  241. if (unlikely((unsigned long)tsk < PAGE_OFFSET ||
  242. (high_memory && (void *)tsk > high_memory) ||
  243. ((unsigned long)tsk & (__alignof__(*tsk) - 1)) != 0)) {
  244. pr_err("Corrupt 'current' %p (sp %#lx)\n", tsk, stack_pointer);
  245. tsk = &corrupt;
  246. }
  247. return tsk;
  248. }
  249. /* Take and return the pointer to the previous task, for schedule_tail(). */
  250. struct task_struct *sim_notify_fork(struct task_struct *prev)
  251. {
  252. struct task_struct *tsk = current;
  253. __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_FORK_PARENT |
  254. (tsk->thread.creator_pid << _SIM_CONTROL_OPERATOR_BITS));
  255. __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_FORK |
  256. (tsk->pid << _SIM_CONTROL_OPERATOR_BITS));
  257. return prev;
  258. }
  259. int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
  260. {
  261. struct pt_regs *ptregs = task_pt_regs(tsk);
  262. elf_core_copy_regs(regs, ptregs);
  263. return 1;
  264. }
  265. #if CHIP_HAS_TILE_DMA()
  266. /* Allow user processes to access the DMA SPRs */
  267. void grant_dma_mpls(void)
  268. {
  269. #if CONFIG_KERNEL_PL == 2
  270. __insn_mtspr(SPR_MPL_DMA_CPL_SET_1, 1);
  271. __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_1, 1);
  272. #else
  273. __insn_mtspr(SPR_MPL_DMA_CPL_SET_0, 1);
  274. __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_0, 1);
  275. #endif
  276. }
  277. /* Forbid user processes from accessing the DMA SPRs */
  278. void restrict_dma_mpls(void)
  279. {
  280. #if CONFIG_KERNEL_PL == 2
  281. __insn_mtspr(SPR_MPL_DMA_CPL_SET_2, 1);
  282. __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_2, 1);
  283. #else
  284. __insn_mtspr(SPR_MPL_DMA_CPL_SET_1, 1);
  285. __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_1, 1);
  286. #endif
  287. }
  288. /* Pause the DMA engine, then save off its state registers. */
  289. static void save_tile_dma_state(struct tile_dma_state *dma)
  290. {
  291. unsigned long state = __insn_mfspr(SPR_DMA_USER_STATUS);
  292. unsigned long post_suspend_state;
  293. /* If we're running, suspend the engine. */
  294. if ((state & DMA_STATUS_MASK) == SPR_DMA_STATUS__RUNNING_MASK)
  295. __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__SUSPEND_MASK);
  296. /*
  297. * Wait for the engine to idle, then save regs. Note that we
  298. * want to record the "running" bit from before suspension,
  299. * and the "done" bit from after, so that we can properly
  300. * distinguish a case where the user suspended the engine from
  301. * the case where the kernel suspended as part of the context
  302. * swap.
  303. */
  304. do {
  305. post_suspend_state = __insn_mfspr(SPR_DMA_USER_STATUS);
  306. } while (post_suspend_state & SPR_DMA_STATUS__BUSY_MASK);
  307. dma->src = __insn_mfspr(SPR_DMA_SRC_ADDR);
  308. dma->src_chunk = __insn_mfspr(SPR_DMA_SRC_CHUNK_ADDR);
  309. dma->dest = __insn_mfspr(SPR_DMA_DST_ADDR);
  310. dma->dest_chunk = __insn_mfspr(SPR_DMA_DST_CHUNK_ADDR);
  311. dma->strides = __insn_mfspr(SPR_DMA_STRIDE);
  312. dma->chunk_size = __insn_mfspr(SPR_DMA_CHUNK_SIZE);
  313. dma->byte = __insn_mfspr(SPR_DMA_BYTE);
  314. dma->status = (state & SPR_DMA_STATUS__RUNNING_MASK) |
  315. (post_suspend_state & SPR_DMA_STATUS__DONE_MASK);
  316. }
  317. /* Restart a DMA that was running before we were context-switched out. */
  318. static void restore_tile_dma_state(struct thread_struct *t)
  319. {
  320. const struct tile_dma_state *dma = &t->tile_dma_state;
  321. /*
  322. * The only way to restore the done bit is to run a zero
  323. * length transaction.
  324. */
  325. if ((dma->status & SPR_DMA_STATUS__DONE_MASK) &&
  326. !(__insn_mfspr(SPR_DMA_USER_STATUS) & SPR_DMA_STATUS__DONE_MASK)) {
  327. __insn_mtspr(SPR_DMA_BYTE, 0);
  328. __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__REQUEST_MASK);
  329. while (__insn_mfspr(SPR_DMA_USER_STATUS) &
  330. SPR_DMA_STATUS__BUSY_MASK)
  331. ;
  332. }
  333. __insn_mtspr(SPR_DMA_SRC_ADDR, dma->src);
  334. __insn_mtspr(SPR_DMA_SRC_CHUNK_ADDR, dma->src_chunk);
  335. __insn_mtspr(SPR_DMA_DST_ADDR, dma->dest);
  336. __insn_mtspr(SPR_DMA_DST_CHUNK_ADDR, dma->dest_chunk);
  337. __insn_mtspr(SPR_DMA_STRIDE, dma->strides);
  338. __insn_mtspr(SPR_DMA_CHUNK_SIZE, dma->chunk_size);
  339. __insn_mtspr(SPR_DMA_BYTE, dma->byte);
  340. /*
  341. * Restart the engine if we were running and not done.
  342. * Clear a pending async DMA fault that we were waiting on return
  343. * to user space to execute, since we expect the DMA engine
  344. * to regenerate those faults for us now. Note that we don't
  345. * try to clear the TIF_ASYNC_TLB flag, since it's relatively
  346. * harmless if set, and it covers both DMA and the SN processor.
  347. */
  348. if ((dma->status & DMA_STATUS_MASK) == SPR_DMA_STATUS__RUNNING_MASK) {
  349. t->dma_async_tlb.fault_num = 0;
  350. __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__REQUEST_MASK);
  351. }
  352. }
  353. #endif
  354. static void save_arch_state(struct thread_struct *t)
  355. {
  356. #if CHIP_HAS_SPLIT_INTR_MASK()
  357. t->interrupt_mask = __insn_mfspr(SPR_INTERRUPT_MASK_0_0) |
  358. ((u64)__insn_mfspr(SPR_INTERRUPT_MASK_0_1) << 32);
  359. #else
  360. t->interrupt_mask = __insn_mfspr(SPR_INTERRUPT_MASK_0);
  361. #endif
  362. t->ex_context[0] = __insn_mfspr(SPR_EX_CONTEXT_0_0);
  363. t->ex_context[1] = __insn_mfspr(SPR_EX_CONTEXT_0_1);
  364. t->system_save[0] = __insn_mfspr(SPR_SYSTEM_SAVE_0_0);
  365. t->system_save[1] = __insn_mfspr(SPR_SYSTEM_SAVE_0_1);
  366. t->system_save[2] = __insn_mfspr(SPR_SYSTEM_SAVE_0_2);
  367. t->system_save[3] = __insn_mfspr(SPR_SYSTEM_SAVE_0_3);
  368. t->intctrl_0 = __insn_mfspr(SPR_INTCTRL_0_STATUS);
  369. #if CHIP_HAS_PROC_STATUS_SPR()
  370. t->proc_status = __insn_mfspr(SPR_PROC_STATUS);
  371. #endif
  372. #if !CHIP_HAS_FIXED_INTVEC_BASE()
  373. t->interrupt_vector_base = __insn_mfspr(SPR_INTERRUPT_VECTOR_BASE_0);
  374. #endif
  375. #if CHIP_HAS_TILE_RTF_HWM()
  376. t->tile_rtf_hwm = __insn_mfspr(SPR_TILE_RTF_HWM);
  377. #endif
  378. #if CHIP_HAS_DSTREAM_PF()
  379. t->dstream_pf = __insn_mfspr(SPR_DSTREAM_PF);
  380. #endif
  381. }
  382. static void restore_arch_state(const struct thread_struct *t)
  383. {
  384. #if CHIP_HAS_SPLIT_INTR_MASK()
  385. __insn_mtspr(SPR_INTERRUPT_MASK_0_0, (u32) t->interrupt_mask);
  386. __insn_mtspr(SPR_INTERRUPT_MASK_0_1, t->interrupt_mask >> 32);
  387. #else
  388. __insn_mtspr(SPR_INTERRUPT_MASK_0, t->interrupt_mask);
  389. #endif
  390. __insn_mtspr(SPR_EX_CONTEXT_0_0, t->ex_context[0]);
  391. __insn_mtspr(SPR_EX_CONTEXT_0_1, t->ex_context[1]);
  392. __insn_mtspr(SPR_SYSTEM_SAVE_0_0, t->system_save[0]);
  393. __insn_mtspr(SPR_SYSTEM_SAVE_0_1, t->system_save[1]);
  394. __insn_mtspr(SPR_SYSTEM_SAVE_0_2, t->system_save[2]);
  395. __insn_mtspr(SPR_SYSTEM_SAVE_0_3, t->system_save[3]);
  396. __insn_mtspr(SPR_INTCTRL_0_STATUS, t->intctrl_0);
  397. #if CHIP_HAS_PROC_STATUS_SPR()
  398. __insn_mtspr(SPR_PROC_STATUS, t->proc_status);
  399. #endif
  400. #if !CHIP_HAS_FIXED_INTVEC_BASE()
  401. __insn_mtspr(SPR_INTERRUPT_VECTOR_BASE_0, t->interrupt_vector_base);
  402. #endif
  403. #if CHIP_HAS_TILE_RTF_HWM()
  404. __insn_mtspr(SPR_TILE_RTF_HWM, t->tile_rtf_hwm);
  405. #endif
  406. #if CHIP_HAS_DSTREAM_PF()
  407. __insn_mtspr(SPR_DSTREAM_PF, t->dstream_pf);
  408. #endif
  409. }
  410. void _prepare_arch_switch(struct task_struct *next)
  411. {
  412. #if CHIP_HAS_SN_PROC()
  413. int snctl;
  414. #endif
  415. #if CHIP_HAS_TILE_DMA()
  416. struct tile_dma_state *dma = &current->thread.tile_dma_state;
  417. if (dma->enabled)
  418. save_tile_dma_state(dma);
  419. #endif
  420. #if CHIP_HAS_SN_PROC()
  421. /*
  422. * Suspend the static network processor if it was running.
  423. * We do not suspend the fabric itself, just like we don't
  424. * try to suspend the UDN.
  425. */
  426. snctl = __insn_mfspr(SPR_SNCTL);
  427. current->thread.sn_proc_running =
  428. (snctl & SPR_SNCTL__FRZPROC_MASK) == 0;
  429. if (current->thread.sn_proc_running)
  430. __insn_mtspr(SPR_SNCTL, snctl | SPR_SNCTL__FRZPROC_MASK);
  431. #endif
  432. }
  433. struct task_struct *__sched _switch_to(struct task_struct *prev,
  434. struct task_struct *next)
  435. {
  436. /* DMA state is already saved; save off other arch state. */
  437. save_arch_state(&prev->thread);
  438. #if CHIP_HAS_TILE_DMA()
  439. /*
  440. * Restore DMA in new task if desired.
  441. * Note that it is only safe to restart here since interrupts
  442. * are disabled, so we can't take any DMATLB miss or access
  443. * interrupts before we have finished switching stacks.
  444. */
  445. if (next->thread.tile_dma_state.enabled) {
  446. restore_tile_dma_state(&next->thread);
  447. grant_dma_mpls();
  448. } else {
  449. restrict_dma_mpls();
  450. }
  451. #endif
  452. /* Restore other arch state. */
  453. restore_arch_state(&next->thread);
  454. #if CHIP_HAS_SN_PROC()
  455. /*
  456. * Restart static network processor in the new process
  457. * if it was running before.
  458. */
  459. if (next->thread.sn_proc_running) {
  460. int snctl = __insn_mfspr(SPR_SNCTL);
  461. __insn_mtspr(SPR_SNCTL, snctl & ~SPR_SNCTL__FRZPROC_MASK);
  462. }
  463. #endif
  464. #ifdef CONFIG_HARDWALL
  465. /* Enable or disable access to the network registers appropriately. */
  466. hardwall_switch_tasks(prev, next);
  467. #endif
  468. /*
  469. * Switch kernel SP, PC, and callee-saved registers.
  470. * In the context of the new task, return the old task pointer
  471. * (i.e. the task that actually called __switch_to).
  472. * Pass the value to use for SYSTEM_SAVE_K_0 when we reset our sp.
  473. */
  474. return __switch_to(prev, next, next_current_ksp0(next));
  475. }
  476. /*
  477. * This routine is called on return from interrupt if any of the
  478. * TIF_WORK_MASK flags are set in thread_info->flags. It is
  479. * entered with interrupts disabled so we don't miss an event
  480. * that modified the thread_info flags. If any flag is set, we
  481. * handle it and return, and the calling assembly code will
  482. * re-disable interrupts, reload the thread flags, and call back
  483. * if more flags need to be handled.
  484. *
  485. * We return whether we need to check the thread_info flags again
  486. * or not. Note that we don't clear TIF_SINGLESTEP here, so it's
  487. * important that it be tested last, and then claim that we don't
  488. * need to recheck the flags.
  489. */
  490. int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
  491. {
  492. /* If we enter in kernel mode, do nothing and exit the caller loop. */
  493. if (!user_mode(regs))
  494. return 0;
  495. /* Enable interrupts; they are disabled again on return to caller. */
  496. local_irq_enable();
  497. if (thread_info_flags & _TIF_NEED_RESCHED) {
  498. schedule();
  499. return 1;
  500. }
  501. #if CHIP_HAS_TILE_DMA() || CHIP_HAS_SN_PROC()
  502. if (thread_info_flags & _TIF_ASYNC_TLB) {
  503. do_async_page_fault(regs);
  504. return 1;
  505. }
  506. #endif
  507. if (thread_info_flags & _TIF_SIGPENDING) {
  508. do_signal(regs);
  509. return 1;
  510. }
  511. if (thread_info_flags & _TIF_NOTIFY_RESUME) {
  512. clear_thread_flag(TIF_NOTIFY_RESUME);
  513. tracehook_notify_resume(regs);
  514. return 1;
  515. }
  516. if (thread_info_flags & _TIF_SINGLESTEP) {
  517. single_step_once(regs);
  518. return 0;
  519. }
  520. panic("work_pending: bad flags %#x\n", thread_info_flags);
  521. }
  522. unsigned long get_wchan(struct task_struct *p)
  523. {
  524. struct KBacktraceIterator kbt;
  525. if (!p || p == current || p->state == TASK_RUNNING)
  526. return 0;
  527. for (KBacktraceIterator_init(&kbt, p, NULL);
  528. !KBacktraceIterator_end(&kbt);
  529. KBacktraceIterator_next(&kbt)) {
  530. if (!in_sched_functions(kbt.it.pc))
  531. return kbt.it.pc;
  532. }
  533. return 0;
  534. }
  535. /* Flush thread state. */
  536. void flush_thread(void)
  537. {
  538. /* Nothing */
  539. }
  540. /*
  541. * Free current thread data structures etc..
  542. */
  543. void exit_thread(void)
  544. {
  545. /* Nothing */
  546. }
  547. void show_regs(struct pt_regs *regs)
  548. {
  549. struct task_struct *tsk = validate_current();
  550. int i;
  551. pr_err("\n");
  552. pr_err(" Pid: %d, comm: %20s, CPU: %d\n",
  553. tsk->pid, tsk->comm, smp_processor_id());
  554. #ifdef __tilegx__
  555. for (i = 0; i < 51; i += 3)
  556. pr_err(" r%-2d: "REGFMT" r%-2d: "REGFMT" r%-2d: "REGFMT"\n",
  557. i, regs->regs[i], i+1, regs->regs[i+1],
  558. i+2, regs->regs[i+2]);
  559. pr_err(" r51: "REGFMT" r52: "REGFMT" tp : "REGFMT"\n",
  560. regs->regs[51], regs->regs[52], regs->tp);
  561. pr_err(" sp : "REGFMT" lr : "REGFMT"\n", regs->sp, regs->lr);
  562. #else
  563. for (i = 0; i < 52; i += 4)
  564. pr_err(" r%-2d: "REGFMT" r%-2d: "REGFMT
  565. " r%-2d: "REGFMT" r%-2d: "REGFMT"\n",
  566. i, regs->regs[i], i+1, regs->regs[i+1],
  567. i+2, regs->regs[i+2], i+3, regs->regs[i+3]);
  568. pr_err(" r52: "REGFMT" tp : "REGFMT" sp : "REGFMT" lr : "REGFMT"\n",
  569. regs->regs[52], regs->tp, regs->sp, regs->lr);
  570. #endif
  571. pr_err(" pc : "REGFMT" ex1: %ld faultnum: %ld\n",
  572. regs->pc, regs->ex1, regs->faultnum);
  573. dump_stack_regs(regs);
  574. }