Commit 229fae38 authored by Shuyi Cheng's avatar Shuyi Cheng Committed by Andrii Nakryiko

libbpf: Add "bool skipped" to struct bpf_map

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. Therefore, when the map is not
created, we mark “map->skipped" as true and then check during relocation
and during pinning.

Fixes: 16e0c35c ("libbpf: Load global data maps lazily on legacy kernels")
Signed-off-by: default avatarShuyi Cheng <chengshuyi@linux.alibaba.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
parent b69c5c07
...@@ -431,6 +431,7 @@ struct bpf_map { ...@@ -431,6 +431,7 @@ struct bpf_map {
char *pin_path; char *pin_path;
bool pinned; bool pinned;
bool reused; bool reused;
bool skipped;
__u64 map_extra; __u64 map_extra;
}; };
...@@ -5087,8 +5088,10 @@ bpf_object__create_maps(struct bpf_object *obj) ...@@ -5087,8 +5088,10 @@ bpf_object__create_maps(struct bpf_object *obj)
* kernels. * kernels.
*/ */
if (bpf_map__is_internal(map) && if (bpf_map__is_internal(map) &&
!kernel_supports(obj, FEAT_GLOBAL_DATA)) !kernel_supports(obj, FEAT_GLOBAL_DATA)) {
map->skipped = true;
continue; continue;
}
retried = false; retried = false;
retry: retry:
...@@ -5717,8 +5720,7 @@ bpf_object__relocate_data(struct bpf_object *obj, struct bpf_program *prog) ...@@ -5717,8 +5720,7 @@ bpf_object__relocate_data(struct bpf_object *obj, struct bpf_program *prog)
} else { } else {
const struct bpf_map *map = &obj->maps[relo->map_idx]; const struct bpf_map *map = &obj->maps[relo->map_idx];
if (bpf_map__is_internal(map) && if (map->skipped) {
!kernel_supports(obj, FEAT_GLOBAL_DATA)) {
pr_warn("prog '%s': relo #%d: kernel doesn't support global data\n", pr_warn("prog '%s': relo #%d: kernel doesn't support global data\n",
prog->name, i); prog->name, i);
return -ENOTSUP; return -ENOTSUP;
...@@ -7926,6 +7928,9 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path) ...@@ -7926,6 +7928,9 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path)
char *pin_path = NULL; char *pin_path = NULL;
char buf[PATH_MAX]; char buf[PATH_MAX];
if (map->skipped)
continue;
if (path) { if (path) {
int len; int len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment