On Thu, 2025-07-17 at 17:10 -0700, Andrii Nakryiko wrote: > Initial __arean global variable support implementation in libbpf > contains a bug: it remembers struct bpf_map pointer for arena, which is > used later on to process relocations. Recording this pointer is > problematic because map pointers are not stable during ELF relocation > collection phase, as an array of struct bpf_map's can be reallocated, > invalidating all the pointers. Libbpf is dealing with similar issues by > using a stable internal map index, though for BPF arena map specifically > this approach wasn't used due to an oversight. > > The resulting behavior is non-deterministic issue which depends on exact > layout of ELF object file, number of actual maps, etc. We didn't hit > this until very recently, when this bug started triggering crash in BPF > CI when validating one of sched-ext BPF programs. > > The fix is rather straightforward: we just follow an established pattern > of remembering map index (just like obj->kconfig_map_idx, for example) > instead of `struct bpf_map *`, and resolving index to a pointer at the > point where map information is necessary. > > While at it also add debug-level message for arena-related relocation > resolution information, which we already have for all other kinds of > maps. > > Fixes: 2e7ba4f8fd1f ("libbpf: Recognize __arena global variables.") > Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > --- Tested using scx jobs failing on CI: https://github.com/kernel-patches/bpf/actions/runs/16354530864/artifacts/3558110958 The change lgtm. Tested-by: Eduard Zingerman <eddyz87@xxxxxxxxx> [...]