Re: [tip:x86/alternatives] [x86/alternatives] ee8962082a: WARNING:at_arch/x86/kernel/cpu/cpuid-deps.c:#do_clear_cpu_cap

From: Borislav Petkov
Date: Mon May 06 2024 - 04:04:52 EST


On Mon, May 06, 2024 at 09:39:03AM +0200, Borislav Petkov wrote:
> On Mon, May 06, 2024 at 03:09:27PM +0800, Oliver Sang wrote:
> > we confirmed after applying them upon ee8962082a, the WARNING which was reported
> > in our original report cannot be reproduced any longer.
> >
> > Tested-by: kernel test robot <oliver.sang@xxxxxxxxx>
>
> Thanks a lot for testing - much appreciated.

Hm, ok, after looking at this more, I think I'm going to go with patch
2 only.

And patch 1 is wrong. At least for now, lemme explain:

So before it, we'd do

if (boot_cpu_has(feature))
WARN_ON(alternatives_patched);

when clearing feature flags, meaning: if the flag is set on the BSP,
that means, alternatives have patched already and we're clearing
potentially on another CPU and it'll warn because it will be wrong.

If we do:

if (c && cpu_has(c, feature))
WARN_ON(alternatives_patched);

then it would warn on *every* CPU but it doesn't need to *BECAUSE* the
alternatives patching is controlled by the boot_cpu_data checks for the
BSP - not the AP ones.

So if the BSP doesn't have the feature, we can just as well clear it on
the APs as it wouldn't have any effect on conditionals further on.

Otherwise, we'll have to go and move every clear_cpu_cap() call after
alternatives have patched to before that, which would be insane.

I mean, we'll do that eventually but can't now.

Lemme write that as a comment in the function so that we don't forget.

Oh boy, I love our feature flags infra. :-\

--
Regards/Gruss,
Boris.

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