Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/s390mach.c |
| 3 | * S/390 machine check handler |
| 4 | * |
| 5 | * S390 version |
| 6 | * Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 7 | * Author(s): Ingo Adlung (adlung@de.ibm.com) |
| 8 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/init.h> |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/workqueue.h> |
Heiko Carstens | 022e4fc | 2006-05-01 12:16:14 -0700 | [diff] [blame] | 15 | #include <linux/time.h> |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 16 | #include <linux/device.h> |
Serge E. Hallyn | 84d11c5 | 2006-06-29 15:03:17 +0200 | [diff] [blame] | 17 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #include <asm/lowcore.h> |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 20 | #include <asm/cio.h> |
| 21 | #include "cio/cio.h" |
| 22 | #include "cio/chsc.h" |
| 23 | #include "cio/css.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "s390mach.h" |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | static struct semaphore m_sem; |
| 27 | |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 28 | static NORET_TYPE void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | s390_handle_damage(char *msg) |
| 30 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #ifdef CONFIG_SMP |
| 32 | smp_send_stop(); |
| 33 | #endif |
| 34 | disabled_wait((unsigned long) __builtin_return_address(0)); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 35 | for(;;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | /* |
| 39 | * Retrieve CRWs and call function to handle event. |
| 40 | * |
| 41 | * Note : we currently process CRWs for io and chsc subchannels only |
| 42 | */ |
| 43 | static int |
| 44 | s390_collect_crw_info(void *param) |
| 45 | { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 46 | struct crw crw[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | int ccode, ret, slow; |
| 48 | struct semaphore *sem; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 49 | unsigned int chain; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | sem = (struct semaphore *)param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | repeat: |
| 53 | down_interruptible(sem); |
| 54 | slow = 0; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 55 | chain = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | while (1) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 57 | if (unlikely(chain > 1)) { |
| 58 | struct crw tmp_crw; |
| 59 | |
| 60 | printk(KERN_WARNING"%s: Code does not support more " |
| 61 | "than two chained crws; please report to " |
| 62 | "linux390@de.ibm.com!\n", __FUNCTION__); |
| 63 | ccode = stcrw(&tmp_crw); |
| 64 | printk(KERN_WARNING"%s: crw reports slct=%d, oflw=%d, " |
| 65 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", |
| 66 | __FUNCTION__, tmp_crw.slct, tmp_crw.oflw, |
| 67 | tmp_crw.chn, tmp_crw.rsc, tmp_crw.anc, |
| 68 | tmp_crw.erc, tmp_crw.rsid); |
| 69 | printk(KERN_WARNING"%s: This was crw number %x in the " |
| 70 | "chain\n", __FUNCTION__, chain); |
| 71 | if (ccode != 0) |
| 72 | break; |
| 73 | chain = tmp_crw.chn ? chain + 1 : 0; |
| 74 | continue; |
| 75 | } |
| 76 | ccode = stcrw(&crw[chain]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | if (ccode != 0) |
| 78 | break; |
Cornelia Huck | 250b2dc | 2006-09-20 15:59:47 +0200 | [diff] [blame] | 79 | printk(KERN_DEBUG "crw_info : CRW reports slct=%d, oflw=%d, " |
| 80 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", |
| 81 | crw[chain].slct, crw[chain].oflw, crw[chain].chn, |
| 82 | crw[chain].rsc, crw[chain].anc, crw[chain].erc, |
| 83 | crw[chain].rsid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* Check for overflows. */ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 85 | if (crw[chain].oflw) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | pr_debug("%s: crw overflow detected!\n", __FUNCTION__); |
| 87 | css_reiterate_subchannels(); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 88 | chain = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | slow = 1; |
| 90 | continue; |
| 91 | } |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 92 | switch (crw[chain].rsc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | case CRW_RSC_SCH: |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 94 | if (crw[0].chn && !chain) |
| 95 | break; |
| 96 | pr_debug("source is subchannel %04X\n", crw[0].rsid); |
| 97 | ret = css_process_crw (crw[0].rsid, |
| 98 | chain ? crw[1].rsid : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (ret == -EAGAIN) |
| 100 | slow = 1; |
| 101 | break; |
| 102 | case CRW_RSC_MONITOR: |
| 103 | pr_debug("source is monitoring facility\n"); |
| 104 | break; |
| 105 | case CRW_RSC_CPATH: |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 106 | pr_debug("source is channel path %02X\n", crw[0].rsid); |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 107 | /* |
| 108 | * Check for solicited machine checks. These are |
| 109 | * created by reset channel path and need not be |
| 110 | * reported to the common I/O layer. |
| 111 | */ |
| 112 | if (crw[chain].slct) { |
Cornelia Huck | 250b2dc | 2006-09-20 15:59:47 +0200 | [diff] [blame] | 113 | pr_debug("solicited machine check for " |
| 114 | "channel path %02X\n", crw[0].rsid); |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 115 | break; |
| 116 | } |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 117 | switch (crw[0].erc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | case CRW_ERC_IPARM: /* Path has come. */ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 119 | ret = chp_process_crw(crw[0].rsid, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | break; |
| 121 | case CRW_ERC_PERRI: /* Path has gone. */ |
| 122 | case CRW_ERC_PERRN: |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 123 | ret = chp_process_crw(crw[0].rsid, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | break; |
| 125 | default: |
| 126 | pr_debug("Don't know how to handle erc=%x\n", |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 127 | crw[0].erc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | ret = 0; |
| 129 | } |
| 130 | if (ret == -EAGAIN) |
| 131 | slow = 1; |
| 132 | break; |
| 133 | case CRW_RSC_CONFIG: |
| 134 | pr_debug("source is configuration-alert facility\n"); |
| 135 | break; |
| 136 | case CRW_RSC_CSS: |
| 137 | pr_debug("source is channel subsystem\n"); |
| 138 | ret = chsc_process_crw(); |
| 139 | if (ret == -EAGAIN) |
| 140 | slow = 1; |
| 141 | break; |
| 142 | default: |
| 143 | pr_debug("unknown source\n"); |
| 144 | break; |
| 145 | } |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 146 | /* chain is always 0 or 1 here. */ |
| 147 | chain = crw[chain].chn ? chain + 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | if (slow) |
| 150 | queue_work(slow_path_wq, &slow_path_work); |
| 151 | goto repeat; |
| 152 | return 0; |
| 153 | } |
| 154 | |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 155 | struct mcck_struct { |
| 156 | int kill_task; |
| 157 | int channel_report; |
| 158 | int warning; |
| 159 | unsigned long long mcck_code; |
| 160 | }; |
| 161 | |
| 162 | static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck); |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 165 | * Main machine check handler function. Will be called with interrupts enabled |
| 166 | * or disabled and machine checks enabled or disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | */ |
| 168 | void |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 169 | s390_handle_mcck(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 171 | unsigned long flags; |
| 172 | struct mcck_struct mcck; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 174 | /* |
| 175 | * Disable machine checks and get the current state of accumulated |
| 176 | * machine checks. Afterwards delete the old state and enable machine |
| 177 | * checks again. |
| 178 | */ |
| 179 | local_irq_save(flags); |
| 180 | local_mcck_disable(); |
| 181 | mcck = __get_cpu_var(cpu_mcck); |
| 182 | memset(&__get_cpu_var(cpu_mcck), 0, sizeof(struct mcck_struct)); |
| 183 | clear_thread_flag(TIF_MCCK_PENDING); |
| 184 | local_mcck_enable(); |
| 185 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 187 | if (mcck.channel_report) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | up(&m_sem); |
| 189 | |
| 190 | #ifdef CONFIG_MACHCHK_WARNING |
| 191 | /* |
| 192 | * The warning may remain for a prolonged period on the bare iron. |
| 193 | * (actually till the machine is powered off, or until the problem is gone) |
| 194 | * So we just stop listening for the WARNING MCH and prevent continuously |
| 195 | * being interrupted. One caveat is however, that we must do this per |
| 196 | * processor and cannot use the smp version of ctl_clear_bit(). |
| 197 | * On VM we only get one interrupt per virtally presented machinecheck. |
| 198 | * Though one suffices, we may get one interrupt per (virtual) processor. |
| 199 | */ |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 200 | if (mcck.warning) { /* WARNING pending ? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static int mchchk_wng_posted = 0; |
| 202 | /* |
| 203 | * Use single machine clear, as we cannot handle smp right now |
| 204 | */ |
| 205 | __ctl_clear_bit(14, 24); /* Disable WARNING MCH */ |
| 206 | if (xchg(&mchchk_wng_posted, 1) == 0) |
Cedric Le Goater | 9ec5209 | 2006-10-02 02:19:00 -0700 | [diff] [blame] | 207 | kill_cad_pid(SIGPWR, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | #endif |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 210 | |
| 211 | if (mcck.kill_task) { |
| 212 | local_irq_enable(); |
| 213 | printk(KERN_EMERG "mcck: Terminating task because of machine " |
| 214 | "malfunction (code 0x%016llx).\n", mcck.mcck_code); |
| 215 | printk(KERN_EMERG "mcck: task: %s, pid: %d.\n", |
| 216 | current->comm, current->pid); |
| 217 | do_exit(SIGSEGV); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * returns 0 if all registers could be validated |
| 223 | * returns 1 otherwise |
| 224 | */ |
| 225 | static int |
| 226 | s390_revalidate_registers(struct mci *mci) |
| 227 | { |
| 228 | int kill_task; |
| 229 | u64 tmpclock; |
| 230 | u64 zero; |
| 231 | void *fpt_save_area, *fpt_creg_save_area; |
| 232 | |
| 233 | kill_task = 0; |
| 234 | zero = 0; |
| 235 | /* General purpose registers */ |
| 236 | if (!mci->gr) |
| 237 | /* |
| 238 | * General purpose registers couldn't be restored and have |
| 239 | * unknown contents. Process needs to be terminated. |
| 240 | */ |
| 241 | kill_task = 1; |
| 242 | |
| 243 | /* Revalidate floating point registers */ |
| 244 | if (!mci->fp) |
| 245 | /* |
| 246 | * Floating point registers can't be restored and |
| 247 | * therefore the process needs to be terminated. |
| 248 | */ |
| 249 | kill_task = 1; |
| 250 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 251 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 252 | asm volatile( |
| 253 | " ld 0,0(%0)\n" |
| 254 | " ld 2,8(%0)\n" |
| 255 | " ld 4,16(%0)\n" |
| 256 | " ld 6,24(%0)" |
| 257 | : : "a" (&S390_lowcore.floating_pt_save_area)); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 258 | #endif |
| 259 | |
| 260 | if (MACHINE_HAS_IEEE) { |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 261 | #ifdef CONFIG_64BIT |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 262 | fpt_save_area = &S390_lowcore.floating_pt_save_area; |
| 263 | fpt_creg_save_area = &S390_lowcore.fpt_creg_save_area; |
| 264 | #else |
| 265 | fpt_save_area = (void *) S390_lowcore.extended_save_area_addr; |
| 266 | fpt_creg_save_area = fpt_save_area+128; |
| 267 | #endif |
| 268 | /* Floating point control register */ |
| 269 | if (!mci->fc) { |
| 270 | /* |
| 271 | * Floating point control register can't be restored. |
| 272 | * Task will be terminated. |
| 273 | */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 274 | asm volatile("lfpc 0(%0)" : : "a" (&zero), "m" (zero)); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 275 | kill_task = 1; |
| 276 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 277 | } else |
| 278 | asm volatile("lfpc 0(%0)" : : "a" (fpt_creg_save_area)); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 279 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 280 | asm volatile( |
| 281 | " ld 0,0(%0)\n" |
| 282 | " ld 1,8(%0)\n" |
| 283 | " ld 2,16(%0)\n" |
| 284 | " ld 3,24(%0)\n" |
| 285 | " ld 4,32(%0)\n" |
| 286 | " ld 5,40(%0)\n" |
| 287 | " ld 6,48(%0)\n" |
| 288 | " ld 7,56(%0)\n" |
| 289 | " ld 8,64(%0)\n" |
| 290 | " ld 9,72(%0)\n" |
| 291 | " ld 10,80(%0)\n" |
| 292 | " ld 11,88(%0)\n" |
| 293 | " ld 12,96(%0)\n" |
| 294 | " ld 13,104(%0)\n" |
| 295 | " ld 14,112(%0)\n" |
| 296 | " ld 15,120(%0)\n" |
| 297 | : : "a" (fpt_save_area)); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* Revalidate access registers */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 301 | asm volatile( |
| 302 | " lam 0,15,0(%0)" |
| 303 | : : "a" (&S390_lowcore.access_regs_save_area)); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 304 | if (!mci->ar) |
| 305 | /* |
| 306 | * Access registers have unknown contents. |
| 307 | * Terminating task. |
| 308 | */ |
| 309 | kill_task = 1; |
| 310 | |
| 311 | /* Revalidate control registers */ |
| 312 | if (!mci->cr) |
| 313 | /* |
| 314 | * Control registers have unknown contents. |
| 315 | * Can't recover and therefore stopping machine. |
| 316 | */ |
| 317 | s390_handle_damage("invalid control registers."); |
| 318 | else |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 319 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 320 | asm volatile( |
| 321 | " lctlg 0,15,0(%0)" |
| 322 | : : "a" (&S390_lowcore.cregs_save_area)); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 323 | #else |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 324 | asm volatile( |
| 325 | " lctl 0,15,0(%0)" |
| 326 | : : "a" (&S390_lowcore.cregs_save_area)); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 327 | #endif |
| 328 | |
| 329 | /* |
| 330 | * We don't even try to revalidate the TOD register, since we simply |
| 331 | * can't write something sensible into that register. |
| 332 | */ |
| 333 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 334 | #ifdef CONFIG_64BIT |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 335 | /* |
| 336 | * See if we can revalidate the TOD programmable register with its |
| 337 | * old contents (should be zero) otherwise set it to zero. |
| 338 | */ |
| 339 | if (!mci->pr) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 340 | asm volatile( |
| 341 | " sr 0,0\n" |
| 342 | " sckpf" |
| 343 | : : : "0", "cc"); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 344 | else |
| 345 | asm volatile( |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 346 | " l 0,0(%0)\n" |
| 347 | " sckpf" |
| 348 | : : "a" (&S390_lowcore.tod_progreg_save_area) |
| 349 | : "0", "cc"); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 350 | #endif |
| 351 | |
| 352 | /* Revalidate clock comparator register */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 353 | asm volatile( |
| 354 | " stck 0(%1)\n" |
| 355 | " sckc 0(%1)" |
| 356 | : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory"); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 357 | |
| 358 | /* Check if old PSW is valid */ |
| 359 | if (!mci->wp) |
| 360 | /* |
| 361 | * Can't tell if we come from user or kernel mode |
| 362 | * -> stopping machine. |
| 363 | */ |
| 364 | s390_handle_damage("old psw invalid."); |
| 365 | |
| 366 | if (!mci->ms || !mci->pm || !mci->ia) |
| 367 | kill_task = 1; |
| 368 | |
| 369 | return kill_task; |
| 370 | } |
| 371 | |
Heiko Carstens | b73d40c | 2006-04-27 18:40:23 -0700 | [diff] [blame] | 372 | #define MAX_IPD_COUNT 29 |
Heiko Carstens | 022e4fc | 2006-05-01 12:16:14 -0700 | [diff] [blame] | 373 | #define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */ |
Heiko Carstens | b73d40c | 2006-04-27 18:40:23 -0700 | [diff] [blame] | 374 | |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 375 | /* |
| 376 | * machine check handler. |
| 377 | */ |
| 378 | void |
| 379 | s390_do_machine_check(struct pt_regs *regs) |
| 380 | { |
Heiko Carstens | b73d40c | 2006-04-27 18:40:23 -0700 | [diff] [blame] | 381 | static DEFINE_SPINLOCK(ipd_lock); |
| 382 | static unsigned long long last_ipd; |
| 383 | static int ipd_count; |
| 384 | unsigned long long tmp; |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 385 | struct mci *mci; |
| 386 | struct mcck_struct *mcck; |
| 387 | int umode; |
| 388 | |
Heiko Carstens | 8e9ccae | 2006-07-03 00:25:00 -0700 | [diff] [blame] | 389 | lockdep_off(); |
| 390 | |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 391 | mci = (struct mci *) &S390_lowcore.mcck_interruption_code; |
| 392 | mcck = &__get_cpu_var(cpu_mcck); |
| 393 | umode = user_mode(regs); |
| 394 | |
| 395 | if (mci->sd) |
| 396 | /* System damage -> stopping machine */ |
| 397 | s390_handle_damage("received system damage machine check."); |
| 398 | |
| 399 | if (mci->pd) { |
| 400 | if (mci->b) { |
| 401 | /* Processing backup -> verify if we can survive this */ |
| 402 | u64 z_mcic, o_mcic, t_mcic; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 403 | #ifdef CONFIG_64BIT |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 404 | z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<29); |
| 405 | o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 | |
| 406 | 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 | |
| 407 | 1ULL<<30 | 1ULL<<21 | 1ULL<<20 | 1ULL<<17 | |
| 408 | 1ULL<<16); |
| 409 | #else |
| 410 | z_mcic = (1ULL<<63 | 1ULL<<59 | 1ULL<<57 | 1ULL<<50 | |
| 411 | 1ULL<<29); |
| 412 | o_mcic = (1ULL<<43 | 1ULL<<42 | 1ULL<<41 | 1ULL<<40 | |
| 413 | 1ULL<<36 | 1ULL<<35 | 1ULL<<34 | 1ULL<<32 | |
| 414 | 1ULL<<30 | 1ULL<<20 | 1ULL<<17 | 1ULL<<16); |
| 415 | #endif |
| 416 | t_mcic = *(u64 *)mci; |
| 417 | |
| 418 | if (((t_mcic & z_mcic) != 0) || |
| 419 | ((t_mcic & o_mcic) != o_mcic)) { |
| 420 | s390_handle_damage("processing backup machine " |
| 421 | "check with damage."); |
| 422 | } |
Heiko Carstens | b73d40c | 2006-04-27 18:40:23 -0700 | [diff] [blame] | 423 | |
| 424 | /* |
| 425 | * Nullifying exigent condition, therefore we might |
| 426 | * retry this instruction. |
| 427 | */ |
| 428 | |
| 429 | spin_lock(&ipd_lock); |
| 430 | |
| 431 | tmp = get_clock(); |
| 432 | |
| 433 | if (((tmp - last_ipd) >> 12) < MAX_IPD_TIME) |
| 434 | ipd_count++; |
| 435 | else |
| 436 | ipd_count = 1; |
| 437 | |
| 438 | last_ipd = tmp; |
| 439 | |
| 440 | if (ipd_count == MAX_IPD_COUNT) |
| 441 | s390_handle_damage("too many ipd retries."); |
| 442 | |
| 443 | spin_unlock(&ipd_lock); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 444 | } |
| 445 | else { |
| 446 | /* Processing damage -> stopping machine */ |
| 447 | s390_handle_damage("received instruction processing " |
| 448 | "damage machine check."); |
| 449 | } |
| 450 | } |
| 451 | if (s390_revalidate_registers(mci)) { |
| 452 | if (umode) { |
| 453 | /* |
| 454 | * Couldn't restore all register contents while in |
| 455 | * user mode -> mark task for termination. |
| 456 | */ |
| 457 | mcck->kill_task = 1; |
| 458 | mcck->mcck_code = *(unsigned long long *) mci; |
| 459 | set_thread_flag(TIF_MCCK_PENDING); |
| 460 | } |
| 461 | else |
| 462 | /* |
| 463 | * Couldn't restore all register contents while in |
| 464 | * kernel mode -> stopping machine. |
| 465 | */ |
| 466 | s390_handle_damage("unable to revalidate registers."); |
| 467 | } |
| 468 | |
| 469 | if (mci->se) |
| 470 | /* Storage error uncorrected */ |
| 471 | s390_handle_damage("received storage error uncorrected " |
| 472 | "machine check."); |
| 473 | |
| 474 | if (mci->ke) |
| 475 | /* Storage key-error uncorrected */ |
| 476 | s390_handle_damage("received storage key-error uncorrected " |
| 477 | "machine check."); |
| 478 | |
| 479 | if (mci->ds && mci->fa) |
| 480 | /* Storage degradation */ |
| 481 | s390_handle_damage("received storage degradation machine " |
| 482 | "check."); |
| 483 | |
| 484 | if (mci->cp) { |
| 485 | /* Channel report word pending */ |
| 486 | mcck->channel_report = 1; |
| 487 | set_thread_flag(TIF_MCCK_PENDING); |
| 488 | } |
| 489 | |
| 490 | if (mci->w) { |
| 491 | /* Warning pending */ |
| 492 | mcck->warning = 1; |
| 493 | set_thread_flag(TIF_MCCK_PENDING); |
| 494 | } |
Heiko Carstens | 8e9ccae | 2006-07-03 00:25:00 -0700 | [diff] [blame] | 495 | lockdep_on(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /* |
| 499 | * s390_init_machine_check |
| 500 | * |
| 501 | * initialize machine check handling |
| 502 | */ |
| 503 | static int |
| 504 | machine_check_init(void) |
| 505 | { |
| 506 | init_MUTEX_LOCKED(&m_sem); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 507 | ctl_clear_bit(14, 25); /* disable external damage MCH */ |
| 508 | ctl_set_bit(14, 27); /* enable system recovery MCH */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | #ifdef CONFIG_MACHCHK_WARNING |
| 510 | ctl_set_bit(14, 24); /* enable warning MCH */ |
| 511 | #endif |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * Initialize the machine check handler really early to be able to |
| 517 | * catch all machine checks that happen during boot |
| 518 | */ |
| 519 | arch_initcall(machine_check_init); |
| 520 | |
| 521 | /* |
| 522 | * Machine checks for the channel subsystem must be enabled |
| 523 | * after the channel subsystem is initialized |
| 524 | */ |
| 525 | static int __init |
| 526 | machine_check_crw_init (void) |
| 527 | { |
Akinobu Mita | b0f1779 | 2007-02-05 21:16:49 +0100 | [diff] [blame^] | 528 | struct task_struct *task; |
| 529 | |
| 530 | task = kthread_run(s390_collect_crw_info, &m_sem, "kmcheck"); |
| 531 | if (IS_ERR(task)) |
| 532 | return PTR_ERR(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | ctl_set_bit(14, 28); /* enable channel report MCH */ |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | device_initcall (machine_check_crw_init); |