Skip to content

Commit 089dd8e

Browse files
author
Peter Zijlstra
committed
x86/speculation: Change FILL_RETURN_BUFFER to work with objtool
Change FILL_RETURN_BUFFER so that objtool groks it and can generate correct ORC unwind information. - Since ORC is alternative invariant; that is, all alternatives should have the same ORC entries, the __FILL_RETURN_BUFFER body can not be part of an alternative. Therefore, move it out of the alternative and keep the alternative as a sort of jump_label around it. - Use the ANNOTATE_INTRA_FUNCTION_CALL annotation to white-list these 'funny' call instructions to nowhere. - Use UNWIND_HINT_EMPTY to 'fill' the speculation traps, otherwise objtool will consider them unreachable. - Move the RSP adjustment into the loop, such that the loop has a deterministic stack layout. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Alexandre Chartre <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 8aa8eb2 commit 089dd8e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

arch/x86/include/asm/nospec-branch.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
#define _ASM_X86_NOSPEC_BRANCH_H_
55

66
#include <linux/static_key.h>
7+
#include <linux/frame.h>
78

89
#include <asm/alternative.h>
910
#include <asm/alternative-asm.h>
1011
#include <asm/cpufeatures.h>
1112
#include <asm/msr-index.h>
13+
#include <asm/unwind_hints.h>
1214

1315
/*
1416
* This should be used immediately before a retpoline alternative. It tells
@@ -46,21 +48,25 @@
4648
#define __FILL_RETURN_BUFFER(reg, nr, sp) \
4749
mov $(nr/2), reg; \
4850
771: \
51+
ANNOTATE_INTRA_FUNCTION_CALL; \
4952
call 772f; \
5053
773: /* speculation trap */ \
54+
UNWIND_HINT_EMPTY; \
5155
pause; \
5256
lfence; \
5357
jmp 773b; \
5458
772: \
59+
ANNOTATE_INTRA_FUNCTION_CALL; \
5560
call 774f; \
5661
775: /* speculation trap */ \
62+
UNWIND_HINT_EMPTY; \
5763
pause; \
5864
lfence; \
5965
jmp 775b; \
6066
774: \
67+
add $(BITS_PER_LONG/8) * 2, sp; \
6168
dec reg; \
62-
jnz 771b; \
63-
add $(BITS_PER_LONG/8) * nr, sp;
69+
jnz 771b;
6470

6571
#ifdef __ASSEMBLY__
6672

@@ -137,10 +143,8 @@
137143
*/
138144
.macro FILL_RETURN_BUFFER reg:req nr:req ftr:req
139145
#ifdef CONFIG_RETPOLINE
140-
ANNOTATE_NOSPEC_ALTERNATIVE
141-
ALTERNATIVE "jmp .Lskip_rsb_\@", \
142-
__stringify(__FILL_RETURN_BUFFER(\reg,\nr,%_ASM_SP)) \
143-
\ftr
146+
ALTERNATIVE "jmp .Lskip_rsb_\@", "", \ftr
147+
__FILL_RETURN_BUFFER(\reg,\nr,%_ASM_SP)
144148
.Lskip_rsb_\@:
145149
#endif
146150
.endm

0 commit comments

Comments
 (0)