Re: [tip:x86/pti] x86/speculation: Use IBRS if available before calling into firmware

From: David Woodhouse
Date: Fri Feb 16 2018 - 14:17:02 EST


On Fri, 2018-02-16 at 10:44 -0800, Tim Chen wrote:
>
> I encountered hang on a machine but not others when using the above
> macro. It is probably an alignment thing with ALTERNATIVE as the
> problem went
> away after I made the change below:
>
> Tim
>
> diff --git a/arch/x86/include/asm/nospec-branch.h
> b/arch/x86/include/asm/nospec-branch.h
> index 8f2ff74..0f65bd2 100644
> --- a/arch/x86/include/asm/nospec-branch.h
> +++ b/arch/x86/include/asm/nospec-branch.h
> @@ -148,6 +148,7 @@ extern char __indirect_thunk_end[];
> Â
> Â#define alternative_msr_write(_msr, _val, _feature)ÂÂÂÂÂÂÂÂÂÂÂ \
> ÂÂÂÂÂÂÂ asm volatile(ALTERNATIVE("",ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ".align 16\n\t"ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "movl %[msr], %%ecx\n\t"ÂÂÂÂÂÂ \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "movl %[val], %%eax\n\t"ÂÂÂÂÂÂ \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "movl $0, %%edx\n\t"ÂÂÂÂÂÂÂÂÂÂ \

That's weird. Note that .align in an altinstr section isn't actually
going to do what you'd expect; the oldinstr and altinstr sections
aren't necessarily aligned the same, so however many NOPs it inserts
into the alternative, might be deliberately *misaligning* it in the
code that actually gets executed.

Are you sure you're not running a kernel where the alternatives code
would turn that alternative which *starts* with a NOP, into *all* NOPs?

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