linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] bpf, mips: Fix build errors about __NR_bpf undeclared
@ 2021-11-25  1:36 Tiezhu Yang
  2021-11-25 23:05 ` Daniel Borkmann
  2021-11-26 21:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Tiezhu Yang @ 2021-11-25  1:36 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Xuefeng Li, netdev, bpf, linux-kernel

Add the __NR_bpf definitions to fix the following build errors for mips.

 $ cd tools/bpf/bpftool
 $ make
 [...]
 bpf.c:54:4: error: #error __NR_bpf not defined. libbpf does not support your arch.
  #  error __NR_bpf not defined. libbpf does not support your arch.
     ^~~~~
 bpf.c: In function ‘sys_bpf’:
 bpf.c:66:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
   return syscall(__NR_bpf, cmd, attr, size);
                  ^~~~~~~~
                  __NR_brk
 [...]
 In file included from gen_loader.c:15:0:
 skel_internal.h: In function ‘skel_sys_bpf’:
 skel_internal.h:53:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
   return syscall(__NR_bpf, cmd, attr, size);
                  ^~~~~~~~
                  __NR_brk

We can see the following generated definitions:

 $ grep -r "#define __NR_bpf" arch/mips
 arch/mips/include/generated/uapi/asm/unistd_o32.h:#define __NR_bpf (__NR_Linux + 355)
 arch/mips/include/generated/uapi/asm/unistd_n64.h:#define __NR_bpf (__NR_Linux + 315)
 arch/mips/include/generated/uapi/asm/unistd_n32.h:#define __NR_bpf (__NR_Linux + 319)

The __NR_Linux is defined in arch/mips/include/uapi/asm/unistd.h:

 $ grep -r "#define __NR_Linux" arch/mips
 arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux	4000
 arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux	5000
 arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux	6000

That is to say, __NR_bpf is
4000 + 355 = 4355 for mips o32,
6000 + 319 = 6319 for mips n32,
5000 + 315 = 5315 for mips n64.

So use the GCC pre-defined macro _ABIO32, _ABIN32 and _ABI64 [1] to define
the corresponding __NR_bpf.

This patch is similar with commit bad1926dd2f6 ("bpf, s390: fix build for
libbpf and selftest suite").

[1] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/mips/mips.h#l549

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---

v2: use a final number without __NR_Linux to define __NR_bpf
    suggested by Andrii Nakryiko, thank you.

 tools/build/feature/test-bpf.c |  6 ++++++
 tools/lib/bpf/bpf.c            |  6 ++++++
 tools/lib/bpf/skel_internal.h  | 10 ++++++++++
 3 files changed, 22 insertions(+)

diff --git a/tools/build/feature/test-bpf.c b/tools/build/feature/test-bpf.c
index 82070ea..727d22e 100644
--- a/tools/build/feature/test-bpf.c
+++ b/tools/build/feature/test-bpf.c
@@ -14,6 +14,12 @@
 #  define __NR_bpf 349
 # elif defined(__s390__)
 #  define __NR_bpf 351
+# elif defined(__mips__) && defined(_ABIO32)
+#  define __NR_bpf 4355
+# elif defined(__mips__) && defined(_ABIN32)
+#  define __NR_bpf 6319
+# elif defined(__mips__) && defined(_ABI64)
+#  define __NR_bpf 5315
 # else
 #  error __NR_bpf not defined. libbpf does not support your arch.
 # endif
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 94560ba..17f9fe2 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -50,6 +50,12 @@
 #  define __NR_bpf 351
 # elif defined(__arc__)
 #  define __NR_bpf 280
+# elif defined(__mips__) && defined(_ABIO32)
+#  define __NR_bpf 4355
+# elif defined(__mips__) && defined(_ABIN32)
+#  define __NR_bpf 6319
+# elif defined(__mips__) && defined(_ABI64)
+#  define __NR_bpf 5315
 # else
 #  error __NR_bpf not defined. libbpf does not support your arch.
 # endif
diff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h
index 9cf6670..064da66 100644
--- a/tools/lib/bpf/skel_internal.h
+++ b/tools/lib/bpf/skel_internal.h
@@ -7,6 +7,16 @@
 #include <sys/syscall.h>
 #include <sys/mman.h>
 
+#ifndef __NR_bpf
+# if defined(__mips__) && defined(_ABIO32)
+#  define __NR_bpf 4355
+# elif defined(__mips__) && defined(_ABIN32)
+#  define __NR_bpf 6319
+# elif defined(__mips__) && defined(_ABI64)
+#  define __NR_bpf 5315
+# endif
+#endif
+
 /* This file is a base header for auto-generated *.lskel.h files.
  * Its contents will change and may become part of auto-generation in the future.
  *
-- 
2.1.0


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

* Re: [PATCH bpf-next v2] bpf, mips: Fix build errors about __NR_bpf undeclared
  2021-11-25  1:36 [PATCH bpf-next v2] bpf, mips: Fix build errors about __NR_bpf undeclared Tiezhu Yang
@ 2021-11-25 23:05 ` Daniel Borkmann
  2021-11-26  1:22   ` Andrii Nakryiko
  2021-11-26 21:20 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Daniel Borkmann @ 2021-11-25 23:05 UTC (permalink / raw)
  To: Tiezhu Yang, Alexei Starovoitov, Andrii Nakryiko
  Cc: Xuefeng Li, netdev, bpf, linux-kernel, johan.almbladh

[ +Johan ]

On 11/25/21 2:36 AM, Tiezhu Yang wrote:
> Add the __NR_bpf definitions to fix the following build errors for mips.
> 
>   $ cd tools/bpf/bpftool
>   $ make
>   [...]
>   bpf.c:54:4: error: #error __NR_bpf not defined. libbpf does not support your arch.
>    #  error __NR_bpf not defined. libbpf does not support your arch.
>       ^~~~~
>   bpf.c: In function ‘sys_bpf’:
>   bpf.c:66:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
>     return syscall(__NR_bpf, cmd, attr, size);
>                    ^~~~~~~~
>                    __NR_brk
>   [...]
>   In file included from gen_loader.c:15:0:
>   skel_internal.h: In function ‘skel_sys_bpf’:
>   skel_internal.h:53:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
>     return syscall(__NR_bpf, cmd, attr, size);
>                    ^~~~~~~~
>                    __NR_brk
> 
> We can see the following generated definitions:
> 
>   $ grep -r "#define __NR_bpf" arch/mips
>   arch/mips/include/generated/uapi/asm/unistd_o32.h:#define __NR_bpf (__NR_Linux + 355)
>   arch/mips/include/generated/uapi/asm/unistd_n64.h:#define __NR_bpf (__NR_Linux + 315)
>   arch/mips/include/generated/uapi/asm/unistd_n32.h:#define __NR_bpf (__NR_Linux + 319)
> 
> The __NR_Linux is defined in arch/mips/include/uapi/asm/unistd.h:
> 
>   $ grep -r "#define __NR_Linux" arch/mips
>   arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux	4000
>   arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux	5000
>   arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux	6000
> 
> That is to say, __NR_bpf is
> 4000 + 355 = 4355 for mips o32,
> 6000 + 319 = 6319 for mips n32,
> 5000 + 315 = 5315 for mips n64.
> 
> So use the GCC pre-defined macro _ABIO32, _ABIN32 and _ABI64 [1] to define
> the corresponding __NR_bpf.
> 
> This patch is similar with commit bad1926dd2f6 ("bpf, s390: fix build for
> libbpf and selftest suite").
> 
> [1] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/mips/mips.h#l549
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
> 
> v2: use a final number without __NR_Linux to define __NR_bpf
>      suggested by Andrii Nakryiko, thank you.
> 
>   tools/build/feature/test-bpf.c |  6 ++++++
>   tools/lib/bpf/bpf.c            |  6 ++++++
>   tools/lib/bpf/skel_internal.h  | 10 ++++++++++
>   3 files changed, 22 insertions(+)
> 
> diff --git a/tools/build/feature/test-bpf.c b/tools/build/feature/test-bpf.c
> index 82070ea..727d22e 100644
> --- a/tools/build/feature/test-bpf.c
> +++ b/tools/build/feature/test-bpf.c
> @@ -14,6 +14,12 @@
>   #  define __NR_bpf 349
>   # elif defined(__s390__)
>   #  define __NR_bpf 351
> +# elif defined(__mips__) && defined(_ABIO32)
> +#  define __NR_bpf 4355
> +# elif defined(__mips__) && defined(_ABIN32)
> +#  define __NR_bpf 6319
> +# elif defined(__mips__) && defined(_ABI64)
> +#  define __NR_bpf 5315
>   # else
>   #  error __NR_bpf not defined. libbpf does not support your arch.
>   # endif
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index 94560ba..17f9fe2 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -50,6 +50,12 @@
>   #  define __NR_bpf 351
>   # elif defined(__arc__)
>   #  define __NR_bpf 280
> +# elif defined(__mips__) && defined(_ABIO32)
> +#  define __NR_bpf 4355
> +# elif defined(__mips__) && defined(_ABIN32)
> +#  define __NR_bpf 6319
> +# elif defined(__mips__) && defined(_ABI64)
> +#  define __NR_bpf 5315
>   # else
>   #  error __NR_bpf not defined. libbpf does not support your arch.
>   # endif
> diff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h
> index 9cf6670..064da66 100644
> --- a/tools/lib/bpf/skel_internal.h
> +++ b/tools/lib/bpf/skel_internal.h
> @@ -7,6 +7,16 @@
>   #include <sys/syscall.h>
>   #include <sys/mman.h>
>   
> +#ifndef __NR_bpf
> +# if defined(__mips__) && defined(_ABIO32)
> +#  define __NR_bpf 4355
> +# elif defined(__mips__) && defined(_ABIN32)
> +#  define __NR_bpf 6319
> +# elif defined(__mips__) && defined(_ABI64)
> +#  define __NR_bpf 5315
> +# endif
> +#endif

Bit unfortunate that mips is the only arch where we run into this apparently? :/
Given we also redefine a skel_sys_bpf(), maybe libbpf should just provide something
like a `LIBBPF_API int libbpf_sys_bpf(enum bpf_cmd cmd, [...])` so we rely implicitly
only on the libbpf-internal __NR_bpf instead of duplicating again?

>   /* This file is a base header for auto-generated *.lskel.h files.
>    * Its contents will change and may become part of auto-generation in the future.
>    *
> 


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

* Re: [PATCH bpf-next v2] bpf, mips: Fix build errors about __NR_bpf undeclared
  2021-11-25 23:05 ` Daniel Borkmann
