mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] libbpf: ensure F_DUPFD_CLOEXEC is defined
@ 2022-02-27 14:25 James Hilliard
  2022-02-28 15:00 ` Daniel Borkmann
  0 siblings, 1 reply; 7+ messages in thread
From: James Hilliard @ 2022-02-27 14:25 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, netdev, linux-kernel, James Hilliard

This definition seems to be missing from some older toolchains.

Note that the fcntl.h in libbpf_internal.h is not a kernel header
but rather a toolchain libc header.

Fixes:
libbpf_internal.h:521:18: error: 'F_DUPFD_CLOEXEC' undeclared (first use in this function); did you mean 'FD_CLOEXEC'?
   fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
                  ^~~~~~~~~~~~~~~
                  FD_CLOEXEC

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 tools/lib/bpf/libbpf_internal.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 4fda8bdf0a0d..d2a86b5a457a 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -31,6 +31,10 @@
 #define EM_BPF 247
 #endif
 
+#ifndef F_DUPFD_CLOEXEC
+#define F_DUPFD_CLOEXEC 1030
+#endif
+
 #ifndef R_BPF_64_64
 #define R_BPF_64_64 1
 #endif
-- 
2.25.1


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

* Re: [PATCH 1/1] libbpf: ensure F_DUPFD_CLOEXEC is defined
  2022-02-27 14:25 [PATCH 1/1] libbpf: ensure F_DUPFD_CLOEXEC is defined James Hilliard
@ 2022-02-28 15:00 ` Daniel Borkmann
  2022-03-04 19:01   ` Andrii Nakryiko
  2022-03-05  9:54   ` James Hilliard
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Borkmann @ 2022-02-28 15:00 UTC (permalink / raw)
  To: James Hilliard, bpf
  Cc: Alexei Starovoitov, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, netdev, linux-kernel

Hi James,

On 2/27/22 3:25 PM, James Hilliard wrote:
> This definition seems to be missing from some older toolchains.
> 
> Note that the fcntl.h in libbpf_internal.h is not a kernel header
> but rather a toolchain libc header.
> 
> Fixes:
> libbpf_internal.h:521:18: error: 'F_DUPFD_CLOEXEC' undeclared (first use in this function); did you mean 'FD_CLOEXEC'?
>     fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
>                    ^~~~~~~~~~~~~~~
>                    FD_CLOEXEC
> 
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>

Do you have some more info on your env (e.g. libc)? Looks like F_DUPFD_CLOEXEC
was added back in 2.6.24 kernel. When did libc add it?

Should we instead just add an include for <linux/fcntl.h> to libbpf_internal.h
(given it defines F_DUPFD_CLOEXEC as well)?

> ---
>   tools/lib/bpf/libbpf_internal.h | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index 4fda8bdf0a0d..d2a86b5a457a 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -31,6 +31,10 @@
>   #define EM_BPF 247
>   #endif
>   
> +#ifndef F_DUPFD_CLOEXEC
> +#define F_DUPFD_CLOEXEC 1030
> +#endif
> +
>   #ifndef R_BPF_64_64
>   #define R_BPF_64_64 1
>   #endif
> 

Thanks,
Daniel

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

