fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / ia64 / kernel / mca_drv.c
index e883d85..afc1403 100644 (file)
@@ -6,8 +6,8 @@
  * Copyright (C) Hidetoshi Seto (seto.hidetoshi@jp.fujitsu.com)
  * Copyright (C) 2005 Silicon Graphics, Inc
  * Copyright (C) 2005 Keith Owens <kaos@sgi.com>
+ * Copyright (C) 2006 Russ Anderson <rja@sgi.com>
  */
-#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/sched.h>
@@ -61,6 +61,11 @@ typedef enum {
        ISOLATE_NONE
 } isolate_status_t;
 
+typedef enum {
+       MCA_NOT_RECOVERED = 0,
+       MCA_RECOVERED     = 1
+} recovery_status_t;
+
 /*
  *  This pool keeps pointers to the section part of SAL error record
  */
@@ -70,6 +75,34 @@ static struct {
        int          max_idx; /* Maximum index of section pointer list pool */
 } slidx_pool;
 
+static int
+fatal_mca(const char *fmt, ...)
+{
+       va_list args;
+       char buf[256];
+
+       va_start(args, fmt);
+       vsnprintf(buf, sizeof(buf), fmt, args);
+       va_end(args);
+       ia64_mca_printk(KERN_ALERT "MCA: %s\n", buf);
+
+       return MCA_NOT_RECOVERED;
+}
+
+static int
+mca_recovered(const char *fmt, ...)
+{
+       va_list args;
+       char buf[256];
+
+       va_start(args, fmt);
+       vsnprintf(buf, sizeof(buf), fmt, args);
+       va_end(args);
+       ia64_mca_printk(KERN_INFO "MCA: %s\n", buf);
+
+       return MCA_RECOVERED;
+}
+
 /**
  * mca_page_isolate - isolate a poisoned page in order not to use it later
  * @paddr:     poisoned memory location
@@ -121,11 +154,13 @@ mca_page_isolate(unsigned long paddr)
  */
 
 void
