Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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:
- https://github.com/cilium/ebpf/issues/925
- https://github.com/cilium/ebpf/pull/930

Fixes: 0cdbb4b09a06 ("devmap: Allow map lookups from eBPF")
Signed-off-by: Yureka Lilian <yuka@yuka.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250814180113.1245565-3-yuka@yuka.dev

authored by

Yureka Lilian and committed by
Andrii Nakryiko
6c6b4146 abdaf49b

+10
+10
tools/lib/bpf/libbpf.c
··· 5093 5093 return false; 5094 5094 } 5095 5095 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 + 5096 5106 return (map_info.type == map->def.type && 5097 5107 map_info.key_size == map->def.key_size && 5098 5108 map_info.value_size == map->def.value_size &&