aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2018-03-28 20:48:31 -0400
committerAlexei Starovoitov <ast@kernel.org>2018-03-28 22:36:13 -0400
commit44d65a47aeabc40619ad6d1900e0f54e5b5145b8 (patch)
treee75ec8e269a5f30f9a14528baa454e9f5d074704
parent289c5b763018be846900da706dc582e572a13864 (diff)
nfp: bpf: add map updates from the datapath
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>
-rw-r--r--drivers/net/ethernet/netronome/nfp/bpf/jit.c6
-rw-r--r--drivers/net/ethernet/netronome/nfp/bpf/main.c3
-rw-r--r--drivers/net/ethernet/netronome/nfp/bpf/main.h2
-rw-r--r--drivers/net/ethernet/netronome/nfp/bpf/verifier.c10
4 files changed, 21 insertions, 0 deletions
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/jit.c b/drivers/net/ethernet/netronome/nfp/bpf/jit.c
index 3799ca9b9826..c63368fc28f6 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/jit.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/jit.c
@@ -1372,6 +1372,8 @@ map_call_stack_common(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
1372 /* Set LM0 to start of key */ 1372 /* Set LM0 to start of key */
1373 if (load_lm_ptr) 1373 if (load_lm_ptr)
1374 emit_csr_wr(nfp_prog, reg_b(2 * 2), NFP_CSR_ACT_LM_ADDR0); 1374 emit_csr_wr(nfp_prog, reg_b(2 * 2), NFP_CSR_ACT_LM_ADDR0);
1375 if (meta->func_id == BPF_FUNC_map_update_elem)
1376 emit_csr_wr(nfp_prog, reg_b(3 * 2), NFP_CSR_ACT_LM_ADDR2);
1375 1377
1376 /* Load map ID into a register, it should actually fit as an immediate 1378 /* Load map ID into a register, it should actually fit as an immediate
1377 * but in case it doesn't deal with it here, not in the delay slots. 1379 * 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)
2326 case BPF_FUNC_xdp_adjust_head: 2328 case BPF_FUNC_xdp_adjust_head:
2327 return adjust_head(nfp_prog, meta); 2329 return adjust_head(nfp_prog, meta);
2328 case BPF_FUNC_map_lookup_elem: 2330 case BPF_FUNC_map_lookup_elem:
2331 case BPF_FUNC_map_update_elem:
2329 return map_call_stack_common(nfp_prog, meta); 2332 return map_call_stack_common(nfp_prog, meta);
2330 default: 2333 default:
2331 WARN_ONCE(1, "verifier allowed unsupported function\n"); 2334 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)
3210 case BPF_FUNC_map_lookup_elem: 3213 case BPF_FUNC_map_lookup_elem:
3211 val = nfp_prog->bpf->helpers.map_lookup; 3214 val = nfp_prog->bpf->helpers.map_lookup;
3212 break; 3215 break;
3216 case BPF_FUNC_map_update_elem:
3217 val = nfp_prog->bpf->helpers.map_update;
3218 break;
3213 default: 3219 default:
3214 pr_err("relocation of unknown helper %d\n", 3220 pr_err("relocation of unknown helper %d\n",
3215 val); 3221 val);
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/main.c b/drivers/net/ethernet/netronome/nfp/bpf/main.c
index 34e98aa6b956..db6940551b32 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/main.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/main.c
@@ -284,6 +284,9 @@ nfp_bpf_parse_cap_func(struct nfp_app_bpf *bpf, void __iomem *value, u32 length)
284 case BPF_FUNC_map_lookup_elem: 284 case BPF_FUNC_map_lookup_elem:
285 bpf->helpers.map_lookup = readl(&cap->func_addr); 285 bpf->helpers.map_lookup = readl(&cap->func_addr);
286 break; 286 break;
287 case BPF_FUNC_map_update_elem:
288 bpf->helpers.map_update = readl(&cap->func_addr);
289 break;
287 } 290 }
288 291
289 return 0; 292 return 0;
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/main.h b/drivers/net/ethernet/netronome/nfp/bpf/main.h
index 0f920bf48b01..0246bd88bff3 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/main.h
+++ b/drivers/net/ethernet/netronome/nfp/bpf/main.h
@@ -128,6 +128,7 @@ enum pkt_vec {
128 * 128 *
129 * @helpers: helper addressess for various calls 129 * @helpers: helper addressess for various calls
130 * @helpers.map_lookup: map lookup helper address 130 * @helpers.map_lookup: map lookup helper address
131 * @helpers.map_update: map update helper address
131 */ 132 */
132struct nfp_app_bpf { 133struct nfp_app_bpf {
133 struct nfp_app *app; 134 struct nfp_app *app;
@@ -162,6 +163,7 @@ struct nfp_app_bpf {
162 163
163 struct { 164 struct {
164 u32 map_lookup; 165 u32 map_lookup;
166 u32 map_update;
165 } helpers; 167 } helpers;
166}; 168};
167 169
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
index acfc4d798116..482a0ce6e755 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
@@ -167,6 +167,7 @@ nfp_bpf_check_call(struct nfp_prog *nfp_prog, struct bpf_verifier_env *env,
167{ 167{
168 const struct bpf_reg_state *reg1 = cur_regs(env) + BPF_REG_1; 168 const struct bpf_reg_state *reg1 = cur_regs(env) + BPF_REG_1;
169 const struct bpf_reg_state *reg2 = cur_regs(env) + BPF_REG_2; 169 const struct bpf_reg_state *reg2 = cur_regs(env) + BPF_REG_2;
170 const struct bpf_reg_state *reg3 = cur_regs(env) + BPF_REG_3;
170 struct nfp_app_bpf *bpf = nfp_prog->bpf; 171 struct nfp_app_bpf *bpf = nfp_prog->bpf;
171 u32 func_id = meta->insn.imm; 172 u32 func_id = meta->insn.imm;
172 173
@@ -191,6 +192,15 @@ nfp_bpf_check_call(struct nfp_prog *nfp_prog, struct bpf_verifier_env *env,
191 meta->func_id ? &meta->arg2 : NULL)) 192 meta->func_id ? &meta->arg2 : NULL))
192 return -EOPNOTSUPP; 193 return -EOPNOTSUPP;
193 break; 194 break;
195
196 case BPF_FUNC_map_update_elem:
197 if (!nfp_bpf_map_call_ok("map_update", env, meta,
198 bpf->helpers.map_update, reg1) ||
199 !nfp_bpf_stack_arg_ok("map_update", env, reg2,
200 meta->func_id ? &meta->arg2 : NULL) ||
201 !nfp_bpf_stack_arg_ok("map_update", env, reg3, NULL))
202 return -EOPNOTSUPP;
203 break;
194 default: 204 default:
195 pr_vlog(env, "unsupported function id: %d\n", func_id); 205 pr_vlog(env, "unsupported function id: %d\n", func_id);
196 return -EOPNOTSUPP; 206 return -EOPNOTSUPP;