On Mon, Nov 18, 2019 at 5:38 PM Daniel Borkmann <daniel@xxxxxxxxxxxxx> wrote: > > Add tracking of constant keys into tail call maps. The signature of > bpf_tail_call_proto is that arg1 is ctx, arg2 map pointer and arg3 > is a index key. The direct call approach for tail calls can be enabled > if the verifier asserted that for all branches leading to the tail call > helper invocation, the map pointer and index key were both constant > and the same. > > Tracking of map pointers we already do from prior work via c93552c443eb > ("bpf: properly enforce index mask to prevent out-of-bounds speculation") > and 09772d92cd5a ("bpf: avoid retpoline for lookup/update/ delete calls > on maps"). > > Given the tail call map index key is not on stack but directly in the > register, we can add similar tracking approach and later in fixup_bpf_calls() > add a poke descriptor to the progs poke_tab with the relevant information > for the JITing phase. > > We internally reuse insn->imm for the rewritten BPF_JMP | BPF_TAIL_CALL > instruction in order to point into the prog's poke_tab, and keep insn->imm > as 0 as indicator that current indirect tail call emission must be used. > > Future work can generalize and add similar approach to optimize plain > array map lookups. Difference there is that we need to look into the key > value that sits on stack. For clarity in bpf_insn_aux_data, map_state > has been renamed into map_ptr_state, so we get map_{ptr,key}_state as > trackers. > > Signed-off-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx> > --- LGTM. Acked-by: Andrii Nakryiko <andriin@xxxxxx> > include/linux/bpf_verifier.h | 3 +- > kernel/bpf/verifier.c | 116 ++++++++++++++++++++++++++++++++--- > 2 files changed, 110 insertions(+), 9 deletions(-) > [...]