@ 2021-11-26  1:22   ` Andrii Nakryiko
  0 siblings, 0 replies; 4+ messages in thread
From: Andrii Nakryiko @ 2021-11-26  1:22 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Tiezhu Yang, Alexei Starovoitov, Andrii Nakryiko, Xuefeng Li,
	Networking, bpf, open list, Johan Almbladh

On Thu, Nov 25, 2021 at 3:05 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> [ +Johan ]
>
> On 11/25/21 2:36 AM, Tiezhu Yang wrote:
> > Add the __NR_bpf definitions to fix the following build errors for mips.
> >
> >   $ cd tools/bpf/bpftool
> >   $ make
> >   [...]
> >   bpf.c:54:4: error: #error __NR_bpf not defined. libbpf does not support your arch.
> >    #  error __NR_bpf not defined. libbpf does not support your arch.
> >       ^~~~~
> >   bpf.c: In function ‘sys_bpf’:
> >   bpf.c:66:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
> >     return syscall(__NR_bpf, cmd, attr, size);
> >                    ^~~~~~~~
> >                    __NR_brk
> >   [...]
> >   In file included from gen_loader.c:15:0:
> >   skel_internal.h: In function ‘skel_sys_bpf’:
> >   skel_internal.h:53:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
> >     return syscall(__NR_bpf, cmd, attr, size);
> >                    ^~~~~~~~
> >                    __NR_brk
> >
> > We can see the following generated definitions:
> >
> >   $ grep -r "#define __NR_bpf" arch/mips
> >   arch/mips/include/generated/uapi/asm/unistd_o32.h:#define __NR_bpf (__NR_Linux + 355)
> >   arch/mips/include/generated/uapi/asm/unistd_n64.h:#define __NR_bpf (__NR_Linux + 315)
> >   arch/mips/include/generated/uapi/asm/unistd_n32.h:#define __NR_bpf (__NR_Linux + 319)
> >
> > The __NR_Linux is defined in arch/mips/include/uapi/asm/unistd.h:
> >
> >   $ grep -r "#define __NR_Linux" arch/mips
> >   arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux      4000
> >   arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux      5000
> >   arch/mips/include/uapi/asm/unistd.h:#define __NR_Linux      6000
> >
> > That is to say, __NR_bpf is
> > 4000 + 355 = 4355 for mips o32,
> > 6000 + 319 = 6319 for mips n32,
> > 5000 + 315 = 5315 for mips n64.
> >
> > So use the GCC pre-defined macro _ABIO32, _ABIN32 and _ABI64 [1] to define
> > the corresponding __NR_bpf.
> >
> > This patch is similar with commit bad1926dd2f6 ("bpf, s390: fix build for
> > libbpf and selftest suite").
> >
> > [1] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/mips/mips.h#l549
> >
> > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> > ---
> >
> > v2: use a final number without __NR_Linux to define __NR_bpf
> >      suggested by Andrii Nakryiko, thank you.
> >
> >   tools/build/feature/test-bpf.c |  6 ++++++
> >   tools/lib/bpf/bpf.c            |  6 ++++++
> >   tools/lib/bpf/skel_internal.h  | 10 ++++++++++
> >   3 files changed, 22 insertions(+)
> >
> > diff --git a/tools/build/feature/test-bpf.c b/tools/build/feature/test-bpf.c
> > index 82070ea..727d22e 100644
> > --- a/tools/build/feature/test-bpf.c
> > +++ b/tools/build/feature/test-bpf.c
> > @@ -14,6 +14,12 @@
> >   #  define __NR_bpf 349
> >   # elif defined(__s390__)
> >   #  define __NR_bpf 351
> > +# elif defined(__mips__) && defined(_ABIO32)
> > +#  define __NR_bpf 4355
> > +# elif defined(__mips__) && defined(_ABIN32)
> > +#  define __NR_bpf 6319
> > +# elif defined(__mips__) && defined(_ABI64)
> > +#  define __NR_bpf 5315
> >   # else
> >   #  error __NR_bpf not defined. libbpf does not support your arch.
> >   # endif
> > diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> > index 94560ba..17f9fe2 100644
> > --- a/tools/lib/bpf/bpf.c
> > +++ b/tools/lib/bpf/bpf.c
> > @@ -50,6 +50,12 @@
> >   #  define __NR_bpf 351
> >   # elif defined(__arc__)
> >   #  define __NR_bpf 280
> > +# elif defined(__mips__) && defined(_ABIO32)
> > +#  define __NR_bpf 4355
> > +# elif defined(__mips__) && defined(_ABIN32)
> > +#  define __NR_bpf 6319
> > +# elif defined(__mips__) && defined(_ABI64)
> > +#  define __NR_bpf 5315
> >   # else
> >   #  error __NR_bpf not defined. libbpf does not support your arch.
> >   # endif
> > diff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h
> > index 9cf6670..064da66 100644
> > --- a/tools/lib/bpf/skel_internal.h
> > +++ b/tools/lib/bpf/skel_internal.h
> > @@ -7,6 +7,16 @@
> >   #include <sys/syscall.h>
> >   #include <sys/mman.h>
> >
> > +#ifndef __NR_bpf
> > +# if defined(__mips__) && defined(_ABIO32)
> > +#  define __NR_bpf 4355
> > +# elif defined(__mips__) && defined(_ABIN32)
> > +#  define __NR_bpf 6319
> > +# elif defined(__mips__) && defined(_ABI64)
> > +#  define __NR_bpf 5315
> > +# endif
> > +#endif
>
> Bit unfortunate that mips is the only arch where we run into this apparently? :/
> Given we also redefine a skel_sys_bpf(), maybe libbpf should just provide something
> like a `LIBBPF_API int libbpf_sys_bpf(enum bpf_cmd cmd, [...])` so we rely implicitly
> only on the libbpf-internal __NR_bpf instead of duplicating again?

Unfortunately the point of skel_internal.h is to not depend on libbpf
APIs. I think for now it should be fine to have this duplication (not
that those numbers are going to change ever) and we can improve this
later.

>
> >   /* This file is a base header for auto-generated *.lskel.h files.
> >    * Its contents will change and may become part of auto-generation in the future.
> >    *
> >
>

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

* Re: [PATCH bpf-next v2] bpf, mips: Fix build errors about __NR_bpf undeclared
  2021-11-25  1:36 [PATCH bpf-next v2] bpf, mips: Fix build errors about __NR_bpf undeclared Tiezhu Yang
  2021-11-25 23:05 ` Daniel Borkmann
