Skip to content

Commit 2adeed9

Browse files
ubizjakIngo Molnar
authored andcommitted
x86/callthunks: Fix and unify call thunks assembly snippets
Currently thunk debug macros explicitly define %gs: segment register prefix for their percpu variables. This is not compatible with !CONFIG_SMP, which requires non-prefixed percpu variables. Fix call thunks debug macros to use PER_CPU_VAR macro from percpu.h to conditionally use %gs: segment register prefix, depending on CONFIG_SMP. Finally, unify ASM_ prefixed assembly macros with their non-prefixed variants. With support of %rip-relative relocations in place, call thunk templates allow %rip-relative addressing, so unified assembly snippet can be used everywhere. Signed-off-by: Uros Bizjak <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 17bce3b commit 2adeed9

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959

6060
#ifdef CONFIG_CALL_THUNKS_DEBUG
6161
# define CALL_THUNKS_DEBUG_INC_CALLS \
62-
incq %gs:__x86_call_count;
62+
incq PER_CPU_VAR(__x86_call_count);
6363
# define CALL_THUNKS_DEBUG_INC_RETS \
64-
incq %gs:__x86_ret_count;
64+
incq PER_CPU_VAR(__x86_ret_count);
6565
# define CALL_THUNKS_DEBUG_INC_STUFFS \
66-
incq %gs:__x86_stuffs_count;
66+
incq PER_CPU_VAR(__x86_stuffs_count);
6767
# define CALL_THUNKS_DEBUG_INC_CTXSW \
68-
incq %gs:__x86_ctxsw_count;
68+
incq PER_CPU_VAR(__x86_ctxsw_count);
6969
#else
7070
# define CALL_THUNKS_DEBUG_INC_CALLS
7171
# define CALL_THUNKS_DEBUG_INC_RETS
@@ -80,9 +80,6 @@
8080
#define CREDIT_CALL_DEPTH \
8181
movq $-1, PER_CPU_VAR(pcpu_hot + X86_call_depth);
8282

83-
#define ASM_CREDIT_CALL_DEPTH \
84-
movq $-1, PER_CPU_VAR(pcpu_hot + X86_call_depth);
85-
8683
#define RESET_CALL_DEPTH \
8784
xor %eax, %eax; \
8885
bts $63, %rax; \
@@ -95,20 +92,14 @@
9592
CALL_THUNKS_DEBUG_INC_CALLS
9693

9794
#define INCREMENT_CALL_DEPTH \
98-
sarq $5, %gs:pcpu_hot + X86_call_depth; \
99-
CALL_THUNKS_DEBUG_INC_CALLS
100-
101-
#define ASM_INCREMENT_CALL_DEPTH \
10295
sarq $5, PER_CPU_VAR(pcpu_hot + X86_call_depth); \
10396
CALL_THUNKS_DEBUG_INC_CALLS
10497

10598
#else
10699
#define CREDIT_CALL_DEPTH
107-
#define ASM_CREDIT_CALL_DEPTH
108100
#define RESET_CALL_DEPTH
109-
#define INCREMENT_CALL_DEPTH
110-
#define ASM_INCREMENT_CALL_DEPTH
111101
#define RESET_CALL_DEPTH_FROM_CALL
102+
#define INCREMENT_CALL_DEPTH
112103
#endif
113104

114105
/*
@@ -158,7 +149,7 @@
158149
jnz 771b; \
159150
/* barrier for jnz misprediction */ \
160151
lfence; \
161-
ASM_CREDIT_CALL_DEPTH \
152+
CREDIT_CALL_DEPTH \
162153
CALL_THUNKS_DEBUG_INC_CTXSW
163154
#else
164155
/*
@@ -325,7 +316,7 @@
325316
.macro CALL_DEPTH_ACCOUNT
326317
#ifdef CONFIG_CALL_DEPTH_TRACKING
327318
ALTERNATIVE "", \
328-
__stringify(ASM_INCREMENT_CALL_DEPTH), X86_FEATURE_CALL_DEPTH
319+
__stringify(INCREMENT_CALL_DEPTH), X86_FEATURE_CALL_DEPTH
329320
#endif
330321
.endm
331322

0 commit comments

Comments
 (0)