nfp: bpf: add map updates from the datapath
authorJakub Kicinski <jakub.kicinski@netronome.com>
Thu, 29 Mar 2018 00:48:31 +0000 (17:48 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 29 Mar 2018 02:36:13 +0000 (19:36 -0700)
Support calling map_update_elem() from the datapath programs
by calling into FW-provided helper.  Value pointer is passed
in LM pointer #2.  Keeping track of old state for arg3 is not
necessary, since LM pointer #2 will be always loaded in this
case, the trivial optimization for value at the bottom of the
stack can't be done here.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jiong Wang <jiong.wang@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
drivers/net/ethernet/netronome/nfp/bpf/jit.c
drivers/net/ethernet/netronome/nfp/bpf/main.c
drivers/net/ethernet/netronome/nfp/bpf/main.h
drivers/net/ethernet/netronome/nfp/bpf/verifier.c

index 3799ca9b98269c4f0e6c3ee9aaf0a88177817bd3..c63368fc28f6ac4b08626a5e8aebaea334d2e702 100644 (file)
@@ -1372,6 +1372,8 @@ map_call_stack_common(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
        /* Set LM0 to start of key */
        if (load_lm_ptr)
                emit_csr_wr(nfp_prog, reg_b(2 * 2), NFP_CSR_ACT_LM_ADDR0);
+       if (meta->func_id == BPF_FUNC_map_update_elem)
+               emit_csr_wr(nfp_prog, reg_b(3 * 2), NFP_CSR_ACT_LM_ADDR2);
 
        /* Load map ID into a register, it should actually fit as an immediate
         * but in case it doesn't deal with it here, not in the delay slots.
@@ -2326,6 +2328,7 @@ static int call(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
        case BPF_FUNC_xdp_adjust_head:
                return adjust_head(nfp_prog, meta);
        case BPF_FUNC_map_lookup_elem:
+       case BPF_FUNC_map_update_elem:
                return map_call_stack_common(nfp_prog, meta);
        default:
                WARN_ONCE(1, "verifier allowed unsupported function\n");
@@ -3210,6 +3213,9 @@ void *nfp_bpf_relo_for_vnic(struct nfp_prog *nfp_prog, struct nfp_bpf_vnic *bv)
                        case BPF_FUNC_map_lookup_elem:
                                val = nfp_prog->bpf->helpers.map_lookup;
                                break;
+                       case BPF_FUNC_map_update_elem:
+                               val = nfp_prog->bpf->helpers.map_update;
+                               break;
                        default:
                                pr_err("relocation of unknown helper %d\n",
                                       val);
index 34e98aa6b95623b354e99d4235962cabec59d700..db6940551b3261a54ddf8231c6951b9559657848 100644 (file)
@@ -284,6 +284,9 @@ nfp_bpf_parse_cap_func(struct nfp_app_bpf *bpf, void __iomem *value, u32 length)
        case BPF_FUNC_map_lookup_elem:
                bpf->helpers.map_lookup = readl(&cap->func_addr);
                break;
+       case BPF_FUNC_map_update_elem:
+               bpf->helpers.map_update = readl(&cap->func_addr);
+               break;
        }
 
        return 0;
index 0f920bf48b01317cc5eb09989af7090b6e92f29d..0246bd88bff34204d81ba6682cde4727d551edc1 100644 (file)
@@ -128,6 +128,7 @@ enum pkt_vec {
  *
  * @helpers:           helper addressess for various calls
  * @helpers.map_lookup:                map lookup helper address
+ * @helpers.map_update:                map update helper address
  */
 struct nfp_app_bpf {
        struct nfp_app *app;
@@ -162,6 +163,7 @@ struct nfp_app_bpf {
 
        struct {
                u32 map_lookup;
+               u32 map_update;
        } helpers;
 };
 
index acfc4d79811653c725c1bfa95431ccc2ed7f28ac..482a0ce6e75544bacc3c02231bd90a727e95a902 100644 (file)
@@ -167,6 +167,7 @@ nfp_bpf_check_call(struct nfp_prog *nfp_prog, struct bpf_verifier_env *env,
 {
        const struct bpf_reg_state *reg1 = cur_regs(env) + BPF_REG_1;
        const struct bpf_reg_state *reg2 = cur_regs(env) + BPF_REG_2;
+       const struct bpf_reg_state *reg3 = cur_regs(env) + BPF_REG_3;
        struct nfp_app_bpf *bpf = nfp_prog->bpf;
        u32 func_id = meta->insn.imm;
 
@@ -191,6 +192,15 @@ nfp_bpf_check_call(struct nfp_prog *nfp_prog, struct bpf_verifier_env *env,
                                          meta->func_id ? &meta->arg2 : NULL))
                        return -EOPNOTSUPP;
                break;
+
+       case BPF_FUNC_map_update_elem:
+               if (!nfp_bpf_map_call_ok("map_update", env, meta,
+                                        bpf->helpers.map_update, reg1) ||
+                   !nfp_bpf_stack_arg_ok("map_update", env, reg2,
+                                         meta->func_id ? &meta->arg2 : NULL) ||
+                   !nfp_bpf_stack_arg_ok("map_update", env, reg3, NULL))
+                       return -EOPNOTSUPP;
+               break;
        default:
                pr_vlog(env, "unsupported function id: %d\n", func_id);
                return -EOPNOTSUPP;