Re: [PATCH v4 7/7] x86/speculation: Add basic IBPB (Indirect Branch Prediction Barrier) support

From: David Woodhouse
Date: Thu Jan 25 2018 - 06:47:48 EST


On Thu, 2018-01-25 at 12:41 +0100, Borislav Petkov wrote:
>
> > +static inline void indirect_branch_prediction_barrier(void)
> > +{
> > +ÂÂÂÂÂasm volatile(ALTERNATIVE("",
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "movl %[msr], %%ecx\n\t"
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "movl %[val], %%eax\n\t"
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "movl $0, %%edx\n\t"
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "wrmsr",
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ X86_FEATURE_IBPB)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ : : [msr] "i" (MSR_IA32_PRED_CMD),
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ [val] "i" (PRED_CMD_IBPB)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ : "eax", "ecx", "edx", "memory");
>
> Lemme paste my simplification suggestion from the other day:
>
> "Btw, we can simplify this a bit by dropping the inputs and marking the 3
> GPRs as clobbered:
>
> ÂÂÂÂÂÂÂ alternative_input("",
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "mov $0x49, %%ecx\n\t"
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "mov $1, %%eax\n\t"
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "xor %%edx, %%edx\n\t"
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "wrmsr\n\t",
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ X86_FEATURE_IBPB,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ASM_NO_INPUT_CLOBBER("eax", "ecx", "edx", "memory"));

Yeah, I saw that; sorry for not replying explicitly.

I did already do the explicit clobbers now you reminded me how to do
them, but I elected not to use ASM_NO_INPUT_CLOBBER() because on
balance, losing the MSR_IA32_PRED_CMD / PRED_CMD_IBPB definitions and
having to hard-code the numbers was not so much of a win.

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