Re: [PATCH 2/3] x86: Sanity-check static_cpu_has usage

H. Peter Anvin
2013-04-29T15:39:14Z

On 04/29/2013 07:04 AM, Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.de>
>
> static_cpu_has may be used only after alternatives have run. Before that
> it always returns false if constant folding with __builtin_constant_p()
> doesn't happen. And you don't want that.
>
> This patch is the result of me debugging an issue where I overzealously
> put static_cpu_has in code which executed before alternatives have run
> and had to spend some time with scratching head and cursing at the
> monitor.
>
> So add a jump to a warning which screams loudly when we use this
> function too early. The alternatives patch that check away in
> conjunction with patching the rest of the kernel image.
>
> This first JMP the compiler then issues should always be a two-byte JMP
> because its relative offset fits in a byte. This gets replaced by only a
> two-byte NOP => less instruction cache bloat.
>

I still would prefer this to be an option.

-hpa