Re: [PATCH 5/8] x86/speculation: Change FILL_RETURN_BUFFER to work with objtool

From: Josh Poimboeuf
Date: Fri Apr 24 2020 - 15:05:02 EST


On Thu, Apr 23, 2020 at 02:47:22PM +0200, Peter Zijlstra wrote:
> #define __FILL_RETURN_BUFFER(reg, nr, sp) \
> mov $(nr/2), reg; \
> 771: \
> + ANNOTATE_INTRA_FUNCTION_CALL \
> call 772f; \
> 773: /* speculation trap */ \
> + UNWIND_HINT_EMPTY; \
> pause; \
> lfence; \
> jmp 773b; \
> 772: \
> + ANNOTATE_INTRA_FUNCTION_CALL \
> call 774f; \
> 775: /* speculation trap */ \
> + UNWIND_HINT_EMPTY; \
> pause; \
> lfence; \
> jmp 775b; \
> 774: \
> + add $(BITS_PER_LONG/8) * 2, sp; \
> dec reg; \
> - jnz 771b; \
> - add $(BITS_PER_LONG/8) * nr, sp;
> + jnz 771b;

Looks weird having semicolons for one annotation but not the other...

>
> #ifdef __ASSEMBLY__
>
> @@ -137,10 +143,8 @@
> */
> .macro FILL_RETURN_BUFFER reg:req nr:req ftr:req
> #ifdef CONFIG_RETPOLINE
> - ANNOTATE_NOSPEC_ALTERNATIVE
> - ALTERNATIVE "jmp .Lskip_rsb_\@", \
> - __stringify(__FILL_RETURN_BUFFER(\reg,\nr,%_ASM_SP)) \
> - \ftr
> + ALTERNATIVE "jmp .Lskip_rsb_\@", "", \ftr
> + __FILL_RETURN_BUFFER(\reg,\nr,%_ASM_SP)

I almost gave my "you can't change the stack in an alternative" lecture,
then I did a double take :-)

We do still need a patch to prevent other code from doing that though.

--
Josh