From: Alexei Starovoitov When the loader is generated there is no arena yet. libbpf maps the placeholder fd at map_extra in the process that generates it. "bpftool gen skeleton -L" dies with SIGBUS when the arena has variables. Skip the mapping. Refuse what the loader cannot do. Nobody maps the arena while the loader runs, so its address has to be in map_extra and it cannot have variables. The map of a jump table is created by the process that generates the loader. Its fd is valid only there and a signature doesn't cover its content. As before, the loader binds no arena: an insn has to refer to it. Signed-off-by: Alexei Starovoitov --- tools/lib/bpf/libbpf.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 9ff6a580078d..2b188e64e356 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -5940,7 +5940,7 @@ bpf_object__create_maps(struct bpf_object *obj) err = bpf_object__populate_internal_map(obj, map); if (err < 0) goto err_out; - } else if (map->def.type == BPF_MAP_TYPE_ARENA) { + } else if (map->def.type == BPF_MAP_TYPE_ARENA && !obj->gen_loader) { map->mmaped = mmap((void *)(long)map->map_extra, bpf_map_mmap_sz(map), PROT_READ | PROT_WRITE, map->map_extra ? MAP_SHARED | MAP_FIXED : MAP_SHARED, @@ -6625,6 +6625,11 @@ static int create_jt_map(struct bpf_object *obj, struct bpf_program *prog, struc __u64 *jt; __u32 i; + if (obj->gen_loader) { + pr_warn("prog '%s': gen_loader does not support jump tables\n", prog->name); + return -EOPNOTSUPP; + } + map_fd = find_jt_map(obj, prog, sym_off); if (map_fd >= 0) return map_fd; @@ -10241,10 +10246,21 @@ static void bpf_object_post_load_cleanup(struct bpf_object *obj, bool force) static int bpf_object_check_gen_loader(struct bpf_object *obj) { struct bpf_program *prog; + struct bpf_map *map; if (!obj->gen_loader) return 0; + /* nobody maps an arena before the programs are loaded */ + bpf_object__for_each_map(map, obj) { + if (map->def.type != BPF_MAP_TYPE_ARENA || !map->autocreate || + (map->map_extra && !obj->arena_data)) + continue; + pr_warn("map '%s': gen_loader needs an arena with map_extra and no variables\n", + map->name); + return -EOPNOTSUPP; + } + /* * gen_loader only records programs loaded by bpf_object__load_progs(), * which skips MANUAL ones. -- 2.55.0