1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/conf.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/systm.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/mutex.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/machparam.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/machthread.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/cpu.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 42*7c478bd9Sstevel@tonic-gate #include <vm/page.h> 43*7c478bd9Sstevel@tonic-gate #include <vm/hat.h> 44*7c478bd9Sstevel@tonic-gate #include <vm/seg.h> 45*7c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/vmem.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/mman.h> 49*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 50*7c478bd9Sstevel@tonic-gate #include <sys/time.h> 51*7c478bd9Sstevel@tonic-gate #include <sys/async.h> 52*7c478bd9Sstevel@tonic-gate #include <sys/spl.h> 53*7c478bd9Sstevel@tonic-gate #include <sys/trap.h> 54*7c478bd9Sstevel@tonic-gate #include <sys/machtrap.h> 55*7c478bd9Sstevel@tonic-gate #include <sys/promif.h> 56*7c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 57*7c478bd9Sstevel@tonic-gate #include <sys/debug.h> 58*7c478bd9Sstevel@tonic-gate #include <sys/x_call.h> 59*7c478bd9Sstevel@tonic-gate #include <sys/membar.h> 60*7c478bd9Sstevel@tonic-gate #include <sys/ivintr.h> 61*7c478bd9Sstevel@tonic-gate #include <sys/cred.h> 62*7c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h> 63*7c478bd9Sstevel@tonic-gate #include <sys/ontrap.h> 64*7c478bd9Sstevel@tonic-gate #include <sys/sdt.h> 65*7c478bd9Sstevel@tonic-gate #include <sys/errorq.h> 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate #define MAX_CE_FLTS 10 68*7c478bd9Sstevel@tonic-gate #define MAX_ASYNC_FLTS 6 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate errorq_t *ue_queue; /* queue of uncorrectable errors */ 71*7c478bd9Sstevel@tonic-gate errorq_t *ce_queue; /* queue of correctable errors */ 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate /* 74*7c478bd9Sstevel@tonic-gate * ce_verbose_memory - covers CEs in DIMMs 75*7c478bd9Sstevel@tonic-gate * ce_verbose_other - covers "others" (ecache, IO, etc.) 76*7c478bd9Sstevel@tonic-gate * 77*7c478bd9Sstevel@tonic-gate * If the value is 0, nothing is logged. 78*7c478bd9Sstevel@tonic-gate * If the value is 1, the error is logged to the log file, but not console. 79*7c478bd9Sstevel@tonic-gate * If the value is 2, the error is logged to the log file and console. 80*7c478bd9Sstevel@tonic-gate */ 81*7c478bd9Sstevel@tonic-gate int ce_verbose_memory = 1; 82*7c478bd9Sstevel@tonic-gate int ce_verbose_other = 1; 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate int ce_show_data = 0; 85*7c478bd9Sstevel@tonic-gate int ce_debug = 0; 86*7c478bd9Sstevel@tonic-gate int ue_debug = 0; 87*7c478bd9Sstevel@tonic-gate int reset_debug = 0; 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate /* 90*7c478bd9Sstevel@tonic-gate * Tunables for controlling the handling of asynchronous faults (AFTs). Setting 91*7c478bd9Sstevel@tonic-gate * these to non-default values on a non-DEBUG kernel is NOT supported. 92*7c478bd9Sstevel@tonic-gate */ 93*7c478bd9Sstevel@tonic-gate int aft_verbose = 0; /* log AFT messages > 1 to log only */ 94*7c478bd9Sstevel@tonic-gate int aft_panic = 0; /* panic (not reboot) on fatal usermode AFLT */ 95*7c478bd9Sstevel@tonic-gate int aft_testfatal = 0; /* force all AFTs to panic immediately */ 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate /* 98*7c478bd9Sstevel@tonic-gate * Panic_* variables specific to the AFT code. These are used to record 99*7c478bd9Sstevel@tonic-gate * information that the platform-specific code will need once we panic. 100*7c478bd9Sstevel@tonic-gate */ 101*7c478bd9Sstevel@tonic-gate struct async_flt panic_aflt; 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate /* 104*7c478bd9Sstevel@tonic-gate * Defined in bus_func.c but initialised in error_init 105*7c478bd9Sstevel@tonic-gate */ 106*7c478bd9Sstevel@tonic-gate extern kmutex_t bfd_lock; 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate /* 109*7c478bd9Sstevel@tonic-gate * Common bus driver async error logging routine. This routine can be shared 110*7c478bd9Sstevel@tonic-gate * by all sun4u CPUs (unlike cpu_async_log_err) because we are assuming that 111*7c478bd9Sstevel@tonic-gate * if an i/o bus error required a panic, the error interrupt handler will 112*7c478bd9Sstevel@tonic-gate * enqueue the error and call panic itself. 113*7c478bd9Sstevel@tonic-gate */ 114*7c478bd9Sstevel@tonic-gate void 115*7c478bd9Sstevel@tonic-gate bus_async_log_err(struct async_flt *aflt) 116*7c478bd9Sstevel@tonic-gate { 117*7c478bd9Sstevel@tonic-gate char unum[UNUM_NAMLEN]; 118*7c478bd9Sstevel@tonic-gate int len; 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate /* 121*7c478bd9Sstevel@tonic-gate * Call back into the processor specific routine 122*7c478bd9Sstevel@tonic-gate * to check for cpu related errors that may 123*7c478bd9Sstevel@tonic-gate * have resulted in this error. (E.g. copyout trap) 124*7c478bd9Sstevel@tonic-gate */ 125*7c478bd9Sstevel@tonic-gate if (aflt->flt_in_memory) 126*7c478bd9Sstevel@tonic-gate cpu_check_allcpus(aflt); 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate /* 129*7c478bd9Sstevel@tonic-gate * Note that aflt->flt_stat is not the CPU afsr. 130*7c478bd9Sstevel@tonic-gate */ 131*7c478bd9Sstevel@tonic-gate (void) cpu_get_mem_unum_aflt(AFLT_STAT_INVALID, aflt, 132*7c478bd9Sstevel@tonic-gate unum, UNUM_NAMLEN, &len); 133*7c478bd9Sstevel@tonic-gate aflt->flt_func(aflt, unum); 134*7c478bd9Sstevel@tonic-gate } 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate /* 137*7c478bd9Sstevel@tonic-gate * ecc_cpu_call called from bus drain functions to run cpu 138*7c478bd9Sstevel@tonic-gate * specific functions to check other cpus and get the unum. 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate void 141*7c478bd9Sstevel@tonic-gate ecc_cpu_call(struct async_flt *ecc, char *unum, int err_type) 142*7c478bd9Sstevel@tonic-gate { 143*7c478bd9Sstevel@tonic-gate int len; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate /* 146*7c478bd9Sstevel@tonic-gate * Call back into the processor 147*7c478bd9Sstevel@tonic-gate * specific routine to check for cpu related errors 148*7c478bd9Sstevel@tonic-gate * that may have resulted in this error. 149*7c478bd9Sstevel@tonic-gate * (E.g. copyout trap) 150*7c478bd9Sstevel@tonic-gate */ 151*7c478bd9Sstevel@tonic-gate if (ecc->flt_in_memory) 152*7c478bd9Sstevel@tonic-gate cpu_check_allcpus(ecc); 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate (void) cpu_get_mem_unum(AFLT_STAT_VALID, ecc->flt_synd, 155*7c478bd9Sstevel@tonic-gate (uint64_t)-1, ecc->flt_addr, 156*7c478bd9Sstevel@tonic-gate ecc->flt_bus_id, ecc->flt_in_memory, 157*7c478bd9Sstevel@tonic-gate ecc->flt_status, unum, 158*7c478bd9Sstevel@tonic-gate UNUM_NAMLEN, &len); 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate if (err_type == ECC_IO_CE) 161*7c478bd9Sstevel@tonic-gate cpu_ce_count_unum(ecc, len, unum); 162*7c478bd9Sstevel@tonic-gate } 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate /* 165*7c478bd9Sstevel@tonic-gate * Handler to process a fatal error. This routine can be called from a 166*7c478bd9Sstevel@tonic-gate * softint, called from trap()'s AST handling, or called from the panic flow. 167*7c478bd9Sstevel@tonic-gate */ 168*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 169*7c478bd9Sstevel@tonic-gate static void 170*7c478bd9Sstevel@tonic-gate ue_drain(void *ignored, struct async_flt *aflt, errorq_elem_t *eqep) 171*7c478bd9Sstevel@tonic-gate { 172*7c478bd9Sstevel@tonic-gate cpu_ue_log_err(aflt); 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate /* 176*7c478bd9Sstevel@tonic-gate * Handler to process a correctable error. This routine can be called from a 177*7c478bd9Sstevel@tonic-gate * softint. We just call the CPU module's logging routine. 178*7c478bd9Sstevel@tonic-gate */ 179*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 180*7c478bd9Sstevel@tonic-gate static void 181*7c478bd9Sstevel@tonic-gate ce_drain(void *ignored, struct async_flt *aflt, errorq_elem_t *eqep) 182*7c478bd9Sstevel@tonic-gate { 183*7c478bd9Sstevel@tonic-gate cpu_ce_log_err(aflt, eqep); 184*7c478bd9Sstevel@tonic-gate } 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate /* 187*7c478bd9Sstevel@tonic-gate * Scrub a non-fatal correctable ecc error. 188*7c478bd9Sstevel@tonic-gate */ 189*7c478bd9Sstevel@tonic-gate void 190*7c478bd9Sstevel@tonic-gate ce_scrub(struct async_flt *aflt) 191*7c478bd9Sstevel@tonic-gate { 192*7c478bd9Sstevel@tonic-gate if (aflt->flt_in_memory) 193*7c478bd9Sstevel@tonic-gate cpu_ce_scrub_mem_err(aflt, B_FALSE); 194*7c478bd9Sstevel@tonic-gate } 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate /* 197*7c478bd9Sstevel@tonic-gate * Allocate error queue sizes based on max_ncpus. max_ncpus is set just 198*7c478bd9Sstevel@tonic-gate * after ncpunode has been determined. ncpus is set in start_other_cpus 199*7c478bd9Sstevel@tonic-gate * which is called after error_init() but may change dynamically. 200*7c478bd9Sstevel@tonic-gate */ 201*7c478bd9Sstevel@tonic-gate void 202*7c478bd9Sstevel@tonic-gate error_init(void) 203*7c478bd9Sstevel@tonic-gate { 204*7c478bd9Sstevel@tonic-gate char tmp_name[MAXSYSNAME]; 205*7c478bd9Sstevel@tonic-gate dnode_t node; 206*7c478bd9Sstevel@tonic-gate size_t size = cpu_aflt_size(); 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate /* 209*7c478bd9Sstevel@tonic-gate * Initialize the correctable and uncorrectable error queues. 210*7c478bd9Sstevel@tonic-gate */ 211*7c478bd9Sstevel@tonic-gate ue_queue = errorq_create("ue_queue", (errorq_func_t)ue_drain, NULL, 212*7c478bd9Sstevel@tonic-gate MAX_ASYNC_FLTS * (max_ncpus + 1), size, PIL_2, ERRORQ_VITAL); 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate ce_queue = errorq_create("ce_queue", (errorq_func_t)ce_drain, NULL, 215*7c478bd9Sstevel@tonic-gate MAX_CE_FLTS * (max_ncpus + 1), size, PIL_1, 0); 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate if (ue_queue == NULL || ce_queue == NULL) 218*7c478bd9Sstevel@tonic-gate panic("failed to create required system error queue"); 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate /* 221*7c478bd9Sstevel@tonic-gate * Initialize the busfunc list mutex. This must be a PIL_15 spin lock 222*7c478bd9Sstevel@tonic-gate * because we will need to acquire it from cpu_async_error(). 223*7c478bd9Sstevel@tonic-gate */ 224*7c478bd9Sstevel@tonic-gate mutex_init(&bfd_lock, NULL, MUTEX_SPIN, (void *)PIL_15); 225*7c478bd9Sstevel@tonic-gate 226*7c478bd9Sstevel@tonic-gate node = prom_rootnode(); 227*7c478bd9Sstevel@tonic-gate if ((node == OBP_NONODE) || (node == OBP_BADNODE)) { 228*7c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "error_init: node 0x%x\n", (uint_t)node); 229*7c478bd9Sstevel@tonic-gate return; 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate if (((size = prom_getproplen(node, "reset-reason")) != -1) && 233*7c478bd9Sstevel@tonic-gate (size <= MAXSYSNAME) && 234*7c478bd9Sstevel@tonic-gate (prom_getprop(node, "reset-reason", tmp_name) != -1)) { 235*7c478bd9Sstevel@tonic-gate if (reset_debug) { 236*7c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "System booting after %s\n", tmp_name); 237*7c478bd9Sstevel@tonic-gate } else if (strncmp(tmp_name, "FATAL", 5) == 0) { 238*7c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, 239*7c478bd9Sstevel@tonic-gate "System booting after fatal error %s\n", tmp_name); 240*7c478bd9Sstevel@tonic-gate } 241*7c478bd9Sstevel@tonic-gate } 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate if (&cpu_error_init) { 244*7c478bd9Sstevel@tonic-gate cpu_error_init((MAX_ASYNC_FLTS + MAX_CE_FLTS) * 245*7c478bd9Sstevel@tonic-gate (max_ncpus + 1)); 246*7c478bd9Sstevel@tonic-gate } 247*7c478bd9Sstevel@tonic-gate } 248*7c478bd9Sstevel@tonic-gate 249*7c478bd9Sstevel@tonic-gate /* 250*7c478bd9Sstevel@tonic-gate * Success flags for ecc_page_zero 251*7c478bd9Sstevel@tonic-gate */ 252*7c478bd9Sstevel@tonic-gate #define PAGE_ZERO_SUCCESS 0 253*7c478bd9Sstevel@tonic-gate #define PAGE_ZERO_FAIL_NOLOCK 1 254*7c478bd9Sstevel@tonic-gate #define PAGE_ZERO_FAIL_ONTRAP 2 255*7c478bd9Sstevel@tonic-gate 256*7c478bd9Sstevel@tonic-gate /* 257*7c478bd9Sstevel@tonic-gate * arg is a physical address - zero out the page that contains it 258*7c478bd9Sstevel@tonic-gate */ 259*7c478bd9Sstevel@tonic-gate void 260*7c478bd9Sstevel@tonic-gate ecc_page_zero(void *arg) 261*7c478bd9Sstevel@tonic-gate { 262*7c478bd9Sstevel@tonic-gate uint64_t pa = (uint64_t)arg; 263*7c478bd9Sstevel@tonic-gate page_t *pp = page_numtopp_nolock((pfn_t)(pa >> MMU_PAGESHIFT)); 264*7c478bd9Sstevel@tonic-gate int ret, success_flag; 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate if (pp == NULL || !page_isretired(pp)) 267*7c478bd9Sstevel@tonic-gate return; 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate /* 270*7c478bd9Sstevel@tonic-gate * Must hold a lock on the page before calling pagezero() 271*7c478bd9Sstevel@tonic-gate * 272*7c478bd9Sstevel@tonic-gate * This will only fail if someone has or wants an exclusive lock on 273*7c478bd9Sstevel@tonic-gate * the page. Since it's a retired page, this shouldn't happen. 274*7c478bd9Sstevel@tonic-gate */ 275*7c478bd9Sstevel@tonic-gate ret = page_lock(pp, SE_SHARED, (kmutex_t *)NULL, P_NO_RECLAIM); 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate if (ret > 0) { 278*7c478bd9Sstevel@tonic-gate on_trap_data_t otd; 279*7c478bd9Sstevel@tonic-gate 280*7c478bd9Sstevel@tonic-gate /* 281*7c478bd9Sstevel@tonic-gate * Protect pagezero() from async faults 282*7c478bd9Sstevel@tonic-gate */ 283*7c478bd9Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_EC)) { 284*7c478bd9Sstevel@tonic-gate pagezero(pp, 0, PAGESIZE); 285*7c478bd9Sstevel@tonic-gate success_flag = PAGE_ZERO_SUCCESS; 286*7c478bd9Sstevel@tonic-gate } else { 287*7c478bd9Sstevel@tonic-gate success_flag = PAGE_ZERO_FAIL_ONTRAP; 288*7c478bd9Sstevel@tonic-gate } 289*7c478bd9Sstevel@tonic-gate no_trap(); 290*7c478bd9Sstevel@tonic-gate page_unlock(pp); 291*7c478bd9Sstevel@tonic-gate } else { 292*7c478bd9Sstevel@tonic-gate success_flag = PAGE_ZERO_FAIL_NOLOCK; 293*7c478bd9Sstevel@tonic-gate } 294*7c478bd9Sstevel@tonic-gate DTRACE_PROBE2(page_zero_result, int, success_flag, uint64_t, pa); 295*7c478bd9Sstevel@tonic-gate } 296