@ 2021-11-26 21:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-26 21:20 UTC (permalink / raw)
  To: Tiezhu Yang; +Cc: ast, daniel, andrii, lixuefeng, netdev, bpf, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Thu, 25 Nov 2021 09:36:07 +0800 you wrote:
> Add the __NR_bpf definitions to fix the following build errors for mips.
> 
>  $ cd tools/bpf/bpftool
>  $ make
>  [...]
>  bpf.c:54:4: error: #error __NR_bpf not defined. libbpf does not support your arch.
>   #  error __NR_bpf not defined. libbpf does not support your arch.
>      ^~~~~
>  bpf.c: In function ‘sys_bpf’:
>  bpf.c:66:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
>    return syscall(__NR_bpf, cmd, attr, size);
>                   ^~~~~~~~
>                   __NR_brk
>  [...]
>  In file included from gen_loader.c:15:0:
>  skel_internal.h: In function ‘skel_sys_bpf’:
>  skel_internal.h:53:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
>    return syscall(__NR_bpf, cmd, attr, size);
>                   ^~~~~~~~
>                   __NR_brk
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2] bpf, mips: Fix build errors about __NR_bpf undeclared
    https://git.kernel.org/bpf/bpf-next/c/e32cb12ff52a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-11-26 21:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25  1:36 [PATCH bpf-next v2] bpf, mips: Fix build errors about __NR_bpf undeclared Tiezhu Yang
2021-11-25 23:05 ` Daniel Borkmann
2021-11-26  1:22   ` Andrii Nakryiko
2021-11-26 21:20 ` patchwork-bot+netdevbpf

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