[PATCH bpf-next] libbpf: Skip the pinning of global data map for old kernels.

Subsystems: bpf [general] (safe dynamic programs and tools), bpf [library] (libbpf), the rest

STALE1761d

3 messages, 2 authors, 2021-12-10 · open the first message on its own page

[PATCH bpf-next] libbpf: Skip the pinning of global data map for old kernels.

From: Shuyi Cheng <hidden>
Date: 2021-12-09 08:44:20

Fix error: "failed to pin map: Bad file descriptor, path:
/sys/fs/bpf/_rodata_str1_1."

In the old kernel, the global data map will not be created, see [0]. So
we should skip the pinning of the global data map to avoid bpf_object__pin_maps returning error.

[0]: https://lore.kernel.org/bpf/20211123200105.387855-1-andrii@kernel.org

Signed-off-by: Shuyi Cheng <redacted>
---
 tools/lib/bpf/libbpf.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 6db0b5e8540e..d96cf49cebab 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7884,6 +7884,10 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path)
 		char *pin_path = NULL;
 		char buf[PATH_MAX];

+		if (bpf_map__is_internal(map) &&
+		    !kernel_supports(obj, FEAT_GLOBAL_DATA))
+			continue;
+
 		if (path) {
 			int len;
-- 
2.19.1.6.gb485710b

Re: [PATCH bpf-next] libbpf: Skip the pinning of global data map for old kernels.

From: Andrii Nakryiko <hidden>
Date: 2021-12-09 17:26:26

On Thu, Dec 9, 2021 at 12:44 AM Shuyi Cheng
[off-list ref] wrote:
quoted hunk

Fix error: "failed to pin map: Bad file descriptor, path:
/sys/fs/bpf/_rodata_str1_1."

In the old kernel, the global data map will not be created, see [0]. So
we should skip the pinning of the global data map to avoid
bpf_object__pin_maps returning error.

[0]: https://lore.kernel.org/bpf/20211123200105.387855-1-andrii@kernel.org

Signed-off-by: Shuyi Cheng <redacted>
---
  tools/lib/bpf/libbpf.c | 4 ++++
  1 file changed, 4 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 6db0b5e8540e..d96cf49cebab 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7884,6 +7884,10 @@ int bpf_object__pin_maps(struct bpf_object *obj,
const char *path)
                char *pin_path = NULL;
                char buf[PATH_MAX];

+               if (bpf_map__is_internal(map) &&
+                   !kernel_supports(obj, FEAT_GLOBAL_DATA))

doing the same check in 3 different places sucks. Let's add "bool
skipped" to struct bpf_map, which will be set in one place (at the map
creation time) and then check during relocation and during pinning?
+                       continue;
+
                if (path) {
                        int len;

--
2.19.1.6.gb485710b

Re: [PATCH bpf-next] libbpf: Skip the pinning of global data map for old kernels.

From: Shuyi Cheng <hidden>
Date: 2021-12-10 03:02:44


On 12/10/21 1:26 AM, Andrii Nakryiko wrote:
On Thu, Dec 9, 2021 at 12:44 AM Shuyi Cheng
[off-list ref] wrote:
quoted

Fix error: "failed to pin map: Bad file descriptor, path:
/sys/fs/bpf/_rodata_str1_1."

In the old kernel, the global data map will not be created, see [0]. So
we should skip the pinning of the global data map to avoid
bpf_object__pin_maps returning error.

[0]: https://lore.kernel.org/bpf/20211123200105.387855-1-andrii@kernel.org

Signed-off-by: Shuyi Cheng <redacted>
---
   tools/lib/bpf/libbpf.c | 4 ++++
   1 file changed, 4 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 6db0b5e8540e..d96cf49cebab 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7884,6 +7884,10 @@ int bpf_object__pin_maps(struct bpf_object *obj,
const char *path)
                 char *pin_path = NULL;
                 char buf[PATH_MAX];

+               if (bpf_map__is_internal(map) &&
+                   !kernel_supports(obj, FEAT_GLOBAL_DATA))

doing the same check in 3 different places sucks. Let's add "bool
skipped" to struct bpf_map, which will be set in one place (at the map
creation time) and then check during relocation and during pinning?
Agree, thanks.

regards,
Shuyi


quoted
+                       continue;
+
                 if (path) {
                         int len;

--
2.19.1.6.gb485710b
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help