Skip to content

Commit 5517d50

Browse files
chleroyPeter Zijlstra
authored andcommitted
static_call: Properly initialise DEFINE_STATIC_CALL_RET0()
When a static call is updated with __static_call_return0() as target, arch_static_call_transform() set it to use an optimised set of instructions which are meant to lay in the same cacheline. But when initialising a static call with DEFINE_STATIC_CALL_RET0(), we get a branch to the real __static_call_return0() function instead of getting the optimised setup: c00d8120 <__SCT__perf_snapshot_branch_stack>: c00d8120: 4b ff ff f4 b c00d8114 <__static_call_return0> c00d8124: 3d 80 c0 0e lis r12,-16370 c00d8128: 81 8c 81 3c lwz r12,-32452(r12) c00d812c: 7d 89 03 a6 mtctr r12 c00d8130: 4e 80 04 20 bctr c00d8134: 38 60 00 00 li r3,0 c00d8138: 4e 80 00 20 blr c00d813c: 00 00 00 00 .long 0x0 Add ARCH_DEFINE_STATIC_CALL_RET0_TRAMP() defined by each architecture to setup the optimised configuration, and rework DEFINE_STATIC_CALL_RET0() to call it: c00d8120 <__SCT__perf_snapshot_branch_stack>: c00d8120: 48 00 00 14 b c00d8134 <__SCT__perf_snapshot_branch_stack+0x14> c00d8124: 3d 80 c0 0e lis r12,-16370 c00d8128: 81 8c 81 3c lwz r12,-32452(r12) c00d812c: 7d 89 03 a6 mtctr r12 c00d8130: 4e 80 04 20 bctr c00d8134: 38 60 00 00 li r3,0 c00d8138: 4e 80 00 20 blr c00d813c: 00 00 00 00 .long 0x0 Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/1e0a61a88f52a460f62a58ffc2a5f847d1f7d9d8.1647253456.git.christophe.leroy@csgroup.eu
1 parent 8fd4ddd commit 5517d50

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

arch/powerpc/include/asm/static_call.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424

2525
#define ARCH_DEFINE_STATIC_CALL_TRAMP(name, func) __PPC_SCT(name, "b " #func)
2626
#define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) __PPC_SCT(name, "blr")
27+
#define ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name) __PPC_SCT(name, "b .+20")
2728

2829
#endif /* _ASM_POWERPC_STATIC_CALL_H */

arch/x86/include/asm/static_call.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) \
3939
__ARCH_DEFINE_STATIC_CALL_TRAMP(name, "ret; int3; nop; nop; nop")
4040

41+
#define ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name) \
42+
ARCH_DEFINE_STATIC_CALL_TRAMP(name, __static_call_return0)
4143

4244
#define ARCH_ADD_TRAMP_KEY(name) \
4345
asm(".pushsection .static_call_tramp_key, \"a\" \n" \

include/linux/static_call.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ extern long __static_call_return0(void);
196196
}; \
197197
ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name)
198198

199+
#define DEFINE_STATIC_CALL_RET0(name, _func) \
200+
DECLARE_STATIC_CALL(name, _func); \
201+
struct static_call_key STATIC_CALL_KEY(name) = { \
202+
.func = __static_call_return0, \
203+
.type = 1, \
204+
}; \
205+
ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name)
206+
199207
#define static_call_cond(name) (void)__static_call(name)
200208

201209
#define EXPORT_STATIC_CALL(name) \
@@ -231,6 +239,12 @@ static inline int static_call_init(void) { return 0; }
231239
}; \
232240
ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name)
233241

242+
#define DEFINE_STATIC_CALL_RET0(name, _func) \
243+
DECLARE_STATIC_CALL(name, _func); \
244+
struct static_call_key STATIC_CALL_KEY(name) = { \
245+
.func = __static_call_return0, \
246+
}; \
247+
ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name)
234248

235249
#define static_call_cond(name) (void)__static_call(name)
236250

@@ -284,6 +298,9 @@ static inline long __static_call_return0(void)
284298
.func = NULL, \
285299
}
286300

301+
#define DEFINE_STATIC_CALL_RET0(name, _func) \
302+
__DEFINE_STATIC_CALL(name, _func, __static_call_return0)
303+
287304
static inline void __static_call_nop(void) { }
288305

289306
/*
@@ -327,7 +344,4 @@ static inline int static_call_text_reserved(void *start, void *end)
327344
#define DEFINE_STATIC_CALL(name, _func) \
328345
__DEFINE_STATIC_CALL(name, _func, _func)
329346

330-
#define DEFINE_STATIC_CALL_RET0(name, _func) \
331-
__DEFINE_STATIC_CALL(name, _func, __static_call_return0)
332-
333347
#endif /* _LINUX_STATIC_CALL_H */

0 commit comments

Comments
 (0)