Skip to contentSkip to conversation

libbpf: Define MFD_CLOEXEC if not available

PATCH Applied Arnaldo Carvalho de Melo 3 participants 4 messages Mar 21, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: Define MFD_CLOEXEC if not available

Since its going directly to the syscall to avoid not having memfd_create() available in some systems, do the same for its MFD_CLOEXEC flags, defining it if not available.

This fixes the build in those systems, noticed while building perf on a set of build containers.

Fixes 9fa5e1a180aa639f ("libbpf: Call memfd_create() syscall directly")
Cc Andrii Nakryiko <[email protected]>
Cc Daniel Borkmann <[email protected]>
---
 tools/lib/bpf/libbpf.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/lib/bpf/libbpf.c +4 -0
index efab29b8935bd9f7..635a38c6f947a34d 100644
@@ -1650,6 +1650,10 @@ static int sys_memfd_create(const char *name, unsigned flags)
 	return syscall(__NR_memfd_create, name, flags);
 }
 
+#ifndef MFD_CLOEXEC
+#define MFD_CLOEXEC 0x0001U
+#endif
+
 static int create_placeholder_fd(void)
 {
 	int fd;
Signature · 1 line
2.44.0
#1 lore raw
Quoted 21 lines · Arnaldo Carvalho de Melo

Since its going directly to the syscall to avoid not having memfd_create() available in some systems, do the same for its MFD_CLOEXEC flags, defining it if not available.

This fixes the build in those systems, noticed while building perf on a set of build containers.

Fixes 9fa5e1a180aa639f ("libbpf: Call memfd_create() syscall directly")
Cc Andrii Nakryiko <[email protected]>
Cc Daniel Borkmann <[email protected]>
---
 tools/lib/bpf/libbpf.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/lib/bpf/libbpf.c +0 -0
index efab29b8935bd9f7..635a38c6f947a34d 100644

tools/lib/bpf/libbpf.c static int sys_memfd_create(const char *name, unsigned flags) · line 1656

Quoted 7 lines
tools/lib/bpf/libbpf.c +4 -0
@@ -1650,6 +1650,10 @@ static int sys_memfd_create(const char *name, unsigned flags)
        return syscall(__NR_memfd_create, name, flags);
 }
 
+#ifndef MFD_CLOEXEC
+#define MFD_CLOEXEC 0x0001U
+#endif
+

makes sense, and lgtm. Do you need it in the bpf or bpf-next tree the most? your patch header doesn't specify this

Quoted 6 lines
tools/lib/bpf/libbpf.c +0 -1
 static int create_placeholder_fd(void)
 {
        int fd;
--

2.44.0

#2 lore raw
Quoted 26 lines · Andrii Nakryiko
Quoted 24 lines · Arnaldo Carvalho de Melo

Since its going directly to the syscall to avoid not having memfd_create() available in some systems, do the same for its MFD_CLOEXEC flags, defining it if not available.

This fixes the build in those systems, noticed while building perf on a set of build containers.

Fixes 9fa5e1a180aa639f ("libbpf: Call memfd_create() syscall directly")
Cc Andrii Nakryiko <[email protected]>
Cc Daniel Borkmann <[email protected]>
---
 tools/lib/bpf/libbpf.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/lib/bpf/libbpf.c +0 -0
index efab29b8935bd9f7..635a38c6f947a34d 100644
@@ -1650,6 +1650,10 @@ static int sys_memfd_create(const char *name, unsigned flags)
        return syscall(__NR_memfd_create, name, flags);
 }
 
Quoted 7 lines

tools/lib/bpf/libbpf.c static int sys_memfd_create(const char *name, unsigned flags) · line 1656

Quoted 4 lines
tools/lib/bpf/libbpf.c +4 -0
+#ifndef MFD_CLOEXEC
+#define MFD_CLOEXEC 0x0001U
+#endif
+

makes sense, and lgtm. Do you need it in the bpf or bpf-next tree the most? your patch header doesn't specify this

Modern distros don't have this problem, so its not urgent, if bpf-next is more convenient for you, so be it.

- Arnaldo

Quoted 7 lines
Quoted 7 lines
tools/lib/bpf/libbpf.c +0 -1
 static int create_placeholder_fd(void)
 {
        int fd;
--

2.44.0

#3 lore raw
In reply to Arnaldo Carvalho de Melo
This patch was applied to bpf/bpf.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Andrii Nakryiko <[email protected]>:

Quoted 8 lines · On Thu, 21 Mar 2024 13:01:58 -0300 you wrote:

Since its going directly to the syscall to avoid not having memfd_create() available in some systems, do the same for its MFD_CLOEXEC flags, defining it if not available.

This fixes the build in those systems, noticed while building perf on a set of build containers.

[...]

Here is the summary with links:
- [1/1] libbpf: Define MFD_CLOEXEC if not available

    https://git.kernel.org/bpf/bpf/c/ddb2ffdc474a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html