Skip to content

Commit 6c6b414

Browse files
yuyuyurekaanakryiko
authored andcommitted
libbpf: Fix reuse of DEVMAP
Previously, re-using pinned DEVMAP maps would always fail, because get_map_info on a DEVMAP always returns flags with BPF_F_RDONLY_PROG set, but BPF_F_RDONLY_PROG being set on a map during creation is invalid. Thus, ignore the BPF_F_RDONLY_PROG flag in the flags returned from get_map_info when checking for compatibility with an existing DEVMAP. The same problem is handled in a third-party ebpf library: - cilium/ebpf#925 - cilium/ebpf#930 Fixes: 0cdbb4b ("devmap: Allow map lookups from eBPF") Signed-off-by: Yureka Lilian <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent abdaf49 commit 6c6b414

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5093,6 +5093,16 @@ static bool map_is_reuse_compat(const struct bpf_map *map, int map_fd)
50935093
return false;
50945094
}
50955095

5096+
/*
5097+
* bpf_get_map_info_by_fd() for DEVMAP will always return flags with
5098+
* BPF_F_RDONLY_PROG set, but it generally is not set at map creation time.
5099+
* Thus, ignore the BPF_F_RDONLY_PROG flag in the flags returned from
5100+
* bpf_get_map_info_by_fd() when checking for compatibility with an
5101+
* existing DEVMAP.
5102+
*/
5103+
if (map->def.type == BPF_MAP_TYPE_DEVMAP || map->def.type == BPF_MAP_TYPE_DEVMAP_HASH)
5104+
map_info.map_flags &= ~BPF_F_RDONLY_PROG;
5105+
50965106
return (map_info.type == map->def.type &&
50975107
map_info.key_size == map->def.key_size &&
50985108
map_info.value_size == map->def.value_size &&

0 commit comments

Comments
 (0)