From: Stijn Tintel <stijn@linux-ipv6.be>
To: toke@redhat.com, netdev@vger.kernel.org
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
kpsingh@kernel.org, john.fastabend@gmail.com, yhs@fb.com,
songliubraving@fb.com, kafai@fb.com, andrii@kernel.org,
daniel@iogearbox.net, ast@kernel.org
Subject: [PATCH] libbpf: fix BPF_MAP_TYPE_PERF_EVENT_ARRAY auto-pinning
Date: Tue, 22 Feb 2022 22:42:36 +0200 [thread overview]
Message-ID: <20220222204236.2192513-1-stijn@linux-ipv6.be> (raw)
When a BPF map of type BPF_MAP_TYPE_PERF_EVENT_ARRAY doesn't have the
max_entries parameter set, this parameter will be set to the number of
possible CPUs. Due to this, the map_is_reuse_compat function will return
false, causing the following error when trying to reuse the map:
libbpf: couldn't reuse pinned map at '/sys/fs/bpf/m_logging': parameter mismatch
Fix this by checking against the number of possible CPUs if the
max_entries parameter is not set in the map definition.
Fixes: 57a00f41644f ("libbpf: Add auto-pinning of maps when loading BPF objects")
Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
---
tools/lib/bpf/libbpf.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 7f10dd501a52..b076ab728f0e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -4750,7 +4750,7 @@ static bool map_is_reuse_compat(const struct bpf_map *map, int map_fd)
struct bpf_map_info map_info = {};
char msg[STRERR_BUFSIZE];
__u32 map_info_len;
- int err;
+ int def_max_entries, err;
map_info_len = sizeof(map_info);
@@ -4763,10 +4763,15 @@ static bool map_is_reuse_compat(const struct bpf_map *map, int map_fd)
return false;
}
+ if (map->def.type == BPF_MAP_TYPE_PERF_EVENT_ARRAY && !map->def.max_entries)
+ def_max_entries = libbpf_num_possible_cpus();
+ else
+ def_max_entries = map->def.max_entries;
+
return (map_info.type == map->def.type &&
map_info.key_size == map->def.key_size &&
map_info.value_size == map->def.value_size &&
- map_info.max_entries == map->def.max_entries &&
+ map_info.max_entries == def_max_entries &&
map_info.map_flags == map->def.map_flags &&
map_info.map_extra == map->map_extra);
}
--
2.34.1
next reply other threads:[~2022-02-22 20:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 20:42 Stijn Tintel [this message]
2022-02-23 2:36 ` Song Liu
2022-02-23 23:15 ` Andrii Nakryiko
2022-02-24 10:08 ` Stijn Tintel
2022-02-24 15:38 ` Stijn Tintel
2022-02-25 3:48 ` Song Liu
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=20220222204236.2192513-1-stijn@linux-ipv6.be \
--to=stijn@linux-ipv6.be \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=toke@redhat.com \
--cc=yhs@fb.com \
/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
all inboxes | Powered by JetHome®