From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
martin.lau@kernel.org
Cc: kernel-team@meta.com, Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH v2 bpf-next 5/9] libbpf: use stable map placeholder FDs
Date: Wed, 03 Jan 2024 22:57:33 +0200 [thread overview]
Message-ID: <b40c235a580968400316d464e14a8a72f09d2013.camel@gmail.com> (raw)
In-Reply-To: <20240102190055.1602698-6-andrii@kernel.org>
Tbh, it looks like calls to zclose(map->fd) were unnecessary
regardless of this patch, as all maps are closed at the end of
bpf_object_load() in case of an error.
[...]
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index f29cfb344f80..e0085aef17d7 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
[...]
> @@ -5275,13 +5289,11 @@ static int bpf_object_create_map(struct bpf_object *obj, struct bpf_map *map, bo
> create_attr.btf_value_type_id = 0;
> map->btf_key_type_id = 0;
> map->btf_value_type_id = 0;
> - map->fd = bpf_map_create(def->type, map_name,
> - def->key_size, def->value_size,
> - def->max_entries, &create_attr);
> + map_fd = bpf_map_create(def->type, map_name,
> + def->key_size, def->value_size,
> + def->max_entries, &create_attr);
> }
>
> - err = map->fd < 0 ? -errno : 0;
> -
> if (bpf_map_type_is_map_in_map(def->type) && map->inner_map) {
> if (obj->gen_loader)
> map->inner_map->fd = -1;
> @@ -5289,7 +5301,19 @@ static int bpf_object_create_map(struct bpf_object *obj, struct bpf_map *map, bo
> zfree(&map->inner_map);
> }
>
> - return err;
> + if (map_fd < 0)
> + return -errno;
Nit: this check is now placed after call to bpf_map_destroy(),
which might call munmap(), which might overwrite "errno",
set by some of the previous calls to bpf_map_create().
[...]
> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index b5d334754e5d..662a3df1e29f 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -555,6 +555,30 @@ static inline int ensure_good_fd(int fd)
> return fd;
> }
>
> +static inline int create_placeholder_fd(void)
> +{
> + int fd;
> +
> + fd = ensure_good_fd(open("/dev/null", O_WRONLY | O_CLOEXEC));
Stupid question: is it ok to assume that /dev is always mounted?
Googling says that kernel chooses if to mount it automatically
depending on the value of CONFIG_DEVTMPFS_MOUNT option.
Another option might be memfd_create().
> + if (fd < 0)
> + return -errno;
> + return fd;
> +}
[...]
next prev parent reply other threads:[~2024-01-03 20:57 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-02 19:00 [PATCH v2 bpf-next 0/9] Libbpf-side __arg_ctx fallback support Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 1/9] libbpf: name internal functions consistently Andrii Nakryiko
2024-01-03 23:12 ` Alexei Starovoitov
2024-01-03 23:17 ` Eduard Zingerman
2024-01-04 0:30 ` Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 2/9] libbpf: make uniform use of btf__fd() accessor inside libbpf Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 3/9] libbpf: use explicit map reuse flag to skip map creation steps Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 4/9] libbpf: don't rely on map->fd as an indicator of map being created Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 5/9] libbpf: use stable map placeholder FDs Andrii Nakryiko
2024-01-03 20:57 ` Eduard Zingerman [this message]
2024-01-03 22:46 ` Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 6/9] libbpf: move exception callbacks assignment logic into relocation step Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 7/9] libbpf: move BTF loading step after " Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 8/9] libbpf: implement __arg_ctx fallback logic Andrii Nakryiko
2024-01-03 20:57 ` Eduard Zingerman
2024-01-03 23:10 ` Andrii Nakryiko
2024-01-03 23:43 ` Eduard Zingerman
2024-01-03 23:59 ` Andrii Nakryiko
2024-01-04 0:09 ` Eduard Zingerman
2024-01-04 0:27 ` Andrii Nakryiko
2024-01-02 19:00 ` [PATCH v2 bpf-next 9/9] selftests/bpf: add arg:ctx cases to test_global_funcs tests Andrii Nakryiko
2024-01-03 20:57 ` Eduard Zingerman
2024-01-03 23:17 ` Andrii Nakryiko
2024-01-03 23:51 ` Eduard Zingerman
2024-01-04 0:26 ` Andrii Nakryiko
2024-01-04 0:28 ` Eduard Zingerman
2024-01-02 19:57 ` [PATCH v2 bpf-next 0/9] Libbpf-side __arg_ctx fallback support Andrii Nakryiko
2024-01-03 20:57 ` Eduard Zingerman
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=b40c235a580968400316d464e14a8a72f09d2013.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jolsa@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox