Re: [PATCH 06/21] x86: microcode: Convert to hotplug state machine

From: Borislav Petkov
Date: Wed Sep 07 2016 - 07:36:47 EST


On Tue, Sep 06, 2016 at 07:04:42PM +0200, Sebastian Andrzej Siewior wrote:
> Install the callbacks via the state machine. There is little hackery with
> mc_cpu_dead() which should only be called if CPU_UP failed durin resume.
> This change may not fully represent the current behaviour. The current code
> also behaves different if the CPU does not come up in the _cpu_up() state vs
> one of the CPU_ONLINE notifier returned an error. Not sure what kind of a
> problem is solved here.

You mean this:

/* The CPU refused to come up during a system resume */
if (action == CPU_UP_CANCELED_FROZEN)
microcode_fini_cpu(cpu);

?

It clears internal state, i.e., invalidates the current microcode patch.

>
> Cc: Borislav Petkov <bp@xxxxxxxxx>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
> ---
> arch/x86/kernel/cpu/microcode/core.c | 71 +++++++++++++++---------------------
> include/linux/cpuhotplug.h | 1 +
> 2 files changed, 30 insertions(+), 42 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
> index df04b2d033f6..4fc67b51e22e 100644
> --- a/arch/x86/kernel/cpu/microcode/core.c
> +++ b/arch/x86/kernel/cpu/microcode/core.c

...

> -static struct notifier_block mc_cpu_notifier = {
> - .notifier_call = mc_cpu_callback,
> -};
> +static int mc_cpu_down_prep(unsigned int cpu)
> +{
> + struct device *dev;
> +
> + dev = get_cpu_device(cpu);
> + /* Suspend is in progress, only remove the interface */
> + sysfs_remove_group(&dev->kobj, &mc_attr_group);
> + pr_debug("CPU%d removed\n", cpu);
> + return 0;
> +}
> +
> +static int mc_cpu_dead(unsigned int cpu)
> +{
> +#ifdef CONFIG_SMP
> + if (cpuhp_tasks_frozen)
> + microcode_fini_cpu(cpu);
> +#endif
> + return 0;
> +}

If this is corresponding to CPU_DEAD, then I'd like to point to that comment:

/*
* 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.
*/

IOW, you don't need mc_cpu_dead().

--
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.