Skip to content

Commit 229fae3

Browse files
chengshuyianakryiko
authored andcommitted
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: 16e0c35 ("libbpf: Load global data maps lazily on legacy kernels") Signed-off-by: Shuyi Cheng <chengshuyi@linux.alibaba.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
1 parent b69c5c0 commit 229fae3

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎tools/lib/bpf/libbpf.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ struct bpf_map {
431431
char *pin_path;
432432
bool pinned;
433433
bool reused;
434+
bool skipped;
434435
__u64 map_extra;
435436
};
436437

@@ -5087,8 +5088,10 @@ bpf_object__create_maps(struct bpf_object *obj)
50875088
* kernels.
50885089
*/
50895090
if (bpf_map__is_internal(map) &&
5090-
!kernel_supports(obj, FEAT_GLOBAL_DATA))
5091+
!kernel_supports(obj, FEAT_GLOBAL_DATA)) {
5092+
map->skipped = true;
50915093
continue;
5094+
}
50925095

50935096
retried = false;
50945097
retry:
@@ -5717,8 +5720,7 @@ bpf_object__relocate_data(struct bpf_object *obj, struct bpf_program *prog)
57175720
} else {
57185721
const struct bpf_map *map = &obj->maps[relo->map_idx];
57195722

5720-
if (bpf_map__is_internal(map) &&
5721-
!kernel_supports(obj, FEAT_GLOBAL_DATA)) {
5723+
if (map->skipped) {
57225724
pr_warn("prog '%s': relo #%d: kernel doesn't support global data\n",
57235725
prog->name, i);
57245726
return -ENOTSUP;
@@ -7926,6 +7928,9 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path)
79267928
char *pin_path = NULL;
79277929
char buf[PATH_MAX];
79287930

7931+
if (map->skipped)
7932+
continue;
7933+
79297934
if (path) {
79307935
int len;
79317936

0 commit comments

Comments
 (0)