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