process.c 18 KB

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