Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebieder...
[linux-2.6-block.git] / arch / x86 / kernel / cpu / mce / core.c
index 10f9f140985e8f40c59456fdc1429891313880e6..743370ee49835650750e331c63ca985b8474e33b 100644 (file)
@@ -1348,7 +1348,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)
                local_irq_enable();
 
                if (kill_it || do_memory_failure(&m))
-                       force_sig(SIGBUS, current);
+                       force_sig(SIGBUS);
                local_irq_disable();
                ist_end_non_atomic();
        } else {
@@ -1490,6 +1490,11 @@ static void __mcheck_cpu_mce_banks_init(void)
        for (i = 0; i < n_banks; i++) {
                struct mce_bank *b = &mce_banks[i];
 
+               /*
+                * Init them all, __mcheck_cpu_apply_quirks() is going to apply
+                * the required vendor quirks before
+                * __mcheck_cpu_init_clear_banks() does the final bank setup.
+                */
                b->ctl = -1ULL;
                b->init = 1;
        }
@@ -1562,6 +1567,33 @@ static void __mcheck_cpu_init_clear_banks(void)
        }
 }
 
+/*
+ * Do a final check to see if there are any unused/RAZ banks.
+ *
+ * This must be done after the banks have been initialized and any quirks have
+ * been applied.
+ *
+ * Do not call this from any user-initiated flows, e.g. CPU hotplug or sysfs.
+ * Otherwise, a user who disables a bank will not be able to re-enable it
+ * without a system reboot.
+ */
+static void __mcheck_cpu_check_banks(void)
+{
+       struct mce_bank *mce_banks = this_cpu_ptr(mce_banks_array);
+       u64 msrval;
+       int i;
+
+       for (i = 0; i < this_cpu_read(mce_num_banks); i++) {
+               struct mce_bank *b = &mce_banks[i];
+
+               if (!b->init)
+                       continue;
+
+               rdmsrl(msr_ops.ctl(i), msrval);
+               b->init = !!msrval;
+       }
+}
+
 /*
  * During IFU recovery Sandy Bridge -EP4S processors set the RIPV and
  * EIPV bits in MCG_STATUS to zero on the affected logical processor (SDM
@@ -1849,6 +1881,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
        __mcheck_cpu_init_generic();
        __mcheck_cpu_init_vendor(c);
        __mcheck_cpu_init_clear_banks();
+       __mcheck_cpu_check_banks();
        __mcheck_cpu_setup_timer();
 }
 
@@ -2085,6 +2118,9 @@ static ssize_t show_bank(struct device *s, struct device_attribute *attr,
 
        b = &per_cpu(mce_banks_array, s->id)[bank];
 
+       if (!b->init)
+               return -ENODEV;
+
        return sprintf(buf, "%llx\n", b->ctl);
 }
 
@@ -2103,6 +2139,9 @@ static ssize_t set_bank(struct device *s, struct device_attribute *attr,
 
        b = &per_cpu(mce_banks_array, s->id)[bank];
 
+       if (!b->init)
+               return -ENODEV;
+
        b->ctl = new;
        mce_restart();
 
@@ -2477,22 +2516,16 @@ static int fake_panic_set(void *data, u64 val)
 DEFINE_DEBUGFS_ATTRIBUTE(fake_panic_fops, fake_panic_get, fake_panic_set,
                         "%llu\n");
 
-static int __init mcheck_debugfs_init(void)
+static void __init mcheck_debugfs_init(void)
 {
-       struct dentry *dmce, *ffake_panic;
+       struct dentry *dmce;
 
        dmce = mce_get_debugfs_dir();
-       if (!dmce)
-               return -ENOMEM;
-       ffake_panic = debugfs_create_file_unsafe("fake_panic", 0444, dmce,
-                                                NULL, &fake_panic_fops);
-       if (!ffake_panic)
-               return -ENOMEM;
-
-       return 0;
+       debugfs_create_file_unsafe("fake_panic", 0444, dmce, NULL,
+                                  &fake_panic_fops);
 }
 #else
-static int __init mcheck_debugfs_init(void) { return -EINVAL; }
+static void __init mcheck_debugfs_init(void) { }
 #endif
 
 DEFINE_STATIC_KEY_FALSE(mcsafe_key);