All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libbpf: ensure functions with always_inline attribute are inline
@ 2022-08-02 23:27 James Hilliard
  2022-08-03  8:19 ` Jiri Olsa
  0 siblings, 1 reply; 3+ messages in thread
From: James Hilliard @ 2022-08-02 23:27 UTC (permalink / raw)
  To: bpf
  Cc: James Hilliard, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	linux-kernel

GCC expects the always_inline attribute to only be set on inline
functions, as such we should make all functions with this attribute
inline.

Fixes errors like:
/home/buildroot/bpf-next/tools/testing/selftests/bpf/tools/include/bpf/bpf_tracing.h:439:1: error: ‘always_inline’ function might not be inlinable [-Werror=attributes]
  439 | ____##name(unsigned long long *ctx, ##args)
      | ^~~~

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 tools/lib/bpf/bpf_tracing.h | 14 +++++++-------
 tools/lib/bpf/usdt.bpf.h    |  4 ++--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
index 43ca3aff2292..ae67fcee912c 100644
--- a/tools/lib/bpf/bpf_tracing.h
+++ b/tools/lib/bpf/bpf_tracing.h
@@ -426,7 +426,7 @@ struct pt_regs;
  */
 #define BPF_PROG(name, args...)						    \
 name(unsigned long long *ctx);						    \
-static __attribute__((always_inline)) typeof(name(0))			    \
+static inline __attribute__((always_inline)) typeof(name(0))		    \
 ____##name(unsigned long long *ctx, ##args);				    \
 typeof(name(0)) name(unsigned long long *ctx)				    \
 {									    \
@@ -435,7 +435,7 @@ typeof(name(0)) name(unsigned long long *ctx)				    \
 	return ____##name(___bpf_ctx_cast(args));			    \
 	_Pragma("GCC diagnostic pop")					    \
 }									    \
-static __attribute__((always_inline)) typeof(name(0))			    \
+static inline __attribute__((always_inline)) typeof(name(0))		    \
 ____##name(unsigned long long *ctx, ##args)
 
 struct pt_regs;
@@ -460,7 +460,7 @@ struct pt_regs;
  */
 #define BPF_KPROBE(name, args...)					    \
 name(struct pt_regs *ctx);						    \
-static __attribute__((always_inline)) typeof(name(0))			    \
+static inline __attribute__((always_inline)) typeof(name(0))		    \
 ____##name(struct pt_regs *ctx, ##args);				    \
 typeof(name(0)) name(struct pt_regs *ctx)				    \
 {									    \
@@ -469,7 +469,7 @@ typeof(name(0)) name(struct pt_regs *ctx)				    \
 	return ____##name(___bpf_kprobe_args(args));			    \
 	_Pragma("GCC diagnostic pop")					    \
 }									    \
-static __attribute__((always_inline)) typeof(name(0))			    \
+static inline __attribute__((always_inline)) typeof(name(0))		    \
 ____##name(struct pt_regs *ctx, ##args)
 
 #define ___bpf_kretprobe_args0()       ctx
@@ -484,7 +484,7 @@ ____##name(struct pt_regs *ctx, ##args)
  */
 #define BPF_KRETPROBE(name, args...)					    \
 name(struct pt_regs *ctx);						    \
-static __attribute__((always_inline)) typeof(name(0))			    \
+static inline __attribute__((always_inline)) typeof(name(0))		    \
 ____##name(struct pt_regs *ctx, ##args);				    \
 typeof(name(0)) name(struct pt_regs *ctx)				    \
 {									    \
@@ -540,7 +540,7 @@ static __always_inline typeof(name(0)) ____##name(struct pt_regs *ctx, ##args)
 #define BPF_KSYSCALL(name, args...)					    \
 name(struct pt_regs *ctx);						    \
 extern _Bool LINUX_HAS_SYSCALL_WRAPPER __kconfig;			    \
-static __attribute__((always_inline)) typeof(name(0))			    \
+static inline __attribute__((always_inline)) typeof(name(0))		    \
 ____##name(struct pt_regs *ctx, ##args);				    \
 typeof(name(0)) name(struct pt_regs *ctx)				    \
 {									    \
@@ -555,7 +555,7 @@ typeof(name(0)) name(struct pt_regs *ctx)				    \
 		return ____##name(___bpf_syscall_args(args));		    \
 	_Pragma("GCC diagnostic pop")					    \
 }									    \
-static __attribute__((always_inline)) typeof(name(0))			    \
+static inline __attribute__((always_inline)) typeof(name(0))		    \
 ____##name(struct pt_regs *ctx, ##args)
 
 #define BPF_KPROBE_SYSCALL BPF_KSYSCALL
diff --git a/tools/lib/bpf/usdt.bpf.h b/tools/lib/bpf/usdt.bpf.h
index 4f2adc0bd6ca..2bd2d80b3751 100644
--- a/tools/lib/bpf/usdt.bpf.h
+++ b/tools/lib/bpf/usdt.bpf.h
@@ -232,7 +232,7 @@ long bpf_usdt_cookie(struct pt_regs *ctx)
  */
 #define BPF_USDT(name, args...)						    \
 name(struct pt_regs *ctx);						    \
-static __attribute__((always_inline)) typeof(name(0))			    \
+static inline __attribute__((always_inline)) typeof(name(0))		    \
 ____##name(struct pt_regs *ctx, ##args);				    \
 typeof(name(0)) name(struct pt_regs *ctx)				    \
 {									    \
@@ -241,7 +241,7 @@ typeof(name(0)) name(struct pt_regs *ctx)				    \
         return ____##name(___bpf_usdt_args(args));			    \
         _Pragma("GCC diagnostic pop")					    \
 }									    \
-static __attribute__((always_inline)) typeof(name(0))			    \
+static inline __attribute__((always_inline)) typeof(name(0))		    \
 ____##name(struct pt_regs *ctx, ##args)
 
 #endif /* __USDT_BPF_H__ */
-- 
2.34.1


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

* Re: [PATCH] libbpf: ensure functions with always_inline attribute are inline
  2022-08-02 23:27 [PATCH] libbpf: ensure functions with always_inline attribute are inline James Hilliard
@ 2022-08-03  8:19 ` Jiri Olsa
  2022-08-03 15:17   ` James Hilliard
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2022-08-03  8:19 UTC (permalink / raw)
  To: James Hilliard
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, linux-kernel

On Tue, Aug 02, 2022 at 05:27:41PM -0600, James Hilliard wrote:
> GCC expects the always_inline attribute to only be set on inline
> functions, as such we should make all functions with this attribute
> inline.
> 
> Fixes errors like:
> /home/buildroot/bpf-next/tools/testing/selftests/bpf/tools/include/bpf/bpf_tracing.h:439:1: error: ‘always_inline’ function might not be inlinable [-Werror=attributes]
>   439 | ____##name(unsigned long long *ctx, ##args)
>       | ^~~~
> 
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
>  tools/lib/bpf/bpf_tracing.h | 14 +++++++-------
>  tools/lib/bpf/usdt.bpf.h    |  4 ++--
>  2 files changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
> index 43ca3aff2292..ae67fcee912c 100644
> --- a/tools/lib/bpf/bpf_tracing.h
> +++ b/tools/lib/bpf/bpf_tracing.h
> @@ -426,7 +426,7 @@ struct pt_regs;
>   */
>  #define BPF_PROG(name, args...)						    \
>  name(unsigned long long *ctx);						    \
> -static __attribute__((always_inline)) typeof(name(0))			    \
> +static inline __attribute__((always_inline)) typeof(name(0))		    \

could you use __always_inline that does exactly that?

jirka

>  ____##name(unsigned long long *ctx, ##args);				    \
>  typeof(name(0)) name(unsigned long long *ctx)				    \
>  {									    \
> @@ -435,7 +435,7 @@ typeof(name(0)) name(unsigned long long *ctx)				    \
>  	return ____##name(___bpf_ctx_cast(args));			    \
>  	_Pragma("GCC diagnostic pop")					    \
>  }									    \
> -static __attribute__((always_inline)) typeof(name(0))			    \
> +static inline __attribute__((always_inline)) typeof(name(0))		    \
>  ____##name(unsigned long long *ctx, ##args)
>  
>  struct pt_regs;
> @@ -460,7 +460,7 @@ struct pt_regs;
>   */
>  #define BPF_KPROBE(name, args...)					    \
>  name(struct pt_regs *ctx);						    \
> -static __attribute__((always_inline)) typeof(name(0))			    \
> +static inline __attribute__((always_inline)) typeof(name(0))		    \
>  ____##name(struct pt_regs *ctx, ##args);				    \
>  typeof(name(0)) name(struct pt_regs *ctx)				    \
>  {									    \
> @@ -469,7 +469,7 @@ typeof(name(0)) name(struct pt_regs *ctx)				    \
>  	return ____##name(___bpf_kprobe_args(args));			    \
>  	_Pragma("GCC diagnostic pop")					    \
>  }									    \
> -static __attribute__((always_inline)) typeof(name(0))			    \
> +static inline __attribute__((always_inline)) typeof(name(0))		    \
>  ____##name(struct pt_regs *ctx, ##args)
>  
>  #define ___bpf_kretprobe_args0()       ctx
> @@ -484,7 +484,7 @@ ____##name(struct pt_regs *ctx, ##args)
>   */
>  #define BPF_KRETPROBE(name, args...)					    \
>  name(struct pt_regs *ctx);						    \
> -static __attribute__((always_inline)) typeof(name(0))			    \
> +static inline __attribute__((always_inline)) typeof(name(0))		    \
>  ____##name(struct pt_regs *ctx, ##args);				    \
>  typeof(name(0)) name(struct pt_regs *ctx)				    \
>  {									    \
> @@ -540,7 +540,7 @@ static __always_inline typeof(name(0)) ____##name(struct pt_regs *ctx, ##args)
>  #define BPF_KSYSCALL(name, args...)					    \
>  name(struct pt_regs *ctx);						    \
>  extern _Bool LINUX_HAS_SYSCALL_WRAPPER __kconfig;			    \
> -static __attribute__((always_inline)) typeof(name(0))			    \
> +static inline __attribute__((always_inline)) typeof(name(0))		    \
>  ____##name(struct pt_regs *ctx, ##args);				    \
>  typeof(name(0)) name(struct pt_regs *ctx)				    \
>  {									    \
> @@ -555,7 +555,7 @@ typeof(name(0)) name(struct pt_regs *ctx)				    \
>  		return ____##name(___bpf_syscall_args(args));		    \
>  	_Pragma("GCC diagnostic pop")					    \
>  }									    \
> -static __attribute__((always_inline)) typeof(name(0))			    \
> +static inline __attribute__((always_inline)) typeof(name(0))		    \
>  ____##name(struct pt_regs *ctx, ##args)
>  
>  #define BPF_KPROBE_SYSCALL BPF_KSYSCALL
> diff --git a/tools/lib/bpf/usdt.bpf.h b/tools/lib/bpf/usdt.bpf.h
> index 4f2adc0bd6ca..2bd2d80b3751 100644
> --- a/tools/lib/bpf/usdt.bpf.h
> +++ b/tools/lib/bpf/usdt.bpf.h
> @@ -232,7 +232,7 @@ long bpf_usdt_cookie(struct pt_regs *ctx)
>   */
>  #define BPF_USDT(name, args...)						    \
>  name(struct pt_regs *ctx);						    \
> -static __attribute__((always_inline)) typeof(name(0))			    \
> +static inline __attribute__((always_inline)) typeof(name(0))		    \
>  ____##name(struct pt_regs *ctx, ##args);				    \
>  typeof(name(0)) name(struct pt_regs *ctx)				    \
>  {									    \
> @@ -241,7 +241,7 @@ typeof(name(0)) name(struct pt_regs *ctx)				    \
>          return ____##name(___bpf_usdt_args(args));			    \
>          _Pragma("GCC diagnostic pop")					    \
>  }									    \
> -static __attribute__((always_inline)) typeof(name(0))			    \
> +static inline __attribute__((always_inline)) typeof(name(0))		    \
>  ____##name(struct pt_regs *ctx, ##args)
>  
>  #endif /* __USDT_BPF_H__ */
> -- 
> 2.34.1
> 

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

* Re: [PATCH] libbpf: ensure functions with always_inline attribute are inline
  2022-08-03  8:19 ` Jiri Olsa