* Re: [PATCH 1/1] libbpf: ensure F_DUPFD_CLOEXEC is defined
  2022-02-28 15:00 ` Daniel Borkmann
@ 2022-03-04 19:01   ` Andrii Nakryiko
  2022-03-04 21:54     ` Daniel Borkmann
  2022-03-05  9:57     ` James Hilliard
  2022-03-05  9:54   ` James Hilliard
  1 sibling, 2 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2022-03-04 19:01 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: James Hilliard, bpf, Alexei Starovoitov, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Networking, open list

On Mon, Feb 28, 2022 at 7:00 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> Hi James,
>
> On 2/27/22 3:25 PM, James Hilliard wrote:
> > This definition seems to be missing from some older toolchains.
> >
> > Note that the fcntl.h in libbpf_internal.h is not a kernel header
> > but rather a toolchain libc header.
> >
> > Fixes:
> > libbpf_internal.h:521:18: error: 'F_DUPFD_CLOEXEC' undeclared (first use in this function); did you mean 'FD_CLOEXEC'?
> >     fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
> >                    ^~~~~~~~~~~~~~~
> >                    FD_CLOEXEC
> >
> > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
>
> Do you have some more info on your env (e.g. libc)? Looks like F_DUPFD_CLOEXEC
> was added back in 2.6.24 kernel. When did libc add it?

It seems like it's guarded by __USE_XOPEN2K8 in glibc (from a quick
glance at glibc code). But it's been there since 2010 or so, at the
very least.

>
> Should we instead just add an include for <linux/fcntl.h> to libbpf_internal.h
> (given it defines F_DUPFD_CLOEXEC as well)?

yep, this is UAPI header so we can use it easily (we'll need to sync
it into Github repo, but that's not a problem)


>
> > ---
> >   tools/lib/bpf/libbpf_internal.h | 4 ++++
> >   1 file changed, 4 insertions(+)
> >
> > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> > index 4fda8bdf0a0d..d2a86b5a457a 100644
> > --- a/tools/lib/bpf/libbpf_internal.h
> > +++ b/tools/lib/bpf/libbpf_internal.h
> > @@ -31,6 +31,10 @@
> >   #define EM_BPF 247
> >   #endif
> >
> > +#ifndef F_DUPFD_CLOEXEC
> > +#define F_DUPFD_CLOEXEC 1030
> > +#endif
> > +
> >   #ifndef R_BPF_64_64
> >   #define R_BPF_64_64 1
> >   #endif
> >
>
> Thanks,
> Daniel

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

* Re: [PATCH 1/1] libbpf: ensure F_DUPFD_CLOEXEC is defined
  2022-03-04 19:01   ` Andrii Nakryiko
@ 2022-03-04 21:54     ` Daniel Borkmann
  2022-03-05  9:57     ` James Hilliard
  1 sibling, 0 replies; 7+ messages in thread
From: Daniel Borkmann @ 2022-03-04 21:54 UTC (permalink / raw)
  To: James Hilliard
  Cc: Andrii Nakryiko, bpf, Alexei Starovoitov, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Networking, open list

