aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/arraymap.c
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2017-08-18 21:12:46 -0400
committerDavid S. Miller <davem@davemloft.net>2017-08-20 00:56:34 -0400
commit7b0c2a0508b90fce79d3782b2e55d0e8bf6a283e (patch)
tree859903eeb8d19cdfeb44fac4c72e594058534a56 /kernel/bpf/arraymap.c
parent89c63074c2bc25874e4e72406ff15a9a8e3df750 (diff)
bpf: inline map in map lookup functions for array and htab
Avoid two successive functions calls for the map in map lookup, first is the bpf_map_lookup_elem() helper call, and second the callback via map->ops->map_lookup_elem() to get to the map in map implementation. Implementation inlines array and htab flavor for map in map lookups. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/arraymap.c')
-rw-r--r--kernel/bpf/arraymap.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 96e9c5c1dfc9..98c0f00c3f5e 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -606,6 +606,31 @@ static void *array_of_map_lookup_elem(struct bpf_map *map, void *key)
606 return READ_ONCE(*inner_map); 606 return READ_ONCE(*inner_map);
607} 607}
608 608
609static u32 array_of_map_gen_lookup(struct bpf_map *map,
610 struct bpf_insn *insn_buf)
611{
612 u32 elem_size = round_up(map->value_size, 8);
613 struct bpf_insn *insn = insn_buf;
614 const int ret = BPF_REG_0;
615 const int map_ptr = BPF_REG_1;
616 const int index = BPF_REG_2;
617
618 *insn++ = BPF_ALU64_IMM(BPF_ADD, map_ptr, offsetof(struct bpf_array, value));
619 *insn++ = BPF_LDX_MEM(BPF_W, ret, index, 0);
620 *insn++ = BPF_JMP_IMM(BPF_JGE, ret, map->max_entries, 5);
621 if (is_power_of_2(elem_size))
622 *insn++ = BPF_ALU64_IMM(BPF_LSH, ret, ilog2(elem_size));
623 else
624 *insn++ = BPF_ALU64_IMM(BPF_MUL, ret, elem_size);
625 *insn++ = BPF_ALU64_REG(BPF_ADD, ret, map_ptr);
626 *insn++ = BPF_LDX_MEM(BPF_DW, ret, ret, 0);
627 *insn++ = BPF_JMP_IMM(BPF_JEQ, ret, 0, 1);
628 *insn++ = BPF_JMP_IMM(BPF_JA, 0, 0, 1);
629 *insn++ = BPF_MOV64_IMM(ret, 0);
630
631 return insn - insn_buf;
632}
633
609const struct bpf_map_ops array_of_maps_map_ops = { 634const struct bpf_map_ops array_of_maps_map_ops = {
610 .map_alloc = array_of_map_alloc, 635 .map_alloc = array_of_map_alloc,
611 .map_free = array_of_map_free, 636 .map_free = array_of_map_free,
@@ -615,4 +640,5 @@ const struct bpf_map_ops array_of_maps_map_ops = {
615 .map_fd_get_ptr = bpf_map_fd_get_ptr, 640 .map_fd_get_ptr = bpf_map_fd_get_ptr,
616 .map_fd_put_ptr = bpf_map_fd_put_ptr, 641 .map_fd_put_ptr = bpf_map_fd_put_ptr,
617 .map_fd_sys_lookup_elem = bpf_map_fd_sys_lookup_elem, 642 .map_fd_sys_lookup_elem = bpf_map_fd_sys_lookup_elem,
643 .map_gen_lookup = array_of_map_gen_lookup,
618}; 644};