x86, microcode: Cleanup cpu hotplug notifier callback
authorBorislav Petkov <borislav.petkov@amd.com>
Mon, 23 Jul 2012 18:15:10 +0000 (20:15 +0200)
committerH. Peter Anvin <hpa@linux.intel.com>
Wed, 22 Aug 2012 23:14:52 +0000 (16:14 -0700)
Mask out CPU_TASKS_FROZEN bit so that all _FROZEN cases can be dropped.
Also, add some more comments as to why CPU_ONLINE falls through to
CPU_DOWN_FAILED (no break), and for the CPU_DEAD case. Realign debug
printks better.

Idea blatantly stolen from a tglx patch:
http://marc.info/?l=linux-kernel&m=134267779513862

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
Link: http://lkml.kernel.org/r/1344361461-10076-5-git-send-email-bp@amd64.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
arch/x86/kernel/microcode_core.c

index 706a5c9..dcde544 100644 (file)
@@ -470,34 +470,41 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
        struct device *dev;
 
        dev = get_cpu_device(cpu);
-       switch (action) {
+
+       switch (action & ~CPU_TASKS_FROZEN) {
        case CPU_ONLINE:
-       case CPU_ONLINE_FROZEN:
                microcode_update_cpu(cpu);
-       case CPU_DOWN_FAILED:
-       case CPU_DOWN_FAILED_FROZEN:
                pr_debug("CPU%d added\n", cpu);
+               /*
+                * "break" is missing on purpose here because we want to fall
+                * through in order to create the sysfs group.
+                */
+
+       case CPU_DOWN_FAILED:
                if (sysfs_create_group(&dev->kobj, &mc_attr_group))
                        pr_err("Failed to create group for CPU%d\n", cpu);
                break;
+
        case CPU_DOWN_PREPARE:
-       case CPU_DOWN_PREPARE_FROZEN:
                /* Suspend is in progress, only remove the interface */
                sysfs_remove_group(&dev->kobj, &mc_attr_group);
                pr_debug("CPU%d removed\n", cpu);
                break;
 
        /*
+        * case CPU_DEAD:
+        *
         * When a CPU goes offline, don't free up or invalidate the copy of
         * the microcode in kernel memory, so that we can reuse it when the
         * CPU comes back online without unnecessarily requesting the userspace
         * for it again.
         */
-       case CPU_UP_CANCELED_FROZEN:
-               /* The CPU refused to come up during a system resume */
-               microcode_fini_cpu(cpu);
-               break;
        }
+
+       /* The CPU refused to come up during a system resume */
+       if (action == CPU_UP_CANCELED_FROZEN)
+               microcode_fini_cpu(cpu);
+
        return NOTIFY_OK;
 }