Commit b07ade27 authored by Quentin Monnet's avatar Quentin Monnet Committed by Alexei Starovoitov

bpf: pass translate() as a callback and remove its ndo_bpf subcommand

As part of the transition from ndo_bpf() to callbacks attached to struct
bpf_offload_dev for some of the eBPF offload operations, move the
functions related to code translation to the struct and remove the
subcommand that was used to call them through the NDO.
Signed-off-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 00db12c3
...@@ -33,9 +33,6 @@ nfp_map_ptr_record(struct nfp_app_bpf *bpf, struct nfp_prog *nfp_prog, ...@@ -33,9 +33,6 @@ nfp_map_ptr_record(struct nfp_app_bpf *bpf, struct nfp_prog *nfp_prog,
struct nfp_bpf_neutral_map *record; struct nfp_bpf_neutral_map *record;
int err; int err;
/* Map record paths are entered via ndo, update side is protected. */
ASSERT_RTNL();
/* Reuse path - other offloaded program is already tracking this map. */ /* Reuse path - other offloaded program is already tracking this map. */
record = rhashtable_lookup_fast(&bpf->maps_neutral, &map->id, record = rhashtable_lookup_fast(&bpf->maps_neutral, &map->id,
nfp_bpf_maps_neutral_params); nfp_bpf_maps_neutral_params);
...@@ -84,8 +81,6 @@ nfp_map_ptrs_forget(struct nfp_app_bpf *bpf, struct nfp_prog *nfp_prog) ...@@ -84,8 +81,6 @@ nfp_map_ptrs_forget(struct nfp_app_bpf *bpf, struct nfp_prog *nfp_prog)
bool freed = false; bool freed = false;
int i; int i;
ASSERT_RTNL();
for (i = 0; i < nfp_prog->map_records_cnt; i++) { for (i = 0; i < nfp_prog->map_records_cnt; i++) {
if (--nfp_prog->map_records[i]->count) { if (--nfp_prog->map_records[i]->count) {
nfp_prog->map_records[i] = NULL; nfp_prog->map_records[i] = NULL;
...@@ -219,9 +214,10 @@ nfp_bpf_verifier_prep(struct net_device *netdev, struct bpf_verifier_env *env) ...@@ -219,9 +214,10 @@ nfp_bpf_verifier_prep(struct net_device *netdev, struct bpf_verifier_env *env)
return ret; return ret;
} }
static int nfp_bpf_translate(struct nfp_net *nn, struct bpf_prog *prog) static int nfp_bpf_translate(struct net_device *netdev, struct bpf_prog *prog)
{ {
struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv; struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv;
struct nfp_net *nn = netdev_priv(netdev);
unsigned int max_instr; unsigned int max_instr;
int err; int err;
...@@ -422,8 +418,6 @@ nfp_bpf_map_free(struct nfp_app_bpf *bpf, struct bpf_offloaded_map *offmap) ...@@ -422,8 +418,6 @@ nfp_bpf_map_free(struct nfp_app_bpf *bpf, struct bpf_offloaded_map *offmap)
int nfp_ndo_bpf(struct nfp_app *app, struct nfp_net *nn, struct netdev_bpf *bpf) int nfp_ndo_bpf(struct nfp_app *app, struct nfp_net *nn, struct netdev_bpf *bpf)
{ {
switch (bpf->command) { switch (bpf->command) {
case BPF_OFFLOAD_TRANSLATE:
return nfp_bpf_translate(nn, bpf->offload.prog);
case BPF_OFFLOAD_DESTROY: case BPF_OFFLOAD_DESTROY:
return nfp_bpf_destroy(nn, bpf->offload.prog); return nfp_bpf_destroy(nn, bpf->offload.prog);
case BPF_OFFLOAD_MAP_ALLOC: case BPF_OFFLOAD_MAP_ALLOC:
...@@ -604,4 +598,5 @@ const struct bpf_prog_offload_ops nfp_bpf_dev_ops = { ...@@ -604,4 +598,5 @@ const struct bpf_prog_offload_ops nfp_bpf_dev_ops = {
.insn_hook = nfp_verify_insn, .insn_hook = nfp_verify_insn,
.finalize = nfp_bpf_finalize, .finalize = nfp_bpf_finalize,
.prepare = nfp_bpf_verifier_prep, .prepare = nfp_bpf_verifier_prep,
.translate = nfp_bpf_translate,
}; };
...@@ -269,6 +269,14 @@ nsim_bpf_verifier_prep(struct net_device *dev, struct bpf_verifier_env *env) ...@@ -269,6 +269,14 @@ nsim_bpf_verifier_prep(struct net_device *dev, struct bpf_verifier_env *env)
return nsim_bpf_create_prog(ns, env->prog); return nsim_bpf_create_prog(ns, env->prog);
} }
static int nsim_bpf_translate(struct net_device *dev, struct bpf_prog *prog)
{
struct nsim_bpf_bound_prog *state = prog->aux->offload->dev_priv;
state->state = "xlated";
return 0;
}
static void nsim_bpf_destroy_prog(struct bpf_prog *prog) static void nsim_bpf_destroy_prog(struct bpf_prog *prog)
{ {
struct nsim_bpf_bound_prog *state; struct nsim_bpf_bound_prog *state;
...@@ -285,6 +293,7 @@ static const struct bpf_prog_offload_ops nsim_bpf_dev_ops = { ...@@ -285,6 +293,7 @@ static const struct bpf_prog_offload_ops nsim_bpf_dev_ops = {
.insn_hook = nsim_bpf_verify_insn, .insn_hook = nsim_bpf_verify_insn,
.finalize = nsim_bpf_finalize, .finalize = nsim_bpf_finalize,
.prepare = nsim_bpf_verifier_prep, .prepare = nsim_bpf_verifier_prep,
.translate = nsim_bpf_translate,
}; };
static int nsim_setup_prog_checks(struct netdevsim *ns, struct netdev_bpf *bpf) static int nsim_setup_prog_checks(struct netdevsim *ns, struct netdev_bpf *bpf)
...@@ -551,11 +560,6 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf) ...@@ -551,11 +560,6 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
ASSERT_RTNL(); ASSERT_RTNL();
switch (bpf->command) { switch (bpf->command) {
case BPF_OFFLOAD_TRANSLATE:
state = bpf->offload.prog->aux->offload->dev_priv;
state->state = "xlated";
return 0;
case BPF_OFFLOAD_DESTROY: case BPF_OFFLOAD_DESTROY:
nsim_bpf_destroy_prog(bpf->offload.prog); nsim_bpf_destroy_prog(bpf->offload.prog);
return 0; return 0;
......
...@@ -269,6 +269,7 @@ struct bpf_prog_offload_ops { ...@@ -269,6 +269,7 @@ struct bpf_prog_offload_ops {
int insn_idx, int prev_insn_idx); int insn_idx, int prev_insn_idx);
int (*finalize)(struct bpf_verifier_env *env); int (*finalize)(struct bpf_verifier_env *env);
int (*prepare)(struct net_device *netdev, struct bpf_verifier_env *env); int (*prepare)(struct net_device *netdev, struct bpf_verifier_env *env);
int (*translate)(struct net_device *netdev, struct bpf_prog *prog);
}; };
struct bpf_prog_offload { struct bpf_prog_offload {
......
...@@ -863,7 +863,6 @@ enum bpf_netdev_command { ...@@ -863,7 +863,6 @@ enum bpf_netdev_command {
XDP_QUERY_PROG, XDP_QUERY_PROG,
XDP_QUERY_PROG_HW, XDP_QUERY_PROG_HW,
/* BPF program for offload callbacks, invoked at program load time. */ /* BPF program for offload callbacks, invoked at program load time. */
BPF_OFFLOAD_TRANSLATE,
BPF_OFFLOAD_DESTROY, BPF_OFFLOAD_DESTROY,
BPF_OFFLOAD_MAP_ALLOC, BPF_OFFLOAD_MAP_ALLOC,
BPF_OFFLOAD_MAP_FREE, BPF_OFFLOAD_MAP_FREE,
...@@ -890,7 +889,7 @@ struct netdev_bpf { ...@@ -890,7 +889,7 @@ struct netdev_bpf {
/* flags with which program was installed */ /* flags with which program was installed */
u32 prog_flags; u32 prog_flags;
}; };
/* BPF_OFFLOAD_TRANSLATE, BPF_OFFLOAD_DESTROY */ /* BPF_OFFLOAD_DESTROY */
struct { struct {
struct bpf_prog *prog; struct bpf_prog *prog;
} offload; } offload;
......
...@@ -219,14 +219,14 @@ void bpf_prog_offload_destroy(struct bpf_prog *prog) ...@@ -219,14 +219,14 @@ void bpf_prog_offload_destroy(struct bpf_prog *prog)
static int bpf_prog_offload_translate(struct bpf_prog *prog) static int bpf_prog_offload_translate(struct bpf_prog *prog)
{ {
struct netdev_bpf data = {}; struct bpf_prog_offload *offload;
int ret; int ret = -ENODEV;
data.offload.prog = prog;
rtnl_lock(); down_read(&bpf_devs_lock);
ret = __bpf_offload_ndo(prog, BPF_OFFLOAD_TRANSLATE, &data); offload = prog->aux->offload;
rtnl_unlock(); if (offload)
ret = offload->offdev->ops->translate(offload->netdev, prog);
up_read(&bpf_devs_lock);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment