bpf_arena_get_kern_vm_start() takes a struct bpf_arena *. The struct itself isn't exposed, so callers outside arena.c that hold only a struct bpf_map * (e.g. struct_ops subsystems handling an arena map fd) can't reach it. Add bpf_arena_map_kern_vm_start() which takes struct bpf_map * and container_of()s to the arena, with a type check. A sched_ext follow-up needs this to translate kern_va <-> uaddr for arena pages it claims. Signed-off-by: Tejun Heo --- include/linux/bpf.h | 1 + kernel/bpf/arena.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 587e5ff387bf..1614af65a2d1 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -617,6 +617,7 @@ void bpf_rb_root_free(const struct btf_field *field, void *rb_root, struct bpf_spin_lock *spin_lock); u64 bpf_arena_get_kern_vm_start(struct bpf_arena *arena); u64 bpf_arena_get_user_vm_start(struct bpf_arena *arena); +u64 bpf_arena_map_kern_vm_start(struct bpf_map *map); int bpf_obj_name_cpy(char *dst, const char *src, unsigned int size); struct bpf_offload_dev; diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c index 73e43617761c..d67a6000221d 100644 --- a/kernel/bpf/arena.c +++ b/kernel/bpf/arena.c @@ -85,6 +85,19 @@ u64 bpf_arena_get_user_vm_start(struct bpf_arena *arena) return arena ? arena->user_vm_start : 0; } +/** + * bpf_arena_map_kern_vm_start - kern_vm_start lookup by struct bpf_map * + * @map: a BPF_MAP_TYPE_ARENA map + * + * Return @map's kern_vm_start, or 0 (with WARN) if @map isn't an arena. + */ +u64 bpf_arena_map_kern_vm_start(struct bpf_map *map) +{ + if (WARN_ON_ONCE(!map || map->map_type != BPF_MAP_TYPE_ARENA)) + return 0; + return bpf_arena_get_kern_vm_start(container_of(map, struct bpf_arena, map)); +} + static long arena_map_peek_elem(struct bpf_map *map, void *value) { return -EOPNOTSUPP; -- 2.53.0