bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] samples/bpf: Add a workaround for asm_inline
@ 2019-10-02 19:16 KP Singh
  2019-10-02 20:22 ` Andrii Nakryiko
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: KP Singh @ 2019-10-02 19:16 UTC (permalink / raw)
  To: linux-kernel, bpf
  Cc: Florent Revest, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Florent Revest,
	Rasmus Villemoes, Arnaldo Carvalho de Melo

From: KP Singh <kpsingh@google.com>

This was added in:

  commit eb111869301e ("compiler-types.h: add asm_inline definition")

and breaks samples/bpf as clang does not support asm __inline.

Co-developed-by: Florent Revest <revest@google.com>
Signed-off-by: Florent Revest <revest@google.com>
Signed-off-by: KP Singh <kpsingh@google.com>
---

Changes since v1:

- Dropped the rename from asm_workaround.h to asm_goto_workaround.h
- Dropped the fix for task_fd_query_user.c as it is updated in
  https://lore.kernel.org/bpf/20191001112249.27341-1-bjorn.topel@gmail.com/

 samples/bpf/asm_goto_workaround.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/samples/bpf/asm_goto_workaround.h b/samples/bpf/asm_goto_workaround.h
index 7409722727ca..7048bb3594d6 100644
--- a/samples/bpf/asm_goto_workaround.h
+++ b/samples/bpf/asm_goto_workaround.h
@@ -3,7 +3,8 @@
 #ifndef __ASM_GOTO_WORKAROUND_H
 #define __ASM_GOTO_WORKAROUND_H
 
-/* this will bring in asm_volatile_goto macro definition
+/*
+ * This will bring in asm_volatile_goto and asm_inline macro definitions
  * if enabled by compiler and config options.
  */
 #include <linux/types.h>
@@ -13,5 +14,15 @@
 #define asm_volatile_goto(x...) asm volatile("invalid use of asm_volatile_goto")
 #endif
 
+/*
+ * asm_inline is defined as asm __inline in "include/linux/compiler_types.h"
+ * if supported by the kernel's CC (i.e CONFIG_CC_HAS_ASM_INLINE) which is not
+ * supported by CLANG.
+ */
+#ifdef asm_inline
+#undef asm_inline
+#define asm_inline asm
+#endif
+
 #define volatile(x...) volatile("")
 #endif
-- 
2.20.1


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

* Re: [PATCH v2] samples/bpf: Add a workaround for asm_inline
  2019-10-02 19:16 [PATCH v2] samples/bpf: Add a workaround for asm_inline KP Singh
@ 2019-10-02 20:22 ` Andrii Nakryiko
  2019-10-02 21:05   ` Song Liu
  2019-10-02 20:52 ` Song Liu
  2019-10-03 15:40 ` Daniel Borkmann
  2 siblings, 1 reply; 6+ messages in thread
From: Andrii Nakryiko @ 2019-10-02 20:22 UTC (permalink / raw)
  To: KP Singh
  Cc: open list, bpf, Florent Revest, Alexei Starovoitov,
	Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	Florent Revest, Rasmus Villemoes, Arnaldo Carvalho de Melo

On Wed, Oct 2, 2019 at 12:17 PM KP Singh <kpsingh@chromium.org> wrote:
>
> From: KP Singh <kpsingh@google.com>
>
> This was added in:
>
>   commit eb111869301e ("compiler-types.h: add asm_inline definition")
>
> and breaks samples/bpf as clang does not support asm __inline.
>
> Co-developed-by: Florent Revest <revest@google.com>
> Signed-off-by: Florent Revest <revest@google.com>
> Signed-off-by: KP Singh <kpsingh@google.com>
> ---
>
> Changes since v1:
>
> - Dropped the rename from asm_workaround.h to asm_goto_workaround.h
> - Dropped the fix for task_fd_query_user.c as it is updated in
>   https://lore.kernel.org/bpf/20191001112249.27341-1-bjorn.topel@gmail.com/
>
>  samples/bpf/asm_goto_workaround.h | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/samples/bpf/asm_goto_workaround.h b/samples/bpf/asm_goto_workaround.h
> index 7409722727ca..7048bb3594d6 100644
> --- a/samples/bpf/asm_goto_workaround.h
> +++ b/samples/bpf/asm_goto_workaround.h
> @@ -3,7 +3,8 @@
>  #ifndef __ASM_GOTO_WORKAROUND_H
>  #define __ASM_GOTO_WORKAROUND_H
>
> -/* this will bring in asm_volatile_goto macro definition
> +/*
> + * This will bring in asm_volatile_goto and asm_inline macro definitions
>   * if enabled by compiler and config options.
>   */
>  #include <linux/types.h>
> @@ -13,5 +14,15 @@
>  #define asm_volatile_goto(x...) asm volatile("invalid use of asm_volatile_goto")
>  #endif
>
> +/*
> + * asm_inline is defined as asm __inline in "include/linux/compiler_types.h"
> + * if supported by the kernel's CC (i.e CONFIG_CC_HAS_ASM_INLINE) which is not
> + * supported by CLANG.
> + */
> +#ifdef asm_inline
> +#undef asm_inline
> +#define asm_inline asm
> +#endif

Would it be better to just #undef CONFIG_CC_HAS_ASM_INLINE for BPF programs?

> +
>  #define volatile(x...) volatile("")
>  #endif
> --
> 2.20.1
>

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

* Re: [PATCH v2] samples/bpf: Add a workaround for asm_inline
  2019-10-02 19:16 [PATCH v2] samples/bpf: Add a workaround for asm_inline KP Singh
  2019-10-02 20:22 ` Andrii Nakryiko
