1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * SGI NMI support routines
5 * Copyright (c) 2009-2013 Silicon Graphics, Inc. All Rights Reserved.
6 * Copyright (c) Mike Travis
10 #include <linux/delay.h>
11 #include <linux/kdb.h>
12 #include <linux/kexec.h>
13 #include <linux/kgdb.h>
14 #include <linux/moduleparam.h>
15 #include <linux/nmi.h>
16 #include <linux/sched.h>
17 #include <linux/sched/debug.h>
18 #include <linux/slab.h>
19 #include <linux/clocksource.h>
22 #include <asm/current.h>
23 #include <asm/kdebug.h>
24 #include <asm/local64.h>
26 #include <asm/traps.h>
27 #include <asm/uv/uv.h>
28 #include <asm/uv/uv_hub.h>
29 #include <asm/uv/uv_mmrs.h>
34 * Handle system-wide NMI events generated by the global 'power nmi' command.
36 * Basic operation is to field the NMI interrupt on each CPU and wait
37 * until all CPU's have arrived into the nmi handler. If some CPU's do not
38 * make it into the handler, try and force them in with the IPI(NMI) signal.
40 * We also have to lessen UV Hub MMR accesses as much as possible as this
41 * disrupts the UV Hub's primary mission of directing NumaLink traffic and
42 * can cause system problems to occur.
44 * To do this we register our primary NMI notifier on the NMI_UNKNOWN
45 * chain. This reduces the number of false NMI calls when the perf
46 * tools are running which generate an enormous number of NMIs per
47 * second (~4M/s for 1024 CPU threads). Our secondary NMI handler is
48 * very short as it only checks that if it has been "pinged" with the
49 * IPI(NMI) signal as mentioned above, and does not read the UV Hub's MMR.
53 static struct uv_hub_nmi_s
**uv_hub_nmi_list
;
55 DEFINE_PER_CPU(struct uv_cpu_nmi_s
, uv_cpu_nmi
);
57 /* UV hubless values */
58 #define NMI_CONTROL_PORT 0x70
59 #define NMI_DUMMY_PORT 0x71
60 #define PAD_OWN_GPP_D_0 0x2c
61 #define GPI_NMI_STS_GPP_D_0 0x164
62 #define GPI_NMI_ENA_GPP_D_0 0x174
63 #define STS_GPP_D_0_MASK 0x1
64 #define PAD_CFG_DW0_GPP_D_0 0x4c0
65 #define GPIROUTNMI (1ul << 17)
66 #define PCH_PCR_GPIO_1_BASE 0xfdae0000ul
67 #define PCH_PCR_GPIO_ADDRESS(offset) (int *)((u64)(pch_base) | (u64)(offset))
70 static unsigned long nmi_mmr
;
71 static unsigned long nmi_mmr_clear
;
72 static unsigned long nmi_mmr_pending
;
74 static atomic_t uv_in_nmi
;
75 static atomic_t uv_nmi_cpu
= ATOMIC_INIT(-1);
76 static atomic_t uv_nmi_cpus_in_nmi
= ATOMIC_INIT(-1);
77 static atomic_t uv_nmi_slave_continue
;
78 static cpumask_var_t uv_nmi_cpu_mask
;
80 /* Values for uv_nmi_slave_continue */
82 #define SLAVE_CONTINUE 1
86 * Default is all stack dumps go to the console and buffer.
87 * Lower level to send to log buffer only.
89 static int uv_nmi_loglevel
= CONSOLE_LOGLEVEL_DEFAULT
;
90 module_param_named(dump_loglevel
, uv_nmi_loglevel
, int, 0644);
93 * The following values show statistics on how perf events are affecting
96 static int param_get_local64(char *buffer
, const struct kernel_param
*kp
)
98 return sprintf(buffer
, "%lu\n", local64_read((local64_t
*)kp
->arg
));
101 static int param_set_local64(const char *val
, const struct kernel_param
*kp
)
103 /* Clear on any write */
104 local64_set((local64_t
*)kp
->arg
, 0);
108 static const struct kernel_param_ops param_ops_local64
= {
109 .get
= param_get_local64
,
110 .set
= param_set_local64
,
112 #define param_check_local64(name, p) __param_check(name, p, local64_t)
114 static local64_t uv_nmi_count
;
115 module_param_named(nmi_count
, uv_nmi_count
, local64
, 0644);
117 static local64_t uv_nmi_misses
;
118 module_param_named(nmi_misses
, uv_nmi_misses
, local64
, 0644);
120 static local64_t uv_nmi_ping_count
;
121 module_param_named(ping_count
, uv_nmi_ping_count
, local64
, 0644);
123 static local64_t uv_nmi_ping_misses
;
124 module_param_named(ping_misses
, uv_nmi_ping_misses
, local64
, 0644);
127 * Following values allow tuning for large systems under heavy loading
129 static int uv_nmi_initial_delay
= 100;
130 module_param_named(initial_delay
, uv_nmi_initial_delay
, int, 0644);
132 static int uv_nmi_slave_delay
= 100;
133 module_param_named(slave_delay
, uv_nmi_slave_delay
, int, 0644);
135 static int uv_nmi_loop_delay
= 100;
136 module_param_named(loop_delay
, uv_nmi_loop_delay
, int, 0644);
138 static int uv_nmi_trigger_delay
= 10000;
139 module_param_named(trigger_delay
, uv_nmi_trigger_delay
, int, 0644);
141 static int uv_nmi_wait_count
= 100;
142 module_param_named(wait_count
, uv_nmi_wait_count
, int, 0644);
144 static int uv_nmi_retry_count
= 500;
145 module_param_named(retry_count
, uv_nmi_retry_count
, int, 0644);
147 static bool uv_pch_intr_enable
= true;
148 static bool uv_pch_intr_now_enabled
;
149 module_param_named(pch_intr_enable
, uv_pch_intr_enable
, bool, 0644);
151 static bool uv_pch_init_enable
= true;
152 module_param_named(pch_init_enable
, uv_pch_init_enable
, bool, 0644);
154 static int uv_nmi_debug
;
155 module_param_named(debug
, uv_nmi_debug
, int, 0644);
157 #define nmi_debug(fmt, ...) \
160 pr_info(fmt, ##__VA_ARGS__); \
163 /* Valid NMI Actions */
164 #define ACTION_LEN 16
165 static struct nmi_action
{
169 { "kdump", "do kernel crash dump" },
170 { "dump", "dump process stack for each cpu" },
171 { "ips", "dump Inst Ptr info for each cpu" },
172 { "kdb", "enter KDB (needs kgdboc= assignment)" },
173 { "kgdb", "enter KGDB (needs gdb target remote)" },
174 { "health", "check if CPUs respond to NMI" },
176 typedef char action_t
[ACTION_LEN
];
177 static action_t uv_nmi_action
= { "dump" };
179 static int param_get_action(char *buffer
, const struct kernel_param
*kp
)
181 return sprintf(buffer
, "%s\n", uv_nmi_action
);
184 static int param_set_action(const char *val
, const struct kernel_param
*kp
)
187 int n
= ARRAY_SIZE(valid_acts
);
188 char arg
[ACTION_LEN
], *p
;
190 /* (remove possible '\n') */
191 strncpy(arg
, val
, ACTION_LEN
- 1);
192 arg
[ACTION_LEN
- 1] = '\0';
193 p
= strchr(arg
, '\n');
197 for (i
= 0; i
< n
; i
++)
198 if (!strcmp(arg
, valid_acts
[i
].action
))
202 strcpy(uv_nmi_action
, arg
);
203 pr_info("UV: New NMI action:%s\n", uv_nmi_action
);
207 pr_err("UV: Invalid NMI action:%s, valid actions are:\n", arg
);
208 for (i
= 0; i
< n
; i
++)
209 pr_err("UV: %-8s - %s\n",
210 valid_acts
[i
].action
, valid_acts
[i
].desc
);
214 static const struct kernel_param_ops param_ops_action
= {
215 .get
= param_get_action
,
216 .set
= param_set_action
,
218 #define param_check_action(name, p) __param_check(name, p, action_t)
220 module_param_named(action
, uv_nmi_action
, action
, 0644);
222 static inline bool uv_nmi_action_is(const char *action
)
224 return (strncmp(uv_nmi_action
, action
, strlen(action
)) == 0);
227 /* Setup which NMI support is present in system */
228 static void uv_nmi_setup_mmrs(void)
230 if (uv_read_local_mmr(UVH_NMI_MMRX_SUPPORTED
)) {
231 uv_write_local_mmr(UVH_NMI_MMRX_REQ
,
232 1UL << UVH_NMI_MMRX_REQ_SHIFT
);
233 nmi_mmr
= UVH_NMI_MMRX
;
234 nmi_mmr_clear
= UVH_NMI_MMRX_CLEAR
;
235 nmi_mmr_pending
= 1UL << UVH_NMI_MMRX_SHIFT
;
236 pr_info("UV: SMI NMI support: %s\n", UVH_NMI_MMRX_TYPE
);
238 nmi_mmr
= UVH_NMI_MMR
;
239 nmi_mmr_clear
= UVH_NMI_MMR_CLEAR
;
240 nmi_mmr_pending
= 1UL << UVH_NMI_MMR_SHIFT
;
241 pr_info("UV: SMI NMI support: %s\n", UVH_NMI_MMR_TYPE
);
245 /* Read NMI MMR and check if NMI flag was set by BMC. */
246 static inline int uv_nmi_test_mmr(struct uv_hub_nmi_s
*hub_nmi
)
248 hub_nmi
->nmi_value
= uv_read_local_mmr(nmi_mmr
);
249 atomic_inc(&hub_nmi
->read_mmr_count
);
250 return !!(hub_nmi
->nmi_value
& nmi_mmr_pending
);
253 static inline void uv_local_mmr_clear_nmi(void)
255 uv_write_local_mmr(nmi_mmr_clear
, nmi_mmr_pending
);
259 * UV hubless NMI handler functions
261 static inline void uv_reassert_nmi(void)
263 /* (from arch/x86/include/asm/mach_traps.h) */
264 outb(0x8f, NMI_CONTROL_PORT
);
265 inb(NMI_DUMMY_PORT
); /* dummy read */
266 outb(0x0f, NMI_CONTROL_PORT
);
267 inb(NMI_DUMMY_PORT
); /* dummy read */
270 static void uv_init_hubless_pch_io(int offset
, int mask
, int data
)
272 int *addr
= PCH_PCR_GPIO_ADDRESS(offset
);
273 int readd
= readl(addr
);
275 if (mask
) { /* OR in new data */
276 int writed
= (readd
& ~mask
) | data
;
278 nmi_debug("UV:PCH: %p = %x & %x | %x (%x)\n",
279 addr
, readd
, ~mask
, data
, writed
);
280 writel(writed
, addr
);
281 } else if (readd
& data
) { /* clear status bit */
282 nmi_debug("UV:PCH: %p = %x\n", addr
, data
);
286 (void)readl(addr
); /* flush write data */
289 static void uv_nmi_setup_hubless_intr(void)
291 uv_pch_intr_now_enabled
= uv_pch_intr_enable
;
293 uv_init_hubless_pch_io(
294 PAD_CFG_DW0_GPP_D_0
, GPIROUTNMI
,
295 uv_pch_intr_now_enabled
? GPIROUTNMI
: 0);
297 nmi_debug("UV:NMI: GPP_D_0 interrupt %s\n",
298 uv_pch_intr_now_enabled
? "enabled" : "disabled");
301 static struct init_nmi
{
306 { /* HOSTSW_OWN_GPP_D_0 */
309 .data
= 0x0, /* ACPI Mode */
313 { /* GPI_INT_STS_GPP_D_0 */
316 .data
= 0x1, /* Clear Status */
318 { /* GPI_GPE_STS_GPP_D_0 */
321 .data
= 0x1, /* Clear Status */
323 { /* GPI_SMI_STS_GPP_D_0 */
326 .data
= 0x1, /* Clear Status */
328 { /* GPI_NMI_STS_GPP_D_0 */
331 .data
= 0x1, /* Clear Status */
334 /* Disable interrupts: */
335 { /* GPI_INT_EN_GPP_D_0 */
338 .data
= 0x0, /* Disable interrupt generation */
340 { /* GPI_GPE_EN_GPP_D_0 */
343 .data
= 0x0, /* Disable interrupt generation */
345 { /* GPI_SMI_EN_GPP_D_0 */
348 .data
= 0x0, /* Disable interrupt generation */
350 { /* GPI_NMI_EN_GPP_D_0 */
353 .data
= 0x0, /* Disable interrupt generation */
356 /* Setup GPP_D_0 Pad Config: */
357 { /* PAD_CFG_DW0_GPP_D_0 */
362 * 31:30 Pad Reset Config (PADRSTCFG): = 2h # PLTRST# (default)
364 * 29 RX Pad State Select (RXPADSTSEL): = 0 # Raw RX pad state directly
365 * from RX buffer (default)
367 * 28 RX Raw Override to '1' (RXRAW1): = 0 # No Override
369 * 26:25 RX Level/Edge Configuration (RXEVCFG):
373 * 23 RX Invert (RXINV): = 0 # No Inversion (signal active high)
375 * 20 GPIO Input Route IOxAPIC (GPIROUTIOXAPIC):
376 * = 0 # Routing does not cause peripheral IRQ...
377 * # (we want an NMI not an IRQ)
379 * 19 GPIO Input Route SCI (GPIROUTSCI): = 0 # Routing does not cause SCI.
380 * 18 GPIO Input Route SMI (GPIROUTSMI): = 0 # Routing does not cause SMI.
381 * 17 GPIO Input Route NMI (GPIROUTNMI): = 1 # Routing can cause NMI.
383 * 11:10 Pad Mode (PMODE1/0): = 0h = GPIO control the Pad.
384 * 9 GPIO RX Disable (GPIORXDIS):
385 * = 0 # Enable the input buffer (active low enable)
387 * 8 GPIO TX Disable (GPIOTXDIS):
388 * = 1 # Disable the output buffer; i.e. Hi-Z
390 * 1 GPIO RX State (GPIORXSTATE): This is the current internal RX pad state..
391 * 0 GPIO TX State (GPIOTXSTATE):
392 * = 0 # (Leave at default)
397 { /* PAD_CFG_DW1_GPP_D_0 */
400 .data
= 0, /* Termination = none (default) */
404 static void uv_init_hubless_pch_d0(void)
408 read
= *PCH_PCR_GPIO_ADDRESS(PAD_OWN_GPP_D_0
);
410 pr_info("UV: Hubless NMI already configured\n");
414 nmi_debug("UV: Initializing UV Hubless NMI on PCH\n");
415 for (i
= 0; i
< ARRAY_SIZE(init_nmi
); i
++) {
416 uv_init_hubless_pch_io(init_nmi
[i
].offset
,
422 static int uv_nmi_test_hubless(struct uv_hub_nmi_s
*hub_nmi
)
424 int *pstat
= PCH_PCR_GPIO_ADDRESS(GPI_NMI_STS_GPP_D_0
);
427 hub_nmi
->nmi_value
= status
;
428 atomic_inc(&hub_nmi
->read_mmr_count
);
430 if (!(status
& STS_GPP_D_0_MASK
)) /* Not a UV external NMI */
433 *pstat
= STS_GPP_D_0_MASK
; /* Is a UV NMI: clear GPP_D_0 status */
434 (void)*pstat
; /* Flush write */
439 static int uv_test_nmi(struct uv_hub_nmi_s
*hub_nmi
)
441 if (hub_nmi
->hub_present
)
442 return uv_nmi_test_mmr(hub_nmi
);
444 if (hub_nmi
->pch_owner
) /* Only PCH owner can check status */
445 return uv_nmi_test_hubless(hub_nmi
);
451 * If first CPU in on this hub, set hub_nmi "in_nmi" and "owner" values and
452 * return true. If first CPU in on the system, set global "in_nmi" flag.
454 static int uv_set_in_nmi(int cpu
, struct uv_hub_nmi_s
*hub_nmi
)
456 int first
= atomic_add_unless(&hub_nmi
->in_nmi
, 1, 1);
459 atomic_set(&hub_nmi
->cpu_owner
, cpu
);
460 if (atomic_add_unless(&uv_in_nmi
, 1, 1))
461 atomic_set(&uv_nmi_cpu
, cpu
);
463 atomic_inc(&hub_nmi
->nmi_count
);
468 /* Check if this is a system NMI event */
469 static int uv_check_nmi(struct uv_hub_nmi_s
*hub_nmi
)
471 int cpu
= smp_processor_id();
473 int nmi_detected
= 0;
475 local64_inc(&uv_nmi_count
);
476 this_cpu_inc(uv_cpu_nmi
.queries
);
479 nmi
= atomic_read(&hub_nmi
->in_nmi
);
483 if (raw_spin_trylock(&hub_nmi
->nmi_lock
)) {
484 nmi_detected
= uv_test_nmi(hub_nmi
);
486 /* Check flag for UV external NMI */
487 if (nmi_detected
> 0) {
488 uv_set_in_nmi(cpu
, hub_nmi
);
493 /* A non-PCH node in a hubless system waits for NMI */
494 else if (nmi_detected
< 0)
497 /* MMR/PCH NMI flag is clear */
498 raw_spin_unlock(&hub_nmi
->nmi_lock
);
502 /* Wait a moment for the HUB NMI locker to set flag */
503 slave_wait
: cpu_relax();
504 udelay(uv_nmi_slave_delay
);
506 /* Re-check hub in_nmi flag */
507 nmi
= atomic_read(&hub_nmi
->in_nmi
);
513 * Check if this BMC missed setting the MMR NMI flag (or)
514 * UV hubless system where only PCH owner can check flag
517 nmi
= atomic_read(&uv_in_nmi
);
519 uv_set_in_nmi(cpu
, hub_nmi
);
522 /* If we're holding the hub lock, release it now */
523 if (nmi_detected
< 0)
524 raw_spin_unlock(&hub_nmi
->nmi_lock
);
529 local64_inc(&uv_nmi_misses
);
534 /* Need to reset the NMI MMR register, but only once per hub. */
535 static inline void uv_clear_nmi(int cpu
)
537 struct uv_hub_nmi_s
*hub_nmi
= uv_hub_nmi
;
539 if (cpu
== atomic_read(&hub_nmi
->cpu_owner
)) {
540 atomic_set(&hub_nmi
->cpu_owner
, -1);
541 atomic_set(&hub_nmi
->in_nmi
, 0);
542 if (hub_nmi
->hub_present
)
543 uv_local_mmr_clear_nmi();
546 raw_spin_unlock(&hub_nmi
->nmi_lock
);
550 /* Ping non-responding CPU's attempting to force them into the NMI handler */
551 static void uv_nmi_nr_cpus_ping(void)
555 for_each_cpu(cpu
, uv_nmi_cpu_mask
)
556 uv_cpu_nmi_per(cpu
).pinging
= 1;
558 apic
->send_IPI_mask(uv_nmi_cpu_mask
, APIC_DM_NMI
);
561 /* Clean up flags for CPU's that ignored both NMI and ping */
562 static void uv_nmi_cleanup_mask(void)
566 for_each_cpu(cpu
, uv_nmi_cpu_mask
) {
567 uv_cpu_nmi_per(cpu
).pinging
= 0;
568 uv_cpu_nmi_per(cpu
).state
= UV_NMI_STATE_OUT
;
569 cpumask_clear_cpu(cpu
, uv_nmi_cpu_mask
);
573 /* Loop waiting as CPU's enter NMI handler */
574 static int uv_nmi_wait_cpus(int first
)
576 int i
, j
, k
, n
= num_online_cpus();
577 int last_k
= 0, waiting
= 0;
578 int cpu
= smp_processor_id();
581 cpumask_copy(uv_nmi_cpu_mask
, cpu_online_mask
);
584 k
= n
- cpumask_weight(uv_nmi_cpu_mask
);
587 /* PCH NMI causes only one CPU to respond */
588 if (first
&& uv_pch_intr_now_enabled
) {
589 cpumask_clear_cpu(cpu
, uv_nmi_cpu_mask
);
593 udelay(uv_nmi_initial_delay
);
594 for (i
= 0; i
< uv_nmi_retry_count
; i
++) {
595 int loop_delay
= uv_nmi_loop_delay
;
597 for_each_cpu(j
, uv_nmi_cpu_mask
) {
598 if (uv_cpu_nmi_per(j
).state
) {
599 cpumask_clear_cpu(j
, uv_nmi_cpu_mask
);
604 if (k
>= n
) { /* all in? */
608 if (last_k
!= k
) { /* abort if no new CPU's coming in */
611 } else if (++waiting
> uv_nmi_wait_count
)
614 /* Extend delay if waiting only for CPU 0: */
615 if (waiting
&& (n
- k
) == 1 &&
616 cpumask_test_cpu(0, uv_nmi_cpu_mask
))
621 atomic_set(&uv_nmi_cpus_in_nmi
, k
);
625 /* Wait until all slave CPU's have entered UV NMI handler */
626 static void uv_nmi_wait(int master
)
628 /* Indicate this CPU is in: */
629 this_cpu_write(uv_cpu_nmi
.state
, UV_NMI_STATE_IN
);
631 /* If not the first CPU in (the master), then we are a slave CPU */
636 /* Wait for all other CPU's to gather here */
637 if (!uv_nmi_wait_cpus(1))
640 /* If not all made it in, send IPI NMI to them */
641 pr_alert("UV: Sending NMI IPI to %d CPUs: %*pbl\n",
642 cpumask_weight(uv_nmi_cpu_mask
),
643 cpumask_pr_args(uv_nmi_cpu_mask
));
645 uv_nmi_nr_cpus_ping();
647 /* If all CPU's are in, then done */
648 if (!uv_nmi_wait_cpus(0))
651 pr_alert("UV: %d CPUs not in NMI loop: %*pbl\n",
652 cpumask_weight(uv_nmi_cpu_mask
),
653 cpumask_pr_args(uv_nmi_cpu_mask
));
656 pr_alert("UV: %d of %d CPUs in NMI\n",
657 atomic_read(&uv_nmi_cpus_in_nmi
), num_online_cpus());
660 /* Dump Instruction Pointer header */
661 static void uv_nmi_dump_cpu_ip_hdr(void)
663 pr_info("\nUV: %4s %6s %-32s %s (Note: PID 0 not listed)\n",
664 "CPU", "PID", "COMMAND", "IP");
667 /* Dump Instruction Pointer info */
668 static void uv_nmi_dump_cpu_ip(int cpu
, struct pt_regs
*regs
)
670 pr_info("UV: %4d %6d %-32.32s %pS",
671 cpu
, current
->pid
, current
->comm
, (void *)regs
->ip
);
675 * Dump this CPU's state. If action was set to "kdump" and the crash_kexec
676 * failed, then we provide "dump" as an alternate action. Action "dump" now
677 * also includes the show "ips" (instruction pointers) action whereas the
678 * action "ips" only displays instruction pointers for the non-idle CPU's.
679 * This is an abbreviated form of the "ps" command.
681 static void uv_nmi_dump_state_cpu(int cpu
, struct pt_regs
*regs
)
683 const char *dots
= " ................................. ";
686 uv_nmi_dump_cpu_ip_hdr();
688 if (current
->pid
!= 0 || !uv_nmi_action_is("ips"))
689 uv_nmi_dump_cpu_ip(cpu
, regs
);
691 if (uv_nmi_action_is("dump")) {
692 pr_info("UV:%sNMI process trace for CPU %d\n", dots
, cpu
);
696 this_cpu_write(uv_cpu_nmi
.state
, UV_NMI_STATE_DUMP_DONE
);
699 /* Trigger a slave CPU to dump it's state */
700 static void uv_nmi_trigger_dump(int cpu
)
702 int retry
= uv_nmi_trigger_delay
;
704 if (uv_cpu_nmi_per(cpu
).state
!= UV_NMI_STATE_IN
)
707 uv_cpu_nmi_per(cpu
).state
= UV_NMI_STATE_DUMP
;
711 if (uv_cpu_nmi_per(cpu
).state
712 != UV_NMI_STATE_DUMP
)
714 } while (--retry
> 0);
716 pr_crit("UV: CPU %d stuck in process dump function\n", cpu
);
717 uv_cpu_nmi_per(cpu
).state
= UV_NMI_STATE_DUMP_DONE
;
720 /* Wait until all CPU's ready to exit */
721 static void uv_nmi_sync_exit(int master
)
723 atomic_dec(&uv_nmi_cpus_in_nmi
);
725 while (atomic_read(&uv_nmi_cpus_in_nmi
) > 0)
727 atomic_set(&uv_nmi_slave_continue
, SLAVE_CLEAR
);
729 while (atomic_read(&uv_nmi_slave_continue
))
734 /* Current "health" check is to check which CPU's are responsive */
735 static void uv_nmi_action_health(int cpu
, struct pt_regs
*regs
, int master
)
738 int in
= atomic_read(&uv_nmi_cpus_in_nmi
);
739 int out
= num_online_cpus() - in
;
741 pr_alert("UV: NMI CPU health check (non-responding:%d)\n", out
);
742 atomic_set(&uv_nmi_slave_continue
, SLAVE_EXIT
);
744 while (!atomic_read(&uv_nmi_slave_continue
))
747 uv_nmi_sync_exit(master
);
750 /* Walk through CPU list and dump state of each */
751 static void uv_nmi_dump_state(int cpu
, struct pt_regs
*regs
, int master
)
756 int saved_console_loglevel
= console_loglevel
;
758 pr_alert("UV: tracing %s for %d CPUs from CPU %d\n",
759 uv_nmi_action_is("ips") ? "IPs" : "processes",
760 atomic_read(&uv_nmi_cpus_in_nmi
), cpu
);
762 console_loglevel
= uv_nmi_loglevel
;
763 atomic_set(&uv_nmi_slave_continue
, SLAVE_EXIT
);
764 for_each_online_cpu(tcpu
) {
765 if (cpumask_test_cpu(tcpu
, uv_nmi_cpu_mask
))
767 else if (tcpu
== cpu
)
768 uv_nmi_dump_state_cpu(tcpu
, regs
);
770 uv_nmi_trigger_dump(tcpu
);
773 pr_alert("UV: %d CPUs ignored NMI\n", ignored
);
775 console_loglevel
= saved_console_loglevel
;
776 pr_alert("UV: process trace complete\n");
778 while (!atomic_read(&uv_nmi_slave_continue
))
780 while (this_cpu_read(uv_cpu_nmi
.state
) != UV_NMI_STATE_DUMP
)
782 uv_nmi_dump_state_cpu(cpu
, regs
);
784 uv_nmi_sync_exit(master
);
787 static void uv_nmi_touch_watchdogs(void)
789 touch_softlockup_watchdog_sync();
790 clocksource_touch_watchdog();
791 rcu_cpu_stall_reset();
792 touch_nmi_watchdog();
795 static atomic_t uv_nmi_kexec_failed
;
797 #if defined(CONFIG_KEXEC_CORE)
798 static void uv_nmi_kdump(int cpu
, int master
, struct pt_regs
*regs
)
800 /* Call crash to dump system state */
802 pr_emerg("UV: NMI executing crash_kexec on CPU%d\n", cpu
);
805 pr_emerg("UV: crash_kexec unexpectedly returned, ");
806 atomic_set(&uv_nmi_kexec_failed
, 1);
807 if (!kexec_crash_image
) {
808 pr_cont("crash kernel not loaded\n");
811 pr_cont("kexec busy, stalling cpus while waiting\n");
814 /* If crash exec fails the slaves should return, otherwise stall */
815 while (atomic_read(&uv_nmi_kexec_failed
) == 0)
819 #else /* !CONFIG_KEXEC_CORE */
820 static inline void uv_nmi_kdump(int cpu
, int master
, struct pt_regs
*regs
)
823 pr_err("UV: NMI kdump: KEXEC not supported in this kernel\n");
824 atomic_set(&uv_nmi_kexec_failed
, 1);
826 #endif /* !CONFIG_KEXEC_CORE */
829 #ifdef CONFIG_KGDB_KDB
830 static inline int uv_nmi_kdb_reason(void)
832 return KDB_REASON_SYSTEM_NMI
;
834 #else /* !CONFIG_KGDB_KDB */
835 static inline int uv_nmi_kdb_reason(void)
837 /* Ensure user is expecting to attach gdb remote */
838 if (uv_nmi_action_is("kgdb"))
841 pr_err("UV: NMI error: KDB is not enabled in this kernel\n");
844 #endif /* CONFIG_KGDB_KDB */
847 * Call KGDB/KDB from NMI handler
849 * Note that if both KGDB and KDB are configured, then the action of 'kgdb' or
850 * 'kdb' has no affect on which is used. See the KGDB documention for further
853 static void uv_call_kgdb_kdb(int cpu
, struct pt_regs
*regs
, int master
)
856 int reason
= uv_nmi_kdb_reason();
862 /* Call KGDB NMI handler as MASTER */
863 ret
= kgdb_nmicallin(cpu
, X86_TRAP_NMI
, regs
, reason
,
864 &uv_nmi_slave_continue
);
866 pr_alert("KGDB returned error, is kgdboc set?\n");
867 atomic_set(&uv_nmi_slave_continue
, SLAVE_EXIT
);
870 /* Wait for KGDB signal that it's ready for slaves to enter */
875 sig
= atomic_read(&uv_nmi_slave_continue
);
878 /* Call KGDB as slave */
879 if (sig
== SLAVE_CONTINUE
)
880 kgdb_nmicallback(cpu
, regs
);
882 uv_nmi_sync_exit(master
);
885 #else /* !CONFIG_KGDB */
886 static inline void uv_call_kgdb_kdb(int cpu
, struct pt_regs
*regs
, int master
)
888 pr_err("UV: NMI error: KGDB is not enabled in this kernel\n");
890 #endif /* !CONFIG_KGDB */
895 static int uv_handle_nmi(unsigned int reason
, struct pt_regs
*regs
)
897 struct uv_hub_nmi_s
*hub_nmi
= uv_hub_nmi
;
898 int cpu
= smp_processor_id();
902 local_irq_save(flags
);
904 /* If not a UV System NMI, ignore */
905 if (!this_cpu_read(uv_cpu_nmi
.pinging
) && !uv_check_nmi(hub_nmi
)) {
906 local_irq_restore(flags
);
910 /* Indicate we are the first CPU into the NMI handler */
911 master
= (atomic_read(&uv_nmi_cpu
) == cpu
);
913 /* If NMI action is "kdump", then attempt to do it */
914 if (uv_nmi_action_is("kdump")) {
915 uv_nmi_kdump(cpu
, master
, regs
);
917 /* Unexpected return, revert action to "dump" */
919 strncpy(uv_nmi_action
, "dump", strlen(uv_nmi_action
));
922 /* Pause as all CPU's enter the NMI handler */
925 /* Process actions other than "kdump": */
926 if (uv_nmi_action_is("health")) {
927 uv_nmi_action_health(cpu
, regs
, master
);
928 } else if (uv_nmi_action_is("ips") || uv_nmi_action_is("dump")) {
929 uv_nmi_dump_state(cpu
, regs
, master
);
930 } else if (uv_nmi_action_is("kdb") || uv_nmi_action_is("kgdb")) {
931 uv_call_kgdb_kdb(cpu
, regs
, master
);
934 pr_alert("UV: unknown NMI action: %s\n", uv_nmi_action
);
935 uv_nmi_sync_exit(master
);
938 /* Clear per_cpu "in_nmi" flag */
939 this_cpu_write(uv_cpu_nmi
.state
, UV_NMI_STATE_OUT
);
941 /* Clear MMR NMI flag on each hub */
944 /* Clear global flags */
946 if (cpumask_weight(uv_nmi_cpu_mask
))
947 uv_nmi_cleanup_mask();
948 atomic_set(&uv_nmi_cpus_in_nmi
, -1);
949 atomic_set(&uv_nmi_cpu
, -1);
950 atomic_set(&uv_in_nmi
, 0);
951 atomic_set(&uv_nmi_kexec_failed
, 0);
952 atomic_set(&uv_nmi_slave_continue
, SLAVE_CLEAR
);
955 uv_nmi_touch_watchdogs();
956 local_irq_restore(flags
);
962 * NMI handler for pulling in CPU's when perf events are grabbing our NMI
964 static int uv_handle_nmi_ping(unsigned int reason
, struct pt_regs
*regs
)
968 this_cpu_inc(uv_cpu_nmi
.queries
);
969 if (!this_cpu_read(uv_cpu_nmi
.pinging
)) {
970 local64_inc(&uv_nmi_ping_misses
);
974 this_cpu_inc(uv_cpu_nmi
.pings
);
975 local64_inc(&uv_nmi_ping_count
);
976 ret
= uv_handle_nmi(reason
, regs
);
977 this_cpu_write(uv_cpu_nmi
.pinging
, 0);
981 static void uv_register_nmi_notifier(void)
983 if (register_nmi_handler(NMI_UNKNOWN
, uv_handle_nmi
, 0, "uv"))
984 pr_warn("UV: NMI handler failed to register\n");
986 if (register_nmi_handler(NMI_LOCAL
, uv_handle_nmi_ping
, 0, "uvping"))
987 pr_warn("UV: PING NMI handler failed to register\n");
990 void uv_nmi_init(void)
995 * Unmask NMI on all CPU's
997 value
= apic_read(APIC_LVT1
) | APIC_DM_NMI
;
998 value
&= ~APIC_LVT_MASKED
;
999 apic_write(APIC_LVT1
, value
);
1002 /* Setup HUB NMI info */
1003 static void __init
uv_nmi_setup_common(bool hubbed
)
1005 int size
= sizeof(void *) * (1 << NODES_SHIFT
);
1008 uv_hub_nmi_list
= kzalloc(size
, GFP_KERNEL
);
1009 nmi_debug("UV: NMI hub list @ 0x%p (%d)\n", uv_hub_nmi_list
, size
);
1010 BUG_ON(!uv_hub_nmi_list
);
1011 size
= sizeof(struct uv_hub_nmi_s
);
1012 for_each_present_cpu(cpu
) {
1013 int nid
= cpu_to_node(cpu
);
1014 if (uv_hub_nmi_list
[nid
] == NULL
) {
1015 uv_hub_nmi_list
[nid
] = kzalloc_node(size
,
1017 BUG_ON(!uv_hub_nmi_list
[nid
]);
1018 raw_spin_lock_init(&(uv_hub_nmi_list
[nid
]->nmi_lock
));
1019 atomic_set(&uv_hub_nmi_list
[nid
]->cpu_owner
, -1);
1020 uv_hub_nmi_list
[nid
]->hub_present
= hubbed
;
1021 uv_hub_nmi_list
[nid
]->pch_owner
= (nid
== 0);
1023 uv_hub_nmi_per(cpu
) = uv_hub_nmi_list
[nid
];
1025 BUG_ON(!alloc_cpumask_var(&uv_nmi_cpu_mask
, GFP_KERNEL
));
1028 /* Setup for UV Hub systems */
1029 void __init
uv_nmi_setup(void)
1031 uv_nmi_setup_mmrs();
1032 uv_nmi_setup_common(true);
1033 uv_register_nmi_notifier();
1034 pr_info("UV: Hub NMI enabled\n");
1037 /* Setup for UV Hubless systems */
1038 void __init
uv_nmi_setup_hubless(void)
1040 uv_nmi_setup_common(false);
1041 pch_base
= xlate_dev_mem_ptr(PCH_PCR_GPIO_1_BASE
);
1042 nmi_debug("UV: PCH base:%p from 0x%lx, GPP_D_0\n",
1043 pch_base
, PCH_PCR_GPIO_1_BASE
);
1044 if (uv_pch_init_enable
)
1045 uv_init_hubless_pch_d0();
1046 uv_init_hubless_pch_io(GPI_NMI_ENA_GPP_D_0
,
1047 STS_GPP_D_0_MASK
, STS_GPP_D_0_MASK
);
1048 uv_nmi_setup_hubless_intr();
1049 /* Ensure NMI enabled in Processor Interface Reg: */
1051 uv_register_nmi_notifier();
1052 pr_info("UV: Hubless NMI enabled\n");