Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 2001 Dave Engebretsen IBM Corporation |
Michael Ellerman | d995310 | 2005-10-24 15:07:30 +1000 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Michael Ellerman | d995310 | 2005-10-24 15:07:30 +1000 | [diff] [blame] | 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Michael Ellerman | d995310 | 2005-10-24 15:07:30 +1000 | [diff] [blame] | 13 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/irq.h> |
Anton Blanchard | 9012899 | 2012-03-21 15:59:04 +0000 | [diff] [blame] | 22 | #include <linux/of.h> |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 23 | #include <linux/fs.h> |
| 24 | #include <linux/reboot.h> |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 25 | #include <linux/irq_work.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/machdep.h> |
| 28 | #include <asm/rtas.h> |
Michael Ellerman | 8c4f1f2 | 2005-12-04 18:39:33 +1100 | [diff] [blame] | 29 | #include <asm/firmware.h> |
Mahesh Salgaonkar | a43c159 | 2018-09-11 19:57:00 +0530 | [diff] [blame] | 30 | #include <asm/mce.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Michael Ellerman | 577830b | 2007-02-08 18:33:51 +1100 | [diff] [blame] | 32 | #include "pseries.h" |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX]; |
| 35 | static DEFINE_SPINLOCK(ras_log_buf_lock); |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static int ras_check_exception_token; |
| 38 | |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 39 | static void mce_process_errlog_event(struct irq_work *work); |
| 40 | static struct irq_work mce_errlog_process_work = { |
| 41 | .func = mce_process_errlog_event, |
| 42 | }; |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define EPOW_SENSOR_TOKEN 9 |
| 45 | #define EPOW_SENSOR_INDEX 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 47 | /* EPOW events counter variable */ |
| 48 | static int num_epow_events; |
| 49 | |
John Allen | b7d9eb3 | 2016-07-07 10:03:44 -0500 | [diff] [blame] | 50 | static irqreturn_t ras_hotplug_interrupt(int irq, void *dev_id); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 51 | static irqreturn_t ras_epow_interrupt(int irq, void *dev_id); |
| 52 | static irqreturn_t ras_error_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Mahesh Salgaonkar | 04fce21 | 2018-09-11 19:56:52 +0530 | [diff] [blame] | 54 | /* RTAS pseries MCE errorlog section. */ |
| 55 | struct pseries_mc_errorlog { |
| 56 | __be32 fru_id; |
| 57 | __be32 proc_id; |
| 58 | u8 error_type; |
| 59 | /* |
| 60 | * sub_err_type (1 byte). Bit fields depends on error_type |
| 61 | * |
| 62 | * MSB0 |
| 63 | * | |
| 64 | * V |
| 65 | * 01234567 |
| 66 | * XXXXXXXX |
| 67 | * |
| 68 | * For error_type == MC_ERROR_TYPE_UE |
| 69 | * XXXXXXXX |
| 70 | * X 1: Permanent or Transient UE. |
| 71 | * X 1: Effective address provided. |
| 72 | * X 1: Logical address provided. |
| 73 | * XX 2: Reserved. |
| 74 | * XXX 3: Type of UE error. |
| 75 | * |
| 76 | * For error_type != MC_ERROR_TYPE_UE |
| 77 | * XXXXXXXX |
| 78 | * X 1: Effective address provided. |
| 79 | * XXXXX 5: Reserved. |
| 80 | * XX 2: Type of SLB/ERAT/TLB error. |
| 81 | */ |
| 82 | u8 sub_err_type; |
| 83 | u8 reserved_1[6]; |
| 84 | __be64 effective_address; |
| 85 | __be64 logical_address; |
| 86 | } __packed; |
| 87 | |
| 88 | /* RTAS pseries MCE error types */ |
| 89 | #define MC_ERROR_TYPE_UE 0x00 |
| 90 | #define MC_ERROR_TYPE_SLB 0x01 |
| 91 | #define MC_ERROR_TYPE_ERAT 0x02 |
| 92 | #define MC_ERROR_TYPE_TLB 0x04 |
| 93 | #define MC_ERROR_TYPE_D_CACHE 0x05 |
| 94 | #define MC_ERROR_TYPE_I_CACHE 0x07 |
| 95 | |
| 96 | /* RTAS pseries MCE error sub types */ |
| 97 | #define MC_ERROR_UE_INDETERMINATE 0 |
| 98 | #define MC_ERROR_UE_IFETCH 1 |
| 99 | #define MC_ERROR_UE_PAGE_TABLE_WALK_IFETCH 2 |
| 100 | #define MC_ERROR_UE_LOAD_STORE 3 |
| 101 | #define MC_ERROR_UE_PAGE_TABLE_WALK_LOAD_STORE 4 |
| 102 | |
| 103 | #define MC_ERROR_SLB_PARITY 0 |
| 104 | #define MC_ERROR_SLB_MULTIHIT 1 |
| 105 | #define MC_ERROR_SLB_INDETERMINATE 2 |
| 106 | |
| 107 | #define MC_ERROR_ERAT_PARITY 1 |
| 108 | #define MC_ERROR_ERAT_MULTIHIT 2 |
| 109 | #define MC_ERROR_ERAT_INDETERMINATE 3 |
| 110 | |
| 111 | #define MC_ERROR_TLB_PARITY 1 |
| 112 | #define MC_ERROR_TLB_MULTIHIT 2 |
| 113 | #define MC_ERROR_TLB_INDETERMINATE 3 |
| 114 | |
| 115 | static inline u8 rtas_mc_error_sub_type(const struct pseries_mc_errorlog *mlog) |
| 116 | { |
| 117 | switch (mlog->error_type) { |
| 118 | case MC_ERROR_TYPE_UE: |
| 119 | return (mlog->sub_err_type & 0x07); |
| 120 | case MC_ERROR_TYPE_SLB: |
| 121 | case MC_ERROR_TYPE_ERAT: |
| 122 | case MC_ERROR_TYPE_TLB: |
| 123 | return (mlog->sub_err_type & 0x03); |
| 124 | default: |
| 125 | return 0; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | static |
| 130 | inline u64 rtas_mc_get_effective_addr(const struct pseries_mc_errorlog *mlog) |
| 131 | { |
| 132 | __be64 addr = 0; |
| 133 | |
| 134 | switch (mlog->error_type) { |
| 135 | case MC_ERROR_TYPE_UE: |
| 136 | if (mlog->sub_err_type & 0x40) |
| 137 | addr = mlog->effective_address; |
| 138 | break; |
| 139 | case MC_ERROR_TYPE_SLB: |
| 140 | case MC_ERROR_TYPE_ERAT: |
| 141 | case MC_ERROR_TYPE_TLB: |
| 142 | if (mlog->sub_err_type & 0x80) |
| 143 | addr = mlog->effective_address; |
| 144 | default: |
| 145 | break; |
| 146 | } |
| 147 | return be64_to_cpu(addr); |
| 148 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* |
Sam Bobroff | c9dccf1 | 2018-02-12 11:19:29 +1100 | [diff] [blame] | 151 | * Enable the hotplug interrupt late because processing them may touch other |
| 152 | * devices or systems (e.g. hugepages) that have not been initialized at the |
| 153 | * subsys stage. |
| 154 | */ |
| 155 | int __init init_ras_hotplug_IRQ(void) |
| 156 | { |
| 157 | struct device_node *np; |
| 158 | |
| 159 | /* Hotplug Events */ |
| 160 | np = of_find_node_by_path("/event-sources/hot-plug-events"); |
| 161 | if (np != NULL) { |
| 162 | if (dlpar_workqueue_init() == 0) |
| 163 | request_event_sources_irqs(np, ras_hotplug_interrupt, |
| 164 | "RAS_HOTPLUG"); |
| 165 | of_node_put(np); |
| 166 | } |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | machine_late_initcall(pseries, init_ras_hotplug_IRQ); |
| 171 | |
| 172 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | * Initialize handlers for the set of interrupts caused by hardware errors |
| 174 | * and power system events. |
| 175 | */ |
| 176 | static int __init init_ras_IRQ(void) |
| 177 | { |
| 178 | struct device_node *np; |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | ras_check_exception_token = rtas_token("check-exception"); |
| 181 | |
| 182 | /* Internal Errors */ |
| 183 | np = of_find_node_by_path("/event-sources/internal-errors"); |
| 184 | if (np != NULL) { |
Mark Nelson | 32c96f7 | 2010-05-18 22:51:00 +0000 | [diff] [blame] | 185 | request_event_sources_irqs(np, ras_error_interrupt, |
| 186 | "RAS_ERROR"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | of_node_put(np); |
| 188 | } |
| 189 | |
| 190 | /* EPOW Events */ |
| 191 | np = of_find_node_by_path("/event-sources/epow-events"); |
| 192 | if (np != NULL) { |
Mark Nelson | 32c96f7 | 2010-05-18 22:51:00 +0000 | [diff] [blame] | 193 | request_event_sources_irqs(np, ras_epow_interrupt, "RAS_EPOW"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | of_node_put(np); |
| 195 | } |
| 196 | |
Anton Blanchard | 69ed332 | 2006-03-28 14:08:39 +1100 | [diff] [blame] | 197 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
Michael Ellerman | 8e83e90 | 2014-07-16 12:02:43 +1000 | [diff] [blame] | 199 | machine_subsys_initcall(pseries, init_ras_IRQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 201 | #define EPOW_SHUTDOWN_NORMAL 1 |
| 202 | #define EPOW_SHUTDOWN_ON_UPS 2 |
| 203 | #define EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS 3 |
| 204 | #define EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH 4 |
| 205 | |
| 206 | static void handle_system_shutdown(char event_modifier) |
| 207 | { |
| 208 | switch (event_modifier) { |
| 209 | case EPOW_SHUTDOWN_NORMAL: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 210 | pr_emerg("Power off requested\n"); |
liguang | 1b7e0cb | 2013-05-30 15:20:33 +0800 | [diff] [blame] | 211 | orderly_poweroff(true); |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 212 | break; |
| 213 | |
| 214 | case EPOW_SHUTDOWN_ON_UPS: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 215 | pr_emerg("Loss of system power detected. System is running on" |
| 216 | " UPS/battery. Check RTAS error log for details\n"); |
Anshuman Khandual | 79872e3 | 2014-10-21 13:41:29 +0530 | [diff] [blame] | 217 | orderly_poweroff(true); |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 218 | break; |
| 219 | |
| 220 | case EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 221 | pr_emerg("Loss of system critical functions detected. Check" |
| 222 | " RTAS error log for details\n"); |
liguang | 1b7e0cb | 2013-05-30 15:20:33 +0800 | [diff] [blame] | 223 | orderly_poweroff(true); |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 224 | break; |
| 225 | |
| 226 | case EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 227 | pr_emerg("High ambient temperature detected. Check RTAS" |
| 228 | " error log for details\n"); |
liguang | 1b7e0cb | 2013-05-30 15:20:33 +0800 | [diff] [blame] | 229 | orderly_poweroff(true); |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 230 | break; |
| 231 | |
| 232 | default: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 233 | pr_err("Unknown power/cooling shutdown event (modifier = %d)\n", |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 234 | event_modifier); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | struct epow_errorlog { |
| 239 | unsigned char sensor_value; |
| 240 | unsigned char event_modifier; |
| 241 | unsigned char extended_modifier; |
| 242 | unsigned char reserved; |
| 243 | unsigned char platform_reason; |
| 244 | }; |
| 245 | |
| 246 | #define EPOW_RESET 0 |
| 247 | #define EPOW_WARN_COOLING 1 |
| 248 | #define EPOW_WARN_POWER 2 |
| 249 | #define EPOW_SYSTEM_SHUTDOWN 3 |
| 250 | #define EPOW_SYSTEM_HALT 4 |
| 251 | #define EPOW_MAIN_ENCLOSURE 5 |
| 252 | #define EPOW_POWER_OFF 7 |
| 253 | |
Anton Blanchard | e51df2c | 2014-08-20 08:55:18 +1000 | [diff] [blame] | 254 | static void rtas_parse_epow_errlog(struct rtas_error_log *log) |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 255 | { |
| 256 | struct pseries_errorlog *pseries_log; |
| 257 | struct epow_errorlog *epow_log; |
| 258 | char action_code; |
| 259 | char modifier; |
| 260 | |
| 261 | pseries_log = get_pseries_errorlog(log, PSERIES_ELOG_SECT_ID_EPOW); |
| 262 | if (pseries_log == NULL) |
| 263 | return; |
| 264 | |
| 265 | epow_log = (struct epow_errorlog *)pseries_log->data; |
| 266 | action_code = epow_log->sensor_value & 0xF; /* bottom 4 bits */ |
| 267 | modifier = epow_log->event_modifier & 0xF; /* bottom 4 bits */ |
| 268 | |
| 269 | switch (action_code) { |
| 270 | case EPOW_RESET: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 271 | if (num_epow_events) { |
| 272 | pr_info("Non critical power/cooling issue cleared\n"); |
| 273 | num_epow_events--; |
| 274 | } |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 275 | break; |
| 276 | |
| 277 | case EPOW_WARN_COOLING: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 278 | pr_info("Non-critical cooling issue detected. Check RTAS error" |
| 279 | " log for details\n"); |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 280 | break; |
| 281 | |
| 282 | case EPOW_WARN_POWER: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 283 | pr_info("Non-critical power issue detected. Check RTAS error" |
| 284 | " log for details\n"); |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 285 | break; |
| 286 | |
| 287 | case EPOW_SYSTEM_SHUTDOWN: |
| 288 | handle_system_shutdown(epow_log->event_modifier); |
| 289 | break; |
| 290 | |
| 291 | case EPOW_SYSTEM_HALT: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 292 | pr_emerg("Critical power/cooling issue detected. Check RTAS" |
| 293 | " error log for details. Powering off.\n"); |
liguang | 1b7e0cb | 2013-05-30 15:20:33 +0800 | [diff] [blame] | 294 | orderly_poweroff(true); |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 295 | break; |
| 296 | |
| 297 | case EPOW_MAIN_ENCLOSURE: |
| 298 | case EPOW_POWER_OFF: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 299 | pr_emerg("System about to lose power. Check RTAS error log " |
| 300 | " for details. Powering off immediately.\n"); |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 301 | emergency_sync(); |
| 302 | kernel_power_off(); |
| 303 | break; |
| 304 | |
| 305 | default: |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 306 | pr_err("Unknown power/cooling event (action code = %d)\n", |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 307 | action_code); |
| 308 | } |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 309 | |
| 310 | /* Increment epow events counter variable */ |
| 311 | if (action_code != EPOW_RESET) |
| 312 | num_epow_events++; |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 313 | } |
| 314 | |
John Allen | b7d9eb3 | 2016-07-07 10:03:44 -0500 | [diff] [blame] | 315 | static irqreturn_t ras_hotplug_interrupt(int irq, void *dev_id) |
| 316 | { |
| 317 | struct pseries_errorlog *pseries_log; |
| 318 | struct pseries_hp_errorlog *hp_elog; |
| 319 | |
| 320 | spin_lock(&ras_log_buf_lock); |
| 321 | |
| 322 | rtas_call(ras_check_exception_token, 6, 1, NULL, |
| 323 | RTAS_VECTOR_EXTERNAL_INTERRUPT, virq_to_hw(irq), |
| 324 | RTAS_HOTPLUG_EVENTS, 0, __pa(&ras_log_buf), |
| 325 | rtas_get_error_log_max()); |
| 326 | |
| 327 | pseries_log = get_pseries_errorlog((struct rtas_error_log *)ras_log_buf, |
| 328 | PSERIES_ELOG_SECT_ID_HOTPLUG); |
| 329 | hp_elog = (struct pseries_hp_errorlog *)pseries_log->data; |
| 330 | |
| 331 | /* |
| 332 | * Since PCI hotplug is not currently supported on pseries, put PCI |
| 333 | * hotplug events on the ras_log_buf to be handled by rtas_errd. |
| 334 | */ |
| 335 | if (hp_elog->resource == PSERIES_HP_ELOG_RESOURCE_MEM || |
Oliver O'Halloran | 4c5d87d | 2018-10-15 10:18:27 +1100 | [diff] [blame] | 336 | hp_elog->resource == PSERIES_HP_ELOG_RESOURCE_CPU || |
| 337 | hp_elog->resource == PSERIES_HP_ELOG_RESOURCE_PMEM) |
Nathan Fontenot | fd12527 | 2018-09-10 09:57:07 -0500 | [diff] [blame] | 338 | queue_hotplug_event(hp_elog); |
John Allen | b7d9eb3 | 2016-07-07 10:03:44 -0500 | [diff] [blame] | 339 | else |
| 340 | log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0); |
| 341 | |
| 342 | spin_unlock(&ras_log_buf_lock); |
| 343 | return IRQ_HANDLED; |
| 344 | } |
| 345 | |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 346 | /* Handle environmental and power warning (EPOW) interrupts. */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 347 | static irqreturn_t ras_epow_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 349 | int status; |
| 350 | int state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | int critical; |
| 352 | |
Thomas Huth | 1c2cb59 | 2015-07-17 12:46:58 +0200 | [diff] [blame] | 353 | status = rtas_get_sensor_fast(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX, |
| 354 | &state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | if (state > 3) |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 357 | critical = 1; /* Time Critical */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | else |
| 359 | critical = 0; |
| 360 | |
| 361 | spin_lock(&ras_log_buf_lock); |
| 362 | |
| 363 | status = rtas_call(ras_check_exception_token, 6, 1, NULL, |
Mark Nelson | b08e281 | 2010-05-26 21:40:39 +0000 | [diff] [blame] | 364 | RTAS_VECTOR_EXTERNAL_INTERRUPT, |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 365 | virq_to_hw(irq), |
Anton Blanchard | 6f43747 | 2012-03-21 15:56:49 +0000 | [diff] [blame] | 366 | RTAS_EPOW_WARNING, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | critical, __pa(&ras_log_buf), |
| 368 | rtas_get_error_log_max()); |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0); |
| 371 | |
Anton Blanchard | 55fc0c5 | 2012-03-21 15:49:59 +0000 | [diff] [blame] | 372 | rtas_parse_epow_errlog((struct rtas_error_log *)ras_log_buf); |
| 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | spin_unlock(&ras_log_buf_lock); |
| 375 | return IRQ_HANDLED; |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * Handle hardware error interrupts. |
| 380 | * |
| 381 | * RTAS check-exception is called to collect data on the exception. If |
| 382 | * the error is deemed recoverable, we log a warning and return. |
| 383 | * For nonrecoverable errors, an error is logged and we stop all processing |
| 384 | * as quickly as possible in order to prevent propagation of the failure. |
| 385 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 386 | static irqreturn_t ras_error_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
| 388 | struct rtas_error_log *rtas_elog; |
Anton Blanchard | cc8b526 | 2012-03-21 15:58:03 +0000 | [diff] [blame] | 389 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | int fatal; |
| 391 | |
| 392 | spin_lock(&ras_log_buf_lock); |
| 393 | |
| 394 | status = rtas_call(ras_check_exception_token, 6, 1, NULL, |
Mark Nelson | b08e281 | 2010-05-26 21:40:39 +0000 | [diff] [blame] | 395 | RTAS_VECTOR_EXTERNAL_INTERRUPT, |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 396 | virq_to_hw(irq), |
Anton Blanchard | cc8b526 | 2012-03-21 15:58:03 +0000 | [diff] [blame] | 397 | RTAS_INTERNAL_ERROR, 1 /* Time Critical */, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | __pa(&ras_log_buf), |
| 399 | rtas_get_error_log_max()); |
| 400 | |
| 401 | rtas_elog = (struct rtas_error_log *)ras_log_buf; |
| 402 | |
Greg Kurz | a08a53ea | 2014-04-04 09:35:13 +0200 | [diff] [blame] | 403 | if (status == 0 && |
| 404 | rtas_error_severity(rtas_elog) >= RTAS_SEVERITY_ERROR_SYNC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | fatal = 1; |
| 406 | else |
| 407 | fatal = 0; |
| 408 | |
| 409 | /* format and print the extended information */ |
| 410 | log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal); |
| 411 | |
| 412 | if (fatal) { |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 413 | pr_emerg("Fatal hardware error detected. Check RTAS error" |
| 414 | " log for details. Powering off immediately\n"); |
Anton Blanchard | cc8b526 | 2012-03-21 15:58:03 +0000 | [diff] [blame] | 415 | emergency_sync(); |
| 416 | kernel_power_off(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } else { |
Vipin K Parashar | b4af279 | 2015-12-01 16:43:42 +0530 | [diff] [blame] | 418 | pr_err("Recoverable hardware error detected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | spin_unlock(&ras_log_buf_lock); |
| 422 | return IRQ_HANDLED; |
| 423 | } |
| 424 | |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 425 | /* |
| 426 | * Some versions of FWNMI place the buffer inside the 4kB page starting at |
| 427 | * 0x7000. Other versions place it inside the rtas buffer. We check both. |
| 428 | */ |
| 429 | #define VALID_FWNMI_BUFFER(A) \ |
| 430 | ((((A) >= 0x7000) && ((A) < 0x7ff0)) || \ |
| 431 | (((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16)))) |
| 432 | |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 433 | static inline struct rtas_error_log *fwnmi_get_errlog(void) |
| 434 | { |
| 435 | return (struct rtas_error_log *)local_paca->mce_data_buf; |
| 436 | } |
| 437 | |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 438 | /* |
| 439 | * Get the error information for errors coming through the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | * FWNMI vectors. The pt_regs' r3 will be updated to reflect |
| 441 | * the actual r3 if possible, and a ptr to the error log entry |
| 442 | * will be returned if found. |
| 443 | * |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 444 | * Use one buffer mce_data_buf per cpu to store RTAS error. |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 445 | * |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 446 | * The mce_data_buf does not have any locks or protection around it, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | * if a second machine check comes in, or a system reset is done |
| 448 | * before we have logged the error, then we will get corruption in the |
| 449 | * error log. This is preferable over holding off on calling |
| 450 | * ibm,nmi-interlock which would result in us checkstopping if a |
| 451 | * second machine check did come in. |
| 452 | */ |
| 453 | static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs) |
| 454 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | unsigned long *savep; |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 456 | struct rtas_error_log *h; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
Mahesh Salgaonkar | ee1dd1e | 2013-07-10 18:32:56 +0530 | [diff] [blame] | 458 | /* Mask top two bits */ |
| 459 | regs->gpr[3] &= ~(0x3UL << 62); |
| 460 | |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 461 | if (!VALID_FWNMI_BUFFER(regs->gpr[3])) { |
Anton Blanchard | f0e939a | 2011-05-10 13:34:03 +0000 | [diff] [blame] | 462 | printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]); |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 463 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 465 | |
| 466 | savep = __va(regs->gpr[3]); |
Mahesh Salgaonkar | cd813e1 | 2018-08-07 19:46:46 +0530 | [diff] [blame] | 467 | regs->gpr[3] = be64_to_cpu(savep[0]); /* restore original r3 */ |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 468 | |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 469 | h = (struct rtas_error_log *)&savep[1]; |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 470 | /* Use the per cpu buffer from paca to store rtas error log */ |
| 471 | memset(local_paca->mce_data_buf, 0, RTAS_ERROR_LOG_MAX); |
Greg Kurz | a08a53ea | 2014-04-04 09:35:13 +0200 | [diff] [blame] | 472 | if (!rtas_error_extended(h)) { |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 473 | memcpy(local_paca->mce_data_buf, h, sizeof(__u64)); |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 474 | } else { |
Greg Kurz | a08a53ea | 2014-04-04 09:35:13 +0200 | [diff] [blame] | 475 | int len, error_log_length; |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 476 | |
Greg Kurz | a08a53ea | 2014-04-04 09:35:13 +0200 | [diff] [blame] | 477 | error_log_length = 8 + rtas_error_extended_log_length(h); |
Mahesh Salgaonkar | 74e96bf | 2018-07-04 23:27:02 +0530 | [diff] [blame] | 478 | len = min_t(int, error_log_length, RTAS_ERROR_LOG_MAX); |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 479 | memcpy(local_paca->mce_data_buf, h, len); |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 482 | return (struct rtas_error_log *)local_paca->mce_data_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /* Call this when done with the data returned by FWNMI_get_errinfo. |
| 486 | * It will release the saved data area for other CPUs in the |
| 487 | * partition to receive FWNMI errors. |
| 488 | */ |
| 489 | static void fwnmi_release_errinfo(void) |
| 490 | { |
| 491 | int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL); |
| 492 | if (ret != 0) |
Anton Blanchard | d368514 | 2011-01-11 19:50:51 +0000 | [diff] [blame] | 493 | printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 496 | int pSeries_system_reset_exception(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
Nicholas Piggin | bded070 | 2017-07-05 13:56:26 +1000 | [diff] [blame] | 498 | #ifdef __LITTLE_ENDIAN__ |
| 499 | /* |
| 500 | * Some firmware byteswaps SRR registers and gives incorrect SRR1. Try |
| 501 | * to detect the bad SRR1 pattern here. Flip the NIP back to correct |
| 502 | * endian for reporting purposes. Unfortunately the MSR can't be fixed, |
| 503 | * so clear it. It will be missing MSR_RI so we won't try to recover. |
| 504 | */ |
| 505 | if ((be64_to_cpu(regs->msr) & |
| 506 | (MSR_LE|MSR_RI|MSR_DR|MSR_IR|MSR_ME|MSR_PR| |
| 507 | MSR_ILE|MSR_HV|MSR_SF)) == (MSR_DR|MSR_SF)) { |
| 508 | regs->nip = be64_to_cpu((__be64)regs->nip); |
| 509 | regs->msr = 0; |
| 510 | } |
| 511 | #endif |
| 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (fwnmi_active) { |
| 514 | struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs); |
| 515 | if (errhdr) { |
| 516 | /* XXX Should look at FWNMI information */ |
| 517 | } |
| 518 | fwnmi_release_errinfo(); |
| 519 | } |
Nicholas Piggin | 102c05e | 2016-12-20 04:30:10 +1000 | [diff] [blame] | 520 | |
| 521 | if (smp_handle_nmi_ipi(regs)) |
| 522 | return 1; |
| 523 | |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 524 | return 0; /* need to perform reset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Mahesh Salgaonkar | 8f0b805 | 2018-09-11 19:57:07 +0530 | [diff] [blame] | 527 | #define VAL_TO_STRING(ar, val) \ |
| 528 | (((val) < ARRAY_SIZE(ar)) ? ar[(val)] : "Unknown") |
| 529 | |
| 530 | static void pseries_print_mce_info(struct pt_regs *regs, |
| 531 | struct rtas_error_log *errp) |
| 532 | { |
| 533 | const char *level, *sevstr; |
| 534 | struct pseries_errorlog *pseries_log; |
| 535 | struct pseries_mc_errorlog *mce_log; |
| 536 | u8 error_type, err_sub_type; |
| 537 | u64 addr; |
| 538 | u8 initiator = rtas_error_initiator(errp); |
| 539 | int disposition = rtas_error_disposition(errp); |
| 540 | |
| 541 | static const char * const initiators[] = { |
| 542 | "Unknown", |
| 543 | "CPU", |
| 544 | "PCI", |
| 545 | "ISA", |
| 546 | "Memory", |
| 547 | "Power Mgmt", |
| 548 | }; |
| 549 | static const char * const mc_err_types[] = { |
| 550 | "UE", |
| 551 | "SLB", |
| 552 | "ERAT", |
Mahesh Salgaonkar | 6f845eb | 2019-03-26 18:00:31 +0530 | [diff] [blame] | 553 | "Unknown", |
Mahesh Salgaonkar | 8f0b805 | 2018-09-11 19:57:07 +0530 | [diff] [blame] | 554 | "TLB", |
| 555 | "D-Cache", |
| 556 | "Unknown", |
| 557 | "I-Cache", |
| 558 | }; |
| 559 | static const char * const mc_ue_types[] = { |
| 560 | "Indeterminate", |
| 561 | "Instruction fetch", |
| 562 | "Page table walk ifetch", |
| 563 | "Load/Store", |
| 564 | "Page table walk Load/Store", |
| 565 | }; |
| 566 | |
| 567 | /* SLB sub errors valid values are 0x0, 0x1, 0x2 */ |
| 568 | static const char * const mc_slb_types[] = { |
| 569 | "Parity", |
| 570 | "Multihit", |
| 571 | "Indeterminate", |
| 572 | }; |
| 573 | |
| 574 | /* TLB and ERAT sub errors valid values are 0x1, 0x2, 0x3 */ |
| 575 | static const char * const mc_soft_types[] = { |
| 576 | "Unknown", |
| 577 | "Parity", |
| 578 | "Multihit", |
| 579 | "Indeterminate", |
| 580 | }; |
| 581 | |
| 582 | if (!rtas_error_extended(errp)) { |
| 583 | pr_err("Machine check interrupt: Missing extended error log\n"); |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | pseries_log = get_pseries_errorlog(errp, PSERIES_ELOG_SECT_ID_MCE); |
| 588 | if (pseries_log == NULL) |
| 589 | return; |
| 590 | |
| 591 | mce_log = (struct pseries_mc_errorlog *)pseries_log->data; |
| 592 | |
| 593 | error_type = mce_log->error_type; |
| 594 | err_sub_type = rtas_mc_error_sub_type(mce_log); |
| 595 | |
| 596 | switch (rtas_error_severity(errp)) { |
| 597 | case RTAS_SEVERITY_NO_ERROR: |
| 598 | level = KERN_INFO; |
| 599 | sevstr = "Harmless"; |
| 600 | break; |
| 601 | case RTAS_SEVERITY_WARNING: |
| 602 | level = KERN_WARNING; |
| 603 | sevstr = ""; |
| 604 | break; |
| 605 | case RTAS_SEVERITY_ERROR: |
| 606 | case RTAS_SEVERITY_ERROR_SYNC: |
| 607 | level = KERN_ERR; |
| 608 | sevstr = "Severe"; |
| 609 | break; |
| 610 | case RTAS_SEVERITY_FATAL: |
| 611 | default: |
| 612 | level = KERN_ERR; |
| 613 | sevstr = "Fatal"; |
| 614 | break; |
| 615 | } |
| 616 | |
Mahesh Salgaonkar | c6d1525 | 2018-09-11 19:57:15 +0530 | [diff] [blame] | 617 | #ifdef CONFIG_PPC_BOOK3S_64 |
| 618 | /* Display faulty slb contents for SLB errors. */ |
| 619 | if (error_type == MC_ERROR_TYPE_SLB) |
| 620 | slb_dump_contents(local_paca->mce_faulty_slbs); |
| 621 | #endif |
| 622 | |
Mahesh Salgaonkar | 8f0b805 | 2018-09-11 19:57:07 +0530 | [diff] [blame] | 623 | printk("%s%s Machine check interrupt [%s]\n", level, sevstr, |
| 624 | disposition == RTAS_DISP_FULLY_RECOVERED ? |
| 625 | "Recovered" : "Not recovered"); |
| 626 | if (user_mode(regs)) { |
| 627 | printk("%s NIP: [%016lx] PID: %d Comm: %s\n", level, |
| 628 | regs->nip, current->pid, current->comm); |
| 629 | } else { |
| 630 | printk("%s NIP [%016lx]: %pS\n", level, regs->nip, |
| 631 | (void *)regs->nip); |
| 632 | } |
| 633 | printk("%s Initiator: %s\n", level, |
| 634 | VAL_TO_STRING(initiators, initiator)); |
| 635 | |
| 636 | switch (error_type) { |
| 637 | case MC_ERROR_TYPE_UE: |
| 638 | printk("%s Error type: %s [%s]\n", level, |
| 639 | VAL_TO_STRING(mc_err_types, error_type), |
| 640 | VAL_TO_STRING(mc_ue_types, err_sub_type)); |
| 641 | break; |
| 642 | case MC_ERROR_TYPE_SLB: |
| 643 | printk("%s Error type: %s [%s]\n", level, |
| 644 | VAL_TO_STRING(mc_err_types, error_type), |
| 645 | VAL_TO_STRING(mc_slb_types, err_sub_type)); |
| 646 | break; |
| 647 | case MC_ERROR_TYPE_ERAT: |
| 648 | case MC_ERROR_TYPE_TLB: |
| 649 | printk("%s Error type: %s [%s]\n", level, |
| 650 | VAL_TO_STRING(mc_err_types, error_type), |
| 651 | VAL_TO_STRING(mc_soft_types, err_sub_type)); |
| 652 | break; |
| 653 | default: |
| 654 | printk("%s Error type: %s\n", level, |
| 655 | VAL_TO_STRING(mc_err_types, error_type)); |
| 656 | break; |
| 657 | } |
| 658 | |
| 659 | addr = rtas_mc_get_effective_addr(mce_log); |
| 660 | if (addr) |
| 661 | printk("%s Effective address: %016llx\n", level, addr); |
| 662 | } |
| 663 | |
Mahesh Salgaonkar | a43c159 | 2018-09-11 19:57:00 +0530 | [diff] [blame] | 664 | static int mce_handle_error(struct rtas_error_log *errp) |
| 665 | { |
| 666 | struct pseries_errorlog *pseries_log; |
| 667 | struct pseries_mc_errorlog *mce_log; |
| 668 | int disposition = rtas_error_disposition(errp); |
| 669 | u8 error_type; |
| 670 | |
| 671 | if (!rtas_error_extended(errp)) |
| 672 | goto out; |
| 673 | |
| 674 | pseries_log = get_pseries_errorlog(errp, PSERIES_ELOG_SECT_ID_MCE); |
| 675 | if (pseries_log == NULL) |
| 676 | goto out; |
| 677 | |
| 678 | mce_log = (struct pseries_mc_errorlog *)pseries_log->data; |
| 679 | error_type = mce_log->error_type; |
| 680 | |
| 681 | #ifdef CONFIG_PPC_BOOK3S_64 |
| 682 | if (disposition == RTAS_DISP_NOT_RECOVERED) { |
| 683 | switch (error_type) { |
| 684 | case MC_ERROR_TYPE_SLB: |
| 685 | case MC_ERROR_TYPE_ERAT: |
Mahesh Salgaonkar | c6d1525 | 2018-09-11 19:57:15 +0530 | [diff] [blame] | 686 | /* |
| 687 | * Store the old slb content in paca before flushing. |
| 688 | * Print this when we go to virtual mode. |
| 689 | * There are chances that we may hit MCE again if there |
| 690 | * is a parity error on the SLB entry we trying to read |
| 691 | * for saving. Hence limit the slb saving to single |
| 692 | * level of recursion. |
| 693 | */ |
| 694 | if (local_paca->in_mce == 1) |
| 695 | slb_save_contents(local_paca->mce_faulty_slbs); |
Mahesh Salgaonkar | a43c159 | 2018-09-11 19:57:00 +0530 | [diff] [blame] | 696 | flush_and_reload_slb(); |
| 697 | disposition = RTAS_DISP_FULLY_RECOVERED; |
| 698 | rtas_set_disposition_recovered(errp); |
| 699 | break; |
| 700 | default: |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | #endif |
| 705 | |
| 706 | out: |
| 707 | return disposition; |
| 708 | } |
| 709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | /* |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 711 | * Process MCE rtas errlog event. |
| 712 | */ |
| 713 | static void mce_process_errlog_event(struct irq_work *work) |
| 714 | { |
| 715 | struct rtas_error_log *err; |
| 716 | |
| 717 | err = fwnmi_get_errlog(); |
| 718 | log_error((char *)err, ERR_TYPE_RTAS_LOG, 0); |
| 719 | } |
| 720 | |
| 721 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | * See if we can recover from a machine check exception. |
| 723 | * This is only called on power4 (or above) and only via |
| 724 | * the Firmware Non-Maskable Interrupts (fwnmi) handler |
| 725 | * which provides the error analysis for us. |
| 726 | * |
| 727 | * Return 1 if corrected (or delivered a signal). |
| 728 | * Return 0 if there is nothing we can do. |
| 729 | */ |
Anton Blanchard | d47d1d8 | 2011-01-11 19:49:19 +0000 | [diff] [blame] | 730 | static int recover_mce(struct pt_regs *regs, struct rtas_error_log *err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | { |
Anton Blanchard | d47d1d8 | 2011-01-11 19:49:19 +0000 | [diff] [blame] | 732 | int recovered = 0; |
Greg Kurz | a08a53ea | 2014-04-04 09:35:13 +0200 | [diff] [blame] | 733 | int disposition = rtas_error_disposition(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
Mahesh Salgaonkar | 8f0b805 | 2018-09-11 19:57:07 +0530 | [diff] [blame] | 735 | pseries_print_mce_info(regs, err); |
| 736 | |
Anton Blanchard | d47d1d8 | 2011-01-11 19:49:19 +0000 | [diff] [blame] | 737 | if (!(regs->msr & MSR_RI)) { |
| 738 | /* If MSR_RI isn't set, we cannot recover */ |
Mahesh Salgaonkar | 8f0b805 | 2018-09-11 19:57:07 +0530 | [diff] [blame] | 739 | pr_err("Machine check interrupt unrecoverable: MSR(RI=0)\n"); |
Anton Blanchard | d47d1d8 | 2011-01-11 19:49:19 +0000 | [diff] [blame] | 740 | recovered = 0; |
| 741 | |
Greg Kurz | a08a53ea | 2014-04-04 09:35:13 +0200 | [diff] [blame] | 742 | } else if (disposition == RTAS_DISP_FULLY_RECOVERED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | /* Platform corrected itself */ |
Anton Blanchard | d47d1d8 | 2011-01-11 19:49:19 +0000 | [diff] [blame] | 744 | recovered = 1; |
| 745 | |
Greg Kurz | a08a53ea | 2014-04-04 09:35:13 +0200 | [diff] [blame] | 746 | } else if (disposition == RTAS_DISP_LIMITED_RECOVERY) { |
Anton Blanchard | d47d1d8 | 2011-01-11 19:49:19 +0000 | [diff] [blame] | 747 | /* Platform corrected itself but could be degraded */ |
| 748 | printk(KERN_ERR "MCE: limited recovery, system may " |
| 749 | "be degraded\n"); |
| 750 | recovered = 1; |
| 751 | |
| 752 | } else if (user_mode(regs) && !is_global_init(current) && |
Greg Kurz | a08a53ea | 2014-04-04 09:35:13 +0200 | [diff] [blame] | 753 | rtas_error_severity(err) == RTAS_SEVERITY_ERROR_SYNC) { |
Anton Blanchard | d47d1d8 | 2011-01-11 19:49:19 +0000 | [diff] [blame] | 754 | |
| 755 | /* |
| 756 | * If we received a synchronous error when in userspace |
| 757 | * kill the task. Firmware may report details of the fail |
| 758 | * asynchronously, so we can't rely on the target and type |
| 759 | * fields being valid here. |
| 760 | */ |
| 761 | printk(KERN_ERR "MCE: uncorrectable error, killing task " |
| 762 | "%s:%d\n", current->comm, current->pid); |
| 763 | |
| 764 | _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip); |
| 765 | recovered = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Mahesh Salgaonkar | 94675cc | 2018-07-04 23:27:21 +0530 | [diff] [blame] | 768 | /* Queue irq work to log this rtas event later. */ |
| 769 | irq_work_queue(&mce_errlog_process_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Anton Blanchard | d47d1d8 | 2011-01-11 19:49:19 +0000 | [diff] [blame] | 771 | return recovered; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /* |
| 775 | * Handle a machine check. |
| 776 | * |
| 777 | * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi) |
| 778 | * should be present. If so the handler which called us tells us if the |
| 779 | * error was recovered (never true if RI=0). |
| 780 | * |
| 781 | * On hardware prior to Power 4 these exceptions were asynchronous which |
| 782 | * means we can't tell exactly where it occurred and so we can't recover. |
| 783 | */ |
| 784 | int pSeries_machine_check_exception(struct pt_regs *regs) |
| 785 | { |
| 786 | struct rtas_error_log *errp; |
| 787 | |
| 788 | if (fwnmi_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | fwnmi_release_errinfo(); |
Mahesh Salgaonkar | a43c159 | 2018-09-11 19:57:00 +0530 | [diff] [blame] | 790 | errp = fwnmi_get_errlog(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | if (errp && recover_mce(regs, errp)) |
| 792 | return 1; |
| 793 | } |
| 794 | |
| 795 | return 0; |
| 796 | } |
Mahesh Salgaonkar | a43c159 | 2018-09-11 19:57:00 +0530 | [diff] [blame] | 797 | |
| 798 | long pseries_machine_check_realmode(struct pt_regs *regs) |
| 799 | { |
| 800 | struct rtas_error_log *errp; |
| 801 | int disposition; |
| 802 | |
| 803 | if (fwnmi_active) { |
| 804 | errp = fwnmi_get_errinfo(regs); |
| 805 | /* |
| 806 | * Call to fwnmi_release_errinfo() in real mode causes kernel |
| 807 | * to panic. Hence we will call it as soon as we go into |
| 808 | * virtual mode. |
| 809 | */ |
| 810 | disposition = mce_handle_error(errp); |
| 811 | if (disposition == RTAS_DISP_FULLY_RECOVERED) |
| 812 | return 1; |
| 813 | } |
| 814 | |
| 815 | return 0; |
| 816 | } |