@ 2019-10-02 20:52 ` Song Liu
  2019-10-03 15:40 ` Daniel Borkmann
  2 siblings, 0 replies; 6+ messages in thread
From: Song Liu @ 2019-10-02 20:52 UTC (permalink / raw)
  To: KP Singh
  Cc: open list, bpf, Florent Revest, Alexei Starovoitov,
	Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	Florent Revest, Rasmus Villemoes, Arnaldo Carvalho de Melo

On Wed, Oct 2, 2019 at 12:17 PM KP Singh <kpsingh@chromium.org> wrote:
>
> From: KP Singh <kpsingh@google.com>
>
> This was added in:
>
>   commit eb111869301e ("compiler-types.h: add asm_inline definition")
>
> and breaks samples/bpf as clang does not support asm __inline.
>
> Co-developed-by: Florent Revest <revest@google.com>
> Signed-off-by: Florent Revest <revest@google.com>
> Signed-off-by: KP Singh <kpsingh@google.com>

Acked-by: Song Liu <songliubraving@fb.com>

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

* Re: [PATCH v2] samples/bpf: Add a workaround for asm_inline
  2019-10-02 20:22 ` Andrii Nakryiko
@ 2019-10-02 21:05   ` Song Liu
  2019-10-02 21:13     ` Andrii Nakryiko
  0 siblings, 1 reply; 6+ messages in thread
From: Song Liu @ 2019-10-02 21:05 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: KP Singh, open list, bpf, Florent Revest, Alexei Starovoitov,
	Daniel Borkmann, Martin Lau, Yonghong Song, Florent Revest,
	Rasmus Villemoes, Arnaldo Carvalho de Melo



> On Oct 2, 2019, at 1:22 PM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
> 
> On Wed, Oct 2, 2019 at 12:17 PM KP Singh <kpsingh@chromium.org> wrote:
>> 
>> From: KP Singh <kpsingh@google.com>
>> 
>> This was added in:
>> 
>>  commit eb111869301e ("compiler-types.h: add asm_inline definition")
>> 
>> and breaks samples/bpf as clang does not support asm __inline.
>> 
>> Co-developed-by: Florent Revest <revest@google.com>
>> Signed-off-by: Florent Revest <revest@google.com>
>> Signed-off-by: KP Singh <kpsingh@google.com>
>> ---
>> 
>> Changes since v1:
>> 
>> - Dropped the rename from asm_workaround.h to asm_goto_workaround.h
>> - Dropped the fix for task_fd_query_user.c as it is updated in
>>  https://lore.kernel.org/bpf/20191001112249.27341-1-bjorn.topel@gmail.com/
>> 
>> samples/bpf/asm_goto_workaround.h | 13 ++++++++++++-
>> 1 file changed, 12 insertions(+), 1 deletion(-)
>> 
>> diff --git a/samples/bpf/asm_goto_workaround.h b/samples/bpf/asm_goto_workaround.h
>> index 7409722727ca..7048bb3594d6 100644
>> --- a/samples/bpf/asm_goto_workaround.h
>> +++ b/samples/bpf/asm_goto_workaround.h
>> @@ -3,7 +3,8 @@
>> #ifndef __ASM_GOTO_WORKAROUND_H
>> #define __ASM_GOTO_WORKAROUND_H
>> 
>> -/* this will bring in asm_volatile_goto macro definition
>> +/*
>> + * This will bring in asm_volatile_goto and asm_inline macro definitions
>>  * if enabled by compiler and config options.
>>  */
>> #include <linux/types.h>
>> @@ -13,5 +14,15 @@
>> #define asm_volatile_goto(x...) asm volatile("invalid use of asm_volatile_goto")
>> #endif
>> 
>> +/*
>> + * asm_inline is defined as asm __inline in "include/linux/compiler_types.h"
>> + * if supported by the kernel's CC (i.e CONFIG_CC_HAS_ASM_INLINE) which is not
>> + * supported by CLANG.
>> + */
>> +#ifdef asm_inline
>> +#undef asm_inline
>> +#define asm_inline asm
>> +#endif
> 
> Would it be better to just #undef CONFIG_CC_HAS_ASM_INLINE for BPF programs?

I guess that is still useful when gcc fully support BPF?

Thanks,
Song


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

* Re: [PATCH v2] samples/bpf: Add a workaround for asm_inline
  2019-10-02 21:05   ` Song Liu