On 3/4/22 8:01 PM, Andrii Nakryiko wrote:
> On Mon, Feb 28, 2022 at 7:00 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>> On 2/27/22 3:25 PM, James Hilliard wrote:
>>> This definition seems to be missing from some older toolchains.
>>>
>>> Note that the fcntl.h in libbpf_internal.h is not a kernel header
>>> but rather a toolchain libc header.
>>>
>>> Fixes:
>>> libbpf_internal.h:521:18: error: 'F_DUPFD_CLOEXEC' undeclared (first use in this function); did you mean 'FD_CLOEXEC'?
>>>      fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
>>>                     ^~~~~~~~~~~~~~~
>>>                     FD_CLOEXEC
>>>
>>> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
>>
>> Do you have some more info on your env (e.g. libc)? Looks like F_DUPFD_CLOEXEC
>> was added back in 2.6.24 kernel. When did libc add it?
> 
> It seems like it's guarded by __USE_XOPEN2K8 in glibc (from a quick
> glance at glibc code). But it's been there since 2010 or so, at the
> very least.
> 
>> Should we instead just add an include for <linux/fcntl.h> to libbpf_internal.h
>> (given it defines F_DUPFD_CLOEXEC as well)?
> 
> yep, this is UAPI header so we can use it easily (we'll need to sync
> it into Github repo, but that's not a problem)

Sgtm, James, could you respin with using the include?

Thanks,
Daniel

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

* Re: [PATCH 1/1] libbpf: ensure F_DUPFD_CLOEXEC is defined
  2022-02-28 15:00 ` Daniel Borkmann
  2022-03-04 19:01   ` Andrii Nakryiko
@ 2022-03-05  9:54   ` James Hilliard
  2022-03-08  1:35     ` Andrii Nakryiko
  1 sibling, 1 reply; 7+ messages in thread
From: James Hilliard @ 2022-03-05  9:54 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: bpf, Alexei Starovoitov, Andrii Nakryiko, Martin KaFai Lau,
	Song Liu, Yonghong Song, John Fastabend, KP Singh, netdev,
	Linux Kernel Mailing List

On Mon, Feb 28, 2022 at 8:00 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> Hi James,
>
> On 2/27/22 3:25 PM, James Hilliard wrote:
> > This definition seems to be missing from some older toolchains.
> >
> > Note that the fcntl.h in libbpf_internal.h is not a kernel header
> > but rather a toolchain libc header.
> >
> > Fixes:
> > libbpf_internal.h:521:18: error: 'F_DUPFD_CLOEXEC' undeclared (first use in this function); did you mean 'FD_CLOEXEC'?
> >     fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
> >                    ^~~~~~~~~~~~~~~
> >                    FD_CLOEXEC
> >
> > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
>
> Do you have some more info on your env (e.g. libc)? Looks like F_DUPFD_CLOEXEC
> was added back in 2.6.24 kernel. When did libc add it?
>
> Should we instead just add an include for <linux/fcntl.h> to libbpf_internal.h
> (given it defines F_DUPFD_CLOEXEC as well)?

That seems to cause a conflict: error: redefinition of ‘struct flock’


>
> > ---
> >   tools/lib/bpf/libbpf_internal.h | 4 ++++
> >   1 file changed, 4 insertions(+)
> >
> > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> > index 4fda8bdf0a0d..d2a86b5a457a 100644
> > --- a/tools/lib/bpf/libbpf_internal.h
> > +++ b/tools/lib/bpf/libbpf_internal.h
> > @@ -31,6 +31,10 @@
> >   #define EM_BPF 247
> >   #endif
> >
> > +#ifndef F_DUPFD_CLOEXEC
> > +#define F_DUPFD_CLOEXEC 1030
> > +#endif
> > +
> >   #ifndef R_BPF_64_64
> >   #define R_BPF_64_64 1
> >   #endif
> >
>
> Thanks,
> Daniel

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

* Re: [PATCH 1/1] libbpf: ensure F_DUPFD_CLOEXEC is defined
  2022-03-04 19:01   ` Andrii Nakryiko
  2022-03-04 21:54     ` Daniel Borkmann
@ 2022-03-05  9:57     ` James Hilliard
  1 sibling, 0 replies; 7+ messages in thread
From: James Hilliard @ 2022-03-05  9:57 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Daniel Borkmann, bpf, Alexei Starovoitov, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Networking, open list

On Fri, Mar 4, 2022 at 12:01 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Mon, Feb 28, 2022 at 7:00 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
> >
> > Hi James,
> >
> > On 2/27/22 3:25 PM, James Hilliard wrote:
> > > This definition seems to be missing from some older toolchains.
> > >
> > > Note that the fcntl.h in libbpf_internal.h is not a kernel header
> > > but rather a toolchain libc header.
> > >
> > > Fixes:
> > > libbpf_internal.h:521:18: error: 'F_DUPFD_CLOEXEC' undeclared (first use in this function); did you mean 'FD_CLOEXEC'?
> > >     fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
> > >                    ^~~~~~~~~~~~~~~
> > >                    FD_CLOEXEC
> > >
> > > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> >
> > Do you have some more info on your env (e.g. libc)? Looks like F_DUPFD_CLOEXEC
> > was added back in 2.6.24 kernel. When did libc add it?
>
> It seems like it's guarded by __USE_XOPEN2K8 in glibc (from a quick
> glance at glibc code). But it's been there since 2010 or so, at the
> very least.

The toolchain that hit this issue appears to be uclibc based which seems to have
had some bugs with the F_DUPFD_CLOEXEC definition.

>
> >
> > Should we instead just add an include for <linux/fcntl.h> to libbpf_internal.h
> > (given it defines F_DUPFD_CLOEXEC as well)?
>
> yep, this is UAPI header so we can use it easily (we'll need to sync
> it into Github repo, but that's not a problem)
>
>
> >
> > > ---
> > >   tools/lib/bpf/libbpf_internal.h | 4 ++++
> > >   1 file changed, 4 insertions(+)
> > >
> > > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> > > index 4fda8bdf0a0d..d2a86b5a457a 100644
> > > --- a/tools/lib/bpf/libbpf_internal.h
> > > +++ b/tools/lib/bpf/libbpf_internal.h
> > > @@ -31,6 +31,10 @@
> > >   #define EM_BPF 247
> > >   #endif
> > >
> > > +#ifndef F_DUPFD_CLOEXEC
> > > +#define F_DUPFD_CLOEXEC 1030
> > > +#endif
> > > +
> > >   #ifndef R_BPF_64_64
> > >   #define R_BPF_64_64 1
> > >   #endif
> > >
> >
> > Thanks,
> > Daniel

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

* Re: [PATCH 1/1] libbpf: ensure F_DUPFD_CLOEXEC is defined
  2022-03-05  9:54   ` James Hilliard
@ 2022-03-08  1:35     ` Andrii Nakryiko
  0 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2022-03-08  1:35 UTC (permalink / raw)
  To: James Hilliard
  Cc: Daniel Borkmann, bpf, Alexei Starovoitov, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Networking, Linux Kernel Mailing List

On Sat, Mar 5, 2022 at 1:54 AM James Hilliard <james.hilliard1@gmail.com> wrote:
>
> On Mon, Feb 28, 2022 at 8:00 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
> >
> > Hi James,
> >
> > On 2/27/22 3:25 PM, James Hilliard wrote:
> > > This definition seems to be missing from some older toolchains.
> > >
> > > Note that the fcntl.h in libbpf_internal.h is not a kernel header
> > > but rather a toolchain libc header.
> > >
> > > Fixes:
> > > libbpf_internal.h:521:18: error: 'F_DUPFD_CLOEXEC' undeclared (first use in this function); did you mean 'FD_CLOEXEC'?
> > >     fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
> > >                    ^~~~~~~~~~~~~~~
> > >                    FD_CLOEXEC
> > >
> > > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> >
> > Do you have some more info on your env (e.g. libc)? Looks like F_DUPFD_CLOEXEC
> > was added back in 2.6.24 kernel. When did libc add it?
> >
> > Should we instead just add an include for <linux/fcntl.h> to libbpf_internal.h
> > (given it defines F_DUPFD_CLOEXEC as well)?
>
> That seems to cause a conflict: error: redefinition of ‘struct flock’
>
>
> >
> > > ---
> > >   tools/lib/bpf/libbpf_internal.h | 4 ++++
> > >   1 file changed, 4 insertions(+)
> > >
> > > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> > > index 4fda8bdf0a0d..d2a86b5a457a 100644
> > > --- a/tools/lib/bpf/libbpf_internal.h
> > > +++ b/tools/lib/bpf/libbpf_internal.h
> > > @@ -31,6 +31,10 @@
> > >   #define EM_BPF 247
> > >   #endif
> > >
> > > +#ifndef F_DUPFD_CLOEXEC
> > > +#define F_DUPFD_CLOEXEC 1030
> > > +#endif

Let's just do this then (assuming the value of F_DUPFD_CLOEXEC is
architecture-independent)

> > > +
> > >   #ifndef R_BPF_64_64
> > >   #define R_BPF_64_64 1
> > >   #endif
> > >
> >
> > Thanks,
> > Daniel

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-27 14:25 [PATCH 1/1] libbpf: ensure F_DUPFD_CLOEXEC is defined James Hilliard
2022-02-28 15:00 ` Daniel Borkmann
2022-03-04 19:01   ` Andrii Nakryiko
2022-03-04 21:54     ` Daniel Borkmann
2022-03-05  9:57     ` James Hilliard
2022-03-05  9:54   ` James Hilliard
2022-03-08  1:35     ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®