-mca_handler_bh(unsigned long paddr)
+mca_handler_bh(unsigned long paddr, void *iip, unsigned long ipsr)
 {
-       printk(KERN_ERR
-               "OS_MCA: process [pid: %d](%s) encounters MCA (paddr=%lx)\n",
-               current->pid, current->comm, paddr);
+       ia64_mlogbuf_dump();
+       printk(KERN_ERR "OS_MCA: process [cpu %d, pid: %d, uid: %d, "
+               "iip: %p, psr: 0x%lx,paddr: 0x%lx](%s) encounters MCA.\n",
+               raw_smp_processor_id(), current->pid, current->uid,
+               iip, ipsr, paddr, current->comm);
 
        spin_lock(&mca_bh_lock);
        switch (mca_page_isolate(paddr)) {
@@ -399,6 +434,50 @@ is_mca_global(peidx_table_t *peidx, pal_bus_check_info_t *pbci,
        return MCA_IS_GLOBAL;
 }
 
+/**
+ * get_target_identifier - Get the valid Cache or Bus check target identifier.
+ * @peidx:     pointer of index of processor error section
+ *
+ * Return value:
+ *     target address on Success / 0 on Failue
+ */
+static u64
+get_target_identifier(peidx_table_t *peidx)
+{
+       u64 target_address = 0;
+       sal_log_mod_error_info_t *smei;
+       pal_cache_check_info_t *pcci;
+       int i, level = 9;
+
+       /*
+        * Look through the cache checks for a valid target identifier
+        * If more than one valid target identifier, return the one
+        * with the lowest cache level.
+        */
+       for (i = 0; i < peidx_cache_check_num(peidx); i++) {
+               smei = (sal_log_mod_error_info_t *)peidx_cache_check(peidx, i);
+               if (smei->valid.target_identifier && smei->target_identifier) {
+                       pcci = (pal_cache_check_info_t *)&(smei->check_info);
+                       if (!target_address || (pcci->level < level)) {
+                               target_address = smei->target_identifier;
+                               level = pcci->level;
+                               continue;
+                       }
+               }
+       }
+       if (target_address)
+               return target_address;
+
+       /*
+        * Look at the bus check for a valid target identifier
+        */
+       smei = peidx_bus_check(peidx, 0);
+       if (smei && smei->valid.target_identifier)
+               return smei->target_identifier;
+
+       return 0;
+}
+
 /**
  * recover_from_read_error - Try to recover the errors which type are "read"s.
  * @slidx:     pointer of index of SAL error record
@@ -415,14 +494,15 @@ recover_from_read_error(slidx_table_t *slidx,
                        peidx_table_t *peidx, pal_bus_check_info_t *pbci,
                        struct ia64_sal_os_state *sos)
 {
-       sal_log_mod_error_info_t *smei;
+       u64 target_identifier;
        pal_min_state_area_t *pmsa;
        struct ia64_psr *psr1, *psr2;
        ia64_fptr_t *mca_hdlr_bh = (ia64_fptr_t*)mca_handler_bhhook;
 
        /* Is target address valid? */
-       if (!pbci->tv)
-               return 0;
+       target_identifier = get_target_identifier(peidx);
+       if (!target_identifier)
+               return fatal_mca("target address not valid");
 
        /*
         * cpu read or memory-mapped io read
@@ -440,40 +520,44 @@ recover_from_read_error(slidx_table_t *slidx,
 
        /* Is minstate valid? */
        if (!peidx_bottom(peidx) || !(peidx_bottom(peidx)->valid.minstate))
-               return 0;
+               return fatal_mca("minstate not valid");
        psr1 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_ipsr);
+       psr2 =(struct ia64_psr *)&(peidx_minstate_area(peidx)->pmsa_xpsr);
 
        /*
         *  Check the privilege level of interrupted context.
         *   If it is user-mode, then terminate affected process.
         */
-       if (psr1->cpl != 0) {
-               smei = peidx_bus_check(peidx, 0);
-               if (smei->valid.target_identifier) {
-                       /*
-                        *  setup for resume to bottom half of MCA,
-                        * "mca_handler_bhhook"
-                        */
-                       pmsa = sos->pal_min_state;
-                       /* pass to bhhook as 1st argument (gr8) */
-                       pmsa->pmsa_gr[8-1] = smei->target_identifier;
-                       /* set interrupted return address (but no use) */
-                       pmsa->pmsa_br0 = pmsa->pmsa_iip;
-                       /* change resume address to bottom half */
-                       pmsa->pmsa_iip = mca_hdlr_bh->fp;
-                       pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp;
-                       /* set cpl with kernel mode */
-                       psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr;
-                       psr2->cpl = 0;
-                       psr2->ri  = 0;
-                       psr2->i  = 0;
-
-                       return 1;
-               }
 
+       pmsa = sos->pal_min_state;
+       if (psr1->cpl != 0 ||
+          ((psr2->cpl != 0) && mca_recover_range(pmsa->pmsa_iip))) {
+               /*
+                *  setup for resume to bottom half of MCA,
+                * "mca_handler_bhhook"
+                */
+               /* pass to bhhook as argument (gr8, ...) */
+               pmsa->pmsa_gr[8-1] = target_identifier;
+               pmsa->pmsa_gr[9-1] = pmsa->pmsa_iip;
+               pmsa->pmsa_gr[10-1] = pmsa->pmsa_ipsr;
+               /* set interrupted return address (but no use) */
+               pmsa->pmsa_br0 = pmsa->pmsa_iip;
+               /* change resume address to bottom half */
+               pmsa->pmsa_iip = mca_hdlr_bh->fp;
+               pmsa->pmsa_gr[1-1] = mca_hdlr_bh->gp;
+               /* set cpl with kernel mode */
+               psr2 = (struct ia64_psr *)&pmsa->pmsa_ipsr;
+               psr2->cpl = 0;
+               psr2->ri  = 0;
+               psr2->bn  = 1;
+               psr2->i  = 0;
+
+               return mca_recovered("user memory corruption. "
+                               "kill affected process - recovered.");
        }
 
-       return 0;
+       return fatal_mca("kernel context not recovered, iip 0x%lx\n",
+                        pmsa->pmsa_iip);
 }
 
 /**
@@ -559,13 +643,13 @@ recover_from_processor_error(int platform, slidx_table_t *slidx,
         * The machine check is corrected.
         */
        if (psp->cm == 1)
-               return 1;
+               return mca_recovered("machine check is already corrected.");
 
        /*
         * The error was not contained.  Software must be reset.
         */
        if (psp->us || psp->ci == 0)
-               return 0;
+               return fatal_mca("error not contained");
 
        /*
         * The cache check and bus check bits have four possible states
@@ -576,20 +660,22 @@ recover_from_processor_error(int platform, slidx_table_t *slidx,
         *    1  1      Memory error, attempt recovery
         */
        if (psp->bc == 0 || pbci == NULL)
-               return 0;
+               return fatal_mca("No bus check");
 
        /*
         * Sorry, we cannot handle so many.
         */
        if (peidx_bus_check_num(peidx) > 1)
-               return 0;
+               return fatal_mca("Too many bus checks");
        /*
         * Well, here is only one bus error.
         */
-       if (pbci->ib || pbci->cc)
-               return 0;
+       if (pbci->ib)
+               return fatal_mca("Internal Bus error");
+       if (pbci->cc)
+               return fatal_mca("Cache-cache error");
        if (pbci->eb && pbci->bsi > 0)
-               return 0;
+               return fatal_mca("External bus check fatal status");
 
        /*
         * This is a local MCA and estimated as recoverble external bus error.
@@ -601,7 +687,7 @@ recover_from_processor_error(int platform, slidx_table_t *slidx,
        /*
         * On account of strange SAL error record, we cannot recover.
         */
-       return 0;
+       return fatal_mca("Strange SAL record");
 }
 
 /**
@@ -630,12 +716,10 @@ mca_try_to_recover(void *rec, struct ia64_sal_os_state *sos)
 
         /* Now, OS can recover when there is one processor error section */
        if (n_proc_err > 1)
-               return 0;
-       else if (n_proc_err == 0) {
-               /* Weird SAL record ... We need not to recover */
-
-               return 1;
-       }
+               return fatal_mca("Too Many Errors");
+       else if (n_proc_err == 0)
+               /* Weird SAL record ... We can't do anything */
+               return fatal_mca("Weird SAL record");
 
        /* Make index of processor error section */
        mca_make_peidx((sal_log_processor_info_t*)
@@ -646,7 +730,7 @@ mca_try_to_recover(void *rec, struct ia64_sal_os_state *sos)
 
        /* Check whether MCA is global or not */
        if (is_mca_global(&peidx, &pbci, sos))
-               return 0;
+               return fatal_mca("global MCA");
        
        /* Try to recover a processor error */
        return recover_from_processor_error(platform_err, &slidx, &peidx,