traps.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. /*
  2. * linux/arch/i386/traps.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. *
  6. * Pentium III FXSR, SSE support
  7. * Gareth Hughes <gareth@valinux.com>, May 2000
  8. */
  9. /*
  10. * 'Traps.c' handles hardware traps and faults after we have saved some
  11. * state in 'asm.s'.
  12. */
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/string.h>
  16. #include <linux/errno.h>
  17. #include <linux/timer.h>
  18. #include <linux/mm.h>
  19. #include <linux/init.h>
  20. #include <linux/delay.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/highmem.h>
  24. #include <linux/kallsyms.h>
  25. #include <linux/ptrace.h>
  26. #include <linux/utsname.h>
  27. #include <linux/kprobes.h>
  28. #include <linux/kexec.h>
  29. #include <linux/unwind.h>
  30. #ifdef CONFIG_EISA
  31. #include <linux/ioport.h>
  32. #include <linux/eisa.h>
  33. #endif
  34. #ifdef CONFIG_MCA
  35. #include <linux/mca.h>
  36. #endif
  37. #include <asm/processor.h>
  38. #include <asm/system.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/io.h>
  41. #include <asm/atomic.h>
  42. #include <asm/debugreg.h>
  43. #include <asm/desc.h>
  44. #include <asm/i387.h>
  45. #include <asm/nmi.h>
  46. #include <asm/unwind.h>
  47. #include <asm/smp.h>
  48. #include <asm/arch_hooks.h>
  49. #include <asm/kdebug.h>
  50. #include <linux/module.h>
  51. #include "mach_traps.h"
  52. asmlinkage int system_call(void);
  53. struct desc_struct default_ldt[] = { { 0, 0 }, { 0, 0 }, { 0, 0 },
  54. { 0, 0 }, { 0, 0 } };
  55. /* Do we ignore FPU interrupts ? */
  56. char ignore_fpu_irq = 0;
  57. /*
  58. * The IDT has to be page-aligned to simplify the Pentium
  59. * F0 0F bug workaround.. We have a special link segment
  60. * for this.
  61. */
  62. struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, };
  63. asmlinkage void divide_error(void);
  64. asmlinkage void debug(void);
  65. asmlinkage void nmi(void);
  66. asmlinkage void int3(void);
  67. asmlinkage void overflow(void);
  68. asmlinkage void bounds(void);
  69. asmlinkage void invalid_op(void);
  70. asmlinkage void device_not_available(void);
  71. asmlinkage void coprocessor_segment_overrun(void);
  72. asmlinkage void invalid_TSS(void);
  73. asmlinkage void segment_not_present(void);
  74. asmlinkage void stack_segment(void);
  75. asmlinkage void general_protection(void);
  76. asmlinkage void page_fault(void);
  77. asmlinkage void coprocessor_error(void);
  78. asmlinkage void simd_coprocessor_error(void);
  79. asmlinkage void alignment_check(void);
  80. asmlinkage void spurious_interrupt_bug(void);
  81. asmlinkage void machine_check(void);
  82. static int kstack_depth_to_print = 24;
  83. #ifdef CONFIG_STACK_UNWIND
  84. static int call_trace = 1;
  85. #else
  86. #define call_trace (-1)
  87. #endif
  88. ATOMIC_NOTIFIER_HEAD(i386die_chain);
  89. int register_die_notifier(struct notifier_block *nb)
  90. {
  91. vmalloc_sync_all();
  92. return atomic_notifier_chain_register(&i386die_chain, nb);
  93. }
  94. EXPORT_SYMBOL(register_die_notifier); /* used modular by kdb */
  95. int unregister_die_notifier(struct notifier_block *nb)
  96. {
  97. return atomic_notifier_chain_unregister(&i386die_chain, nb);
  98. }
  99. EXPORT_SYMBOL(unregister_die_notifier); /* used modular by kdb */
  100. static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
  101. {
  102. return p > (void *)tinfo &&
  103. p < (void *)tinfo + THREAD_SIZE - 3;
  104. }
  105. /*
  106. * Print one address/symbol entries per line.
  107. */
  108. static inline void print_addr_and_symbol(unsigned long addr, char *log_lvl)
  109. {
  110. printk(" [<%08lx>] ", addr);
  111. print_symbol("%s\n", addr);
  112. }
  113. static inline unsigned long print_context_stack(struct thread_info *tinfo,
  114. unsigned long *stack, unsigned long ebp,
  115. char *log_lvl)
  116. {
  117. unsigned long addr;
  118. #ifdef CONFIG_FRAME_POINTER
  119. while (valid_stack_ptr(tinfo, (void *)ebp)) {
  120. addr = *(unsigned long *)(ebp + 4);
  121. print_addr_and_symbol(addr, log_lvl);
  122. /*
  123. * break out of recursive entries (such as
  124. * end_of_stack_stop_unwind_function):
  125. */
  126. if (ebp == *(unsigned long *)ebp)
  127. break;
  128. ebp = *(unsigned long *)ebp;
  129. }
  130. #else
  131. while (valid_stack_ptr(tinfo, stack)) {
  132. addr = *stack++;
  133. if (__kernel_text_address(addr))
  134. print_addr_and_symbol(addr, log_lvl);
  135. }
  136. #endif
  137. return ebp;
  138. }
  139. static asmlinkage int
  140. show_trace_unwind(struct unwind_frame_info *info, void *log_lvl)
  141. {
  142. int n = 0;
  143. while (unwind(info) == 0 && UNW_PC(info)) {
  144. n++;
  145. print_addr_and_symbol(UNW_PC(info), log_lvl);
  146. if (arch_unw_user_mode(info))
  147. break;
  148. }
  149. return n;
  150. }
  151. static void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
  152. unsigned long *stack, char *log_lvl)
  153. {
  154. unsigned long ebp;
  155. if (!task)
  156. task = current;
  157. if (call_trace >= 0) {
  158. int unw_ret = 0;
  159. struct unwind_frame_info info;
  160. if (regs) {
  161. if (unwind_init_frame_info(&info, task, regs) == 0)
  162. unw_ret = show_trace_unwind(&info, log_lvl);
  163. } else if (task == current)
  164. unw_ret = unwind_init_running(&info, show_trace_unwind, log_lvl);
  165. else {
  166. if (unwind_init_blocked(&info, task) == 0)
  167. unw_ret = show_trace_unwind(&info, log_lvl);
  168. }
  169. if (unw_ret > 0) {
  170. if (call_trace == 1 && !arch_unw_user_mode(&info)) {
  171. print_symbol("DWARF2 unwinder stuck at %s\n",
  172. UNW_PC(&info));
  173. if (UNW_SP(&info) >= PAGE_OFFSET) {
  174. printk("Leftover inexact backtrace:\n");
  175. stack = (void *)UNW_SP(&info);
  176. } else
  177. printk("Full inexact backtrace again:\n");
  178. } else if (call_trace >= 1)
  179. return;
  180. else
  181. printk("Full inexact backtrace again:\n");
  182. } else
  183. printk("Inexact backtrace:\n");
  184. }
  185. if (task == current) {
  186. /* Grab ebp right from our regs */
  187. asm ("movl %%ebp, %0" : "=r" (ebp) : );
  188. } else {
  189. /* ebp is the last reg pushed by switch_to */
  190. ebp = *(unsigned long *) task->thread.esp;
  191. }
  192. while (1) {
  193. struct thread_info *context;
  194. context = (struct thread_info *)
  195. ((unsigned long)stack & (~(THREAD_SIZE - 1)));
  196. ebp = print_context_stack(context, stack, ebp, log_lvl);
  197. stack = (unsigned long*)context->previous_esp;
  198. if (!stack)
  199. break;
  200. printk("%s =======================\n", log_lvl);
  201. }
  202. }
  203. void show_trace(struct task_struct *task, struct pt_regs *regs, unsigned long * stack)
  204. {
  205. show_trace_log_lvl(task, regs, stack, "");
  206. }
  207. static void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
  208. unsigned long *esp, char *log_lvl)
  209. {
  210. unsigned long *stack;
  211. int i;
  212. if (esp == NULL) {
  213. if (task)
  214. esp = (unsigned long*)task->thread.esp;
  215. else
  216. esp = (unsigned long *)&esp;
  217. }
  218. stack = esp;
  219. for(i = 0; i < kstack_depth_to_print; i++) {
  220. if (kstack_end(stack))
  221. break;
  222. if (i && ((i % 8) == 0))
  223. printk("\n%s ", log_lvl);
  224. printk("%08lx ", *stack++);
  225. }
  226. printk("\n%sCall Trace:\n", log_lvl);
  227. show_trace_log_lvl(task, regs, esp, log_lvl);
  228. }
  229. void show_stack(struct task_struct *task, unsigned long *esp)
  230. {
  231. printk(" ");
  232. show_stack_log_lvl(task, NULL, esp, "");
  233. }
  234. /*
  235. * The architecture-independent dump_stack generator
  236. */
  237. void dump_stack(void)
  238. {
  239. unsigned long stack;
  240. show_trace(current, NULL, &stack);
  241. }
  242. EXPORT_SYMBOL(dump_stack);
  243. void show_registers(struct pt_regs *regs)
  244. {
  245. int i;
  246. int in_kernel = 1;
  247. unsigned long esp;
  248. unsigned short ss;
  249. esp = (unsigned long) (&regs->esp);
  250. savesegment(ss, ss);
  251. if (user_mode_vm(regs)) {
  252. in_kernel = 0;
  253. esp = regs->esp;
  254. ss = regs->xss & 0xffff;
  255. }
  256. print_modules();
  257. printk(KERN_EMERG "CPU: %d\nEIP: %04x:[<%08lx>] %s VLI\n"
  258. "EFLAGS: %08lx (%s %.*s) \n",
  259. smp_processor_id(), 0xffff & regs->xcs, regs->eip,
  260. print_tainted(), regs->eflags, system_utsname.release,
  261. (int)strcspn(system_utsname.version, " "),
  262. system_utsname.version);
  263. print_symbol(KERN_EMERG "EIP is at %s\n", regs->eip);
  264. printk(KERN_EMERG "eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n",
  265. regs->eax, regs->ebx, regs->ecx, regs->edx);
  266. printk(KERN_EMERG "esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n",
  267. regs->esi, regs->edi, regs->ebp, esp);
  268. printk(KERN_EMERG "ds: %04x es: %04x ss: %04x\n",
  269. regs->xds & 0xffff, regs->xes & 0xffff, ss);
  270. printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)",
  271. TASK_COMM_LEN, current->comm, current->pid,
  272. current_thread_info(), current, current->thread_info);
  273. /*
  274. * When in-kernel, we also print out the stack and code at the
  275. * time of the fault..
  276. */
  277. if (in_kernel) {
  278. u8 __user *eip;
  279. printk("\n" KERN_EMERG "Stack: ");
  280. show_stack_log_lvl(NULL, regs, (unsigned long *)esp, KERN_EMERG);
  281. printk(KERN_EMERG "Code: ");
  282. eip = (u8 __user *)regs->eip - 43;
  283. for (i = 0; i < 64; i++, eip++) {
  284. unsigned char c;
  285. if (eip < (u8 __user *)PAGE_OFFSET || __get_user(c, eip)) {
  286. printk(" Bad EIP value.");
  287. break;
  288. }
  289. if (eip == (u8 __user *)regs->eip)
  290. printk("<%02x> ", c);
  291. else
  292. printk("%02x ", c);
  293. }
  294. }
  295. printk("\n");
  296. }
  297. static void handle_BUG(struct pt_regs *regs)
  298. {
  299. unsigned long eip = regs->eip;
  300. unsigned short ud2;
  301. if (eip < PAGE_OFFSET)
  302. return;
  303. if (__get_user(ud2, (unsigned short __user *)eip))
  304. return;
  305. if (ud2 != 0x0b0f)
  306. return;
  307. printk(KERN_EMERG "------------[ cut here ]------------\n");
  308. #ifdef CONFIG_DEBUG_BUGVERBOSE
  309. do {
  310. unsigned short line;
  311. char *file;
  312. char c;
  313. if (__get_user(line, (unsigned short __user *)(eip + 2)))
  314. break;
  315. if (__get_user(file, (char * __user *)(eip + 4)) ||
  316. (unsigned long)file < PAGE_OFFSET || __get_user(c, file))
  317. file = "<bad filename>";
  318. printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line);
  319. return;
  320. } while (0);
  321. #endif
  322. printk(KERN_EMERG "Kernel BUG at [verbose debug info unavailable]\n");
  323. }
  324. /* This is gone through when something in the kernel
  325. * has done something bad and is about to be terminated.
  326. */
  327. void die(const char * str, struct pt_regs * regs, long err)
  328. {
  329. static struct {
  330. spinlock_t lock;
  331. u32 lock_owner;
  332. int lock_owner_depth;
  333. } die = {
  334. .lock = SPIN_LOCK_UNLOCKED,
  335. .lock_owner = -1,
  336. .lock_owner_depth = 0
  337. };
  338. static int die_counter;
  339. unsigned long flags;
  340. oops_enter();
  341. if (die.lock_owner != raw_smp_processor_id()) {
  342. console_verbose();
  343. spin_lock_irqsave(&die.lock, flags);
  344. die.lock_owner = smp_processor_id();
  345. die.lock_owner_depth = 0;
  346. bust_spinlocks(1);
  347. }
  348. else
  349. local_save_flags(flags);
  350. if (++die.lock_owner_depth < 3) {
  351. int nl = 0;
  352. unsigned long esp;
  353. unsigned short ss;
  354. handle_BUG(regs);
  355. printk(KERN_EMERG "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
  356. #ifdef CONFIG_PREEMPT
  357. printk(KERN_EMERG "PREEMPT ");
  358. nl = 1;
  359. #endif
  360. #ifdef CONFIG_SMP
  361. if (!nl)
  362. printk(KERN_EMERG);
  363. printk("SMP ");
  364. nl = 1;
  365. #endif
  366. #ifdef CONFIG_DEBUG_PAGEALLOC
  367. if (!nl)
  368. printk(KERN_EMERG);
  369. printk("DEBUG_PAGEALLOC");
  370. nl = 1;
  371. #endif
  372. if (nl)
  373. printk("\n");
  374. if (notify_die(DIE_OOPS, str, regs, err,
  375. current->thread.trap_no, SIGSEGV) !=
  376. NOTIFY_STOP) {
  377. show_registers(regs);
  378. /* Executive summary in case the oops scrolled away */
  379. esp = (unsigned long) (&regs->esp);
  380. savesegment(ss, ss);
  381. if (user_mode(regs)) {
  382. esp = regs->esp;
  383. ss = regs->xss & 0xffff;
  384. }
  385. printk(KERN_EMERG "EIP: [<%08lx>] ", regs->eip);
  386. print_symbol("%s", regs->eip);
  387. printk(" SS:ESP %04x:%08lx\n", ss, esp);
  388. }
  389. else
  390. regs = NULL;
  391. } else
  392. printk(KERN_EMERG "Recursive die() failure, output suppressed\n");
  393. bust_spinlocks(0);
  394. die.lock_owner = -1;
  395. spin_unlock_irqrestore(&die.lock, flags);
  396. if (!regs)
  397. return;
  398. if (kexec_should_crash(current))
  399. crash_kexec(regs);
  400. if (in_interrupt())
  401. panic("Fatal exception in interrupt");
  402. if (panic_on_oops)
  403. panic("Fatal exception");
  404. oops_exit();
  405. do_exit(SIGSEGV);
  406. }
  407. static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err)
  408. {
  409. if (!user_mode_vm(regs))
  410. die(str, regs, err);
  411. }
  412. static void __kprobes do_trap(int trapnr, int signr, char *str, int vm86,
  413. struct pt_regs * regs, long error_code,
  414. siginfo_t *info)
  415. {
  416. struct task_struct *tsk = current;
  417. tsk->thread.error_code = error_code;
  418. tsk->thread.trap_no = trapnr;
  419. if (regs->eflags & VM_MASK) {
  420. if (vm86)
  421. goto vm86_trap;
  422. goto trap_signal;
  423. }
  424. if (!user_mode(regs))
  425. goto kernel_trap;
  426. trap_signal: {
  427. if (info)
  428. force_sig_info(signr, info, tsk);
  429. else
  430. force_sig(signr, tsk);
  431. return;
  432. }
  433. kernel_trap: {
  434. if (!fixup_exception(regs))
  435. die(str, regs, error_code);
  436. return;
  437. }
  438. vm86_trap: {
  439. int ret = handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, trapnr);
  440. if (ret) goto trap_signal;
  441. return;
  442. }
  443. }
  444. #define DO_ERROR(trapnr, signr, str, name) \
  445. fastcall void do_##name(struct pt_regs * regs, long error_code) \
  446. { \
  447. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
  448. == NOTIFY_STOP) \
  449. return; \
  450. do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \
  451. }
  452. #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
  453. fastcall void do_##name(struct pt_regs * regs, long error_code) \
  454. { \
  455. siginfo_t info; \
  456. info.si_signo = signr; \
  457. info.si_errno = 0; \
  458. info.si_code = sicode; \
  459. info.si_addr = (void __user *)siaddr; \
  460. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
  461. == NOTIFY_STOP) \
  462. return; \
  463. do_trap(trapnr, signr, str, 0, regs, error_code, &info); \
  464. }
  465. #define DO_VM86_ERROR(trapnr, signr, str, name) \
  466. fastcall void do_##name(struct pt_regs * regs, long error_code) \
  467. { \
  468. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
  469. == NOTIFY_STOP) \
  470. return; \
  471. do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \
  472. }
  473. #define DO_VM86_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
  474. fastcall void do_##name(struct pt_regs * regs, long error_code) \
  475. { \
  476. siginfo_t info; \
  477. info.si_signo = signr; \
  478. info.si_errno = 0; \
  479. info.si_code = sicode; \
  480. info.si_addr = (void __user *)siaddr; \
  481. if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
  482. == NOTIFY_STOP) \
  483. return; \
  484. do_trap(trapnr, signr, str, 1, regs, error_code, &info); \
  485. }
  486. DO_VM86_ERROR_INFO( 0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->eip)
  487. #ifndef CONFIG_KPROBES
  488. DO_VM86_ERROR( 3, SIGTRAP, "int3", int3)
  489. #endif
  490. DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow)
  491. DO_VM86_ERROR( 5, SIGSEGV, "bounds", bounds)
  492. DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->eip)
  493. DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
  494. DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
  495. DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
  496. DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
  497. DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
  498. DO_ERROR_INFO(32, SIGSEGV, "iret exception", iret_error, ILL_BADSTK, 0)
  499. fastcall void __kprobes do_general_protection(struct pt_regs * regs,
  500. long error_code)
  501. {
  502. int cpu = get_cpu();
  503. struct tss_struct *tss = &per_cpu(init_tss, cpu);
  504. struct thread_struct *thread = &current->thread;
  505. /*
  506. * Perform the lazy TSS's I/O bitmap copy. If the TSS has an
  507. * invalid offset set (the LAZY one) and the faulting thread has
  508. * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS
  509. * and we set the offset field correctly. Then we let the CPU to
  510. * restart the faulting instruction.
  511. */
  512. if (tss->io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY &&
  513. thread->io_bitmap_ptr) {
  514. memcpy(tss->io_bitmap, thread->io_bitmap_ptr,
  515. thread->io_bitmap_max);
  516. /*
  517. * If the previously set map was extending to higher ports
  518. * than the current one, pad extra space with 0xff (no access).
  519. */
  520. if (thread->io_bitmap_max < tss->io_bitmap_max)
  521. memset((char *) tss->io_bitmap +
  522. thread->io_bitmap_max, 0xff,
  523. tss->io_bitmap_max - thread->io_bitmap_max);
  524. tss->io_bitmap_max = thread->io_bitmap_max;
  525. tss->io_bitmap_base = IO_BITMAP_OFFSET;
  526. tss->io_bitmap_owner = thread;
  527. put_cpu();
  528. return;
  529. }
  530. put_cpu();
  531. current->thread.error_code = error_code;
  532. current->thread.trap_no = 13;
  533. if (regs->eflags & VM_MASK)
  534. goto gp_in_vm86;
  535. if (!user_mode(regs))
  536. goto gp_in_kernel;
  537. current->thread.error_code = error_code;
  538. current->thread.trap_no = 13;
  539. force_sig(SIGSEGV, current);
  540. return;
  541. gp_in_vm86:
  542. local_irq_enable();
  543. handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
  544. return;
  545. gp_in_kernel:
  546. if (!fixup_exception(regs)) {
  547. if (notify_die(DIE_GPF, "general protection fault", regs,
  548. error_code, 13, SIGSEGV) == NOTIFY_STOP)
  549. return;
  550. die("general protection fault", regs, error_code);
  551. }
  552. }
  553. static void mem_parity_error(unsigned char reason, struct pt_regs * regs)
  554. {
  555. printk(KERN_EMERG "Uhhuh. NMI received. Dazed and confused, but trying "
  556. "to continue\n");
  557. printk(KERN_EMERG "You probably have a hardware problem with your RAM "
  558. "chips\n");
  559. /* Clear and disable the memory parity error line. */
  560. clear_mem_error(reason);
  561. }
  562. static void io_check_error(unsigned char reason, struct pt_regs * regs)
  563. {
  564. unsigned long i;
  565. printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n");
  566. show_registers(regs);
  567. /* Re-enable the IOCK line, wait for a few seconds */
  568. reason = (reason & 0xf) | 8;
  569. outb(reason, 0x61);
  570. i = 2000;
  571. while (--i) udelay(1000);
  572. reason &= ~8;
  573. outb(reason, 0x61);
  574. }
  575. static void unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
  576. {
  577. #ifdef CONFIG_MCA
  578. /* Might actually be able to figure out what the guilty party
  579. * is. */
  580. if( MCA_bus ) {
  581. mca_handle_nmi();
  582. return;
  583. }
  584. #endif
  585. printk("Uhhuh. NMI received for unknown reason %02x on CPU %d.\n",
  586. reason, smp_processor_id());
  587. printk("Dazed and confused, but trying to continue\n");
  588. printk("Do you have a strange power saving mode enabled?\n");
  589. }
  590. static DEFINE_SPINLOCK(nmi_print_lock);
  591. void die_nmi (struct pt_regs *regs, const char *msg)
  592. {
  593. if (notify_die(DIE_NMIWATCHDOG, msg, regs, 0, 2, SIGINT) ==
  594. NOTIFY_STOP)
  595. return;
  596. spin_lock(&nmi_print_lock);
  597. /*
  598. * We are in trouble anyway, lets at least try
  599. * to get a message out.
  600. */
  601. bust_spinlocks(1);
  602. printk(KERN_EMERG "%s", msg);
  603. printk(" on CPU%d, eip %08lx, registers:\n",
  604. smp_processor_id(), regs->eip);
  605. show_registers(regs);
  606. printk(KERN_EMERG "console shuts up ...\n");
  607. console_silent();
  608. spin_unlock(&nmi_print_lock);
  609. bust_spinlocks(0);
  610. /* If we are in kernel we are probably nested up pretty bad
  611. * and might aswell get out now while we still can.
  612. */
  613. if (!user_mode_vm(regs)) {
  614. current->thread.trap_no = 2;
  615. crash_kexec(regs);
  616. }
  617. do_exit(SIGSEGV);
  618. }
  619. static void default_do_nmi(struct pt_regs * regs)
  620. {
  621. unsigned char reason = 0;
  622. /* Only the BSP gets external NMIs from the system. */
  623. if (!smp_processor_id())
  624. reason = get_nmi_reason();
  625. if (!(reason & 0xc0)) {
  626. if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
  627. == NOTIFY_STOP)
  628. return;
  629. #ifdef CONFIG_X86_LOCAL_APIC
  630. /*
  631. * Ok, so this is none of the documented NMI sources,
  632. * so it must be the NMI watchdog.
  633. */
  634. if (nmi_watchdog) {
  635. nmi_watchdog_tick(regs);
  636. return;
  637. }
  638. #endif
  639. unknown_nmi_error(reason, regs);
  640. return;
  641. }
  642. if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
  643. return;
  644. if (reason & 0x80)
  645. mem_parity_error(reason, regs);
  646. if (reason & 0x40)
  647. io_check_error(reason, regs);
  648. /*
  649. * Reassert NMI in case it became active meanwhile
  650. * as it's edge-triggered.
  651. */
  652. reassert_nmi();
  653. }
  654. static int dummy_nmi_callback(struct pt_regs * regs, int cpu)
  655. {
  656. return 0;
  657. }
  658. static nmi_callback_t nmi_callback = dummy_nmi_callback;
  659. fastcall void do_nmi(struct pt_regs * regs, long error_code)
  660. {
  661. int cpu;
  662. nmi_enter();
  663. cpu = smp_processor_id();
  664. ++nmi_count(cpu);
  665. if (!rcu_dereference(nmi_callback)(regs, cpu))
  666. default_do_nmi(regs);
  667. nmi_exit();
  668. }
  669. void set_nmi_callback(nmi_callback_t callback)
  670. {
  671. vmalloc_sync_all();
  672. rcu_assign_pointer(nmi_callback, callback);
  673. }
  674. EXPORT_SYMBOL_GPL(set_nmi_callback);
  675. void unset_nmi_callback(void)
  676. {
  677. nmi_callback = dummy_nmi_callback;
  678. }
  679. EXPORT_SYMBOL_GPL(unset_nmi_callback);
  680. #ifdef CONFIG_KPROBES
  681. fastcall void __kprobes do_int3(struct pt_regs *regs, long error_code)
  682. {
  683. if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
  684. == NOTIFY_STOP)
  685. return;
  686. /* This is an interrupt gate, because kprobes wants interrupts
  687. disabled. Normal trap handlers don't. */
  688. restore_interrupts(regs);
  689. do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
  690. }
  691. #endif
  692. /*
  693. * Our handling of the processor debug registers is non-trivial.
  694. * We do not clear them on entry and exit from the kernel. Therefore
  695. * it is possible to get a watchpoint trap here from inside the kernel.
  696. * However, the code in ./ptrace.c has ensured that the user can
  697. * only set watchpoints on userspace addresses. Therefore the in-kernel
  698. * watchpoint trap can only occur in code which is reading/writing
  699. * from user space. Such code must not hold kernel locks (since it
  700. * can equally take a page fault), therefore it is safe to call
  701. * force_sig_info even though that claims and releases locks.
  702. *
  703. * Code in ./signal.c ensures that the debug control register
  704. * is restored before we deliver any signal, and therefore that
  705. * user code runs with the correct debug control register even though
  706. * we clear it here.
  707. *
  708. * Being careful here means that we don't have to be as careful in a
  709. * lot of more complicated places (task switching can be a bit lazy
  710. * about restoring all the debug state, and ptrace doesn't have to
  711. * find every occurrence of the TF bit that could be saved away even
  712. * by user code)
  713. */
  714. fastcall void __kprobes do_debug(struct pt_regs * regs, long error_code)
  715. {
  716. unsigned int condition;
  717. struct task_struct *tsk = current;
  718. get_debugreg(condition, 6);
  719. if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
  720. SIGTRAP) == NOTIFY_STOP)
  721. return;
  722. /* It's safe to allow irq's after DR6 has been saved */
  723. if (regs->eflags & X86_EFLAGS_IF)
  724. local_irq_enable();
  725. /* Mask out spurious debug traps due to lazy DR7 setting */
  726. if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
  727. if (!tsk->thread.debugreg[7])
  728. goto clear_dr7;
  729. }
  730. if (regs->eflags & VM_MASK)
  731. goto debug_vm86;
  732. /* Save debug status register where ptrace can see it */
  733. tsk->thread.debugreg[6] = condition;
  734. /*
  735. * Single-stepping through TF: make sure we ignore any events in
  736. * kernel space (but re-enable TF when returning to user mode).
  737. */
  738. if (condition & DR_STEP) {
  739. /*
  740. * We already checked v86 mode above, so we can
  741. * check for kernel mode by just checking the CPL
  742. * of CS.
  743. */
  744. if (!user_mode(regs))
  745. goto clear_TF_reenable;
  746. }
  747. /* Ok, finally something we can handle */
  748. send_sigtrap(tsk, regs, error_code);
  749. /* Disable additional traps. They'll be re-enabled when
  750. * the signal is delivered.
  751. */
  752. clear_dr7:
  753. set_debugreg(0, 7);
  754. return;
  755. debug_vm86:
  756. handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1);
  757. return;
  758. clear_TF_reenable:
  759. set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
  760. regs->eflags &= ~TF_MASK;
  761. return;
  762. }
  763. /*
  764. * Note that we play around with the 'TS' bit in an attempt to get
  765. * the correct behaviour even in the presence of the asynchronous
  766. * IRQ13 behaviour
  767. */
  768. void math_error(void __user *eip)
  769. {
  770. struct task_struct * task;
  771. siginfo_t info;
  772. unsigned short cwd, swd;
  773. /*
  774. * Save the info for the exception handler and clear the error.
  775. */
  776. task = current;
  777. save_init_fpu(task);
  778. task->thread.trap_no = 16;
  779. task->thread.error_code = 0;
  780. info.si_signo = SIGFPE;
  781. info.si_errno = 0;
  782. info.si_code = __SI_FAULT;
  783. info.si_addr = eip;
  784. /*
  785. * (~cwd & swd) will mask out exceptions that are not set to unmasked
  786. * status. 0x3f is the exception bits in these regs, 0x200 is the
  787. * C1 reg you need in case of a stack fault, 0x040 is the stack
  788. * fault bit. We should only be taking one exception at a time,
  789. * so if this combination doesn't produce any single exception,
  790. * then we have a bad program that isn't syncronizing its FPU usage
  791. * and it will suffer the consequences since we won't be able to
  792. * fully reproduce the context of the exception
  793. */
  794. cwd = get_fpu_cwd(task);
  795. swd = get_fpu_swd(task);
  796. switch (swd & ~cwd & 0x3f) {
  797. case 0x000: /* No unmasked exception */
  798. return;
  799. default: /* Multiple exceptions */
  800. break;
  801. case 0x001: /* Invalid Op */
  802. /*
  803. * swd & 0x240 == 0x040: Stack Underflow
  804. * swd & 0x240 == 0x240: Stack Overflow
  805. * User must clear the SF bit (0x40) if set
  806. */
  807. info.si_code = FPE_FLTINV;
  808. break;
  809. case 0x002: /* Denormalize */
  810. case 0x010: /* Underflow */
  811. info.si_code = FPE_FLTUND;
  812. break;
  813. case 0x004: /* Zero Divide */
  814. info.si_code = FPE_FLTDIV;
  815. break;
  816. case 0x008: /* Overflow */
  817. info.si_code = FPE_FLTOVF;
  818. break;
  819. case 0x020: /* Precision */
  820. info.si_code = FPE_FLTRES;
  821. break;
  822. }
  823. force_sig_info(SIGFPE, &info, task);
  824. }
  825. fastcall void do_coprocessor_error(struct pt_regs * regs, long error_code)
  826. {
  827. ignore_fpu_irq = 1;
  828. math_error((void __user *)regs->eip);
  829. }
  830. static void simd_math_error(void __user *eip)
  831. {
  832. struct task_struct * task;
  833. siginfo_t info;
  834. unsigned short mxcsr;
  835. /*
  836. * Save the info for the exception handler and clear the error.
  837. */
  838. task = current;
  839. save_init_fpu(task);
  840. task->thread.trap_no = 19;
  841. task->thread.error_code = 0;
  842. info.si_signo = SIGFPE;
  843. info.si_errno = 0;
  844. info.si_code = __SI_FAULT;
  845. info.si_addr = eip;
  846. /*
  847. * The SIMD FPU exceptions are handled a little differently, as there
  848. * is only a single status/control register. Thus, to determine which
  849. * unmasked exception was caught we must mask the exception mask bits
  850. * at 0x1f80, and then use these to mask the exception bits at 0x3f.
  851. */
  852. mxcsr = get_fpu_mxcsr(task);
  853. switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
  854. case 0x000:
  855. default:
  856. break;
  857. case 0x001: /* Invalid Op */
  858. info.si_code = FPE_FLTINV;
  859. break;
  860. case 0x002: /* Denormalize */
  861. case 0x010: /* Underflow */
  862. info.si_code = FPE_FLTUND;
  863. break;
  864. case 0x004: /* Zero Divide */
  865. info.si_code = FPE_FLTDIV;
  866. break;
  867. case 0x008: /* Overflow */
  868. info.si_code = FPE_FLTOVF;
  869. break;
  870. case 0x020: /* Precision */
  871. info.si_code = FPE_FLTRES;
  872. break;
  873. }
  874. force_sig_info(SIGFPE, &info, task);
  875. }
  876. fastcall void do_simd_coprocessor_error(struct pt_regs * regs,
  877. long error_code)
  878. {
  879. if (cpu_has_xmm) {
  880. /* Handle SIMD FPU exceptions on PIII+ processors. */
  881. ignore_fpu_irq = 1;
  882. simd_math_error((void __user *)regs->eip);
  883. } else {
  884. /*
  885. * Handle strange cache flush from user space exception
  886. * in all other cases. This is undocumented behaviour.
  887. */
  888. if (regs->eflags & VM_MASK) {
  889. handle_vm86_fault((struct kernel_vm86_regs *)regs,
  890. error_code);
  891. return;
  892. }
  893. current->thread.trap_no = 19;
  894. current->thread.error_code = error_code;
  895. die_if_kernel("cache flush denied", regs, error_code);
  896. force_sig(SIGSEGV, current);
  897. }
  898. }
  899. fastcall void do_spurious_interrupt_bug(struct pt_regs * regs,
  900. long error_code)
  901. {
  902. #if 0
  903. /* No need to warn about this any longer. */
  904. printk("Ignoring P6 Local APIC Spurious Interrupt Bug...\n");
  905. #endif
  906. }
  907. fastcall void setup_x86_bogus_stack(unsigned char * stk)
  908. {
  909. unsigned long *switch16_ptr, *switch32_ptr;
  910. struct pt_regs *regs;
  911. unsigned long stack_top, stack_bot;
  912. unsigned short iret_frame16_off;
  913. int cpu = smp_processor_id();
  914. /* reserve the space on 32bit stack for the magic switch16 pointer */
  915. memmove(stk, stk + 8, sizeof(struct pt_regs));
  916. switch16_ptr = (unsigned long *)(stk + sizeof(struct pt_regs));
  917. regs = (struct pt_regs *)stk;
  918. /* now the switch32 on 16bit stack */
  919. stack_bot = (unsigned long)&per_cpu(cpu_16bit_stack, cpu);
  920. stack_top = stack_bot + CPU_16BIT_STACK_SIZE;
  921. switch32_ptr = (unsigned long *)(stack_top - 8);
  922. iret_frame16_off = CPU_16BIT_STACK_SIZE - 8 - 20;
  923. /* copy iret frame on 16bit stack */
  924. memcpy((void *)(stack_bot + iret_frame16_off), &regs->eip, 20);
  925. /* fill in the switch pointers */
  926. switch16_ptr[0] = (regs->esp & 0xffff0000) | iret_frame16_off;
  927. switch16_ptr[1] = __ESPFIX_SS;
  928. switch32_ptr[0] = (unsigned long)stk + sizeof(struct pt_regs) +
  929. 8 - CPU_16BIT_STACK_SIZE;
  930. switch32_ptr[1] = __KERNEL_DS;
  931. }
  932. fastcall unsigned char * fixup_x86_bogus_stack(unsigned short sp)
  933. {
  934. unsigned long *switch32_ptr;
  935. unsigned char *stack16, *stack32;
  936. unsigned long stack_top, stack_bot;
  937. int len;
  938. int cpu = smp_processor_id();
  939. stack_bot = (unsigned long)&per_cpu(cpu_16bit_stack, cpu);
  940. stack_top = stack_bot + CPU_16BIT_STACK_SIZE;
  941. switch32_ptr = (unsigned long *)(stack_top - 8);
  942. /* copy the data from 16bit stack to 32bit stack */
  943. len = CPU_16BIT_STACK_SIZE - 8 - sp;
  944. stack16 = (unsigned char *)(stack_bot + sp);
  945. stack32 = (unsigned char *)
  946. (switch32_ptr[0] + CPU_16BIT_STACK_SIZE - 8 - len);
  947. memcpy(stack32, stack16, len);
  948. return stack32;
  949. }
  950. /*
  951. * 'math_state_restore()' saves the current math information in the
  952. * old math state array, and gets the new ones from the current task
  953. *
  954. * Careful.. There are problems with IBM-designed IRQ13 behaviour.
  955. * Don't touch unless you *really* know how it works.
  956. *
  957. * Must be called with kernel preemption disabled (in this case,
  958. * local interrupts are disabled at the call-site in entry.S).
  959. */
  960. asmlinkage void math_state_restore(struct pt_regs regs)
  961. {
  962. struct thread_info *thread = current_thread_info();
  963. struct task_struct *tsk = thread->task;
  964. clts(); /* Allow maths ops (or we recurse) */
  965. if (!tsk_used_math(tsk))
  966. init_fpu(tsk);
  967. restore_fpu(tsk);
  968. thread->status |= TS_USEDFPU; /* So we fnsave on switch_to() */
  969. }
  970. #ifndef CONFIG_MATH_EMULATION
  971. asmlinkage void math_emulate(long arg)
  972. {
  973. printk(KERN_EMERG "math-emulation not enabled and no coprocessor found.\n");
  974. printk(KERN_EMERG "killing %s.\n",current->comm);
  975. force_sig(SIGFPE,current);
  976. schedule();
  977. }
  978. #endif /* CONFIG_MATH_EMULATION */
  979. #ifdef CONFIG_X86_F00F_BUG
  980. void __init trap_init_f00f_bug(void)
  981. {
  982. __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
  983. /*
  984. * Update the IDT descriptor and reload the IDT so that
  985. * it uses the read-only mapped virtual address.
  986. */
  987. idt_descr.address = fix_to_virt(FIX_F00F_IDT);
  988. load_idt(&idt_descr);
  989. }
  990. #endif
  991. #define _set_gate(gate_addr,type,dpl,addr,seg) \
  992. do { \
  993. int __d0, __d1; \
  994. __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
  995. "movw %4,%%dx\n\t" \
  996. "movl %%eax,%0\n\t" \
  997. "movl %%edx,%1" \
  998. :"=m" (*((long *) (gate_addr))), \
  999. "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
  1000. :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
  1001. "3" ((char *) (addr)),"2" ((seg) << 16)); \
  1002. } while (0)
  1003. /*
  1004. * This needs to use 'idt_table' rather than 'idt', and
  1005. * thus use the _nonmapped_ version of the IDT, as the
  1006. * Pentium F0 0F bugfix can have resulted in the mapped
  1007. * IDT being write-protected.
  1008. */
  1009. void set_intr_gate(unsigned int n, void *addr)
  1010. {
  1011. _set_gate(idt_table+n,14,0,addr,__KERNEL_CS);
  1012. }
  1013. /*
  1014. * This routine sets up an interrupt gate at directory privilege level 3.
  1015. */
  1016. static inline void set_system_intr_gate(unsigned int n, void *addr)
  1017. {
  1018. _set_gate(idt_table+n, 14, 3, addr, __KERNEL_CS);
  1019. }
  1020. static void __init set_trap_gate(unsigned int n, void *addr)
  1021. {
  1022. _set_gate(idt_table+n,15,0,addr,__KERNEL_CS);
  1023. }
  1024. static void __init set_system_gate(unsigned int n, void *addr)
  1025. {
  1026. _set_gate(idt_table+n,15,3,addr,__KERNEL_CS);
  1027. }
  1028. static void __init set_task_gate(unsigned int n, unsigned int gdt_entry)
  1029. {
  1030. _set_gate(idt_table+n,5,0,0,(gdt_entry<<3));
  1031. }
  1032. void __init trap_init(void)
  1033. {
  1034. #ifdef CONFIG_EISA
  1035. void __iomem *p = ioremap(0x0FFFD9, 4);
  1036. if (readl(p) == 'E'+('I'<<8)+('S'<<16)+('A'<<24)) {
  1037. EISA_bus = 1;
  1038. }
  1039. iounmap(p);
  1040. #endif
  1041. #ifdef CONFIG_X86_LOCAL_APIC
  1042. init_apic_mappings();
  1043. #endif
  1044. set_trap_gate(0,&divide_error);
  1045. set_intr_gate(1,&debug);
  1046. set_intr_gate(2,&nmi);
  1047. set_system_intr_gate(3, &int3); /* int3/4 can be called from all */
  1048. set_system_gate(4,&overflow);
  1049. set_trap_gate(5,&bounds);
  1050. set_trap_gate(6,&invalid_op);
  1051. set_trap_gate(7,&device_not_available);
  1052. set_task_gate(8,GDT_ENTRY_DOUBLEFAULT_TSS);
  1053. set_trap_gate(9,&coprocessor_segment_overrun);
  1054. set_trap_gate(10,&invalid_TSS);
  1055. set_trap_gate(11,&segment_not_present);
  1056. set_trap_gate(12,&stack_segment);
  1057. set_trap_gate(13,&general_protection);
  1058. set_intr_gate(14,&page_fault);
  1059. set_trap_gate(15,&spurious_interrupt_bug);
  1060. set_trap_gate(16,&coprocessor_error);
  1061. set_trap_gate(17,&alignment_check);
  1062. #ifdef CONFIG_X86_MCE
  1063. set_trap_gate(18,&machine_check);
  1064. #endif
  1065. set_trap_gate(19,&simd_coprocessor_error);
  1066. if (cpu_has_fxsr) {
  1067. /*
  1068. * Verify that the FXSAVE/FXRSTOR data will be 16-byte aligned.
  1069. * Generates a compile-time "error: zero width for bit-field" if
  1070. * the alignment is wrong.
  1071. */
  1072. struct fxsrAlignAssert {
  1073. int _:!(offsetof(struct task_struct,
  1074. thread.i387.fxsave) & 15);
  1075. };
  1076. printk(KERN_INFO "Enabling fast FPU save and restore... ");
  1077. set_in_cr4(X86_CR4_OSFXSR);
  1078. printk("done.\n");
  1079. }
  1080. if (cpu_has_xmm) {
  1081. printk(KERN_INFO "Enabling unmasked SIMD FPU exception "
  1082. "support... ");
  1083. set_in_cr4(X86_CR4_OSXMMEXCPT);
  1084. printk("done.\n");
  1085. }
  1086. set_system_gate(SYSCALL_VECTOR,&system_call);
  1087. /*
  1088. * Should be a barrier for any external CPU state.
  1089. */
  1090. cpu_init();
  1091. trap_init_hook();
  1092. }
  1093. static int __init kstack_setup(char *s)
  1094. {
  1095. kstack_depth_to_print = simple_strtoul(s, NULL, 0);
  1096. return 1;
  1097. }
  1098. __setup("kstack=", kstack_setup);
  1099. #ifdef CONFIG_STACK_UNWIND
  1100. static int __init call_trace_setup(char *s)
  1101. {
  1102. if (strcmp(s, "old") == 0)
  1103. call_trace = -1;
  1104. else if (strcmp(s, "both") == 0)
  1105. call_trace = 0;
  1106. else if (strcmp(s, "newfallback") == 0)
  1107. call_trace = 1;
  1108. else if (strcmp(s, "new") == 2)
  1109. call_trace = 2;
  1110. return 1;
  1111. }
  1112. __setup("call_trace=", call_trace_setup);
  1113. #endif