On Tue, Jul 1, 2025 at 5:34 PM Emil Tsalapatis <emil@xxxxxxxxxxxxxxx> wrote: > > Add a new BPF arena kfunc for reserving a range of arena virtual > addresses without backing them with pages. This prevents the range from > being populated using bpf_arena_alloc_pages(). > > Signed-off-by: Emil Tsalapatis <emil@xxxxxxxxxxxxxxx> > --- > kernel/bpf/arena.c | 43 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) > > diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c > index 0d56cea71602..18db8b826836 100644 > --- a/kernel/bpf/arena.c > +++ b/kernel/bpf/arena.c > @@ -550,6 +550,34 @@ static void arena_free_pages(struct bpf_arena *arena, long uaddr, long page_cnt) > } > } > > +/* > + * Reserve an arena virtual address range without populating it. This call stops > + * bpf_arena_alloc_pages from adding pages to this range. > + */ > +static int arena_reserve_pages(struct bpf_arena *arena, long uaddr, u32 page_cnt) > +{ > + long page_cnt_max = (arena->user_vm_end - arena->user_vm_start) >> PAGE_SHIFT; > + long pgoff; > + int ret; > + > + if (uaddr & ~PAGE_MASK) > + return 0; > + > + pgoff = compute_pgoff(arena, uaddr); > + if (pgoff + page_cnt > page_cnt_max) > + return -EINVAL; > + > + guard(mutex)(&arena->lock); > + > + /* Cannot guard already allocated pages. */ > + ret = is_range_tree_set(&arena->rt, pgoff, page_cnt); > + if (ret) > + return -EALREADY; Overall looks good, but this error code gives me a pause. We never used it in a bpf subsystem. We typically return EBUSY in such cases. Unless there is a strong reason to use this new error code my preference is to stick to old code. -- pw-bot: cr