@ 2019-10-02 21:13     ` Andrii Nakryiko
  0 siblings, 0 replies; 6+ messages in thread
From: Andrii Nakryiko @ 2019-10-02 21:13 UTC (permalink / raw)
  To: Song Liu
  Cc: KP Singh, open list, bpf, Florent Revest, Alexei Starovoitov,
	Daniel Borkmann, Martin Lau, Yonghong Song, Florent Revest,
	Rasmus Villemoes, Arnaldo Carvalho de Melo

On Wed, Oct 2, 2019 at 2:05 PM Song Liu <songliubraving@fb.com> wrote:
>
>
>
> > On Oct 2, 2019, at 1:22 PM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
> >
> > On Wed, Oct 2, 2019 at 12:17 PM KP Singh <kpsingh@chromium.org> wrote:
> >>
> >> From: KP Singh <kpsingh@google.com>
> >>
> >> This was added in:
> >>
> >>  commit eb111869301e ("compiler-types.h: add asm_inline definition")
> >>
> >> and breaks samples/bpf as clang does not support asm __inline.
> >>
> >> Co-developed-by: Florent Revest <revest@google.com>
> >> Signed-off-by: Florent Revest <revest@google.com>
> >> Signed-off-by: KP Singh <kpsingh@google.com>
> >> ---
> >>
> >> Changes since v1:
> >>
> >> - Dropped the rename from asm_workaround.h to asm_goto_workaround.h
> >> - Dropped the fix for task_fd_query_user.c as it is updated in
> >>  https://lore.kernel.org/bpf/20191001112249.27341-1-bjorn.topel@gmail.com/
> >>
> >> samples/bpf/asm_goto_workaround.h | 13 ++++++++++++-
> >> 1 file changed, 12 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/samples/bpf/asm_goto_workaround.h b/samples/bpf/asm_goto_workaround.h
> >> index 7409722727ca..7048bb3594d6 100644
> >> --- a/samples/bpf/asm_goto_workaround.h
> >> +++ b/samples/bpf/asm_goto_workaround.h
> >> @@ -3,7 +3,8 @@
> >> #ifndef __ASM_GOTO_WORKAROUND_H
> >> #define __ASM_GOTO_WORKAROUND_H
> >>
> >> -/* this will bring in asm_volatile_goto macro definition
> >> +/*
> >> + * This will bring in asm_volatile_goto and asm_inline macro definitions
> >>  * if enabled by compiler and config options.
> >>  */
> >> #include <linux/types.h>
> >> @@ -13,5 +14,15 @@
> >> #define asm_volatile_goto(x...) asm volatile("invalid use of asm_volatile_goto")
> >> #endif
> >>
> >> +/*
> >> + * asm_inline is defined as asm __inline in "include/linux/compiler_types.h"
> >> + * if supported by the kernel's CC (i.e CONFIG_CC_HAS_ASM_INLINE) which is not
> >> + * supported by CLANG.
> >> + */
> >> +#ifdef asm_inline
> >> +#undef asm_inline
> >> +#define asm_inline asm
> >> +#endif
> >
> > Would it be better to just #undef CONFIG_CC_HAS_ASM_INLINE for BPF programs?
>
> I guess that is still useful when gcc fully support BPF?

Ah, I missed that it's Clang-specific, not BPF target-specific thing.
Yeah, then it makes sense.

Acked-by: Andrii Nakryiko <andriin@fb.com>

>
> Thanks,
> Song
>

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

* Re: [PATCH v2] samples/bpf: Add a workaround for asm_inline
  2019-10-02 19:16 [PATCH v2] samples/bpf: Add a workaround for asm_inline KP Singh
  2019-10-02 20:22 ` Andrii Nakryiko
  2019-10-02 20:52 ` Song Liu
@ 2019-10-03 15:40 ` Daniel Borkmann
  2 siblings, 0 replies; 6+ messages in thread
From: Daniel Borkmann @ 2019-10-03 15:40 UTC (permalink / raw)
  To: KP Singh
  Cc: linux-kernel, bpf, Florent Revest, Alexei Starovoitov,
	Martin KaFai Lau, Song Liu, Yonghong Song, Florent Revest,
	Rasmus Villemoes, Arnaldo Carvalho de Melo

On Wed, Oct 02, 2019 at 09:16:52PM +0200, KP Singh wrote:
> From: KP Singh <kpsingh@google.com>
> 
> This was added in:
> 
>   commit eb111869301e ("compiler-types.h: add asm_inline definition")
> 
> and breaks samples/bpf as clang does not support asm __inline.
> 
> Co-developed-by: Florent Revest <revest@google.com>
> Signed-off-by: Florent Revest <revest@google.com>
> Signed-off-by: KP Singh <kpsingh@google.com>

Applied, thanks!

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

end of thread, other threads:[~2019-10-03 15:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-02 19:16 [PATCH v2] samples/bpf: Add a workaround for asm_inline KP Singh
2019-10-02 20:22 ` Andrii Nakryiko
2019-10-02 21:05   ` Song Liu
2019-10-02 21:13     ` Andrii Nakryiko
2019-10-02 20:52 ` Song Liu
2019-10-03 15:40 ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).