Commit b26b6946 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

netdevsim: make bpf_offload_dev_create() per-sdev instead of first ns

offload dev is stored in sdev struct. However, first netdevsim instance
is used as a priv. Change this to be sdev to as it is shared among
multiple netdevsim instances.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 38f58c97
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
bpf_verifier_log_write(env, "[netdevsim] " fmt, ##__VA_ARGS__) bpf_verifier_log_write(env, "[netdevsim] " fmt, ##__VA_ARGS__)
struct nsim_bpf_bound_prog { struct nsim_bpf_bound_prog {
struct netdevsim *ns; struct netdevsim_shared_dev *sdev;
struct bpf_prog *prog; struct bpf_prog *prog;
struct dentry *ddir; struct dentry *ddir;
const char *state; const char *state;
...@@ -65,8 +65,8 @@ nsim_bpf_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn) ...@@ -65,8 +65,8 @@ nsim_bpf_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn)
struct nsim_bpf_bound_prog *state; struct nsim_bpf_bound_prog *state;
state = env->prog->aux->offload->dev_priv; state = env->prog->aux->offload->dev_priv;
if (state->ns->sdev->bpf_bind_verifier_delay && !insn_idx) if (state->sdev->bpf_bind_verifier_delay && !insn_idx)
msleep(state->ns->sdev->bpf_bind_verifier_delay); msleep(state->sdev->bpf_bind_verifier_delay);
if (insn_idx == env->prog->len - 1) if (insn_idx == env->prog->len - 1)
pr_vlog(env, "Hello from netdevsim!\n"); pr_vlog(env, "Hello from netdevsim!\n");
...@@ -213,7 +213,8 @@ nsim_xdp_set_prog(struct netdevsim *ns, struct netdev_bpf *bpf, ...@@ -213,7 +213,8 @@ nsim_xdp_set_prog(struct netdevsim *ns, struct netdev_bpf *bpf,
return 0; return 0;
} }
static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog) static int nsim_bpf_create_prog(struct netdevsim_shared_dev *sdev,
struct bpf_prog *prog)
{ {
struct nsim_bpf_bound_prog *state; struct nsim_bpf_bound_prog *state;
char name[16]; char name[16];
...@@ -222,13 +223,13 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog) ...@@ -222,13 +223,13 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog)
if (!state) if (!state)
return -ENOMEM; return -ENOMEM;
state->ns = ns; state->sdev = sdev;
state->prog = prog; state->prog = prog;
state->state = "verify"; state->state = "verify";
/* Program id is not populated yet when we create the state. */ /* Program id is not populated yet when we create the state. */
sprintf(name, "%u", ns->sdev->prog_id_gen++); sprintf(name, "%u", sdev->prog_id_gen++);
state->ddir = debugfs_create_dir(name, ns->sdev->ddir_bpf_bound_progs); state->ddir = debugfs_create_dir(name, sdev->ddir_bpf_bound_progs);
if (IS_ERR_OR_NULL(state->ddir)) { if (IS_ERR_OR_NULL(state->ddir)) {
kfree(state); kfree(state);
return -ENOMEM; return -ENOMEM;
...@@ -239,7 +240,7 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog) ...@@ -239,7 +240,7 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog)
&state->state, &nsim_bpf_string_fops); &state->state, &nsim_bpf_string_fops);
debugfs_create_bool("loaded", 0400, state->ddir, &state->is_loaded); debugfs_create_bool("loaded", 0400, state->ddir, &state->is_loaded);
list_add_tail(&state->l, &ns->sdev->bpf_bound_progs); list_add_tail(&state->l, &sdev->bpf_bound_progs);
prog->aux->offload->dev_priv = state; prog->aux->offload->dev_priv = state;
...@@ -248,12 +249,13 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog) ...@@ -248,12 +249,13 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog)
static int nsim_bpf_verifier_prep(struct bpf_prog *prog) static int nsim_bpf_verifier_prep(struct bpf_prog *prog)
{ {
struct netdevsim *ns = bpf_offload_dev_priv(prog->aux->offload->offdev); struct netdevsim_shared_dev *sdev =
bpf_offload_dev_priv(prog->aux->offload->offdev);
if (!ns->sdev->bpf_bind_accept) if (!sdev->bpf_bind_accept)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return nsim_bpf_create_prog(ns, prog); return nsim_bpf_create_prog(sdev, prog);
} }
static int nsim_bpf_translate(struct bpf_prog *prog) static int nsim_bpf_translate(struct bpf_prog *prog)
...@@ -590,7 +592,7 @@ int nsim_bpf_init(struct netdevsim *ns) ...@@ -590,7 +592,7 @@ int nsim_bpf_init(struct netdevsim *ns)
return -ENOMEM; return -ENOMEM;
ns->sdev->bpf_dev = bpf_offload_dev_create(&nsim_bpf_dev_ops, ns->sdev->bpf_dev = bpf_offload_dev_create(&nsim_bpf_dev_ops,
ns); ns->sdev);
err = PTR_ERR_OR_ZERO(ns->sdev->bpf_dev); err = PTR_ERR_OR_ZERO(ns->sdev->bpf_dev);
if (err) if (err)
return err; return err;
......
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