@ 2022-08-03 15:17   ` James Hilliard
  0 siblings, 0 replies; 3+ messages in thread
From: James Hilliard @ 2022-08-03 15:17 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, linux-kernel

On Wed, Aug 3, 2022 at 2:19 AM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> On Tue, Aug 02, 2022 at 05:27:41PM -0600, James Hilliard wrote:
> > GCC expects the always_inline attribute to only be set on inline
> > functions, as such we should make all functions with this attribute
> > inline.
> >
> > Fixes errors like:
> > /home/buildroot/bpf-next/tools/testing/selftests/bpf/tools/include/bpf/bpf_tracing.h:439:1: error: ‘always_inline’ function might not be inlinable [-Werror=attributes]
> >   439 | ____##name(unsigned long long *ctx, ##args)
> >       | ^~~~
> >
> > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > ---
> >  tools/lib/bpf/bpf_tracing.h | 14 +++++++-------
> >  tools/lib/bpf/usdt.bpf.h    |  4 ++--
> >  2 files changed, 9 insertions(+), 9 deletions(-)
> >
> > diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
> > index 43ca3aff2292..ae67fcee912c 100644
> > --- a/tools/lib/bpf/bpf_tracing.h
> > +++ b/tools/lib/bpf/bpf_tracing.h
> > @@ -426,7 +426,7 @@ struct pt_regs;
> >   */
> >  #define BPF_PROG(name, args...)                                                  \
> >  name(unsigned long long *ctx);                                                   \
> > -static __attribute__((always_inline)) typeof(name(0))                            \
> > +static inline __attribute__((always_inline)) typeof(name(0))             \
>
> could you use __always_inline that does exactly that?

Sure, changed to use the __always_inline macro in v2:
https://lore.kernel.org/bpf/20220803151403.793024-1-james.hilliard1@gmail.com/

>
> jirka
>
> >  ____##name(unsigned long long *ctx, ##args);                             \
> >  typeof(name(0)) name(unsigned long long *ctx)                                    \
> >  {                                                                        \
> > @@ -435,7 +435,7 @@ typeof(name(0)) name(unsigned long long *ctx)                                 \
> >       return ____##name(___bpf_ctx_cast(args));                           \
> >       _Pragma("GCC diagnostic pop")                                       \
> >  }                                                                        \
> > -static __attribute__((always_inline)) typeof(name(0))                            \
> > +static inline __attribute__((always_inline)) typeof(name(0))             \
> >  ____##name(unsigned long long *ctx, ##args)
> >
> >  struct pt_regs;
> > @@ -460,7 +460,7 @@ struct pt_regs;
> >   */
> >  #define BPF_KPROBE(name, args...)                                        \
> >  name(struct pt_regs *ctx);                                               \
> > -static __attribute__((always_inline)) typeof(name(0))                            \
> > +static inline __attribute__((always_inline)) typeof(name(0))             \
> >  ____##name(struct pt_regs *ctx, ##args);                                 \
> >  typeof(name(0)) name(struct pt_regs *ctx)                                \
> >  {                                                                        \
> > @@ -469,7 +469,7 @@ typeof(name(0)) name(struct pt_regs *ctx)                             \
> >       return ____##name(___bpf_kprobe_args(args));                        \
> >       _Pragma("GCC diagnostic pop")                                       \
> >  }                                                                        \
> > -static __attribute__((always_inline)) typeof(name(0))                            \
> > +static inline __attribute__((always_inline)) typeof(name(0))             \
> >  ____##name(struct pt_regs *ctx, ##args)
> >
> >  #define ___bpf_kretprobe_args0()       ctx
> > @@ -484,7 +484,7 @@ ____##name(struct pt_regs *ctx, ##args)
> >   */
> >  #define BPF_KRETPROBE(name, args...)                                     \
> >  name(struct pt_regs *ctx);                                               \
> > -static __attribute__((always_inline)) typeof(name(0))                            \
> > +static inline __attribute__((always_inline)) typeof(name(0))             \
> >  ____##name(struct pt_regs *ctx, ##args);                                 \
> >  typeof(name(0)) name(struct pt_regs *ctx)                                \
> >  {                                                                        \
> > @@ -540,7 +540,7 @@ static __always_inline typeof(name(0)) ____##name(struct pt_regs *ctx, ##args)
> >  #define BPF_KSYSCALL(name, args...)                                      \
> >  name(struct pt_regs *ctx);                                               \
> >  extern _Bool LINUX_HAS_SYSCALL_WRAPPER __kconfig;                        \
> > -static __attribute__((always_inline)) typeof(name(0))                            \
> > +static inline __attribute__((always_inline)) typeof(name(0))             \
> >  ____##name(struct pt_regs *ctx, ##args);                                 \
> >  typeof(name(0)) name(struct pt_regs *ctx)                                \
> >  {                                                                        \
> > @@ -555,7 +555,7 @@ typeof(name(0)) name(struct pt_regs *ctx)                             \
> >               return ____##name(___bpf_syscall_args(args));               \
> >       _Pragma("GCC diagnostic pop")                                       \
> >  }                                                                        \
> > -static __attribute__((always_inline)) typeof(name(0))                            \
> > +static inline __attribute__((always_inline)) typeof(name(0))             \
> >  ____##name(struct pt_regs *ctx, ##args)
> >
> >  #define BPF_KPROBE_SYSCALL BPF_KSYSCALL
> > diff --git a/tools/lib/bpf/usdt.bpf.h b/tools/lib/bpf/usdt.bpf.h
> > index 4f2adc0bd6ca..2bd2d80b3751 100644
> > --- a/tools/lib/bpf/usdt.bpf.h
> > +++ b/tools/lib/bpf/usdt.bpf.h
> > @@ -232,7 +232,7 @@ long bpf_usdt_cookie(struct pt_regs *ctx)
> >   */
> >  #define BPF_USDT(name, args...)                                                  \
> >  name(struct pt_regs *ctx);                                               \
> > -static __attribute__((always_inline)) typeof(name(0))                            \
> > +static inline __attribute__((always_inline)) typeof(name(0))             \
> >  ____##name(struct pt_regs *ctx, ##args);                                 \
> >  typeof(name(0)) name(struct pt_regs *ctx)                                \
> >  {                                                                        \
> > @@ -241,7 +241,7 @@ typeof(name(0)) name(struct pt_regs *ctx)                             \
> >          return ____##name(___bpf_usdt_args(args));                       \
> >          _Pragma("GCC diagnostic pop")                                            \
> >  }                                                                        \
> > -static __attribute__((always_inline)) typeof(name(0))                            \
> > +static inline __attribute__((always_inline)) typeof(name(0))             \
> >  ____##name(struct pt_regs *ctx, ##args)
> >
> >  #endif /* __USDT_BPF_H__ */
> > --
> > 2.34.1
> >

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

end of thread, other threads:[~2022-08-03 15:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-02 23:27 [PATCH] libbpf: ensure functions with always_inline attribute are inline James Hilliard
2022-08-03  8:19 ` Jiri Olsa
2022-08-03 15:17   ` James Hilliard

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.