All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	martin.lau@kernel.org
Cc: andrii@kernel.org, kernel-team@meta.com
Subject: [PATCH bpf-next 1/5] libbpf: call memfd_create() syscall directly
Date: Tue, 30 Jan 2024 11:36:45 -0800	[thread overview]
Message-ID: <20240130193649.3753476-2-andrii@kernel.org> (raw)
In-Reply-To: <20240130193649.3753476-1-andrii@kernel.org>

Some versions of Android do not implement memfd_create() wrapper in
their libc implementation, leading to build failures ([0]). On the other
hand, memfd_create() is available as a syscall on quite old kernels
(3.17+, while bpf() syscall itself is available since 3.18+), so it is
ok to assume that syscall availability and call into it with syscall()
helper to avoid Android-specific workarounds.

Validated in libbpf-bootstrap's CI ([1]).

  [0] https://github.com/libbpf/libbpf-bootstrap/actions/runs/7701003207/job/20986080319#step:5:83
  [1] https://github.com/libbpf/libbpf-bootstrap/actions/runs/7715988887/job/21031767212?pr=253

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/libbpf.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index db65ea59a05a..b21fda6b9b85 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1525,11 +1525,20 @@ static Elf64_Sym *find_elf_var_sym(const struct bpf_object *obj, const char *nam
 	return ERR_PTR(-ENOENT);
 }
 
+/* Some versions of Android don't provide memfd_create() in their libc
+ * implementation, so avoid complications and just go straight to Linux
+ * syscall.
+ */
+static int sys_memfd_create(const char *name, unsigned flags)
+{
+	return syscall(__NR_memfd_create, name, flags);
+}
+
 static int create_placeholder_fd(void)
 {
 	int fd;
 
-	fd = ensure_good_fd(memfd_create("libbpf-placeholder-fd", MFD_CLOEXEC));
+	fd = ensure_good_fd(sys_memfd_create("libbpf-placeholder-fd", MFD_CLOEXEC));
 	if (fd < 0)
 		return -errno;
 	return fd;
-- 
2.34.1


  reply	other threads:[~2024-01-30 19:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30 19:36 [PATCH bpf-next 0/5] Libbpf API and memfd_create() fixes Andrii Nakryiko
2024-01-30 19:36 ` Andrii Nakryiko [this message]
2024-01-31  5:04   ` [PATCH bpf-next 1/5] libbpf: call memfd_create() syscall directly Yonghong Song
2024-01-30 19:36 ` [PATCH bpf-next 2/5] libbpf: add missing LIBBPF_API annotation to libbpf_set_memlock_rlim API Andrii Nakryiko
2024-01-31  5:16   ` Yonghong Song
2024-01-31 17:09     ` Andrii Nakryiko
2024-01-31 17:23       ` Yonghong Song
2024-01-31 17:37         ` Andrii Nakryiko
2024-01-30 19:36 ` [PATCH bpf-next 3/5] libbpf: add btf__new_split() API that was declared but not implemented Andrii Nakryiko
2024-01-31  5:30   ` Yonghong Song
2024-01-31 17:20     ` Andrii Nakryiko
2024-01-31 17:27       ` Yonghong Song
2024-01-30 19:36 ` [PATCH bpf-next 4/5] libbpf: add missed btf_ext__raw_data() API Andrii Nakryiko
2024-01-31  7:39   ` Yonghong Song
2024-01-30 19:36 ` [PATCH bpf-next 5/5] selftests/bpf: fix bench runner SIGSEGV Andrii Nakryiko
2024-01-31  7:41   ` Yonghong Song
2024-01-31 17:17     ` Andrii Nakryiko
2024-01-31 17:25       ` Yonghong Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240130193649.3753476-2-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.