Re: [patch V3 26/30] x86/microcode: Protect against instrumentation

From: Borislav Petkov
Date: Thu Sep 28 2023 - 06:52:25 EST


On Tue, Sep 12, 2023 at 09:58:24AM +0200, Thomas Gleixner wrote:
> for (timeout = 0; timeout < USEC_PER_SEC; timeout++) {
> - if (!atomic_read(cnt))
> + if (!raw_atomic_read(cnt))
> return true;
> - udelay(1);
> +
> + for (loops = 0; loops < loops_per_usec; loops++)
> + cpu_relax();
> +

Ah, you're dropping udelay because it is not noinstr...

> @@ -427,25 +464,43 @@ static void ucode_load_primary(unsigned
> }
> }
>
> -static bool microcode_update_handler(void)
> +static noinstr bool microcode_update_handler(void)
> {
> - unsigned int cpu = smp_processor_id();
> + unsigned int cpu = raw_smp_processor_id();
>
> - if (this_cpu_read(ucode_ctrl.ctrl_cpu) == cpu)
> + if (raw_cpu_read(ucode_ctrl.ctrl_cpu) == cpu) {
> + instrumentation_begin();
> ucode_load_primary(cpu);
> - else
> + instrumentation_end();

Might as well make the load on the primary noinstr too. I wouldn't lose
any sleep over the late microcode loading code not being traceable.

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette