bpf: propagate poke descriptors to subprograms
authorMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Wed, 16 Sep 2020 21:10:05 +0000 (23:10 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 17 Sep 2020 19:59:31 +0000 (12:59 -0700)
commita748c6975dea325da540610c2ba9b5f332c603e6
tree9d380f6dab08bd114fb3a6328a16fc407e9d16c2
parent0d4ddce300bd9031a36b55451045d505ebf7cae2
bpf: propagate poke descriptors to subprograms

Previously, there was no need for poke descriptors being present in
subprogram's bpf_prog_aux struct since tailcalls were simply not allowed
in them. Each subprog is JITed independently so in order to enable
JITing subprograms that use tailcalls, do the following:

- in fixup_bpf_calls() store the index of tailcall insn onto the generated
  poke descriptor,
- in case when insn patching occurs, adjust the tailcall insn idx from
  bpf_patch_insn_data,
- then in jit_subprogs() check whether the given poke descriptor belongs
  to the current subprog by checking if that previously stored absolute
  index of tail call insn is in the scope of the insns of given subprog,
- update the insn->imm with new poke descriptor slot so that while JITing
  the proper poke descriptor will be grabbed

This way each of the main program's poke descriptors are distributed
across the subprograms poke descriptor array, so main program's
descriptors can be untracked out of the prog array map.

Add also subprog's aux struct to the BPF map poke_progs list by calling
on it map_poke_track().

In case of any error, call the map_poke_untrack() on subprog's aux
structs that have already been registered to prog array map.

Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf.h
kernel/bpf/verifier.c