uv_nmi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * SGI NMI support routines
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * Copyright (c) 2009-2013 Silicon Graphics, Inc. All Rights Reserved.
  19. * Copyright (c) Mike Travis
  20. */
  21. #include <linux/cpu.h>
  22. #include <linux/delay.h>
  23. #include <linux/kexec.h>
  24. #include <linux/module.h>
  25. #include <linux/nmi.h>
  26. #include <linux/sched.h>
  27. #include <linux/slab.h>
  28. #include <asm/apic.h>
  29. #include <asm/current.h>
  30. #include <asm/kdebug.h>
  31. #include <asm/local64.h>
  32. #include <asm/nmi.h>
  33. #include <asm/uv/uv.h>
  34. #include <asm/uv/uv_hub.h>
  35. #include <asm/uv/uv_mmrs.h>
  36. /*
  37. * UV handler for NMI
  38. *
  39. * Handle system-wide NMI events generated by the global 'power nmi' command.
  40. *
  41. * Basic operation is to field the NMI interrupt on each cpu and wait
  42. * until all cpus have arrived into the nmi handler. If some cpus do not
  43. * make it into the handler, try and force them in with the IPI(NMI) signal.
  44. *
  45. * We also have to lessen UV Hub MMR accesses as much as possible as this
  46. * disrupts the UV Hub's primary mission of directing NumaLink traffic and
  47. * can cause system problems to occur.
  48. *
  49. * To do this we register our primary NMI notifier on the NMI_UNKNOWN
  50. * chain. This reduces the number of false NMI calls when the perf
  51. * tools are running which generate an enormous number of NMIs per
  52. * second (~4M/s for 1024 cpu threads). Our secondary NMI handler is
  53. * very short as it only checks that if it has been "pinged" with the
  54. * IPI(NMI) signal as mentioned above, and does not read the UV Hub's MMR.
  55. *
  56. */
  57. static struct uv_hub_nmi_s **uv_hub_nmi_list;
  58. DEFINE_PER_CPU(struct uv_cpu_nmi_s, __uv_cpu_nmi);
  59. EXPORT_PER_CPU_SYMBOL_GPL(__uv_cpu_nmi);
  60. static unsigned long nmi_mmr;
  61. static unsigned long nmi_mmr_clear;
  62. static unsigned long nmi_mmr_pending;
  63. static atomic_t uv_in_nmi;
  64. static atomic_t uv_nmi_cpu = ATOMIC_INIT(-1);
  65. static atomic_t uv_nmi_cpus_in_nmi = ATOMIC_INIT(-1);
  66. static atomic_t uv_nmi_slave_continue;
  67. static atomic_t uv_nmi_kexec_failed;
  68. static cpumask_var_t uv_nmi_cpu_mask;
  69. /* Values for uv_nmi_slave_continue */
  70. #define SLAVE_CLEAR 0
  71. #define SLAVE_CONTINUE 1
  72. #define SLAVE_EXIT 2
  73. /*
  74. * Default is all stack dumps go to the console and buffer.
  75. * Lower level to send to log buffer only.
  76. */
  77. static int uv_nmi_loglevel = 7;
  78. module_param_named(dump_loglevel, uv_nmi_loglevel, int, 0644);
  79. /*
  80. * The following values show statistics on how perf events are affecting
  81. * this system.
  82. */
  83. static int param_get_local64(char *buffer, const struct kernel_param *kp)
  84. {
  85. return sprintf(buffer, "%lu\n", local64_read((local64_t *)kp->arg));
  86. }
  87. static int param_set_local64(const char *val, const struct kernel_param *kp)
  88. {
  89. /* clear on any write */
  90. local64_set((local64_t *)kp->arg, 0);
  91. return 0;
  92. }
  93. static struct kernel_param_ops param_ops_local64 = {
  94. .get = param_get_local64,
  95. .set = param_set_local64,
  96. };
  97. #define param_check_local64(name, p) __param_check(name, p, local64_t)
  98. static local64_t uv_nmi_count;
  99. module_param_named(nmi_count, uv_nmi_count, local64, 0644);
  100. static local64_t uv_nmi_misses;
  101. module_param_named(nmi_misses, uv_nmi_misses, local64, 0644);
  102. static local64_t uv_nmi_ping_count;
  103. module_param_named(ping_count, uv_nmi_ping_count, local64, 0644);
  104. static local64_t uv_nmi_ping_misses;
  105. module_param_named(ping_misses, uv_nmi_ping_misses, local64, 0644);
  106. /*
  107. * Following values allow tuning for large systems under heavy loading
  108. */
  109. static int uv_nmi_initial_delay = 100;
  110. module_param_named(initial_delay, uv_nmi_initial_delay, int, 0644);
  111. static int uv_nmi_slave_delay = 100;
  112. module_param_named(slave_delay, uv_nmi_slave_delay, int, 0644);
  113. static int uv_nmi_loop_delay = 100;
  114. module_param_named(loop_delay, uv_nmi_loop_delay, int, 0644);
  115. static int uv_nmi_trigger_delay = 10000;
  116. module_param_named(trigger_delay, uv_nmi_trigger_delay, int, 0644);
  117. static int uv_nmi_wait_count = 100;
  118. module_param_named(wait_count, uv_nmi_wait_count, int, 0644);
  119. static int uv_nmi_retry_count = 500;
  120. module_param_named(retry_count, uv_nmi_retry_count, int, 0644);
  121. /*
  122. * Valid NMI Actions:
  123. * "dump" - dump process stack for each cpu
  124. * "ips" - dump IP info for each cpu
  125. * "kdump" - do crash dump
  126. */
  127. static char uv_nmi_action[8] = "dump";
  128. module_param_string(action, uv_nmi_action, sizeof(uv_nmi_action), 0644);
  129. static inline bool uv_nmi_action_is(const char *action)
  130. {
  131. return (strncmp(uv_nmi_action, action, strlen(action)) == 0);
  132. }
  133. /* Setup which NMI support is present in system */
  134. static void uv_nmi_setup_mmrs(void)
  135. {
  136. if (uv_read_local_mmr(UVH_NMI_MMRX_SUPPORTED)) {
  137. uv_write_local_mmr(UVH_NMI_MMRX_REQ,
  138. 1UL << UVH_NMI_MMRX_REQ_SHIFT);
  139. nmi_mmr = UVH_NMI_MMRX;
  140. nmi_mmr_clear = UVH_NMI_MMRX_CLEAR;
  141. nmi_mmr_pending = 1UL << UVH_NMI_MMRX_SHIFT;
  142. pr_info("UV: SMI NMI support: %s\n", UVH_NMI_MMRX_TYPE);
  143. } else {
  144. nmi_mmr = UVH_NMI_MMR;
  145. nmi_mmr_clear = UVH_NMI_MMR_CLEAR;
  146. nmi_mmr_pending = 1UL << UVH_NMI_MMR_SHIFT;
  147. pr_info("UV: SMI NMI support: %s\n", UVH_NMI_MMR_TYPE);
  148. }
  149. }
  150. /* Read NMI MMR and check if NMI flag was set by BMC. */
  151. static inline int uv_nmi_test_mmr(struct uv_hub_nmi_s *hub_nmi)
  152. {
  153. hub_nmi->nmi_value = uv_read_local_mmr(nmi_mmr);
  154. atomic_inc(&hub_nmi->read_mmr_count);
  155. return !!(hub_nmi->nmi_value & nmi_mmr_pending);
  156. }
  157. static inline void uv_local_mmr_clear_nmi(void)
  158. {
  159. uv_write_local_mmr(nmi_mmr_clear, nmi_mmr_pending);
  160. }
  161. /*
  162. * If first cpu in on this hub, set hub_nmi "in_nmi" and "owner" values and
  163. * return true. If first cpu in on the system, set global "in_nmi" flag.
  164. */
  165. static int uv_set_in_nmi(int cpu, struct uv_hub_nmi_s *hub_nmi)
  166. {
  167. int first = atomic_add_unless(&hub_nmi->in_nmi, 1, 1);
  168. if (first) {
  169. atomic_set(&hub_nmi->cpu_owner, cpu);
  170. if (atomic_add_unless(&uv_in_nmi, 1, 1))
  171. atomic_set(&uv_nmi_cpu, cpu);
  172. atomic_inc(&hub_nmi->nmi_count);
  173. }
  174. return first;
  175. }
  176. /* Check if this is a system NMI event */
  177. static int uv_check_nmi(struct uv_hub_nmi_s *hub_nmi)
  178. {
  179. int cpu = smp_processor_id();
  180. int nmi = 0;
  181. local64_inc(&uv_nmi_count);
  182. uv_cpu_nmi.queries++;
  183. do {
  184. nmi = atomic_read(&hub_nmi->in_nmi);
  185. if (nmi)
  186. break;
  187. if (raw_spin_trylock(&hub_nmi->nmi_lock)) {
  188. /* check hub MMR NMI flag */
  189. if (uv_nmi_test_mmr(hub_nmi)) {
  190. uv_set_in_nmi(cpu, hub_nmi);
  191. nmi = 1;
  192. break;
  193. }
  194. /* MMR NMI flag is clear */
  195. raw_spin_unlock(&hub_nmi->nmi_lock);
  196. } else {
  197. /* wait a moment for the hub nmi locker to set flag */
  198. cpu_relax();
  199. udelay(uv_nmi_slave_delay);
  200. /* re-check hub in_nmi flag */
  201. nmi = atomic_read(&hub_nmi->in_nmi);
  202. if (nmi)
  203. break;
  204. }
  205. /* check if this BMC missed setting the MMR NMI flag */
  206. if (!nmi) {
  207. nmi = atomic_read(&uv_in_nmi);
  208. if (nmi)
  209. uv_set_in_nmi(cpu, hub_nmi);
  210. }
  211. } while (0);
  212. if (!nmi)
  213. local64_inc(&uv_nmi_misses);
  214. return nmi;
  215. }
  216. /* Need to reset the NMI MMR register, but only once per hub. */
  217. static inline void uv_clear_nmi(int cpu)
  218. {
  219. struct uv_hub_nmi_s *hub_nmi = uv_hub_nmi;
  220. if (cpu == atomic_read(&hub_nmi->cpu_owner)) {
  221. atomic_set(&hub_nmi->cpu_owner, -1);
  222. atomic_set(&hub_nmi->in_nmi, 0);
  223. uv_local_mmr_clear_nmi();
  224. raw_spin_unlock(&hub_nmi->nmi_lock);
  225. }
  226. }
  227. /* Print non-responding cpus */
  228. static void uv_nmi_nr_cpus_pr(char *fmt)
  229. {
  230. static char cpu_list[1024];
  231. int len = sizeof(cpu_list);
  232. int c = cpumask_weight(uv_nmi_cpu_mask);
  233. int n = cpulist_scnprintf(cpu_list, len, uv_nmi_cpu_mask);
  234. if (n >= len-1)
  235. strcpy(&cpu_list[len - 6], "...\n");
  236. printk(fmt, c, cpu_list);
  237. }
  238. /* Ping non-responding cpus attemping to force them into the NMI handler */
  239. static void uv_nmi_nr_cpus_ping(void)
  240. {
  241. int cpu;
  242. for_each_cpu(cpu, uv_nmi_cpu_mask)
  243. atomic_set(&uv_cpu_nmi_per(cpu).pinging, 1);
  244. apic->send_IPI_mask(uv_nmi_cpu_mask, APIC_DM_NMI);
  245. }
  246. /* Clean up flags for cpus that ignored both NMI and ping */
  247. static void uv_nmi_cleanup_mask(void)
  248. {
  249. int cpu;
  250. for_each_cpu(cpu, uv_nmi_cpu_mask) {
  251. atomic_set(&uv_cpu_nmi_per(cpu).pinging, 0);
  252. atomic_set(&uv_cpu_nmi_per(cpu).state, UV_NMI_STATE_OUT);
  253. cpumask_clear_cpu(cpu, uv_nmi_cpu_mask);
  254. }
  255. }
  256. /* Loop waiting as cpus enter nmi handler */
  257. static int uv_nmi_wait_cpus(int first)
  258. {
  259. int i, j, k, n = num_online_cpus();
  260. int last_k = 0, waiting = 0;
  261. if (first) {
  262. cpumask_copy(uv_nmi_cpu_mask, cpu_online_mask);
  263. k = 0;
  264. } else {
  265. k = n - cpumask_weight(uv_nmi_cpu_mask);
  266. }
  267. udelay(uv_nmi_initial_delay);
  268. for (i = 0; i < uv_nmi_retry_count; i++) {
  269. int loop_delay = uv_nmi_loop_delay;
  270. for_each_cpu(j, uv_nmi_cpu_mask) {
  271. if (atomic_read(&uv_cpu_nmi_per(j).state)) {
  272. cpumask_clear_cpu(j, uv_nmi_cpu_mask);
  273. if (++k >= n)
  274. break;
  275. }
  276. }
  277. if (k >= n) { /* all in? */
  278. k = n;
  279. break;
  280. }
  281. if (last_k != k) { /* abort if no new cpus coming in */
  282. last_k = k;
  283. waiting = 0;
  284. } else if (++waiting > uv_nmi_wait_count)
  285. break;
  286. /* extend delay if waiting only for cpu 0 */
  287. if (waiting && (n - k) == 1 &&
  288. cpumask_test_cpu(0, uv_nmi_cpu_mask))
  289. loop_delay *= 100;
  290. udelay(loop_delay);
  291. }
  292. atomic_set(&uv_nmi_cpus_in_nmi, k);
  293. return n - k;
  294. }
  295. /* Wait until all slave cpus have entered UV NMI handler */
  296. static void uv_nmi_wait(int master)
  297. {
  298. /* indicate this cpu is in */
  299. atomic_set(&uv_cpu_nmi.state, UV_NMI_STATE_IN);
  300. /* if not the first cpu in (the master), then we are a slave cpu */
  301. if (!master)
  302. return;
  303. do {
  304. /* wait for all other cpus to gather here */
  305. if (!uv_nmi_wait_cpus(1))
  306. break;
  307. /* if not all made it in, send IPI NMI to them */
  308. uv_nmi_nr_cpus_pr(KERN_ALERT
  309. "UV: Sending NMI IPI to %d non-responding CPUs: %s\n");
  310. uv_nmi_nr_cpus_ping();
  311. /* if all cpus are in, then done */
  312. if (!uv_nmi_wait_cpus(0))
  313. break;
  314. uv_nmi_nr_cpus_pr(KERN_ALERT
  315. "UV: %d CPUs not in NMI loop: %s\n");
  316. } while (0);
  317. pr_alert("UV: %d of %d CPUs in NMI\n",
  318. atomic_read(&uv_nmi_cpus_in_nmi), num_online_cpus());
  319. }
  320. static void uv_nmi_dump_cpu_ip_hdr(void)
  321. {
  322. printk(KERN_DEFAULT
  323. "\nUV: %4s %6s %-32s %s (Note: PID 0 not listed)\n",
  324. "CPU", "PID", "COMMAND", "IP");
  325. }
  326. static void uv_nmi_dump_cpu_ip(int cpu, struct pt_regs *regs)
  327. {
  328. printk(KERN_DEFAULT "UV: %4d %6d %-32.32s ",
  329. cpu, current->pid, current->comm);
  330. printk_address(regs->ip, 1);
  331. }
  332. /* Dump this cpu's state */
  333. static void uv_nmi_dump_state_cpu(int cpu, struct pt_regs *regs)
  334. {
  335. const char *dots = " ................................. ";
  336. if (uv_nmi_action_is("ips")) {
  337. if (cpu == 0)
  338. uv_nmi_dump_cpu_ip_hdr();
  339. if (current->pid != 0)
  340. uv_nmi_dump_cpu_ip(cpu, regs);
  341. } else if (uv_nmi_action_is("dump")) {
  342. printk(KERN_DEFAULT
  343. "UV:%sNMI process trace for CPU %d\n", dots, cpu);
  344. show_regs(regs);
  345. }
  346. atomic_set(&uv_cpu_nmi.state, UV_NMI_STATE_DUMP_DONE);
  347. }
  348. /* Trigger a slave cpu to dump it's state */
  349. static void uv_nmi_trigger_dump(int cpu)
  350. {
  351. int retry = uv_nmi_trigger_delay;
  352. if (atomic_read(&uv_cpu_nmi_per(cpu).state) != UV_NMI_STATE_IN)
  353. return;
  354. atomic_set(&uv_cpu_nmi_per(cpu).state, UV_NMI_STATE_DUMP);
  355. do {
  356. cpu_relax();
  357. udelay(10);
  358. if (atomic_read(&uv_cpu_nmi_per(cpu).state)
  359. != UV_NMI_STATE_DUMP)
  360. return;
  361. } while (--retry > 0);
  362. pr_crit("UV: CPU %d stuck in process dump function\n", cpu);
  363. atomic_set(&uv_cpu_nmi_per(cpu).state, UV_NMI_STATE_DUMP_DONE);
  364. }
  365. /* Wait until all cpus ready to exit */
  366. static void uv_nmi_sync_exit(int master)
  367. {
  368. atomic_dec(&uv_nmi_cpus_in_nmi);
  369. if (master) {
  370. while (atomic_read(&uv_nmi_cpus_in_nmi) > 0)
  371. cpu_relax();
  372. atomic_set(&uv_nmi_slave_continue, SLAVE_CLEAR);
  373. } else {
  374. while (atomic_read(&uv_nmi_slave_continue))
  375. cpu_relax();
  376. }
  377. }
  378. /* Walk through cpu list and dump state of each */
  379. static void uv_nmi_dump_state(int cpu, struct pt_regs *regs, int master)
  380. {
  381. if (master) {
  382. int tcpu;
  383. int ignored = 0;
  384. int saved_console_loglevel = console_loglevel;
  385. pr_alert("UV: tracing %s for %d CPUs from CPU %d\n",
  386. uv_nmi_action_is("ips") ? "IPs" : "processes",
  387. atomic_read(&uv_nmi_cpus_in_nmi), cpu);
  388. console_loglevel = uv_nmi_loglevel;
  389. atomic_set(&uv_nmi_slave_continue, SLAVE_EXIT);
  390. for_each_online_cpu(tcpu) {
  391. if (cpumask_test_cpu(tcpu, uv_nmi_cpu_mask))
  392. ignored++;
  393. else if (tcpu == cpu)
  394. uv_nmi_dump_state_cpu(tcpu, regs);
  395. else
  396. uv_nmi_trigger_dump(tcpu);
  397. }
  398. if (ignored)
  399. printk(KERN_DEFAULT "UV: %d CPUs ignored NMI\n",
  400. ignored);
  401. console_loglevel = saved_console_loglevel;
  402. pr_alert("UV: process trace complete\n");
  403. } else {
  404. while (!atomic_read(&uv_nmi_slave_continue))
  405. cpu_relax();
  406. while (atomic_read(&uv_cpu_nmi.state) != UV_NMI_STATE_DUMP)
  407. cpu_relax();
  408. uv_nmi_dump_state_cpu(cpu, regs);
  409. }
  410. uv_nmi_sync_exit(master);
  411. }
  412. static void uv_nmi_touch_watchdogs(void)
  413. {
  414. touch_softlockup_watchdog_sync();
  415. clocksource_touch_watchdog();
  416. rcu_cpu_stall_reset();
  417. touch_nmi_watchdog();
  418. }
  419. #if defined(CONFIG_KEXEC)
  420. static void uv_nmi_kdump(int cpu, int master, struct pt_regs *regs)
  421. {
  422. /* Call crash to dump system state */
  423. if (master) {
  424. pr_emerg("UV: NMI executing crash_kexec on CPU%d\n", cpu);
  425. crash_kexec(regs);
  426. pr_emerg("UV: crash_kexec unexpectedly returned, ");
  427. if (!kexec_crash_image) {
  428. pr_cont("crash kernel not loaded\n");
  429. atomic_set(&uv_nmi_kexec_failed, 1);
  430. uv_nmi_sync_exit(1);
  431. return;
  432. }
  433. pr_cont("kexec busy, stalling cpus while waiting\n");
  434. }
  435. /* If crash exec fails the slaves should return, otherwise stall */
  436. while (atomic_read(&uv_nmi_kexec_failed) == 0)
  437. mdelay(10);
  438. /* Crash kernel most likely not loaded, return in an orderly fashion */
  439. uv_nmi_sync_exit(0);
  440. }
  441. #else /* !CONFIG_KEXEC */
  442. static inline void uv_nmi_kdump(int cpu, int master, struct pt_regs *regs)
  443. {
  444. if (master)
  445. pr_err("UV: NMI kdump: KEXEC not supported in this kernel\n");
  446. }
  447. #endif /* !CONFIG_KEXEC */
  448. /*
  449. * UV NMI handler
  450. */
  451. int uv_handle_nmi(unsigned int reason, struct pt_regs *regs)
  452. {
  453. struct uv_hub_nmi_s *hub_nmi = uv_hub_nmi;
  454. int cpu = smp_processor_id();
  455. int master = 0;
  456. unsigned long flags;
  457. local_irq_save(flags);
  458. /* If not a UV System NMI, ignore */
  459. if (!atomic_read(&uv_cpu_nmi.pinging) && !uv_check_nmi(hub_nmi)) {
  460. local_irq_restore(flags);
  461. return NMI_DONE;
  462. }
  463. /* Indicate we are the first CPU into the NMI handler */
  464. master = (atomic_read(&uv_nmi_cpu) == cpu);
  465. /* If NMI action is "kdump", then attempt to do it */
  466. if (uv_nmi_action_is("kdump"))
  467. uv_nmi_kdump(cpu, master, regs);
  468. /* Pause as all cpus enter the NMI handler */
  469. uv_nmi_wait(master);
  470. /* Dump state of each cpu */
  471. if (uv_nmi_action_is("ips") || uv_nmi_action_is("dump"))
  472. uv_nmi_dump_state(cpu, regs, master);
  473. /* Clear per_cpu "in nmi" flag */
  474. atomic_set(&uv_cpu_nmi.state, UV_NMI_STATE_OUT);
  475. /* Clear MMR NMI flag on each hub */
  476. uv_clear_nmi(cpu);
  477. /* Clear global flags */
  478. if (master) {
  479. if (cpumask_weight(uv_nmi_cpu_mask))
  480. uv_nmi_cleanup_mask();
  481. atomic_set(&uv_nmi_cpus_in_nmi, -1);
  482. atomic_set(&uv_nmi_cpu, -1);
  483. atomic_set(&uv_in_nmi, 0);
  484. }
  485. uv_nmi_touch_watchdogs();
  486. local_irq_restore(flags);
  487. return NMI_HANDLED;
  488. }
  489. /*
  490. * NMI handler for pulling in CPUs when perf events are grabbing our NMI
  491. */
  492. int uv_handle_nmi_ping(unsigned int reason, struct pt_regs *regs)
  493. {
  494. int ret;
  495. uv_cpu_nmi.queries++;
  496. if (!atomic_read(&uv_cpu_nmi.pinging)) {
  497. local64_inc(&uv_nmi_ping_misses);
  498. return NMI_DONE;
  499. }
  500. uv_cpu_nmi.pings++;
  501. local64_inc(&uv_nmi_ping_count);
  502. ret = uv_handle_nmi(reason, regs);
  503. atomic_set(&uv_cpu_nmi.pinging, 0);
  504. return ret;
  505. }
  506. void uv_register_nmi_notifier(void)
  507. {
  508. if (register_nmi_handler(NMI_UNKNOWN, uv_handle_nmi, 0, "uv"))
  509. pr_warn("UV: NMI handler failed to register\n");
  510. if (register_nmi_handler(NMI_LOCAL, uv_handle_nmi_ping, 0, "uvping"))
  511. pr_warn("UV: PING NMI handler failed to register\n");
  512. }
  513. void uv_nmi_init(void)
  514. {
  515. unsigned int value;
  516. /*
  517. * Unmask NMI on all cpus
  518. */
  519. value = apic_read(APIC_LVT1) | APIC_DM_NMI;
  520. value &= ~APIC_LVT_MASKED;
  521. apic_write(APIC_LVT1, value);
  522. }
  523. void uv_nmi_setup(void)
  524. {
  525. int size = sizeof(void *) * (1 << NODES_SHIFT);
  526. int cpu, nid;
  527. /* Setup hub nmi info */
  528. uv_nmi_setup_mmrs();
  529. uv_hub_nmi_list = kzalloc(size, GFP_KERNEL);
  530. pr_info("UV: NMI hub list @ 0x%p (%d)\n", uv_hub_nmi_list, size);
  531. BUG_ON(!uv_hub_nmi_list);
  532. size = sizeof(struct uv_hub_nmi_s);
  533. for_each_present_cpu(cpu) {
  534. nid = cpu_to_node(cpu);
  535. if (uv_hub_nmi_list[nid] == NULL) {
  536. uv_hub_nmi_list[nid] = kzalloc_node(size,
  537. GFP_KERNEL, nid);
  538. BUG_ON(!uv_hub_nmi_list[nid]);
  539. raw_spin_lock_init(&(uv_hub_nmi_list[nid]->nmi_lock));
  540. atomic_set(&uv_hub_nmi_list[nid]->cpu_owner, -1);
  541. }
  542. uv_hub_nmi_per(cpu) = uv_hub_nmi_list[nid];
  543. }
  544. alloc_cpumask_var(&uv_nmi_cpu_mask, GFP_KERNEL);
  545. BUG_ON(!uv_nmi_cpu_mask);
  546. }