nmi.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. * linux/arch/i386/nmi.c
  3. *
  4. * NMI watchdog support on APIC systems
  5. *
  6. * Started by Ingo Molnar <mingo@redhat.com>
  7. *
  8. * Fixes:
  9. * Mikael Pettersson : AMD K7 support for local APIC NMI watchdog.
  10. * Mikael Pettersson : Power Management for local APIC NMI watchdog.
  11. * Mikael Pettersson : Pentium 4 support for local APIC NMI watchdog.
  12. * Pavel Machek and
  13. * Mikael Pettersson : PM converted to driver model. Disable/enable API.
  14. */
  15. #include <linux/config.h>
  16. #include <linux/mm.h>
  17. #include <linux/delay.h>
  18. #include <linux/bootmem.h>
  19. #include <linux/smp_lock.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/mc146818rtc.h>
  22. #include <linux/kernel_stat.h>
  23. #include <linux/module.h>
  24. #include <linux/nmi.h>
  25. #include <linux/sysdev.h>
  26. #include <linux/sysctl.h>
  27. #include <asm/smp.h>
  28. #include <asm/div64.h>
  29. #include <asm/nmi.h>
  30. #include "mach_traps.h"
  31. unsigned int nmi_watchdog = NMI_NONE;
  32. extern int unknown_nmi_panic;
  33. static unsigned int nmi_hz = HZ;
  34. static unsigned int nmi_perfctr_msr; /* the MSR to reset in NMI handler */
  35. static unsigned int nmi_p4_cccr_val;
  36. extern void show_registers(struct pt_regs *regs);
  37. /*
  38. * lapic_nmi_owner tracks the ownership of the lapic NMI hardware:
  39. * - it may be reserved by some other driver, or not
  40. * - when not reserved by some other driver, it may be used for
  41. * the NMI watchdog, or not
  42. *
  43. * This is maintained separately from nmi_active because the NMI
  44. * watchdog may also be driven from the I/O APIC timer.
  45. */
  46. static DEFINE_SPINLOCK(lapic_nmi_owner_lock);
  47. static unsigned int lapic_nmi_owner;
  48. #define LAPIC_NMI_WATCHDOG (1<<0)
  49. #define LAPIC_NMI_RESERVED (1<<1)
  50. /* nmi_active:
  51. * +1: the lapic NMI watchdog is active, but can be disabled
  52. * 0: the lapic NMI watchdog has not been set up, and cannot
  53. * be enabled
  54. * -1: the lapic NMI watchdog is disabled, but can be enabled
  55. */
  56. int nmi_active;
  57. #define K7_EVNTSEL_ENABLE (1 << 22)
  58. #define K7_EVNTSEL_INT (1 << 20)
  59. #define K7_EVNTSEL_OS (1 << 17)
  60. #define K7_EVNTSEL_USR (1 << 16)
  61. #define K7_EVENT_CYCLES_PROCESSOR_IS_RUNNING 0x76
  62. #define K7_NMI_EVENT K7_EVENT_CYCLES_PROCESSOR_IS_RUNNING
  63. #define P6_EVNTSEL0_ENABLE (1 << 22)
  64. #define P6_EVNTSEL_INT (1 << 20)
  65. #define P6_EVNTSEL_OS (1 << 17)
  66. #define P6_EVNTSEL_USR (1 << 16)
  67. #define P6_EVENT_CPU_CLOCKS_NOT_HALTED 0x79
  68. #define P6_NMI_EVENT P6_EVENT_CPU_CLOCKS_NOT_HALTED
  69. #define MSR_P4_MISC_ENABLE 0x1A0
  70. #define MSR_P4_MISC_ENABLE_PERF_AVAIL (1<<7)
  71. #define MSR_P4_MISC_ENABLE_PEBS_UNAVAIL (1<<12)
  72. #define MSR_P4_PERFCTR0 0x300
  73. #define MSR_P4_CCCR0 0x360
  74. #define P4_ESCR_EVENT_SELECT(N) ((N)<<25)
  75. #define P4_ESCR_OS (1<<3)
  76. #define P4_ESCR_USR (1<<2)
  77. #define P4_CCCR_OVF_PMI0 (1<<26)
  78. #define P4_CCCR_OVF_PMI1 (1<<27)
  79. #define P4_CCCR_THRESHOLD(N) ((N)<<20)
  80. #define P4_CCCR_COMPLEMENT (1<<19)
  81. #define P4_CCCR_COMPARE (1<<18)
  82. #define P4_CCCR_REQUIRED (3<<16)
  83. #define P4_CCCR_ESCR_SELECT(N) ((N)<<13)
  84. #define P4_CCCR_ENABLE (1<<12)
  85. /* Set up IQ_COUNTER0 to behave like a clock, by having IQ_CCCR0 filter
  86. CRU_ESCR0 (with any non-null event selector) through a complemented
  87. max threshold. [IA32-Vol3, Section 14.9.9] */
  88. #define MSR_P4_IQ_COUNTER0 0x30C
  89. #define P4_NMI_CRU_ESCR0 (P4_ESCR_EVENT_SELECT(0x3F)|P4_ESCR_OS|P4_ESCR_USR)
  90. #define P4_NMI_IQ_CCCR0 \
  91. (P4_CCCR_OVF_PMI0|P4_CCCR_THRESHOLD(15)|P4_CCCR_COMPLEMENT| \
  92. P4_CCCR_COMPARE|P4_CCCR_REQUIRED|P4_CCCR_ESCR_SELECT(4)|P4_CCCR_ENABLE)
  93. #ifdef CONFIG_SMP
  94. /* The performance counters used by NMI_LOCAL_APIC don't trigger when
  95. * the CPU is idle. To make sure the NMI watchdog really ticks on all
  96. * CPUs during the test make them busy.
  97. */
  98. static __init void nmi_cpu_busy(void *data)
  99. {
  100. volatile int *endflag = data;
  101. local_irq_enable();
  102. /* Intentionally don't use cpu_relax here. This is
  103. to make sure that the performance counter really ticks,
  104. even if there is a simulator or similar that catches the
  105. pause instruction. On a real HT machine this is fine because
  106. all other CPUs are busy with "useless" delay loops and don't
  107. care if they get somewhat less cycles. */
  108. while (*endflag == 0)
  109. barrier();
  110. }
  111. #endif
  112. static int __init check_nmi_watchdog(void)
  113. {
  114. volatile int endflag = 0;
  115. unsigned int *prev_nmi_count;
  116. int cpu;
  117. if (nmi_watchdog == NMI_NONE)
  118. return 0;
  119. prev_nmi_count = kmalloc(NR_CPUS * sizeof(int), GFP_KERNEL);
  120. if (!prev_nmi_count)
  121. return -1;
  122. printk(KERN_INFO "Testing NMI watchdog ... ");
  123. if (nmi_watchdog == NMI_LOCAL_APIC)
  124. smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0);
  125. for_each_possible_cpu(cpu)
  126. prev_nmi_count[cpu] = per_cpu(irq_stat, cpu).__nmi_count;
  127. local_irq_enable();
  128. mdelay((10*1000)/nmi_hz); // wait 10 ticks
  129. for_each_possible_cpu(cpu) {
  130. #ifdef CONFIG_SMP
  131. /* Check cpu_callin_map here because that is set
  132. after the timer is started. */
  133. if (!cpu_isset(cpu, cpu_callin_map))
  134. continue;
  135. #endif
  136. if (nmi_count(cpu) - prev_nmi_count[cpu] <= 5) {
  137. endflag = 1;
  138. printk("CPU#%d: NMI appears to be stuck (%d->%d)!\n",
  139. cpu,
  140. prev_nmi_count[cpu],
  141. nmi_count(cpu));
  142. nmi_active = 0;
  143. lapic_nmi_owner &= ~LAPIC_NMI_WATCHDOG;
  144. kfree(prev_nmi_count);
  145. return -1;
  146. }
  147. }
  148. endflag = 1;
  149. printk("OK.\n");
  150. /* now that we know it works we can reduce NMI frequency to
  151. something more reasonable; makes a difference in some configs */
  152. if (nmi_watchdog == NMI_LOCAL_APIC)
  153. nmi_hz = 1;
  154. kfree(prev_nmi_count);
  155. return 0;
  156. }
  157. /* This needs to happen later in boot so counters are working */
  158. late_initcall(check_nmi_watchdog);
  159. static int __init setup_nmi_watchdog(char *str)
  160. {
  161. int nmi;
  162. get_option(&str, &nmi);
  163. if (nmi >= NMI_INVALID)
  164. return 0;
  165. if (nmi == NMI_NONE)
  166. nmi_watchdog = nmi;
  167. /*
  168. * If any other x86 CPU has a local APIC, then
  169. * please test the NMI stuff there and send me the
  170. * missing bits. Right now Intel P6/P4 and AMD K7 only.
  171. */
  172. if ((nmi == NMI_LOCAL_APIC) &&
  173. (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
  174. (boot_cpu_data.x86 == 6 || boot_cpu_data.x86 == 15))
  175. nmi_watchdog = nmi;
  176. if ((nmi == NMI_LOCAL_APIC) &&
  177. (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) &&
  178. (boot_cpu_data.x86 == 6 || boot_cpu_data.x86 == 15))
  179. nmi_watchdog = nmi;
  180. /*
  181. * We can enable the IO-APIC watchdog
  182. * unconditionally.
  183. */
  184. if (nmi == NMI_IO_APIC) {
  185. nmi_active = 1;
  186. nmi_watchdog = nmi;
  187. }
  188. return 1;
  189. }
  190. __setup("nmi_watchdog=", setup_nmi_watchdog);
  191. static void disable_lapic_nmi_watchdog(void)
  192. {
  193. if (nmi_active <= 0)
  194. return;
  195. switch (boot_cpu_data.x86_vendor) {
  196. case X86_VENDOR_AMD:
  197. wrmsr(MSR_K7_EVNTSEL0, 0, 0);
  198. break;
  199. case X86_VENDOR_INTEL:
  200. switch (boot_cpu_data.x86) {
  201. case 6:
  202. if (boot_cpu_data.x86_model > 0xd)
  203. break;
  204. wrmsr(MSR_P6_EVNTSEL0, 0, 0);
  205. break;
  206. case 15:
  207. if (boot_cpu_data.x86_model > 0x4)
  208. break;
  209. wrmsr(MSR_P4_IQ_CCCR0, 0, 0);
  210. wrmsr(MSR_P4_CRU_ESCR0, 0, 0);
  211. break;
  212. }
  213. break;
  214. }
  215. nmi_active = -1;
  216. /* tell do_nmi() and others that we're not active any more */
  217. nmi_watchdog = 0;
  218. }
  219. static void enable_lapic_nmi_watchdog(void)
  220. {
  221. if (nmi_active < 0) {
  222. nmi_watchdog = NMI_LOCAL_APIC;
  223. setup_apic_nmi_watchdog();
  224. }
  225. }
  226. int reserve_lapic_nmi(void)
  227. {
  228. unsigned int old_owner;
  229. spin_lock(&lapic_nmi_owner_lock);
  230. old_owner = lapic_nmi_owner;
  231. lapic_nmi_owner |= LAPIC_NMI_RESERVED;
  232. spin_unlock(&lapic_nmi_owner_lock);
  233. if (old_owner & LAPIC_NMI_RESERVED)
  234. return -EBUSY;
  235. if (old_owner & LAPIC_NMI_WATCHDOG)
  236. disable_lapic_nmi_watchdog();
  237. return 0;
  238. }
  239. void release_lapic_nmi(void)
  240. {
  241. unsigned int new_owner;
  242. spin_lock(&lapic_nmi_owner_lock);
  243. new_owner = lapic_nmi_owner & ~LAPIC_NMI_RESERVED;
  244. lapic_nmi_owner = new_owner;
  245. spin_unlock(&lapic_nmi_owner_lock);
  246. if (new_owner & LAPIC_NMI_WATCHDOG)
  247. enable_lapic_nmi_watchdog();
  248. }
  249. void disable_timer_nmi_watchdog(void)
  250. {
  251. if ((nmi_watchdog != NMI_IO_APIC) || (nmi_active <= 0))
  252. return;
  253. unset_nmi_callback();
  254. nmi_active = -1;
  255. nmi_watchdog = NMI_NONE;
  256. }
  257. void enable_timer_nmi_watchdog(void)
  258. {
  259. if (nmi_active < 0) {
  260. nmi_watchdog = NMI_IO_APIC;
  261. touch_nmi_watchdog();
  262. nmi_active = 1;
  263. }
  264. }
  265. #ifdef CONFIG_PM
  266. static int nmi_pm_active; /* nmi_active before suspend */
  267. static int lapic_nmi_suspend(struct sys_device *dev, pm_message_t state)
  268. {
  269. nmi_pm_active = nmi_active;
  270. disable_lapic_nmi_watchdog();
  271. return 0;
  272. }
  273. static int lapic_nmi_resume(struct sys_device *dev)
  274. {
  275. if (nmi_pm_active > 0)
  276. enable_lapic_nmi_watchdog();
  277. return 0;
  278. }
  279. static struct sysdev_class nmi_sysclass = {
  280. set_kset_name("lapic_nmi"),
  281. .resume = lapic_nmi_resume,
  282. .suspend = lapic_nmi_suspend,
  283. };
  284. static struct sys_device device_lapic_nmi = {
  285. .id = 0,
  286. .cls = &nmi_sysclass,
  287. };
  288. static int __init init_lapic_nmi_sysfs(void)
  289. {
  290. int error;
  291. if (nmi_active == 0 || nmi_watchdog != NMI_LOCAL_APIC)
  292. return 0;
  293. error = sysdev_class_register(&nmi_sysclass);
  294. if (!error)
  295. error = sysdev_register(&device_lapic_nmi);
  296. return error;
  297. }
  298. /* must come after the local APIC's device_initcall() */
  299. late_initcall(init_lapic_nmi_sysfs);
  300. #endif /* CONFIG_PM */
  301. /*
  302. * Activate the NMI watchdog via the local APIC.
  303. * Original code written by Keith Owens.
  304. */
  305. static void clear_msr_range(unsigned int base, unsigned int n)
  306. {
  307. unsigned int i;
  308. for(i = 0; i < n; ++i)
  309. wrmsr(base+i, 0, 0);
  310. }
  311. static void write_watchdog_counter(const char *descr)
  312. {
  313. u64 count = (u64)cpu_khz * 1000;
  314. do_div(count, nmi_hz);
  315. if(descr)
  316. Dprintk("setting %s to -0x%08Lx\n", descr, count);
  317. wrmsrl(nmi_perfctr_msr, 0 - count);
  318. }
  319. static void setup_k7_watchdog(void)
  320. {
  321. unsigned int evntsel;
  322. nmi_perfctr_msr = MSR_K7_PERFCTR0;
  323. clear_msr_range(MSR_K7_EVNTSEL0, 4);
  324. clear_msr_range(MSR_K7_PERFCTR0, 4);
  325. evntsel = K7_EVNTSEL_INT
  326. | K7_EVNTSEL_OS
  327. | K7_EVNTSEL_USR
  328. | K7_NMI_EVENT;
  329. wrmsr(MSR_K7_EVNTSEL0, evntsel, 0);
  330. write_watchdog_counter("K7_PERFCTR0");
  331. apic_write(APIC_LVTPC, APIC_DM_NMI);
  332. evntsel |= K7_EVNTSEL_ENABLE;
  333. wrmsr(MSR_K7_EVNTSEL0, evntsel, 0);
  334. }
  335. static void setup_p6_watchdog(void)
  336. {
  337. unsigned int evntsel;
  338. nmi_perfctr_msr = MSR_P6_PERFCTR0;
  339. clear_msr_range(MSR_P6_EVNTSEL0, 2);
  340. clear_msr_range(MSR_P6_PERFCTR0, 2);
  341. evntsel = P6_EVNTSEL_INT
  342. | P6_EVNTSEL_OS
  343. | P6_EVNTSEL_USR
  344. | P6_NMI_EVENT;
  345. wrmsr(MSR_P6_EVNTSEL0, evntsel, 0);
  346. write_watchdog_counter("P6_PERFCTR0");
  347. apic_write(APIC_LVTPC, APIC_DM_NMI);
  348. evntsel |= P6_EVNTSEL0_ENABLE;
  349. wrmsr(MSR_P6_EVNTSEL0, evntsel, 0);
  350. }
  351. static int setup_p4_watchdog(void)
  352. {
  353. unsigned int misc_enable, dummy;
  354. rdmsr(MSR_P4_MISC_ENABLE, misc_enable, dummy);
  355. if (!(misc_enable & MSR_P4_MISC_ENABLE_PERF_AVAIL))
  356. return 0;
  357. nmi_perfctr_msr = MSR_P4_IQ_COUNTER0;
  358. nmi_p4_cccr_val = P4_NMI_IQ_CCCR0;
  359. #ifdef CONFIG_SMP
  360. if (smp_num_siblings == 2)
  361. nmi_p4_cccr_val |= P4_CCCR_OVF_PMI1;
  362. #endif
  363. if (!(misc_enable & MSR_P4_MISC_ENABLE_PEBS_UNAVAIL))
  364. clear_msr_range(0x3F1, 2);
  365. /* MSR 0x3F0 seems to have a default value of 0xFC00, but current
  366. docs doesn't fully define it, so leave it alone for now. */
  367. if (boot_cpu_data.x86_model >= 0x3) {
  368. /* MSR_P4_IQ_ESCR0/1 (0x3ba/0x3bb) removed */
  369. clear_msr_range(0x3A0, 26);
  370. clear_msr_range(0x3BC, 3);
  371. } else {
  372. clear_msr_range(0x3A0, 31);
  373. }
  374. clear_msr_range(0x3C0, 6);
  375. clear_msr_range(0x3C8, 6);
  376. clear_msr_range(0x3E0, 2);
  377. clear_msr_range(MSR_P4_CCCR0, 18);
  378. clear_msr_range(MSR_P4_PERFCTR0, 18);
  379. wrmsr(MSR_P4_CRU_ESCR0, P4_NMI_CRU_ESCR0, 0);
  380. wrmsr(MSR_P4_IQ_CCCR0, P4_NMI_IQ_CCCR0 & ~P4_CCCR_ENABLE, 0);
  381. write_watchdog_counter("P4_IQ_COUNTER0");
  382. apic_write(APIC_LVTPC, APIC_DM_NMI);
  383. wrmsr(MSR_P4_IQ_CCCR0, nmi_p4_cccr_val, 0);
  384. return 1;
  385. }
  386. void setup_apic_nmi_watchdog (void)
  387. {
  388. switch (boot_cpu_data.x86_vendor) {
  389. case X86_VENDOR_AMD:
  390. if (boot_cpu_data.x86 != 6 && boot_cpu_data.x86 != 15)
  391. return;
  392. setup_k7_watchdog();
  393. break;
  394. case X86_VENDOR_INTEL:
  395. switch (boot_cpu_data.x86) {
  396. case 6:
  397. if (boot_cpu_data.x86_model > 0xd)
  398. return;
  399. setup_p6_watchdog();
  400. break;
  401. case 15:
  402. if (boot_cpu_data.x86_model > 0x4)
  403. return;
  404. if (!setup_p4_watchdog())
  405. return;
  406. break;
  407. default:
  408. return;
  409. }
  410. break;
  411. default:
  412. return;
  413. }
  414. lapic_nmi_owner = LAPIC_NMI_WATCHDOG;
  415. nmi_active = 1;
  416. }
  417. /*
  418. * the best way to detect whether a CPU has a 'hard lockup' problem
  419. * is to check it's local APIC timer IRQ counts. If they are not
  420. * changing then that CPU has some problem.
  421. *
  422. * as these watchdog NMI IRQs are generated on every CPU, we only
  423. * have to check the current processor.
  424. *
  425. * since NMIs don't listen to _any_ locks, we have to be extremely
  426. * careful not to rely on unsafe variables. The printk might lock
  427. * up though, so we have to break up any console locks first ...
  428. * [when there will be more tty-related locks, break them up
  429. * here too!]
  430. */
  431. static unsigned int
  432. last_irq_sums [NR_CPUS],
  433. alert_counter [NR_CPUS];
  434. void touch_nmi_watchdog (void)
  435. {
  436. int i;
  437. /*
  438. * Just reset the alert counters, (other CPUs might be
  439. * spinning on locks we hold):
  440. */
  441. for_each_possible_cpu(i)
  442. alert_counter[i] = 0;
  443. /*
  444. * Tickle the softlockup detector too:
  445. */
  446. touch_softlockup_watchdog();
  447. }
  448. extern void die_nmi(struct pt_regs *, const char *msg);
  449. void nmi_watchdog_tick (struct pt_regs * regs)
  450. {
  451. /*
  452. * Since current_thread_info()-> is always on the stack, and we
  453. * always switch the stack NMI-atomically, it's safe to use
  454. * smp_processor_id().
  455. */
  456. unsigned int sum;
  457. int cpu = smp_processor_id();
  458. sum = per_cpu(irq_stat, cpu).apic_timer_irqs;
  459. if (last_irq_sums[cpu] == sum) {
  460. /*
  461. * Ayiee, looks like this CPU is stuck ...
  462. * wait a few IRQs (5 seconds) before doing the oops ...
  463. */
  464. alert_counter[cpu]++;
  465. if (alert_counter[cpu] == 5*nmi_hz)
  466. /*
  467. * die_nmi will return ONLY if NOTIFY_STOP happens..
  468. */
  469. die_nmi(regs, "BUG: NMI Watchdog detected LOCKUP");
  470. } else {
  471. last_irq_sums[cpu] = sum;
  472. alert_counter[cpu] = 0;
  473. }
  474. if (nmi_perfctr_msr) {
  475. if (nmi_perfctr_msr == MSR_P4_IQ_COUNTER0) {
  476. /*
  477. * P4 quirks:
  478. * - An overflown perfctr will assert its interrupt
  479. * until the OVF flag in its CCCR is cleared.
  480. * - LVTPC is masked on interrupt and must be
  481. * unmasked by the LVTPC handler.
  482. */
  483. wrmsr(MSR_P4_IQ_CCCR0, nmi_p4_cccr_val, 0);
  484. apic_write(APIC_LVTPC, APIC_DM_NMI);
  485. }
  486. else if (nmi_perfctr_msr == MSR_P6_PERFCTR0) {
  487. /* Only P6 based Pentium M need to re-unmask
  488. * the apic vector but it doesn't hurt
  489. * other P6 variant */
  490. apic_write(APIC_LVTPC, APIC_DM_NMI);
  491. }
  492. write_watchdog_counter(NULL);
  493. }
  494. }
  495. #ifdef CONFIG_SYSCTL
  496. static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
  497. {
  498. unsigned char reason = get_nmi_reason();
  499. char buf[64];
  500. if (!(reason & 0xc0)) {
  501. sprintf(buf, "NMI received for unknown reason %02x\n", reason);
  502. die_nmi(regs, buf);
  503. }
  504. return 0;
  505. }
  506. /*
  507. * proc handler for /proc/sys/kernel/unknown_nmi_panic
  508. */
  509. int proc_unknown_nmi_panic(ctl_table *table, int write, struct file *file,
  510. void __user *buffer, size_t *length, loff_t *ppos)
  511. {
  512. int old_state;
  513. old_state = unknown_nmi_panic;
  514. proc_dointvec(table, write, file, buffer, length, ppos);
  515. if (!!old_state == !!unknown_nmi_panic)
  516. return 0;
  517. if (unknown_nmi_panic) {
  518. if (reserve_lapic_nmi() < 0) {
  519. unknown_nmi_panic = 0;
  520. return -EBUSY;
  521. } else {
  522. set_nmi_callback(unknown_nmi_panic_callback);
  523. }
  524. } else {
  525. release_lapic_nmi();
  526. unset_nmi_callback();
  527. }
  528. return 0;
  529. }
  530. #endif
  531. EXPORT_SYMBOL(nmi_active);
  532. EXPORT_SYMBOL(nmi_watchdog);
  533. EXPORT_SYMBOL(reserve_lapic_nmi);
  534. EXPORT_SYMBOL(release_lapic_nmi);
  535. EXPORT_SYMBOL(disable_timer_nmi_watchdog);
  536. EXPORT_SYMBOL(enable_timer_nmi_watchdog);