Re: [PATCH 3/5] x86/ibrs: Add direct access support for MSR_IA32_SPEC_CTRL
From: David Woodhouse
Date: Mon Jan 15 2018 - 08:59:48 EST
On Mon, 2018-01-15 at 14:45 +0100, Peter Zijlstra wrote:
> On Fri, Jan 12, 2018 at 10:09:08AM +0000, David Woodhouse wrote:
> > static_cpu_has() + asm-goto is NOT SUFFICIENT.
> >Â
> > It's still *possible* for a missed optimisation in GCC to still leave
> > us with a conditional branch around the wrmsr, letting the CPU
> > speculate around it too.
>
> OK, so GCC would have to be bloody retarded to mess this up;
Like *that's* never happened before? In corner cases where it just gets
confused and certain optimisations go out the window?
> but would something like the below work for you?
>
> The usage is like:
>
> Â if (static_branch_unlikely(key)) {
> ÂÂÂÂÂÂÂÂarch_static_assert();
> ÂÂÂÂÂÂÂÂstuff();
> Â }
>
> And then objtool will fail things if the first instruction into that
> branch is not immediately after a NOP/JMP patch site (on either the NOP
> or the JMP+disp side of things).
That seems reasonable; thanks. Bonus points if you can make the
arch_static_assert happen() automatically with vile tricks like
#define IF_FEATURE(ftr) if (static_cpu_has(ftr)) arch_static_assert,Â
So then it just becomes
 ÂIF_FEATURE(key) {
   Âstuff();
 Â}
There might not be a sane way to do that though. And it's OK to have to
manually annotate the call sites where this is for correctness and not
purely optimisation.Attachment:
smime.p7s
Description: S/MIME cryptographic signature