Re: [PATCH bpf-next v4 07/10] bpf: Support calling non-tailcall bpf prog

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 10/10/24 1:28 PM, Alexei Starovoitov wrote:
On Thu, Oct 10, 2024 at 10:56 AM Yonghong Song <yonghong.song@xxxxxxxxx> wrote:
A kfunc bpf_prog_call() is introduced such that it can call another bpf
prog within a bpf prog. It has the same parameters as bpf_tail_call()
but acts like a normal function call.

But bpf_prog_call() could recurse to the caller prog itself. So if a bpf
prog calls bpf_prog_call(), that bpf prog will use private stacks with
maximum recursion level 4. The 4 level recursion should work for most
cases.

bpf_prog_call() cannot be used if tail_call exists in the same prog
since tail_call does not use private stack. If both prog_call and
tail_call in the same prog, verification will fail.
..

+__bpf_kfunc int bpf_prog_call(void *ctx, struct bpf_map *p__map, u32 index)
+{
+       struct bpf_array *array;
+       struct bpf_prog *prog;
+
+       if (p__map->map_type != BPF_MAP_TYPE_PROG_ARRAY)
+               return -EINVAL;
+
+       array = container_of(p__map, struct bpf_array, map);
+       if (unlikely(index >= array->map.max_entries))
+               return -E2BIG;
+
+       prog = READ_ONCE(array->ptrs[index]);
+       if (!prog)
+               return -ENOENT;
+
+       return bpf_prog_run(prog, ctx);
+}
bpf_tail_call() was a hack during the early days,
since I didn't know any better :(
I really don't want to use that as a pattern.
prog life time rules, tail call cnt, prog_array_compatible, etc.
caused plenty of pain. Don't want to see a repeat.

Progs that need to call another prog can use freplace mechanism already.
There is no need for bpf_prog_call.

In this case, it could call itself.


Let's get priv_stack in shape first (the first ~6 patches).

I am okay to focus on the first 6 patches. But I would like to get
Tejun's comments about what is the best way to support hierarchical
bpf based scheduler.


pw-bot: cr




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux