All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] static_call: Use single copy of static_call_return0
@ 2021-04-25 21:11 Andi Kleen
  2021-04-26  8:17 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Andi Kleen @ 2021-04-25 21:11 UTC (permalink / raw)
  To: peterz; +Cc: jpoimboe, jbaron, linux-kernel, Andi Kleen

With the inline version of static calls it is trying to use
all static call functions inline. But this doesn't work for
__static_call_return0, because its address is always taken,
which forces the compiler to generate a out of line copy.

If it only exists as a static inline this means there are
many copies generated. Instead use the out of line in static_call.c
for this.

This fixes another bug. When _INLINE is set static_inline.c was
not compiled at all, which disabled the self test even when
it was enabled in the configuration.

This fixes a build problem with gcc LTO. __static_call_return0
is referenced from assembler, which requires making it global
because the assembler can end in a different file than the other
C code.  But that's not possible for a static inline function.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 include/linux/static_call.h | 9 ++-------
 kernel/Makefile             | 2 +-
 kernel/static_call.c        | 4 ++++
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/include/linux/static_call.h b/include/linux/static_call.h
index ae04b1123a93..e75aef659224 100644
--- a/include/linux/static_call.h
+++ b/include/linux/static_call.h
@@ -100,6 +100,8 @@
 #ifdef CONFIG_HAVE_STATIC_CALL
 #include <asm/static_call.h>
 
+extern long __static_call_return0(void);
+
 /*
  * Either @site or @tramp can be NULL.
  */
@@ -148,8 +150,6 @@ extern void __static_call_update(struct static_call_key *key, void *tramp, void
 extern int static_call_mod_init(struct module *mod);
 extern int static_call_text_reserved(void *start, void *end);
 
-extern long __static_call_return0(void);
-
 #define __DEFINE_STATIC_CALL(name, _func, _func_init)			\
 	DECLARE_STATIC_CALL(name, _func);				\
 	__visible struct static_call_key STATIC_CALL_KEY(name) = {	\
@@ -221,11 +221,6 @@ static inline int static_call_text_reserved(void *start, void *end)
 	return 0;
 }
 
-static inline long __static_call_return0(void)
-{
-	return 0;
-}
-
 #define EXPORT_STATIC_CALL(name)					\
 	EXPORT_SYMBOL(STATIC_CALL_KEY(name));				\
 	EXPORT_SYMBOL(STATIC_CALL_TRAMP(name))
diff --git a/kernel/Makefile b/kernel/Makefile
index 320f1f3941b7..b589442c7724 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -110,7 +110,7 @@ obj-$(CONFIG_CPU_PM) += cpu_pm.o
 obj-$(CONFIG_BPF) += bpf/
 obj-$(CONFIG_KCSAN) += kcsan/
 obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o
-obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call.o
+obj-$(CONFIG_HAVE_STATIC_CALL) += static_call.o
 
 obj-$(CONFIG_PERF_EVENTS) += events/
 
diff --git a/kernel/static_call.c b/kernel/static_call.c
index 6d332c0c9134..7ec8608d94ab 100644
--- a/kernel/static_call.c
+++ b/kernel/static_call.c
@@ -10,6 +10,8 @@
 #include <linux/processor.h>
 #include <asm/sections.h>
 
+#ifdef CONFIG_HAVE_STATIC_CALL_INLINE
+
 extern struct static_call_site __start_static_call_sites[],
 			       __stop_static_call_sites[];
 extern struct static_call_tramp_key __start_static_call_tramp_key[],
@@ -496,6 +498,8 @@ int __init static_call_init(void)
 }
 early_initcall(static_call_init);
 
+#endif /* HAVE_STATIC_CALL_INLINE */
+
 long __static_call_return0(void)
 {
 	return 0;
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] static_call: Use single copy of static_call_return0
  2021-04-25 21:11 [PATCH] static_call: Use single copy of static_call_return0 Andi Kleen
@ 2021-04-26  8:17 ` Peter Zijlstra
  2021-04-26 14:47   ` Andi Kleen
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2021-04-26  8:17 UTC (permalink / raw)
  To: Andi Kleen; +Cc: jpoimboe, jbaron, linux-kernel

On Sun, Apr 25, 2021 at 02:11:40PM -0700, Andi Kleen wrote:
> With the inline version of static calls it is trying to use
> all static call functions inline. But this doesn't work for
> __static_call_return0, because its address is always taken,
> which forces the compiler to generate a out of line copy.
> 
> If it only exists as a static inline this means there are
> many copies generated. Instead use the out of line in static_call.c
> for this.
> 
> This fixes another bug. When _INLINE is set static_inline.c was
> not compiled at all, which disabled the self test even when
> it was enabled in the configuration.
> 
> This fixes a build problem with gcc LTO. __static_call_return0
> is referenced from assembler, which requires making it global
> because the assembler can end in a different file than the other
> C code.  But that's not possible for a static inline function.

This is ARCH=i386 only afaict, why do we care?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] static_call: Use single copy of static_call_return0
  2021-04-26  8:17 ` Peter Zijlstra
@ 2021-04-26 14:47   ` Andi Kleen
  0 siblings, 0 replies; 3+ messages in thread
From: Andi Kleen @ 2021-04-26 14:47 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: jpoimboe, jbaron, linux-kernel

> This is ARCH=i386 only afaict, why do we care?

Well I'm trying to make LTO build even for 32bit.

Besides the bug with self test is real everywhere.

But looks like the patch didn't apply (I had some earlier
patches which were apparently needed). I'll rebase and repost.

-Andi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-26 14:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-25 21:11 [PATCH] static_call: Use single copy of static_call_return0 Andi Kleen
2021-04-26  8:17 ` Peter Zijlstra
2021-04-26 14:47   ` Andi Kleen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.