netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf_helpers.h: Add note for building with vmlinux.h or linux/types.h
@ 2020-04-21  0:05 Yoshiki Komachi
  2020-04-21  1:56 ` Andrii Nakryiko
  2020-04-23  5:27 ` Alexei Starovoitov
  0 siblings, 2 replies; 3+ messages in thread
From: Yoshiki Komachi @ 2020-04-21  0:05 UTC (permalink / raw)
  To: David S. Miller, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko
  Cc: Yoshiki Komachi, netdev, bpf

The following error was shown when a bpf program was compiled without
vmlinux.h auto-generated from BTF:

 # clang -I./linux/tools/lib/ -I/lib/modules/$(uname -r)/build/include/ \
   -O2 -Wall -target bpf -emit-llvm -c bpf_prog.c -o bpf_prog.bc
 ...
 In file included from linux/tools/lib/bpf/bpf_helpers.h:5:
 linux/tools/lib/bpf/bpf_helper_defs.h:56:82: error: unknown type name '__u64'
 ...

It seems that bpf programs are intended for being built together with
the vmlinux.h (which will have all the __u64 and other typedefs). But
users may mistakenly think "include <linux/types.h>" is missing
because the vmlinux.h is not common for non-bpf developers. IMO, an
explicit comment therefore should be added to bpf_helpers.h as this
patch shows.

Signed-off-by: Yoshiki Komachi <komachi.yoshiki@gmail.com>
---
 tools/lib/bpf/bpf_helpers.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
index f69cc208778a..60aad054eea1 100644
--- a/tools/lib/bpf/bpf_helpers.h
+++ b/tools/lib/bpf/bpf_helpers.h
@@ -2,6 +2,12 @@
 #ifndef __BPF_HELPERS__
 #define __BPF_HELPERS__
 
+/*
+ * Note that bpf programs need to include either
+ * vmlinux.h (auto-generated from BTF) or linux/types.h
+ * in advance since bpf_helper_defs.h uses such types
+ * as __u64.
+ */
 #include "bpf_helper_defs.h"
 
 #define __uint(name, val) int (*name)[val]
-- 
2.24.1


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

* Re: [PATCH bpf-next] bpf_helpers.h: Add note for building with vmlinux.h or linux/types.h
  2020-04-21  0:05 [PATCH bpf-next] bpf_helpers.h: Add note for building with vmlinux.h or linux/types.h Yoshiki Komachi
@ 2020-04-21  1:56 ` Andrii Nakryiko
  2020-04-23  5:27 ` Alexei Starovoitov
  1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2020-04-21  1:56 UTC (permalink / raw)
  To: Yoshiki Komachi
  Cc: David S. Miller, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	Networking, bpf

On Mon, Apr 20, 2020 at 5:06 PM Yoshiki Komachi
<komachi.yoshiki@gmail.com> wrote:
>
> The following error was shown when a bpf program was compiled without
> vmlinux.h auto-generated from BTF:
>
>  # clang -I./linux/tools/lib/ -I/lib/modules/$(uname -r)/build/include/ \
>    -O2 -Wall -target bpf -emit-llvm -c bpf_prog.c -o bpf_prog.bc
>  ...
>  In file included from linux/tools/lib/bpf/bpf_helpers.h:5:
>  linux/tools/lib/bpf/bpf_helper_defs.h:56:82: error: unknown type name '__u64'
>  ...
>
> It seems that bpf programs are intended for being built together with
> the vmlinux.h (which will have all the __u64 and other typedefs). But
> users may mistakenly think "include <linux/types.h>" is missing
> because the vmlinux.h is not common for non-bpf developers. IMO, an
> explicit comment therefore should be added to bpf_helpers.h as this
> patch shows.
>
> Signed-off-by: Yoshiki Komachi <komachi.yoshiki@gmail.com>
> ---

LGTM.

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

>  tools/lib/bpf/bpf_helpers.h | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
> index f69cc208778a..60aad054eea1 100644
> --- a/tools/lib/bpf/bpf_helpers.h
> +++ b/tools/lib/bpf/bpf_helpers.h
> @@ -2,6 +2,12 @@
>  #ifndef __BPF_HELPERS__
>  #define __BPF_HELPERS__
>
> +/*
> + * Note that bpf programs need to include either
> + * vmlinux.h (auto-generated from BTF) or linux/types.h
> + * in advance since bpf_helper_defs.h uses such types
> + * as __u64.
> + */
>  #include "bpf_helper_defs.h"
>
>  #define __uint(name, val) int (*name)[val]
> --
> 2.24.1
>

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

* Re: [PATCH bpf-next] bpf_helpers.h: Add note for building with vmlinux.h or linux/types.h
  2020-04-21  0:05 [PATCH bpf-next] bpf_helpers.h: Add note for building with vmlinux.h or linux/types.h Yoshiki Komachi
  2020-04-21  1:56 ` Andrii Nakryiko
@ 2020-04-23  5:27 ` Alexei Starovoitov
  1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2020-04-23  5:27 UTC (permalink / raw)
  To: Yoshiki Komachi
  Cc: David S. Miller, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	Network Development, bpf

On Mon, Apr 20, 2020 at 5:05 PM Yoshiki Komachi
<komachi.yoshiki@gmail.com> wrote:
>
> The following error was shown when a bpf program was compiled without
> vmlinux.h auto-generated from BTF:
>
>  # clang -I./linux/tools/lib/ -I/lib/modules/$(uname -r)/build/include/ \
>    -O2 -Wall -target bpf -emit-llvm -c bpf_prog.c -o bpf_prog.bc
>  ...
>  In file included from linux/tools/lib/bpf/bpf_helpers.h:5:
>  linux/tools/lib/bpf/bpf_helper_defs.h:56:82: error: unknown type name '__u64'
>  ...
>
> It seems that bpf programs are intended for being built together with
> the vmlinux.h (which will have all the __u64 and other typedefs). But
> users may mistakenly think "include <linux/types.h>" is missing
> because the vmlinux.h is not common for non-bpf developers. IMO, an
> explicit comment therefore should be added to bpf_helpers.h as this
> patch shows.
>
> Signed-off-by: Yoshiki Komachi <komachi.yoshiki@gmail.com>

Applied. Thanks

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

end of thread, other threads:[~2020-04-23  5:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21  0:05 [PATCH bpf-next] bpf_helpers.h: Add note for building with vmlinux.h or linux/types.h Yoshiki Komachi
2020-04-21  1:56 ` Andrii Nakryiko
2020-04-23  5:27 ` Alexei Starovoitov

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).