process.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. /*
  2. * Derived from "arch/i386/kernel/process.c"
  3. * Copyright (C) 1995 Linus Torvalds
  4. *
  5. * Updated and modified by Cort Dougan (cort@cs.nmt.edu) and
  6. * Paul Mackerras (paulus@cs.anu.edu.au)
  7. *
  8. * PowerPC version
  9. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #include <linux/errno.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/smp.h>
  21. #include <linux/stddef.h>
  22. #include <linux/unistd.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/slab.h>
  25. #include <linux/user.h>
  26. #include <linux/elf.h>
  27. #include <linux/init.h>
  28. #include <linux/prctl.h>
  29. #include <linux/init_task.h>
  30. #include <linux/module.h>
  31. #include <linux/kallsyms.h>
  32. #include <linux/mqueue.h>
  33. #include <linux/hardirq.h>
  34. #include <linux/utsname.h>
  35. #include <linux/ftrace.h>
  36. #include <linux/kernel_stat.h>
  37. #include <linux/personality.h>
  38. #include <linux/random.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/uaccess.h>
  41. #include <asm/system.h>
  42. #include <asm/io.h>
  43. #include <asm/processor.h>
  44. #include <asm/mmu.h>
  45. #include <asm/prom.h>
  46. #include <asm/machdep.h>
  47. #include <asm/time.h>
  48. #include <asm/syscalls.h>
  49. #ifdef CONFIG_PPC64
  50. #include <asm/firmware.h>
  51. #endif
  52. #include <linux/kprobes.h>
  53. #include <linux/kdebug.h>
  54. extern unsigned long _get_SP(void);
  55. #ifndef CONFIG_SMP
  56. struct task_struct *last_task_used_math = NULL;
  57. struct task_struct *last_task_used_altivec = NULL;
  58. struct task_struct *last_task_used_vsx = NULL;
  59. struct task_struct *last_task_used_spe = NULL;
  60. #endif
  61. /*
  62. * Make sure the floating-point register state in the
  63. * the thread_struct is up to date for task tsk.
  64. */
  65. void flush_fp_to_thread(struct task_struct *tsk)
  66. {
  67. if (tsk->thread.regs) {
  68. /*
  69. * We need to disable preemption here because if we didn't,
  70. * another process could get scheduled after the regs->msr
  71. * test but before we have finished saving the FP registers
  72. * to the thread_struct. That process could take over the
  73. * FPU, and then when we get scheduled again we would store
  74. * bogus values for the remaining FP registers.
  75. */
  76. preempt_disable();
  77. if (tsk->thread.regs->msr & MSR_FP) {
  78. #ifdef CONFIG_SMP
  79. /*
  80. * This should only ever be called for current or
  81. * for a stopped child process. Since we save away
  82. * the FP register state on context switch on SMP,
  83. * there is something wrong if a stopped child appears
  84. * to still have its FP state in the CPU registers.
  85. */
  86. BUG_ON(tsk != current);
  87. #endif
  88. giveup_fpu(tsk);
  89. }
  90. preempt_enable();
  91. }
  92. }
  93. void enable_kernel_fp(void)
  94. {
  95. WARN_ON(preemptible());
  96. #ifdef CONFIG_SMP
  97. if (current->thread.regs && (current->thread.regs->msr & MSR_FP))
  98. giveup_fpu(current);
  99. else
  100. giveup_fpu(NULL); /* just enables FP for kernel */
  101. #else
  102. giveup_fpu(last_task_used_math);
  103. #endif /* CONFIG_SMP */
  104. }
  105. EXPORT_SYMBOL(enable_kernel_fp);
  106. #ifdef CONFIG_ALTIVEC
  107. void enable_kernel_altivec(void)
  108. {
  109. WARN_ON(preemptible());
  110. #ifdef CONFIG_SMP
  111. if (current->thread.regs && (current->thread.regs->msr & MSR_VEC))
  112. giveup_altivec(current);
  113. else
  114. giveup_altivec(NULL); /* just enable AltiVec for kernel - force */
  115. #else
  116. giveup_altivec(last_task_used_altivec);
  117. #endif /* CONFIG_SMP */
  118. }
  119. EXPORT_SYMBOL(enable_kernel_altivec);
  120. /*
  121. * Make sure the VMX/Altivec register state in the
  122. * the thread_struct is up to date for task tsk.
  123. */
  124. void flush_altivec_to_thread(struct task_struct *tsk)
  125. {
  126. if (tsk->thread.regs) {
  127. preempt_disable();
  128. if (tsk->thread.regs->msr & MSR_VEC) {
  129. #ifdef CONFIG_SMP
  130. BUG_ON(tsk != current);
  131. #endif
  132. giveup_altivec(tsk);
  133. }
  134. preempt_enable();
  135. }
  136. }
  137. #endif /* CONFIG_ALTIVEC */
  138. #ifdef CONFIG_VSX
  139. #if 0
  140. /* not currently used, but some crazy RAID module might want to later */
  141. void enable_kernel_vsx(void)
  142. {
  143. WARN_ON(preemptible());
  144. #ifdef CONFIG_SMP
  145. if (current->thread.regs && (current->thread.regs->msr & MSR_VSX))
  146. giveup_vsx(current);
  147. else
  148. giveup_vsx(NULL); /* just enable vsx for kernel - force */
  149. #else
  150. giveup_vsx(last_task_used_vsx);
  151. #endif /* CONFIG_SMP */
  152. }
  153. EXPORT_SYMBOL(enable_kernel_vsx);
  154. #endif
  155. void giveup_vsx(struct task_struct *tsk)
  156. {
  157. giveup_fpu(tsk);
  158. giveup_altivec(tsk);
  159. __giveup_vsx(tsk);
  160. }
  161. void flush_vsx_to_thread(struct task_struct *tsk)
  162. {
  163. if (tsk->thread.regs) {
  164. preempt_disable();
  165. if (tsk->thread.regs->msr & MSR_VSX) {
  166. #ifdef CONFIG_SMP
  167. BUG_ON(tsk != current);
  168. #endif
  169. giveup_vsx(tsk);
  170. }
  171. preempt_enable();
  172. }
  173. }
  174. #endif /* CONFIG_VSX */
  175. #ifdef CONFIG_SPE
  176. void enable_kernel_spe(void)
  177. {
  178. WARN_ON(preemptible());
  179. #ifdef CONFIG_SMP
  180. if (current->thread.regs && (current->thread.regs->msr & MSR_SPE))
  181. giveup_spe(current);
  182. else
  183. giveup_spe(NULL); /* just enable SPE for kernel - force */
  184. #else
  185. giveup_spe(last_task_used_spe);
  186. #endif /* __SMP __ */
  187. }
  188. EXPORT_SYMBOL(enable_kernel_spe);
  189. void flush_spe_to_thread(struct task_struct *tsk)
  190. {
  191. if (tsk->thread.regs) {
  192. preempt_disable();
  193. if (tsk->thread.regs->msr & MSR_SPE) {
  194. #ifdef CONFIG_SMP
  195. BUG_ON(tsk != current);
  196. #endif
  197. giveup_spe(tsk);
  198. }
  199. preempt_enable();
  200. }
  201. }
  202. #endif /* CONFIG_SPE */
  203. #ifndef CONFIG_SMP
  204. /*
  205. * If we are doing lazy switching of CPU state (FP, altivec or SPE),
  206. * and the current task has some state, discard it.
  207. */
  208. void discard_lazy_cpu_state(void)
  209. {
  210. preempt_disable();
  211. if (last_task_used_math == current)
  212. last_task_used_math = NULL;
  213. #ifdef CONFIG_ALTIVEC
  214. if (last_task_used_altivec == current)
  215. last_task_used_altivec = NULL;
  216. #endif /* CONFIG_ALTIVEC */
  217. #ifdef CONFIG_VSX
  218. if (last_task_used_vsx == current)
  219. last_task_used_vsx = NULL;
  220. #endif /* CONFIG_VSX */
  221. #ifdef CONFIG_SPE
  222. if (last_task_used_spe == current)
  223. last_task_used_spe = NULL;
  224. #endif
  225. preempt_enable();
  226. }
  227. #endif /* CONFIG_SMP */
  228. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  229. void do_send_trap(struct pt_regs *regs, unsigned long address,
  230. unsigned long error_code, int signal_code, int breakpt)
  231. {
  232. siginfo_t info;
  233. if (notify_die(DIE_DABR_MATCH, "dabr_match", regs, error_code,
  234. 11, SIGSEGV) == NOTIFY_STOP)
  235. return;
  236. /* Deliver the signal to userspace */
  237. info.si_signo = SIGTRAP;
  238. info.si_errno = breakpt; /* breakpoint or watchpoint id */
  239. info.si_code = signal_code;
  240. info.si_addr = (void __user *)address;
  241. force_sig_info(SIGTRAP, &info, current);
  242. }
  243. #else /* !CONFIG_PPC_ADV_DEBUG_REGS */
  244. void do_dabr(struct pt_regs *regs, unsigned long address,
  245. unsigned long error_code)
  246. {
  247. siginfo_t info;
  248. if (notify_die(DIE_DABR_MATCH, "dabr_match", regs, error_code,
  249. 11, SIGSEGV) == NOTIFY_STOP)
  250. return;
  251. if (debugger_dabr_match(regs))
  252. return;
  253. /* Clear the DABR */
  254. set_dabr(0);
  255. /* Deliver the signal to userspace */
  256. info.si_signo = SIGTRAP;
  257. info.si_errno = 0;
  258. info.si_code = TRAP_HWBKPT;
  259. info.si_addr = (void __user *)address;
  260. force_sig_info(SIGTRAP, &info, current);
  261. }
  262. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  263. static DEFINE_PER_CPU(unsigned long, current_dabr);
  264. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  265. /*
  266. * Set the debug registers back to their default "safe" values.
  267. */
  268. static void set_debug_reg_defaults(struct thread_struct *thread)
  269. {
  270. thread->iac1 = thread->iac2 = 0;
  271. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  272. thread->iac3 = thread->iac4 = 0;
  273. #endif
  274. thread->dac1 = thread->dac2 = 0;
  275. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  276. thread->dvc1 = thread->dvc2 = 0;
  277. #endif
  278. thread->dbcr0 = 0;
  279. #ifdef CONFIG_BOOKE
  280. /*
  281. * Force User/Supervisor bits to b11 (user-only MSR[PR]=1)
  282. */
  283. thread->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US | \
  284. DBCR1_IAC3US | DBCR1_IAC4US;
  285. /*
  286. * Force Data Address Compare User/Supervisor bits to be User-only
  287. * (0b11 MSR[PR]=1) and set all other bits in DBCR2 register to be 0.
  288. */
  289. thread->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
  290. #else
  291. thread->dbcr1 = 0;
  292. #endif
  293. }
  294. static void prime_debug_regs(struct thread_struct *thread)
  295. {
  296. mtspr(SPRN_IAC1, thread->iac1);
  297. mtspr(SPRN_IAC2, thread->iac2);
  298. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  299. mtspr(SPRN_IAC3, thread->iac3);
  300. mtspr(SPRN_IAC4, thread->iac4);
  301. #endif
  302. mtspr(SPRN_DAC1, thread->dac1);
  303. mtspr(SPRN_DAC2, thread->dac2);
  304. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  305. mtspr(SPRN_DVC1, thread->dvc1);
  306. mtspr(SPRN_DVC2, thread->dvc2);
  307. #endif
  308. mtspr(SPRN_DBCR0, thread->dbcr0);
  309. mtspr(SPRN_DBCR1, thread->dbcr1);
  310. #ifdef CONFIG_BOOKE
  311. mtspr(SPRN_DBCR2, thread->dbcr2);
  312. #endif
  313. }
  314. /*
  315. * Unless neither the old or new thread are making use of the
  316. * debug registers, set the debug registers from the values
  317. * stored in the new thread.
  318. */
  319. static void switch_booke_debug_regs(struct thread_struct *new_thread)
  320. {
  321. if ((current->thread.dbcr0 & DBCR0_IDM)
  322. || (new_thread->dbcr0 & DBCR0_IDM))
  323. prime_debug_regs(new_thread);
  324. }
  325. #else /* !CONFIG_PPC_ADV_DEBUG_REGS */
  326. static void set_debug_reg_defaults(struct thread_struct *thread)
  327. {
  328. if (thread->dabr) {
  329. thread->dabr = 0;
  330. set_dabr(0);
  331. }
  332. }
  333. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  334. int set_dabr(unsigned long dabr)
  335. {
  336. __get_cpu_var(current_dabr) = dabr;
  337. if (ppc_md.set_dabr)
  338. return ppc_md.set_dabr(dabr);
  339. /* XXX should we have a CPU_FTR_HAS_DABR ? */
  340. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  341. mtspr(SPRN_DAC1, dabr);
  342. #elif defined(CONFIG_PPC_BOOK3S)
  343. mtspr(SPRN_DABR, dabr);
  344. #endif
  345. return 0;
  346. }
  347. #ifdef CONFIG_PPC64
  348. DEFINE_PER_CPU(struct cpu_usage, cpu_usage_array);
  349. #endif
  350. struct task_struct *__switch_to(struct task_struct *prev,
  351. struct task_struct *new)
  352. {
  353. struct thread_struct *new_thread, *old_thread;
  354. unsigned long flags;
  355. struct task_struct *last;
  356. #ifdef CONFIG_SMP
  357. /* avoid complexity of lazy save/restore of fpu
  358. * by just saving it every time we switch out if
  359. * this task used the fpu during the last quantum.
  360. *
  361. * If it tries to use the fpu again, it'll trap and
  362. * reload its fp regs. So we don't have to do a restore
  363. * every switch, just a save.
  364. * -- Cort
  365. */
  366. if (prev->thread.regs && (prev->thread.regs->msr & MSR_FP))
  367. giveup_fpu(prev);
  368. #ifdef CONFIG_ALTIVEC
  369. /*
  370. * If the previous thread used altivec in the last quantum
  371. * (thus changing altivec regs) then save them.
  372. * We used to check the VRSAVE register but not all apps
  373. * set it, so we don't rely on it now (and in fact we need
  374. * to save & restore VSCR even if VRSAVE == 0). -- paulus
  375. *
  376. * On SMP we always save/restore altivec regs just to avoid the
  377. * complexity of changing processors.
  378. * -- Cort
  379. */
  380. if (prev->thread.regs && (prev->thread.regs->msr & MSR_VEC))
  381. giveup_altivec(prev);
  382. #endif /* CONFIG_ALTIVEC */
  383. #ifdef CONFIG_VSX
  384. if (prev->thread.regs && (prev->thread.regs->msr & MSR_VSX))
  385. /* VMX and FPU registers are already save here */
  386. __giveup_vsx(prev);
  387. #endif /* CONFIG_VSX */
  388. #ifdef CONFIG_SPE
  389. /*
  390. * If the previous thread used spe in the last quantum
  391. * (thus changing spe regs) then save them.
  392. *
  393. * On SMP we always save/restore spe regs just to avoid the
  394. * complexity of changing processors.
  395. */
  396. if ((prev->thread.regs && (prev->thread.regs->msr & MSR_SPE)))
  397. giveup_spe(prev);
  398. #endif /* CONFIG_SPE */
  399. #else /* CONFIG_SMP */
  400. #ifdef CONFIG_ALTIVEC
  401. /* Avoid the trap. On smp this this never happens since
  402. * we don't set last_task_used_altivec -- Cort
  403. */
  404. if (new->thread.regs && last_task_used_altivec == new)
  405. new->thread.regs->msr |= MSR_VEC;
  406. #endif /* CONFIG_ALTIVEC */
  407. #ifdef CONFIG_VSX
  408. if (new->thread.regs && last_task_used_vsx == new)
  409. new->thread.regs->msr |= MSR_VSX;
  410. #endif /* CONFIG_VSX */
  411. #ifdef CONFIG_SPE
  412. /* Avoid the trap. On smp this this never happens since
  413. * we don't set last_task_used_spe
  414. */
  415. if (new->thread.regs && last_task_used_spe == new)
  416. new->thread.regs->msr |= MSR_SPE;
  417. #endif /* CONFIG_SPE */
  418. #endif /* CONFIG_SMP */
  419. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  420. switch_booke_debug_regs(&new->thread);
  421. #else
  422. if (unlikely(__get_cpu_var(current_dabr) != new->thread.dabr))
  423. set_dabr(new->thread.dabr);
  424. #endif
  425. new_thread = &new->thread;
  426. old_thread = &current->thread;
  427. #ifdef CONFIG_PPC64
  428. /*
  429. * Collect processor utilization data per process
  430. */
  431. if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
  432. struct cpu_usage *cu = &__get_cpu_var(cpu_usage_array);
  433. long unsigned start_tb, current_tb;
  434. start_tb = old_thread->start_tb;
  435. cu->current_tb = current_tb = mfspr(SPRN_PURR);
  436. old_thread->accum_tb += (current_tb - start_tb);
  437. new_thread->start_tb = current_tb;
  438. }
  439. #endif
  440. local_irq_save(flags);
  441. account_system_vtime(current);
  442. account_process_vtime(current);
  443. calculate_steal_time();
  444. /*
  445. * We can't take a PMU exception inside _switch() since there is a
  446. * window where the kernel stack SLB and the kernel stack are out
  447. * of sync. Hard disable here.
  448. */
  449. hard_irq_disable();
  450. last = _switch(old_thread, new_thread);
  451. local_irq_restore(flags);
  452. return last;
  453. }
  454. static int instructions_to_print = 16;
  455. static void show_instructions(struct pt_regs *regs)
  456. {
  457. int i;
  458. unsigned long pc = regs->nip - (instructions_to_print * 3 / 4 *
  459. sizeof(int));
  460. printk("Instruction dump:");
  461. for (i = 0; i < instructions_to_print; i++) {
  462. int instr;
  463. if (!(i % 8))
  464. printk("\n");
  465. #if !defined(CONFIG_BOOKE)
  466. /* If executing with the IMMU off, adjust pc rather
  467. * than print XXXXXXXX.
  468. */
  469. if (!(regs->msr & MSR_IR))
  470. pc = (unsigned long)phys_to_virt(pc);
  471. #endif
  472. /* We use __get_user here *only* to avoid an OOPS on a
  473. * bad address because the pc *should* only be a
  474. * kernel address.
  475. */
  476. if (!__kernel_text_address(pc) ||
  477. __get_user(instr, (unsigned int __user *)pc)) {
  478. printk("XXXXXXXX ");
  479. } else {
  480. if (regs->nip == pc)
  481. printk("<%08x> ", instr);
  482. else
  483. printk("%08x ", instr);
  484. }
  485. pc += sizeof(int);
  486. }
  487. printk("\n");
  488. }
  489. static struct regbit {
  490. unsigned long bit;
  491. const char *name;
  492. } msr_bits[] = {
  493. {MSR_EE, "EE"},
  494. {MSR_PR, "PR"},
  495. {MSR_FP, "FP"},
  496. {MSR_VEC, "VEC"},
  497. {MSR_VSX, "VSX"},
  498. {MSR_ME, "ME"},
  499. {MSR_CE, "CE"},
  500. {MSR_DE, "DE"},
  501. {MSR_IR, "IR"},
  502. {MSR_DR, "DR"},
  503. {0, NULL}
  504. };
  505. static void printbits(unsigned long val, struct regbit *bits)
  506. {
  507. const char *sep = "";
  508. printk("<");
  509. for (; bits->bit; ++bits)
  510. if (val & bits->bit) {
  511. printk("%s%s", sep, bits->name);
  512. sep = ",";
  513. }
  514. printk(">");
  515. }
  516. #ifdef CONFIG_PPC64
  517. #define REG "%016lx"
  518. #define REGS_PER_LINE 4
  519. #define LAST_VOLATILE 13
  520. #else
  521. #define REG "%08lx"
  522. #define REGS_PER_LINE 8
  523. #define LAST_VOLATILE 12
  524. #endif
  525. void show_regs(struct pt_regs * regs)
  526. {
  527. int i, trap;
  528. printk("NIP: "REG" LR: "REG" CTR: "REG"\n",
  529. regs->nip, regs->link, regs->ctr);
  530. printk("REGS: %p TRAP: %04lx %s (%s)\n",
  531. regs, regs->trap, print_tainted(), init_utsname()->release);
  532. printk("MSR: "REG" ", regs->msr);
  533. printbits(regs->msr, msr_bits);
  534. printk(" CR: %08lx XER: %08lx\n", regs->ccr, regs->xer);
  535. trap = TRAP(regs);
  536. if (trap == 0x300 || trap == 0x600)
  537. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  538. printk("DEAR: "REG", ESR: "REG"\n", regs->dar, regs->dsisr);
  539. #else
  540. printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
  541. #endif
  542. printk("TASK = %p[%d] '%s' THREAD: %p",
  543. current, task_pid_nr(current), current->comm, task_thread_info(current));
  544. #ifdef CONFIG_SMP
  545. printk(" CPU: %d", raw_smp_processor_id());
  546. #endif /* CONFIG_SMP */
  547. for (i = 0; i < 32; i++) {
  548. if ((i % REGS_PER_LINE) == 0)
  549. printk("\nGPR%02d: ", i);
  550. printk(REG " ", regs->gpr[i]);
  551. if (i == LAST_VOLATILE && !FULL_REGS(regs))
  552. break;
  553. }
  554. printk("\n");
  555. #ifdef CONFIG_KALLSYMS
  556. /*
  557. * Lookup NIP late so we have the best change of getting the
  558. * above info out without failing
  559. */
  560. printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
  561. printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
  562. #endif
  563. show_stack(current, (unsigned long *) regs->gpr[1]);
  564. if (!user_mode(regs))
  565. show_instructions(regs);
  566. }
  567. void exit_thread(void)
  568. {
  569. discard_lazy_cpu_state();
  570. }
  571. void flush_thread(void)
  572. {
  573. discard_lazy_cpu_state();
  574. set_debug_reg_defaults(&current->thread);
  575. }
  576. void
  577. release_thread(struct task_struct *t)
  578. {
  579. }
  580. /*
  581. * This gets called before we allocate a new thread and copy
  582. * the current task into it.
  583. */
  584. void prepare_to_copy(struct task_struct *tsk)
  585. {
  586. flush_fp_to_thread(current);
  587. flush_altivec_to_thread(current);
  588. flush_vsx_to_thread(current);
  589. flush_spe_to_thread(current);
  590. }
  591. /*
  592. * Copy a thread..
  593. */
  594. int copy_thread(unsigned long clone_flags, unsigned long usp,
  595. unsigned long unused, struct task_struct *p,
  596. struct pt_regs *regs)
  597. {
  598. struct pt_regs *childregs, *kregs;
  599. extern void ret_from_fork(void);
  600. unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE;
  601. CHECK_FULL_REGS(regs);
  602. /* Copy registers */
  603. sp -= sizeof(struct pt_regs);
  604. childregs = (struct pt_regs *) sp;
  605. *childregs = *regs;
  606. if ((childregs->msr & MSR_PR) == 0) {
  607. /* for kernel thread, set `current' and stackptr in new task */
  608. childregs->gpr[1] = sp + sizeof(struct pt_regs);
  609. #ifdef CONFIG_PPC32
  610. childregs->gpr[2] = (unsigned long) p;
  611. #else
  612. clear_tsk_thread_flag(p, TIF_32BIT);
  613. #endif
  614. p->thread.regs = NULL; /* no user register state */
  615. } else {
  616. childregs->gpr[1] = usp;
  617. p->thread.regs = childregs;
  618. if (clone_flags & CLONE_SETTLS) {
  619. #ifdef CONFIG_PPC64
  620. if (!test_thread_flag(TIF_32BIT))
  621. childregs->gpr[13] = childregs->gpr[6];
  622. else
  623. #endif
  624. childregs->gpr[2] = childregs->gpr[6];
  625. }
  626. }
  627. childregs->gpr[3] = 0; /* Result from fork() */
  628. sp -= STACK_FRAME_OVERHEAD;
  629. /*
  630. * The way this works is that at some point in the future
  631. * some task will call _switch to switch to the new task.
  632. * That will pop off the stack frame created below and start
  633. * the new task running at ret_from_fork. The new task will
  634. * do some house keeping and then return from the fork or clone
  635. * system call, using the stack frame created above.
  636. */
  637. sp -= sizeof(struct pt_regs);
  638. kregs = (struct pt_regs *) sp;
  639. sp -= STACK_FRAME_OVERHEAD;
  640. p->thread.ksp = sp;
  641. p->thread.ksp_limit = (unsigned long)task_stack_page(p) +
  642. _ALIGN_UP(sizeof(struct thread_info), 16);
  643. #ifdef CONFIG_PPC_STD_MMU_64
  644. if (cpu_has_feature(CPU_FTR_SLB)) {
  645. unsigned long sp_vsid;
  646. unsigned long llp = mmu_psize_defs[mmu_linear_psize].sllp;
  647. if (cpu_has_feature(CPU_FTR_1T_SEGMENT))
  648. sp_vsid = get_kernel_vsid(sp, MMU_SEGSIZE_1T)
  649. << SLB_VSID_SHIFT_1T;
  650. else
  651. sp_vsid = get_kernel_vsid(sp, MMU_SEGSIZE_256M)
  652. << SLB_VSID_SHIFT;
  653. sp_vsid |= SLB_VSID_KERNEL | llp;
  654. p->thread.ksp_vsid = sp_vsid;
  655. }
  656. #endif /* CONFIG_PPC_STD_MMU_64 */
  657. /*
  658. * The PPC64 ABI makes use of a TOC to contain function
  659. * pointers. The function (ret_from_except) is actually a pointer
  660. * to the TOC entry. The first entry is a pointer to the actual
  661. * function.
  662. */
  663. #ifdef CONFIG_PPC64
  664. kregs->nip = *((unsigned long *)ret_from_fork);
  665. #else
  666. kregs->nip = (unsigned long)ret_from_fork;
  667. #endif
  668. return 0;
  669. }
  670. /*
  671. * Set up a thread for executing a new program
  672. */
  673. void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp)
  674. {
  675. #ifdef CONFIG_PPC64
  676. unsigned long load_addr = regs->gpr[2]; /* saved by ELF_PLAT_INIT */
  677. #endif
  678. set_fs(USER_DS);
  679. /*
  680. * If we exec out of a kernel thread then thread.regs will not be
  681. * set. Do it now.
  682. */
  683. if (!current->thread.regs) {
  684. struct pt_regs *regs = task_stack_page(current) + THREAD_SIZE;
  685. current->thread.regs = regs - 1;
  686. }
  687. memset(regs->gpr, 0, sizeof(regs->gpr));
  688. regs->ctr = 0;
  689. regs->link = 0;
  690. regs->xer = 0;
  691. regs->ccr = 0;
  692. regs->gpr[1] = sp;
  693. /*
  694. * We have just cleared all the nonvolatile GPRs, so make
  695. * FULL_REGS(regs) return true. This is necessary to allow
  696. * ptrace to examine the thread immediately after exec.
  697. */
  698. regs->trap &= ~1UL;
  699. #ifdef CONFIG_PPC32
  700. regs->mq = 0;
  701. regs->nip = start;
  702. regs->msr = MSR_USER;
  703. #else
  704. if (!test_thread_flag(TIF_32BIT)) {
  705. unsigned long entry, toc;
  706. /* start is a relocated pointer to the function descriptor for
  707. * the elf _start routine. The first entry in the function
  708. * descriptor is the entry address of _start and the second
  709. * entry is the TOC value we need to use.
  710. */
  711. __get_user(entry, (unsigned long __user *)start);
  712. __get_user(toc, (unsigned long __user *)start+1);
  713. /* Check whether the e_entry function descriptor entries
  714. * need to be relocated before we can use them.
  715. */
  716. if (load_addr != 0) {
  717. entry += load_addr;
  718. toc += load_addr;
  719. }
  720. regs->nip = entry;
  721. regs->gpr[2] = toc;
  722. regs->msr = MSR_USER64;
  723. } else {
  724. regs->nip = start;
  725. regs->gpr[2] = 0;
  726. regs->msr = MSR_USER32;
  727. }
  728. #endif
  729. discard_lazy_cpu_state();
  730. #ifdef CONFIG_VSX
  731. current->thread.used_vsr = 0;
  732. #endif
  733. memset(current->thread.fpr, 0, sizeof(current->thread.fpr));
  734. current->thread.fpscr.val = 0;
  735. #ifdef CONFIG_ALTIVEC
  736. memset(current->thread.vr, 0, sizeof(current->thread.vr));
  737. memset(&current->thread.vscr, 0, sizeof(current->thread.vscr));
  738. current->thread.vscr.u[3] = 0x00010000; /* Java mode disabled */
  739. current->thread.vrsave = 0;
  740. current->thread.used_vr = 0;
  741. #endif /* CONFIG_ALTIVEC */
  742. #ifdef CONFIG_SPE
  743. memset(current->thread.evr, 0, sizeof(current->thread.evr));
  744. current->thread.acc = 0;
  745. current->thread.spefscr = 0;
  746. current->thread.used_spe = 0;
  747. #endif /* CONFIG_SPE */
  748. }
  749. #define PR_FP_ALL_EXCEPT (PR_FP_EXC_DIV | PR_FP_EXC_OVF | PR_FP_EXC_UND \
  750. | PR_FP_EXC_RES | PR_FP_EXC_INV)
  751. int set_fpexc_mode(struct task_struct *tsk, unsigned int val)
  752. {
  753. struct pt_regs *regs = tsk->thread.regs;
  754. /* This is a bit hairy. If we are an SPE enabled processor
  755. * (have embedded fp) we store the IEEE exception enable flags in
  756. * fpexc_mode. fpexc_mode is also used for setting FP exception
  757. * mode (asyn, precise, disabled) for 'Classic' FP. */
  758. if (val & PR_FP_EXC_SW_ENABLE) {
  759. #ifdef CONFIG_SPE
  760. if (cpu_has_feature(CPU_FTR_SPE)) {
  761. tsk->thread.fpexc_mode = val &
  762. (PR_FP_EXC_SW_ENABLE | PR_FP_ALL_EXCEPT);
  763. return 0;
  764. } else {
  765. return -EINVAL;
  766. }
  767. #else
  768. return -EINVAL;
  769. #endif
  770. }
  771. /* on a CONFIG_SPE this does not hurt us. The bits that
  772. * __pack_fe01 use do not overlap with bits used for
  773. * PR_FP_EXC_SW_ENABLE. Additionally, the MSR[FE0,FE1] bits
  774. * on CONFIG_SPE implementations are reserved so writing to
  775. * them does not change anything */
  776. if (val > PR_FP_EXC_PRECISE)
  777. return -EINVAL;
  778. tsk->thread.fpexc_mode = __pack_fe01(val);
  779. if (regs != NULL && (regs->msr & MSR_FP) != 0)
  780. regs->msr = (regs->msr & ~(MSR_FE0|MSR_FE1))
  781. | tsk->thread.fpexc_mode;
  782. return 0;
  783. }
  784. int get_fpexc_mode(struct task_struct *tsk, unsigned long adr)
  785. {
  786. unsigned int val;
  787. if (tsk->thread.fpexc_mode & PR_FP_EXC_SW_ENABLE)
  788. #ifdef CONFIG_SPE
  789. if (cpu_has_feature(CPU_FTR_SPE))
  790. val = tsk->thread.fpexc_mode;
  791. else
  792. return -EINVAL;
  793. #else
  794. return -EINVAL;
  795. #endif
  796. else
  797. val = __unpack_fe01(tsk->thread.fpexc_mode);
  798. return put_user(val, (unsigned int __user *) adr);
  799. }
  800. int set_endian(struct task_struct *tsk, unsigned int val)
  801. {
  802. struct pt_regs *regs = tsk->thread.regs;
  803. if ((val == PR_ENDIAN_LITTLE && !cpu_has_feature(CPU_FTR_REAL_LE)) ||
  804. (val == PR_ENDIAN_PPC_LITTLE && !cpu_has_feature(CPU_FTR_PPC_LE)))
  805. return -EINVAL;
  806. if (regs == NULL)
  807. return -EINVAL;
  808. if (val == PR_ENDIAN_BIG)
  809. regs->msr &= ~MSR_LE;
  810. else if (val == PR_ENDIAN_LITTLE || val == PR_ENDIAN_PPC_LITTLE)
  811. regs->msr |= MSR_LE;
  812. else
  813. return -EINVAL;
  814. return 0;
  815. }
  816. int get_endian(struct task_struct *tsk, unsigned long adr)
  817. {
  818. struct pt_regs *regs = tsk->thread.regs;
  819. unsigned int val;
  820. if (!cpu_has_feature(CPU_FTR_PPC_LE) &&
  821. !cpu_has_feature(CPU_FTR_REAL_LE))
  822. return -EINVAL;
  823. if (regs == NULL)
  824. return -EINVAL;
  825. if (regs->msr & MSR_LE) {
  826. if (cpu_has_feature(CPU_FTR_REAL_LE))
  827. val = PR_ENDIAN_LITTLE;
  828. else
  829. val = PR_ENDIAN_PPC_LITTLE;
  830. } else
  831. val = PR_ENDIAN_BIG;
  832. return put_user(val, (unsigned int __user *)adr);
  833. }
  834. int set_unalign_ctl(struct task_struct *tsk, unsigned int val)
  835. {
  836. tsk->thread.align_ctl = val;
  837. return 0;
  838. }
  839. int get_unalign_ctl(struct task_struct *tsk, unsigned long adr)
  840. {
  841. return put_user(tsk->thread.align_ctl, (unsigned int __user *)adr);
  842. }
  843. #define TRUNC_PTR(x) ((typeof(x))(((unsigned long)(x)) & 0xffffffff))
  844. int sys_clone(unsigned long clone_flags, unsigned long usp,
  845. int __user *parent_tidp, void __user *child_threadptr,
  846. int __user *child_tidp, int p6,
  847. struct pt_regs *regs)
  848. {
  849. CHECK_FULL_REGS(regs);
  850. if (usp == 0)
  851. usp = regs->gpr[1]; /* stack pointer for child */
  852. #ifdef CONFIG_PPC64
  853. if (test_thread_flag(TIF_32BIT)) {
  854. parent_tidp = TRUNC_PTR(parent_tidp);
  855. child_tidp = TRUNC_PTR(child_tidp);
  856. }
  857. #endif
  858. return do_fork(clone_flags, usp, regs, 0, parent_tidp, child_tidp);
  859. }
  860. int sys_fork(unsigned long p1, unsigned long p2, unsigned long p3,
  861. unsigned long p4, unsigned long p5, unsigned long p6,
  862. struct pt_regs *regs)
  863. {
  864. CHECK_FULL_REGS(regs);
  865. return do_fork(SIGCHLD, regs->gpr[1], regs, 0, NULL, NULL);
  866. }
  867. int sys_vfork(unsigned long p1, unsigned long p2, unsigned long p3,
  868. unsigned long p4, unsigned long p5, unsigned long p6,
  869. struct pt_regs *regs)
  870. {
  871. CHECK_FULL_REGS(regs);
  872. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->gpr[1],
  873. regs, 0, NULL, NULL);
  874. }
  875. int sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,
  876. unsigned long a3, unsigned long a4, unsigned long a5,
  877. struct pt_regs *regs)
  878. {
  879. int error;
  880. char *filename;
  881. filename = getname((char __user *) a0);
  882. error = PTR_ERR(filename);
  883. if (IS_ERR(filename))
  884. goto out;
  885. flush_fp_to_thread(current);
  886. flush_altivec_to_thread(current);
  887. flush_spe_to_thread(current);
  888. error = do_execve(filename, (char __user * __user *) a1,
  889. (char __user * __user *) a2, regs);
  890. putname(filename);
  891. out:
  892. return error;
  893. }
  894. #ifdef CONFIG_IRQSTACKS
  895. static inline int valid_irq_stack(unsigned long sp, struct task_struct *p,
  896. unsigned long nbytes)
  897. {
  898. unsigned long stack_page;
  899. unsigned long cpu = task_cpu(p);
  900. /*
  901. * Avoid crashing if the stack has overflowed and corrupted
  902. * task_cpu(p), which is in the thread_info struct.
  903. */
  904. if (cpu < NR_CPUS && cpu_possible(cpu)) {
  905. stack_page = (unsigned long) hardirq_ctx[cpu];
  906. if (sp >= stack_page + sizeof(struct thread_struct)
  907. && sp <= stack_page + THREAD_SIZE - nbytes)
  908. return 1;
  909. stack_page = (unsigned long) softirq_ctx[cpu];
  910. if (sp >= stack_page + sizeof(struct thread_struct)
  911. && sp <= stack_page + THREAD_SIZE - nbytes)
  912. return 1;
  913. }
  914. return 0;
  915. }
  916. #else
  917. #define valid_irq_stack(sp, p, nb) 0
  918. #endif /* CONFIG_IRQSTACKS */
  919. int validate_sp(unsigned long sp, struct task_struct *p,
  920. unsigned long nbytes)
  921. {
  922. unsigned long stack_page = (unsigned long)task_stack_page(p);
  923. if (sp >= stack_page + sizeof(struct thread_struct)
  924. && sp <= stack_page + THREAD_SIZE - nbytes)
  925. return 1;
  926. return valid_irq_stack(sp, p, nbytes);
  927. }
  928. EXPORT_SYMBOL(validate_sp);
  929. unsigned long get_wchan(struct task_struct *p)
  930. {
  931. unsigned long ip, sp;
  932. int count = 0;
  933. if (!p || p == current || p->state == TASK_RUNNING)
  934. return 0;
  935. sp = p->thread.ksp;
  936. if (!validate_sp(sp, p, STACK_FRAME_OVERHEAD))
  937. return 0;
  938. do {
  939. sp = *(unsigned long *)sp;
  940. if (!validate_sp(sp, p, STACK_FRAME_OVERHEAD))
  941. return 0;
  942. if (count > 0) {
  943. ip = ((unsigned long *)sp)[STACK_FRAME_LR_SAVE];
  944. if (!in_sched_functions(ip))
  945. return ip;
  946. }
  947. } while (count++ < 16);
  948. return 0;
  949. }
  950. static int kstack_depth_to_print = CONFIG_PRINT_STACK_DEPTH;
  951. void show_stack(struct task_struct *tsk, unsigned long *stack)
  952. {
  953. unsigned long sp, ip, lr, newsp;
  954. int count = 0;
  955. int firstframe = 1;
  956. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  957. int curr_frame = current->curr_ret_stack;
  958. extern void return_to_handler(void);
  959. unsigned long rth = (unsigned long)return_to_handler;
  960. unsigned long mrth = -1;
  961. #ifdef CONFIG_PPC64
  962. extern void mod_return_to_handler(void);
  963. rth = *(unsigned long *)rth;
  964. mrth = (unsigned long)mod_return_to_handler;
  965. mrth = *(unsigned long *)mrth;
  966. #endif
  967. #endif
  968. sp = (unsigned long) stack;
  969. if (tsk == NULL)
  970. tsk = current;
  971. if (sp == 0) {
  972. if (tsk == current)
  973. asm("mr %0,1" : "=r" (sp));
  974. else
  975. sp = tsk->thread.ksp;
  976. }
  977. lr = 0;
  978. printk("Call Trace:\n");
  979. do {
  980. if (!validate_sp(sp, tsk, STACK_FRAME_OVERHEAD))
  981. return;
  982. stack = (unsigned long *) sp;
  983. newsp = stack[0];
  984. ip = stack[STACK_FRAME_LR_SAVE];
  985. if (!firstframe || ip != lr) {
  986. printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
  987. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  988. if ((ip == rth || ip == mrth) && curr_frame >= 0) {
  989. printk(" (%pS)",
  990. (void *)current->ret_stack[curr_frame].ret);
  991. curr_frame--;
  992. }
  993. #endif
  994. if (firstframe)
  995. printk(" (unreliable)");
  996. printk("\n");
  997. }
  998. firstframe = 0;
  999. /*
  1000. * See if this is an exception frame.
  1001. * We look for the "regshere" marker in the current frame.
  1002. */
  1003. if (validate_sp(sp, tsk, STACK_INT_FRAME_SIZE)
  1004. && stack[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) {
  1005. struct pt_regs *regs = (struct pt_regs *)
  1006. (sp + STACK_FRAME_OVERHEAD);
  1007. lr = regs->link;
  1008. printk("--- Exception: %lx at %pS\n LR = %pS\n",
  1009. regs->trap, (void *)regs->nip, (void *)lr);
  1010. firstframe = 1;
  1011. }
  1012. sp = newsp;
  1013. } while (count++ < kstack_depth_to_print);
  1014. }
  1015. void dump_stack(void)
  1016. {
  1017. show_stack(current, NULL);
  1018. }
  1019. EXPORT_SYMBOL(dump_stack);
  1020. #ifdef CONFIG_PPC64
  1021. void ppc64_runlatch_on(void)
  1022. {
  1023. unsigned long ctrl;
  1024. if (cpu_has_feature(CPU_FTR_CTRL) && !test_thread_flag(TIF_RUNLATCH)) {
  1025. HMT_medium();
  1026. ctrl = mfspr(SPRN_CTRLF);
  1027. ctrl |= CTRL_RUNLATCH;
  1028. mtspr(SPRN_CTRLT, ctrl);
  1029. set_thread_flag(TIF_RUNLATCH);
  1030. }
  1031. }
  1032. void ppc64_runlatch_off(void)
  1033. {
  1034. unsigned long ctrl;
  1035. if (cpu_has_feature(CPU_FTR_CTRL) && test_thread_flag(TIF_RUNLATCH)) {
  1036. HMT_medium();
  1037. clear_thread_flag(TIF_RUNLATCH);
  1038. ctrl = mfspr(SPRN_CTRLF);
  1039. ctrl &= ~CTRL_RUNLATCH;
  1040. mtspr(SPRN_CTRLT, ctrl);
  1041. }
  1042. }
  1043. #endif
  1044. #if THREAD_SHIFT < PAGE_SHIFT
  1045. static struct kmem_cache *thread_info_cache;
  1046. struct thread_info *alloc_thread_info(struct task_struct *tsk)
  1047. {
  1048. struct thread_info *ti;
  1049. ti = kmem_cache_alloc(thread_info_cache, GFP_KERNEL);
  1050. if (unlikely(ti == NULL))
  1051. return NULL;
  1052. #ifdef CONFIG_DEBUG_STACK_USAGE
  1053. memset(ti, 0, THREAD_SIZE);
  1054. #endif
  1055. return ti;
  1056. }
  1057. void free_thread_info(struct thread_info *ti)
  1058. {
  1059. kmem_cache_free(thread_info_cache, ti);
  1060. }
  1061. void thread_info_cache_init(void)
  1062. {
  1063. thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
  1064. THREAD_SIZE, 0, NULL);
  1065. BUG_ON(thread_info_cache == NULL);
  1066. }
  1067. #endif /* THREAD_SHIFT < PAGE_SHIFT */
  1068. unsigned long arch_align_stack(unsigned long sp)
  1069. {
  1070. if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
  1071. sp -= get_random_int() & ~PAGE_MASK;
  1072. return sp & ~0xf;
  1073. }
  1074. static inline unsigned long brk_rnd(void)
  1075. {
  1076. unsigned long rnd = 0;
  1077. /* 8MB for 32bit, 1GB for 64bit */
  1078. if (is_32bit_task())
  1079. rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
  1080. else
  1081. rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
  1082. return rnd << PAGE_SHIFT;
  1083. }
  1084. unsigned long arch_randomize_brk(struct mm_struct *mm)
  1085. {
  1086. unsigned long base = mm->brk;
  1087. unsigned long ret;
  1088. #ifdef CONFIG_PPC_STD_MMU_64
  1089. /*
  1090. * If we are using 1TB segments and we are allowed to randomise
  1091. * the heap, we can put it above 1TB so it is backed by a 1TB
  1092. * segment. Otherwise the heap will be in the bottom 1TB
  1093. * which always uses 256MB segments and this may result in a
  1094. * performance penalty.
  1095. */
  1096. if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
  1097. base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
  1098. #endif
  1099. ret = PAGE_ALIGN(base + brk_rnd());
  1100. if (ret < mm->brk)
  1101. return mm->brk;
  1102. return ret;
  1103. }
  1104. unsigned long randomize_et_dyn(unsigned long base)
  1105. {
  1106. unsigned long ret = PAGE_ALIGN(base + brk_rnd());
  1107. if (ret < base)
  1108. return base;
  1109. return ret;
  1110. }