Re: [PATCH 3/5] x86/ibrs: Add direct access support for MSR_IA32_SPEC_CTRL

From: David Woodhouse
Date: Fri Jan 12 2018 - 05:09:47 EST


On Fri, 2018-01-12 at 10:51 +0100, Peter Zijlstra wrote:
> On Thu, Jan 11, 2018 at 05:58:11PM -0800, Dave Hansen wrote:
> > On 01/11/2018 05:32 PM, Ashok Raj wrote:
> > > +static void save_guest_spec_ctrl(struct vcpu_vmx *vmx)
> > > +{
> > > +ÂÂÂif (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
> > > +ÂÂÂÂÂÂÂÂÂÂÂvmx->spec_ctrl = spec_ctrl_get();
> > > +ÂÂÂÂÂÂÂÂÂÂÂspec_ctrl_restriction_on();
> > > +ÂÂÂ} else
> > > +ÂÂÂÂÂÂÂÂÂÂÂrmb();
> > > +}
>
> > Does this need to be "ifence()"? Better yet, do we just need to create
> > a helper for boot_cpu_has(X86_FEATURE_SPEC_CTRL) that does the barrier?
>
> static_cpu_has() + hard asm-goto requirement. Please drop all the above
> nonsense on the floor hard.

Peter, NO!

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.

Come on, Peter, we've learned this lesson long and hard since the 1990s
when every GCC update would break some stupid shit we did. Don't
regress. WE DO NOT RELY ON UNGUARANTEED BEHAVIOUR OF THE COMPILER.

Devise a sanity check which will force a build-fail if GCC ever misses
the optimisation, and that's fine. (Or point me to an existing way that
it's guaranteed to fail, if such is true already. Don't just ignore the
objection.)

Do not just ASSUME that GCC will always and forever manage to make that
optimisation in every case.

--Â
dwmw2


 In our defence, back then there was often no *other* way to do some
 of the things we did, except the "stupid" way. These days, it's much
 easier to add features to GCC and elicit guarantees. Although I'm
 getting rather pissed off at them bikeshedding the retpoline patches
 *so* hard they can't even agree on a command-line option and the name
 of the thunk symbol, regardless of the internal implementation
 details we don't give a shit about.

Attachment: smime.p7s
Description: S/MIME cryptographic signature