Skip to contentSkip to conversation

libbpf: Skip the pinning of global data map for old kernels.

PATCH In review Shuyi Cheng 2 participants 3 messages Dec 9, 2021 – Dec 10, 2021

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

PATCH 1/1 libbpf: Skip the pinning of global data map for old kernels.

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/[email protected]

---
 tools/lib/bpf/libbpf.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/lib/bpf/libbpf.c +4 -0
index 6db0b5e8540e..d96cf49cebab 100644
@@ -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;
 
Signature · 1 line
2.19.1.6.gb485710b
#1 lore raw
Quoted 21 lines · Shuyi Cheng

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/[email protected]

---
  tools/lib/bpf/libbpf.c | 4 ++++
  1 file changed, 4 insertions(+)
tools/lib/bpf/libbpf.c +0 -0
index 6db0b5e8540e..d96cf49cebab 100644

tools/lib/bpf/libbpf.c int bpf_object__pin_maps(struct bpf_object *obj, · line 7889

Quoted 6 lines
tools/lib/bpf/libbpf.c +2 -0
@@ -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?

Quoted 7 lines
tools/lib/bpf/libbpf.c +2 -1
+                       continue;
+
                if (path) {
                        int len;
 
--

2.19.1.6.gb485710b

#2 lore raw
Quoted 27 lines · Andrii Nakryiko
Quoted 25 lines · Shuyi Cheng

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/[email protected]

---
   tools/lib/bpf/libbpf.c | 4 ++++
   1 file changed, 4 insertions(+)
tools/lib/bpf/libbpf.c +0 -0
index 6db0b5e8540e..d96cf49cebab 100644
@@ -7884,6 +7884,10 @@ int bpf_object__pin_maps(struct bpf_object *obj,
 const char *path)
                 char *pin_path = NULL;
                 char buf[PATH_MAX];
 
Quoted 8 lines

tools/lib/bpf/libbpf.c int bpf_object__pin_maps(struct bpf_object *obj, const char *path) · line 7888

Quoted 2 lines
tools/lib/bpf/libbpf.c +2 -0
+               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 7 lines
Quoted 7 lines
tools/lib/bpf/libbpf.c +2 -1
+                       continue;
+
                 if (path) {
                         int len;
 
--

2.19.1.6.gb485710b