mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
bpf/arena: Add bpf_arena_map_kern_vm_start() and bpf_prog_arena()
struct bpf_arena is opaque to callers outside arena.c. Add two helpers
for struct_ops subsystems that need to reach into an arena:
bpf_arena_map_kern_vm_start(struct bpf_map *map)
returns @map's kern_vm_start. A sched_ext follow-up needs this
to translate kern_va <-> uaddr.
bpf_prog_arena(struct bpf_prog *prog)
returns the bpf_map of the arena referenced by @prog (NULL if
@prog references no arena). The verifier enforces at most one
arena per program. Used by struct_ops callers that auto-discover
an arena from a member prog and need to take a map reference.
Suggested-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
Link: https://lore.kernel.org/r/20260522172219.1423324-6-tj@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
7c48a28c1b
commit
53cc12a2dc
|
|
@ -618,6 +618,8 @@ 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);
|
||||
struct bpf_map *bpf_prog_arena(struct bpf_prog *prog);
|
||||
int bpf_obj_name_cpy(char *dst, const char *src, unsigned int size);
|
||||
|
||||
struct bpf_offload_dev;
|
||||
|
|
|
|||
|
|
@ -84,6 +84,32 @@ 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.
|
||||
*/
|
||||
u64 bpf_arena_map_kern_vm_start(struct bpf_map *map)
|
||||
{
|
||||
return bpf_arena_get_kern_vm_start(container_of(map, struct bpf_arena, map));
|
||||
}
|
||||
|
||||
/**
|
||||
* bpf_prog_arena - return the bpf_map of the arena referenced by @prog
|
||||
* @prog: a loaded BPF program
|
||||
*
|
||||
* The verifier enforces at most one arena per program and stores it in
|
||||
* prog->aux->arena. Return that arena's underlying bpf_map, or NULL if
|
||||
* @prog does not reference an arena.
|
||||
*/
|
||||
struct bpf_map *bpf_prog_arena(struct bpf_prog *prog)
|
||||
{
|
||||
struct bpf_arena *arena = prog->aux->arena;
|
||||
|
||||
return arena ? &arena->map : NULL;
|
||||
}
|
||||
|
||||
static long arena_map_peek_elem(struct bpf_map *map, void *value)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user