Re: [PATCH net-next 1/4] bpf: allow bpf programs to tail-call other bpf programs

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

 



On 05/20/2015 01:59 AM, Alexei Starovoitov wrote:
introduce bpf_tail_call(ctx, &jmp_table, index) helper function
which can be used from BPF programs like:
int bpf_prog(struct pt_regs *ctx)
{
   ...
   bpf_tail_call(ctx, &jmp_table, index);
   ...
}
that is roughly equivalent to:
int bpf_prog(struct pt_regs *ctx)
{
   ...
   if (jmp_table[index])
     return (*jmp_table[index])(ctx);
   ...
}
The important detail that it's not a normal call, but a tail call.
The kernel stack is precious, so this helper reuses the current
stack frame and jumps into another BPF program without adding
extra call frame.
It's trivially done in interpreter and a bit trickier in JITs.
In case of x64 JIT the bigger part of generated assembler prologue
is common for all programs, so it is simply skipped while jumping.
Other JITs can do similar prologue-skipping optimization or
do stack unwind before jumping into the next program.

...
Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxxxx>

LGTM, thanks!

Acked-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux