2 * SGI NMI support routines
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.
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.
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
18 * Copyright (c) 2009-2013 Silicon Graphics, Inc. All Rights Reserved.
19 * Copyright (c) Mike Travis
22 #include <linux/cpu.h>
23 #include <linux/delay.h>
24 #include <linux/kdb.h>
25 #include <linux/kexec.h>
26 #include <linux/kgdb.h>
27 #include <linux/moduleparam.h>
28 #include <linux/nmi.h>
29 #include <linux/sched.h>
30 #include <linux/sched/debug.h>
31 #include <linux/slab.h>
32 #include <linux/clocksource.h>
35 #include <asm/current.h>
36 #include <asm/kdebug.h>
37 #include <asm/local64.h>
39 #include <asm/traps.h>
40 #include <asm/uv/uv.h>
41 #include <asm/uv/uv_hub.h>
42 #include <asm/uv/uv_mmrs.h>
47 * Handle system-wide NMI events generated by the global 'power nmi' command.
49 * Basic operation is to field the NMI interrupt on each CPU and wait
50 * until all CPU's have arrived into the nmi handler. If some CPU's do not
51 * make it into the handler, try and force them in with the IPI(NMI) signal.
53 * We also have to lessen UV Hub MMR accesses as much as possible as this
54 * disrupts the UV Hub's primary mission of directing NumaLink traffic and
55 * can cause system problems to occur.
57 * To do this we register our primary NMI notifier on the NMI_UNKNOWN
58 * chain. This reduces the number of false NMI calls when the perf
59 * tools are running which generate an enormous number of NMIs per
60 * second (~4M/s for 1024 CPU threads). Our secondary NMI handler is
61 * very short as it only checks that if it has been "pinged" with the
62 * IPI(NMI) signal as mentioned above, and does not read the UV Hub's MMR.
66 static struct uv_hub_nmi_s
**uv_hub_nmi_list
;
68 DEFINE_PER_CPU(struct uv_cpu_nmi_s
, uv_cpu_nmi
);
70 /* UV hubless values */
71 #define NMI_CONTROL_PORT 0x70
72 #define NMI_DUMMY_PORT 0x71
73 #define PAD_OWN_GPP_D_0 0x2c
74 #define GPI_NMI_STS_GPP_D_0 0x164
75 #define GPI_NMI_ENA_GPP_D_0 0x174
76 #define STS_GPP_D_0_MASK 0x1
77 #define PAD_CFG_DW0_GPP_D_0 0x4c0
78 #define GPIROUTNMI (1ul << 17)
79 #define PCH_PCR_GPIO_1_BASE 0xfdae0000ul
80 #define PCH_PCR_GPIO_ADDRESS(offset) (int *)((u64)(pch_base) | (u64)(offset))
83 static unsigned long nmi_mmr
;
84 static unsigned long nmi_mmr_clear
;
85 static unsigned long nmi_mmr_pending
;
87 static atomic_t uv_in_nmi
;
88 static atomic_t uv_nmi_cpu
= ATOMIC_INIT(-1);
89 static atomic_t uv_nmi_cpus_in_nmi
= ATOMIC_INIT(-1);
90 static atomic_t uv_nmi_slave_continue
;
91 static cpumask_var_t uv_nmi_cpu_mask
;
93 /* Values for uv_nmi_slave_continue */
95 #define SLAVE_CONTINUE 1
99 * Default is all stack dumps go to the console and buffer.
100 * Lower level to send to log buffer only.
102 static int uv_nmi_loglevel
= CONSOLE_LOGLEVEL_DEFAULT
;
103 module_param_named(dump_loglevel
, uv_nmi_loglevel
, int, 0644);
106 * The following values show statistics on how perf events are affecting
109 static int param_get_local64(char *buffer
, const struct kernel_param
*kp
)
111 return sprintf(buffer
, "%lu\n", local64_read((local64_t
*)kp
->arg
));
114 static int param_set_local64(const char *val
, const struct kernel_param
*kp
)
116 /* Clear on any write */
117 local64_set((local64_t
*)kp
->arg
, 0);
121 static const struct kernel_param_ops param_ops_local64
= {
122 .get
= param_get_local64
,
123 .set
= param_set_local64
,
125 #define param_check_local64(name, p) __param_check(name, p, local64_t)
127 static local64_t uv_nmi_count
;
128 module_param_named(nmi_count
, uv_nmi_count
, local64
, 0644);
130 static local64_t uv_nmi_misses
;
131 module_param_named(nmi_misses
, uv_nmi_misses
, local64
, 0644);
133 static local64_t uv_nmi_ping_count
;
134 module_param_named(ping_count
, uv_nmi_ping_count
, local64
, 0644);
136 static local64_t uv_nmi_ping_misses
;
137 module_param_named(ping_misses
, uv_nmi_ping_misses
, local64
, 0644);
140 * Following values allow tuning for large systems under heavy loading
142 static int uv_nmi_initial_delay
= 100;
143 module_param_named(initial_delay
, uv_nmi_initial_delay
, int, 0644);
145 static int uv_nmi_slave_delay
= 100;
146 module_param_named(slave_delay
, uv_nmi_slave_delay
, int, 0644);
148 static int uv_nmi_loop_delay
= 100;
149 module_param_named(loop_delay
, uv_nmi_loop_delay
, int, 0644);
151 static int uv_nmi_trigger_delay
= 10000;
152 module_param_named(trigger_delay
, uv_nmi_trigger_delay
, int, 0644);
154 static int uv_nmi_wait_count
= 100;
155 module_param_named(wait_count
, uv_nmi_wait_count
, int, 0644);
157 static int uv_nmi_retry_count
= 500;
158 module_param_named(retry_count
, uv_nmi_retry_count
, int, 0644);
160 static bool uv_pch_intr_enable
= true;
161 static bool uv_pch_intr_now_enabled
;
162 module_param_named(pch_intr_enable
, uv_pch_intr_enable
, bool, 0644);
164 static bool uv_pch_init_enable
= true;
165 module_param_named(pch_init_enable
, uv_pch_init_enable
, bool, 0644);
167 static int uv_nmi_debug
;
168 module_param_named(debug
, uv_nmi_debug
, int, 0644);
170 #define nmi_debug(fmt, ...) \
173 pr_info(fmt, ##__VA_ARGS__); \
176 /* Valid NMI Actions */
177 #define ACTION_LEN 16
178 static struct nmi_action
{
182 { "kdump", "do kernel crash dump" },
183 { "dump", "dump process stack for each cpu" },
184 { "ips", "dump Inst Ptr info for each cpu" },
185 { "kdb", "enter KDB (needs kgdboc= assignment)" },
186 { "kgdb", "enter KGDB (needs gdb target remote)" },
187 { "health", "check if CPUs respond to NMI" },
189 typedef char action_t
[ACTION_LEN
];
190 static action_t uv_nmi_action
= { "dump" };
192 static int param_get_action(char *buffer
, const struct kernel_param
*kp
)
194 return sprintf(buffer
, "%s\n", uv_nmi_action
);
197 static int param_set_action(const char *val
, const struct kernel_param
*kp
)
200 int n
= ARRAY_SIZE(valid_acts
);
201 char arg
[ACTION_LEN
], *p
;
203 /* (remove possible '\n') */
204 strncpy(arg
, val
, ACTION_LEN
- 1);
205 arg
[ACTION_LEN
- 1] = '\0';
206 p
= strchr(arg
, '\n');
210 for (i
= 0; i
< n
; i
++)
211 if (!strcmp(arg
, valid_acts
[i
].action
))
215 strcpy(uv_nmi_action
, arg
);
216 pr_info("UV: New NMI action:%s\n", uv_nmi_action
);
220 pr_err("UV: Invalid NMI action:%s, valid actions are:\n", arg
);
221 for (i
= 0; i
< n
; i
++)
222 pr_err("UV: %-8s - %s\n",
223 valid_acts
[i
].action
, valid_acts
[i
].desc
);
227 static const struct kernel_param_ops param_ops_action
= {
228 .get
= param_get_action
,
229 .set
= param_set_action
,
231 #define param_check_action(name, p) __param_check(name, p, action_t)
233 module_param_named(action
, uv_nmi_action
, action
, 0644);
235 static inline bool uv_nmi_action_is(const char *action
)
237 return (strncmp(uv_nmi_action
, action
, strlen(action
)) == 0);
240 /* Setup which NMI support is present in system */
241 static void uv_nmi_setup_mmrs(void)
243 if (uv_read_local_mmr(UVH_NMI_MMRX_SUPPORTED
)) {
244 uv_write_local_mmr(UVH_NMI_MMRX_REQ
,
245 1UL << UVH_NMI_MMRX_REQ_SHIFT
);
246 nmi_mmr
= UVH_NMI_MMRX
;
247 nmi_mmr_clear
= UVH_NMI_MMRX_CLEAR
;
248 nmi_mmr_pending
= 1UL << UVH_NMI_MMRX_SHIFT
;
249 pr_info("UV: SMI NMI support: %s\n", UVH_NMI_MMRX_TYPE
);
251 nmi_mmr
= UVH_NMI_MMR
;
252 nmi_mmr_clear
= UVH_NMI_MMR_CLEAR
;
253 nmi_mmr_pending
= 1UL << UVH_NMI_MMR_SHIFT
;
254 pr_info("UV: SMI NMI support: %s\n", UVH_NMI_MMR_TYPE
);
258 /* Read NMI MMR and check if NMI flag was set by BMC. */
259 static inline int uv_nmi_test_mmr(struct uv_hub_nmi_s
*hub_nmi
)
261 hub_nmi
->nmi_value
= uv_read_local_mmr(nmi_mmr
);
262 atomic_inc(&hub_nmi
->read_mmr_count
);
263 return !!(hub_nmi
->nmi_value
& nmi_mmr_pending
);
266 static inline void uv_local_mmr_clear_nmi(void)
268 uv_write_local_mmr(nmi_mmr_clear
, nmi_mmr_pending
);
272 * UV hubless NMI handler functions
274 static inline void uv_reassert_nmi(void)
276 /* (from arch/x86/include/asm/mach_traps.h) */
277 outb(0x8f, NMI_CONTROL_PORT
);
278 inb(NMI_DUMMY_PORT
); /* dummy read */
279 outb(0x0f, NMI_CONTROL_PORT
);
280 inb(NMI_DUMMY_PORT
); /* dummy read */
283 static void uv_init_hubless_pch_io(int offset
, int mask
, int data
)
285 int *addr
= PCH_PCR_GPIO_ADDRESS(offset
);
286 int readd
= readl(addr
);
288 if (mask
) { /* OR in new data */
289 int writed
= (readd
& ~mask
) | data
;
291 nmi_debug("UV:PCH: %p = %x & %x | %x (%x)\n",
292 addr
, readd
, ~mask
, data
, writed
);
293 writel(writed
, addr
);
294 } else if (readd
& data
) { /* clear status bit */
295 nmi_debug("UV:PCH: %p = %x\n", addr
, data
);
299 (void)readl(addr
); /* flush write data */
302 static void uv_nmi_setup_hubless_intr(void)
304 uv_pch_intr_now_enabled
= uv_pch_intr_enable
;
306 uv_init_hubless_pch_io(
307 PAD_CFG_DW0_GPP_D_0
, GPIROUTNMI
,
308 uv_pch_intr_now_enabled
? GPIROUTNMI
: 0);
310 nmi_debug("UV:NMI: GPP_D_0 interrupt %s\n",
311 uv_pch_intr_now_enabled
? "enabled" : "disabled");
314 static struct init_nmi
{
319 { /* HOSTSW_OWN_GPP_D_0 */
322 .data
= 0x0, /* ACPI Mode */
326 { /* GPI_INT_STS_GPP_D_0 */
329 .data
= 0x1, /* Clear Status */
331 { /* GPI_GPE_STS_GPP_D_0 */
334 .data
= 0x1, /* Clear Status */
336 { /* GPI_SMI_STS_GPP_D_0 */
339 .data
= 0x1, /* Clear Status */
341 { /* GPI_NMI_STS_GPP_D_0 */
344 .data
= 0x1, /* Clear Status */
347 /* Disable interrupts: */
348 { /* GPI_INT_EN_GPP_D_0 */
351 .data
= 0x0, /* Disable interrupt generation */
353 { /* GPI_GPE_EN_GPP_D_0 */
356 .data
= 0x0, /* Disable interrupt generation */
358 { /* GPI_SMI_EN_GPP_D_0 */
361 .data
= 0x0, /* Disable interrupt generation */
363 { /* GPI_NMI_EN_GPP_D_0 */
366 .data
= 0x0, /* Disable interrupt generation */
369 /* Setup GPP_D_0 Pad Config: */
370 { /* PAD_CFG_DW0_GPP_D_0 */
375 * 31:30 Pad Reset Config (PADRSTCFG): = 2h # PLTRST# (default)
377 * 29 RX Pad State Select (RXPADSTSEL): = 0 # Raw RX pad state directly
378 * from RX buffer (default)
380 * 28 RX Raw Override to '1' (RXRAW1): = 0 # No Override
382 * 26:25 RX Level/Edge Configuration (RXEVCFG):
386 * 23 RX Invert (RXINV): = 0 # No Inversion (signal active high)
388 * 20 GPIO Input Route IOxAPIC (GPIROUTIOXAPIC):
389 * = 0 # Routing does not cause peripheral IRQ...
390 * # (we want an NMI not an IRQ)
392 * 19 GPIO Input Route SCI (GPIROUTSCI): = 0 # Routing does not cause SCI.
393 * 18 GPIO Input Route SMI (GPIROUTSMI): = 0 # Routing does not cause SMI.
394 * 17 GPIO Input Route NMI (GPIROUTNMI): = 1 # Routing can cause NMI.
396 * 11:10 Pad Mode (PMODE1/0): = 0h = GPIO control the Pad.
397 * 9 GPIO RX Disable (GPIORXDIS):
398 * = 0 # Enable the input buffer (active low enable)
400 * 8 GPIO TX Disable (GPIOTXDIS):
401 * = 1 # Disable the output buffer; i.e. Hi-Z
403 * 1 GPIO RX State (GPIORXSTATE): This is the current internal RX pad state..
404 * 0 GPIO TX State (GPIOTXSTATE):
405 * = 0 # (Leave at default)
410 { /* PAD_CFG_DW1_GPP_D_0 */
413 .data
= 0, /* Termination = none (default) */
417 static void uv_init_hubless_pch_d0(void)
421 read
= *PCH_PCR_GPIO_ADDRESS(PAD_OWN_GPP_D_0
);
423 pr_info("UV: Hubless NMI already configured\n");
427 nmi_debug("UV: Initializing UV Hubless NMI on PCH\n");
428 for (i
= 0; i
< ARRAY_SIZE(init_nmi
); i
++) {
429 uv_init_hubless_pch_io(init_nmi
[i
].offset
,
435 static int uv_nmi_test_hubless(struct uv_hub_nmi_s
*hub_nmi
)
437 int *pstat
= PCH_PCR_GPIO_ADDRESS(GPI_NMI_STS_GPP_D_0
);
440 hub_nmi
->nmi_value
= status
;
441 atomic_inc(&hub_nmi
->read_mmr_count
);
443 if (!(status
& STS_GPP_D_0_MASK
)) /* Not a UV external NMI */
446 *pstat
= STS_GPP_D_0_MASK
; /* Is a UV NMI: clear GPP_D_0 status */
447 (void)*pstat
; /* Flush write */
452 static int uv_test_nmi(struct uv_hub_nmi_s
*hub_nmi
)
454 if (hub_nmi
->hub_present
)
455 return uv_nmi_test_mmr(hub_nmi
);
457 if (hub_nmi
->pch_owner
) /* Only PCH owner can check status */
458 return uv_nmi_test_hubless(hub_nmi
);
464 * If first CPU in on this hub, set hub_nmi "in_nmi" and "owner" values and
465 * return true. If first CPU in on the system, set global "in_nmi" flag.
467 static int uv_set_in_nmi(int cpu
, struct uv_hub_nmi_s
*hub_nmi
)
469 int first
= atomic_add_unless(&hub_nmi
->in_nmi
, 1, 1);
472 atomic_set(&hub_nmi
->cpu_owner
, cpu
);
473 if (atomic_add_unless(&uv_in_nmi
, 1, 1))
474 atomic_set(&uv_nmi_cpu
, cpu
);
476 atomic_inc(&hub_nmi
->nmi_count
);
481 /* Check if this is a system NMI event */
482 static int uv_check_nmi(struct uv_hub_nmi_s
*hub_nmi
)
484 int cpu
= smp_processor_id();
486 int nmi_detected
= 0;
488 local64_inc(&uv_nmi_count
);
489 this_cpu_inc(uv_cpu_nmi
.queries
);
492 nmi
= atomic_read(&hub_nmi
->in_nmi
);
496 if (raw_spin_trylock(&hub_nmi
->nmi_lock
)) {
497 nmi_detected
= uv_test_nmi(hub_nmi
);
499 /* Check flag for UV external NMI */
500 if (nmi_detected
> 0) {
501 uv_set_in_nmi(cpu
, hub_nmi
);
506 /* A non-PCH node in a hubless system waits for NMI */
507 else if (nmi_detected
< 0)
510 /* MMR/PCH NMI flag is clear */
511 raw_spin_unlock(&hub_nmi
->nmi_lock
);
515 /* Wait a moment for the HUB NMI locker to set flag */
516 slave_wait
: cpu_relax();
517 udelay(uv_nmi_slave_delay
);
519 /* Re-check hub in_nmi flag */
520 nmi
= atomic_read(&hub_nmi
->in_nmi
);
526 * Check if this BMC missed setting the MMR NMI flag (or)
527 * UV hubless system where only PCH owner can check flag
530 nmi
= atomic_read(&uv_in_nmi
);
532 uv_set_in_nmi(cpu
, hub_nmi
);
535 /* If we're holding the hub lock, release it now */
536 if (nmi_detected
< 0)
537 raw_spin_unlock(&hub_nmi
->nmi_lock
);
542 local64_inc(&uv_nmi_misses
);
547 /* Need to reset the NMI MMR register, but only once per hub. */
548 static inline void uv_clear_nmi(int cpu
)
550 struct uv_hub_nmi_s
*hub_nmi
= uv_hub_nmi
;
552 if (cpu
== atomic_read(&hub_nmi
->cpu_owner
)) {
553 atomic_set(&hub_nmi
->cpu_owner
, -1);
554 atomic_set(&hub_nmi
->in_nmi
, 0);
555 if (hub_nmi
->hub_present
)
556 uv_local_mmr_clear_nmi();
559 raw_spin_unlock(&hub_nmi
->nmi_lock
);
563 /* Ping non-responding CPU's attemping to force them into the NMI handler */
564 static void uv_nmi_nr_cpus_ping(void)
568 for_each_cpu(cpu
, uv_nmi_cpu_mask
)
569 uv_cpu_nmi_per(cpu
).pinging
= 1;
571 apic
->send_IPI_mask(uv_nmi_cpu_mask
, APIC_DM_NMI
);
574 /* Clean up flags for CPU's that ignored both NMI and ping */
575 static void uv_nmi_cleanup_mask(void)
579 for_each_cpu(cpu
, uv_nmi_cpu_mask
) {
580 uv_cpu_nmi_per(cpu
).pinging
= 0;
581 uv_cpu_nmi_per(cpu
).state
= UV_NMI_STATE_OUT
;
582 cpumask_clear_cpu(cpu
, uv_nmi_cpu_mask
);
586 /* Loop waiting as CPU's enter NMI handler */
587 static int uv_nmi_wait_cpus(int first
)
589 int i
, j
, k
, n
= num_online_cpus();
590 int last_k
= 0, waiting
= 0;
591 int cpu
= smp_processor_id();
594 cpumask_copy(uv_nmi_cpu_mask
, cpu_online_mask
);
597 k
= n
- cpumask_weight(uv_nmi_cpu_mask
);
600 /* PCH NMI causes only one CPU to respond */
601 if (first
&& uv_pch_intr_now_enabled
) {
602 cpumask_clear_cpu(cpu
, uv_nmi_cpu_mask
);
606 udelay(uv_nmi_initial_delay
);
607 for (i
= 0; i
< uv_nmi_retry_count
; i
++) {
608 int loop_delay
= uv_nmi_loop_delay
;
610 for_each_cpu(j
, uv_nmi_cpu_mask
) {
611 if (uv_cpu_nmi_per(j
).state
) {
612 cpumask_clear_cpu(j
, uv_nmi_cpu_mask
);
617 if (k
>= n
) { /* all in? */
621 if (last_k
!= k
) { /* abort if no new CPU's coming in */
624 } else if (++waiting
> uv_nmi_wait_count
)
627 /* Extend delay if waiting only for CPU 0: */
628 if (waiting
&& (n
- k
) == 1 &&
629 cpumask_test_cpu(0, uv_nmi_cpu_mask
))
634 atomic_set(&uv_nmi_cpus_in_nmi
, k
);
638 /* Wait until all slave CPU's have entered UV NMI handler */
639 static void uv_nmi_wait(int master
)
641 /* Indicate this CPU is in: */
642 this_cpu_write(uv_cpu_nmi
.state
, UV_NMI_STATE_IN
);
644 /* If not the first CPU in (the master), then we are a slave CPU */
649 /* Wait for all other CPU's to gather here */
650 if (!uv_nmi_wait_cpus(1))
653 /* If not all made it in, send IPI NMI to them */
654 pr_alert("UV: Sending NMI IPI to %d CPUs: %*pbl\n",
655 cpumask_weight(uv_nmi_cpu_mask
),
656 cpumask_pr_args(uv_nmi_cpu_mask
));
658 uv_nmi_nr_cpus_ping();
660 /* If all CPU's are in, then done */
661 if (!uv_nmi_wait_cpus(0))
664 pr_alert("UV: %d CPUs not in NMI loop: %*pbl\n",
665 cpumask_weight(uv_nmi_cpu_mask
),
666 cpumask_pr_args(uv_nmi_cpu_mask
));
669 pr_alert("UV: %d of %d CPUs in NMI\n",
670 atomic_read(&uv_nmi_cpus_in_nmi
), num_online_cpus());
673 /* Dump Instruction Pointer header */
674 static void uv_nmi_dump_cpu_ip_hdr(void)
676 pr_info("\nUV: %4s %6s %-32s %s (Note: PID 0 not listed)\n",
677 "CPU", "PID", "COMMAND", "IP");
680 /* Dump Instruction Pointer info */
681 static void uv_nmi_dump_cpu_ip(int cpu
, struct pt_regs
*regs
)
683 pr_info("UV: %4d %6d %-32.32s %pS",
684 cpu
, current
->pid
, current
->comm
, (void *)regs
->ip
);
688 * Dump this CPU's state. If action was set to "kdump" and the crash_kexec
689 * failed, then we provide "dump" as an alternate action. Action "dump" now
690 * also includes the show "ips" (instruction pointers) action whereas the
691 * action "ips" only displays instruction pointers for the non-idle CPU's.
692 * This is an abbreviated form of the "ps" command.
694 static void uv_nmi_dump_state_cpu(int cpu
, struct pt_regs
*regs
)
696 const char *dots
= " ................................. ";
699 uv_nmi_dump_cpu_ip_hdr();
701 if (current
->pid
!= 0 || !uv_nmi_action_is("ips"))
702 uv_nmi_dump_cpu_ip(cpu
, regs
);
704 if (uv_nmi_action_is("dump")) {
705 pr_info("UV:%sNMI process trace for CPU %d\n", dots
, cpu
);
709 this_cpu_write(uv_cpu_nmi
.state
, UV_NMI_STATE_DUMP_DONE
);
712 /* Trigger a slave CPU to dump it's state */
713 static void uv_nmi_trigger_dump(int cpu
)
715 int retry
= uv_nmi_trigger_delay
;
717 if (uv_cpu_nmi_per(cpu
).state
!= UV_NMI_STATE_IN
)
720 uv_cpu_nmi_per(cpu
).state
= UV_NMI_STATE_DUMP
;
724 if (uv_cpu_nmi_per(cpu
).state
725 != UV_NMI_STATE_DUMP
)
727 } while (--retry
> 0);
729 pr_crit("UV: CPU %d stuck in process dump function\n", cpu
);
730 uv_cpu_nmi_per(cpu
).state
= UV_NMI_STATE_DUMP_DONE
;
733 /* Wait until all CPU's ready to exit */
734 static void uv_nmi_sync_exit(int master
)
736 atomic_dec(&uv_nmi_cpus_in_nmi
);
738 while (atomic_read(&uv_nmi_cpus_in_nmi
) > 0)
740 atomic_set(&uv_nmi_slave_continue
, SLAVE_CLEAR
);
742 while (atomic_read(&uv_nmi_slave_continue
))
747 /* Current "health" check is to check which CPU's are responsive */
748 static void uv_nmi_action_health(int cpu
, struct pt_regs
*regs
, int master
)
751 int in
= atomic_read(&uv_nmi_cpus_in_nmi
);
752 int out
= num_online_cpus() - in
;
754 pr_alert("UV: NMI CPU health check (non-responding:%d)\n", out
);
755 atomic_set(&uv_nmi_slave_continue
, SLAVE_EXIT
);
757 while (!atomic_read(&uv_nmi_slave_continue
))
760 uv_nmi_sync_exit(master
);
763 /* Walk through CPU list and dump state of each */
764 static void uv_nmi_dump_state(int cpu
, struct pt_regs
*regs
, int master
)
769 int saved_console_loglevel
= console_loglevel
;
771 pr_alert("UV: tracing %s for %d CPUs from CPU %d\n",
772 uv_nmi_action_is("ips") ? "IPs" : "processes",
773 atomic_read(&uv_nmi_cpus_in_nmi
), cpu
);
775 console_loglevel
= uv_nmi_loglevel
;
776 atomic_set(&uv_nmi_slave_continue
, SLAVE_EXIT
);
777 for_each_online_cpu(tcpu
) {
778 if (cpumask_test_cpu(tcpu
, uv_nmi_cpu_mask
))
780 else if (tcpu
== cpu
)
781 uv_nmi_dump_state_cpu(tcpu
, regs
);
783 uv_nmi_trigger_dump(tcpu
);
786 pr_alert("UV: %d CPUs ignored NMI\n", ignored
);
788 console_loglevel
= saved_console_loglevel
;
789 pr_alert("UV: process trace complete\n");
791 while (!atomic_read(&uv_nmi_slave_continue
))
793 while (this_cpu_read(uv_cpu_nmi
.state
) != UV_NMI_STATE_DUMP
)
795 uv_nmi_dump_state_cpu(cpu
, regs
);
797 uv_nmi_sync_exit(master
);
800 static void uv_nmi_touch_watchdogs(void)
802 touch_softlockup_watchdog_sync();
803 clocksource_touch_watchdog();
804 rcu_cpu_stall_reset();
805 touch_nmi_watchdog();
808 static atomic_t uv_nmi_kexec_failed
;
810 #if defined(CONFIG_KEXEC_CORE)
811 static void uv_nmi_kdump(int cpu
, int master
, struct pt_regs
*regs
)
813 /* Call crash to dump system state */
815 pr_emerg("UV: NMI executing crash_kexec on CPU%d\n", cpu
);
818 pr_emerg("UV: crash_kexec unexpectedly returned, ");
819 atomic_set(&uv_nmi_kexec_failed
, 1);
820 if (!kexec_crash_image
) {
821 pr_cont("crash kernel not loaded\n");
824 pr_cont("kexec busy, stalling cpus while waiting\n");
827 /* If crash exec fails the slaves should return, otherwise stall */
828 while (atomic_read(&uv_nmi_kexec_failed
) == 0)
832 #else /* !CONFIG_KEXEC_CORE */
833 static inline void uv_nmi_kdump(int cpu
, int master
, struct pt_regs
*regs
)
836 pr_err("UV: NMI kdump: KEXEC not supported in this kernel\n");
837 atomic_set(&uv_nmi_kexec_failed
, 1);
839 #endif /* !CONFIG_KEXEC_CORE */
842 #ifdef CONFIG_KGDB_KDB
843 static inline int uv_nmi_kdb_reason(void)
845 return KDB_REASON_SYSTEM_NMI
;
847 #else /* !CONFIG_KGDB_KDB */
848 static inline int uv_nmi_kdb_reason(void)
850 /* Ensure user is expecting to attach gdb remote */
851 if (uv_nmi_action_is("kgdb"))
854 pr_err("UV: NMI error: KDB is not enabled in this kernel\n");
857 #endif /* CONFIG_KGDB_KDB */
860 * Call KGDB/KDB from NMI handler
862 * Note that if both KGDB and KDB are configured, then the action of 'kgdb' or
863 * 'kdb' has no affect on which is used. See the KGDB documention for further
866 static void uv_call_kgdb_kdb(int cpu
, struct pt_regs
*regs
, int master
)
869 int reason
= uv_nmi_kdb_reason();
875 /* Call KGDB NMI handler as MASTER */
876 ret
= kgdb_nmicallin(cpu
, X86_TRAP_NMI
, regs
, reason
,
877 &uv_nmi_slave_continue
);
879 pr_alert("KGDB returned error, is kgdboc set?\n");
880 atomic_set(&uv_nmi_slave_continue
, SLAVE_EXIT
);
883 /* Wait for KGDB signal that it's ready for slaves to enter */
888 sig
= atomic_read(&uv_nmi_slave_continue
);
891 /* Call KGDB as slave */
892 if (sig
== SLAVE_CONTINUE
)
893 kgdb_nmicallback(cpu
, regs
);
895 uv_nmi_sync_exit(master
);
898 #else /* !CONFIG_KGDB */
899 static inline void uv_call_kgdb_kdb(int cpu
, struct pt_regs
*regs
, int master
)
901 pr_err("UV: NMI error: KGDB is not enabled in this kernel\n");
903 #endif /* !CONFIG_KGDB */
908 static int uv_handle_nmi(unsigned int reason
, struct pt_regs
*regs
)
910 struct uv_hub_nmi_s
*hub_nmi
= uv_hub_nmi
;
911 int cpu
= smp_processor_id();
915 local_irq_save(flags
);
917 /* If not a UV System NMI, ignore */
918 if (!this_cpu_read(uv_cpu_nmi
.pinging
) && !uv_check_nmi(hub_nmi
)) {
919 local_irq_restore(flags
);
923 /* Indicate we are the first CPU into the NMI handler */
924 master
= (atomic_read(&uv_nmi_cpu
) == cpu
);
926 /* If NMI action is "kdump", then attempt to do it */
927 if (uv_nmi_action_is("kdump")) {
928 uv_nmi_kdump(cpu
, master
, regs
);
930 /* Unexpected return, revert action to "dump" */
932 strncpy(uv_nmi_action
, "dump", strlen(uv_nmi_action
));
935 /* Pause as all CPU's enter the NMI handler */
938 /* Process actions other than "kdump": */
939 if (uv_nmi_action_is("health")) {
940 uv_nmi_action_health(cpu
, regs
, master
);
941 } else if (uv_nmi_action_is("ips") || uv_nmi_action_is("dump")) {
942 uv_nmi_dump_state(cpu
, regs
, master
);
943 } else if (uv_nmi_action_is("kdb") || uv_nmi_action_is("kgdb")) {
944 uv_call_kgdb_kdb(cpu
, regs
, master
);
947 pr_alert("UV: unknown NMI action: %s\n", uv_nmi_action
);
948 uv_nmi_sync_exit(master
);
951 /* Clear per_cpu "in_nmi" flag */
952 this_cpu_write(uv_cpu_nmi
.state
, UV_NMI_STATE_OUT
);
954 /* Clear MMR NMI flag on each hub */
957 /* Clear global flags */
959 if (cpumask_weight(uv_nmi_cpu_mask
))
960 uv_nmi_cleanup_mask();
961 atomic_set(&uv_nmi_cpus_in_nmi
, -1);
962 atomic_set(&uv_nmi_cpu
, -1);
963 atomic_set(&uv_in_nmi
, 0);
964 atomic_set(&uv_nmi_kexec_failed
, 0);
965 atomic_set(&uv_nmi_slave_continue
, SLAVE_CLEAR
);
968 uv_nmi_touch_watchdogs();
969 local_irq_restore(flags
);
975 * NMI handler for pulling in CPU's when perf events are grabbing our NMI
977 static int uv_handle_nmi_ping(unsigned int reason
, struct pt_regs
*regs
)
981 this_cpu_inc(uv_cpu_nmi
.queries
);
982 if (!this_cpu_read(uv_cpu_nmi
.pinging
)) {
983 local64_inc(&uv_nmi_ping_misses
);
987 this_cpu_inc(uv_cpu_nmi
.pings
);
988 local64_inc(&uv_nmi_ping_count
);
989 ret
= uv_handle_nmi(reason
, regs
);
990 this_cpu_write(uv_cpu_nmi
.pinging
, 0);
994 static void uv_register_nmi_notifier(void)
996 if (register_nmi_handler(NMI_UNKNOWN
, uv_handle_nmi
, 0, "uv"))
997 pr_warn("UV: NMI handler failed to register\n");
999 if (register_nmi_handler(NMI_LOCAL
, uv_handle_nmi_ping
, 0, "uvping"))
1000 pr_warn("UV: PING NMI handler failed to register\n");
1003 void uv_nmi_init(void)
1008 * Unmask NMI on all CPU's
1010 value
= apic_read(APIC_LVT1
) | APIC_DM_NMI
;
1011 value
&= ~APIC_LVT_MASKED
;
1012 apic_write(APIC_LVT1
, value
);
1015 /* Setup HUB NMI info */
1016 static void __init
uv_nmi_setup_common(bool hubbed
)
1018 int size
= sizeof(void *) * (1 << NODES_SHIFT
);
1021 uv_hub_nmi_list
= kzalloc(size
, GFP_KERNEL
);
1022 nmi_debug("UV: NMI hub list @ 0x%p (%d)\n", uv_hub_nmi_list
, size
);
1023 BUG_ON(!uv_hub_nmi_list
);
1024 size
= sizeof(struct uv_hub_nmi_s
);
1025 for_each_present_cpu(cpu
) {
1026 int nid
= cpu_to_node(cpu
);
1027 if (uv_hub_nmi_list
[nid
] == NULL
) {
1028 uv_hub_nmi_list
[nid
] = kzalloc_node(size
,
1030 BUG_ON(!uv_hub_nmi_list
[nid
]);
1031 raw_spin_lock_init(&(uv_hub_nmi_list
[nid
]->nmi_lock
));
1032 atomic_set(&uv_hub_nmi_list
[nid
]->cpu_owner
, -1);
1033 uv_hub_nmi_list
[nid
]->hub_present
= hubbed
;
1034 uv_hub_nmi_list
[nid
]->pch_owner
= (nid
== 0);
1036 uv_hub_nmi_per(cpu
) = uv_hub_nmi_list
[nid
];
1038 BUG_ON(!alloc_cpumask_var(&uv_nmi_cpu_mask
, GFP_KERNEL
));
1041 /* Setup for UV Hub systems */
1042 void __init
uv_nmi_setup(void)
1044 uv_nmi_setup_mmrs();
1045 uv_nmi_setup_common(true);
1046 uv_register_nmi_notifier();
1047 pr_info("UV: Hub NMI enabled\n");
1050 /* Setup for UV Hubless systems */
1051 void __init
uv_nmi_setup_hubless(void)
1053 uv_nmi_setup_common(false);
1054 pch_base
= xlate_dev_mem_ptr(PCH_PCR_GPIO_1_BASE
);
1055 nmi_debug("UV: PCH base:%p from 0x%lx, GPP_D_0\n",
1056 pch_base
, PCH_PCR_GPIO_1_BASE
);
1057 if (uv_pch_init_enable
)
1058 uv_init_hubless_pch_d0();
1059 uv_init_hubless_pch_io(GPI_NMI_ENA_GPP_D_0
,
1060 STS_GPP_D_0_MASK
, STS_GPP_D_0_MASK
);
1061 uv_nmi_setup_hubless_intr();
1062 /* Ensure NMI enabled in Processor Interface Reg: */
1064 uv_register_nmi_notifier();
1065 pr_info("UV: Hubless NMI enabled\n");