aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/netdevsim/bpf.c
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2018-07-17 13:53:21 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-07-18 09:10:33 -0400
commitd6d6071388e9fc81e11c6f4392666a9f072befe6 (patch)
tree3bcbcd87847aefd262c31d737029cae612d1a3c8 /drivers/net/netdevsim/bpf.c
parenteeeaaf185eca5790529fa184c89452ead7c8c859 (diff)
netdevsim: associate bound programs with shared dev
Move bound program information from netdevsim to shared sub-object, as programs will soon be shared between netdevs of the same ASIC. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'drivers/net/netdevsim/bpf.c')
-rw-r--r--drivers/net/netdevsim/bpf.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c
index c36d2a768202..357f9e62f306 100644
--- a/drivers/net/netdevsim/bpf.c
+++ b/drivers/net/netdevsim/bpf.c
@@ -238,8 +238,8 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog)
238 state->state = "verify"; 238 state->state = "verify";
239 239
240 /* Program id is not populated yet when we create the state. */ 240 /* Program id is not populated yet when we create the state. */
241 sprintf(name, "%u", ns->prog_id_gen++); 241 sprintf(name, "%u", ns->sdev->prog_id_gen++);
242 state->ddir = debugfs_create_dir(name, ns->ddir_bpf_bound_progs); 242 state->ddir = debugfs_create_dir(name, ns->sdev->ddir_bpf_bound_progs);
243 if (IS_ERR_OR_NULL(state->ddir)) { 243 if (IS_ERR_OR_NULL(state->ddir)) {
244 kfree(state); 244 kfree(state);
245 return -ENOMEM; 245 return -ENOMEM;
@@ -250,7 +250,7 @@ static int nsim_bpf_create_prog(struct netdevsim *ns, struct bpf_prog *prog)
250 &state->state, &nsim_bpf_string_fops); 250 &state->state, &nsim_bpf_string_fops);
251 debugfs_create_bool("loaded", 0400, state->ddir, &state->is_loaded); 251 debugfs_create_bool("loaded", 0400, state->ddir, &state->is_loaded);
252 252
253 list_add_tail(&state->l, &ns->bpf_bound_progs); 253 list_add_tail(&state->l, &ns->sdev->bpf_bound_progs);
254 254
255 prog->aux->offload->dev_priv = state; 255 prog->aux->offload->dev_priv = state;
256 256
@@ -497,7 +497,7 @@ nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap)
497 } 497 }
498 498
499 offmap->dev_ops = &nsim_bpf_map_ops; 499 offmap->dev_ops = &nsim_bpf_map_ops;
500 list_add_tail(&nmap->l, &ns->bpf_bound_maps); 500 list_add_tail(&nmap->l, &ns->sdev->bpf_bound_maps);
501 501
502 return 0; 502 return 0;
503 503
@@ -582,8 +582,15 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
582 582
583int nsim_bpf_init(struct netdevsim *ns) 583int nsim_bpf_init(struct netdevsim *ns)
584{ 584{
585 INIT_LIST_HEAD(&ns->bpf_bound_progs); 585 if (ns->sdev->refcnt == 1) {
586 INIT_LIST_HEAD(&ns->bpf_bound_maps); 586 INIT_LIST_HEAD(&ns->sdev->bpf_bound_progs);
587 INIT_LIST_HEAD(&ns->sdev->bpf_bound_maps);
588
589 ns->sdev->ddir_bpf_bound_progs =
590 debugfs_create_dir("bpf_bound_progs", ns->sdev->ddir);
591 if (IS_ERR_OR_NULL(ns->sdev->ddir_bpf_bound_progs))
592 return -ENOMEM;
593 }
587 594
588 debugfs_create_u32("bpf_offloaded_id", 0400, ns->ddir, 595 debugfs_create_u32("bpf_offloaded_id", 0400, ns->ddir,
589 &ns->bpf_offloaded_id); 596 &ns->bpf_offloaded_id);
@@ -593,10 +600,6 @@ int nsim_bpf_init(struct netdevsim *ns)
593 &ns->bpf_bind_accept); 600 &ns->bpf_bind_accept);
594 debugfs_create_u32("bpf_bind_verifier_delay", 0600, ns->ddir, 601 debugfs_create_u32("bpf_bind_verifier_delay", 0600, ns->ddir,
595 &ns->bpf_bind_verifier_delay); 602 &ns->bpf_bind_verifier_delay);
596 ns->ddir_bpf_bound_progs =
597 debugfs_create_dir("bpf_bound_progs", ns->ddir);
598 if (IS_ERR_OR_NULL(ns->ddir_bpf_bound_progs))
599 return -ENOMEM;
600 603
601 ns->bpf_tc_accept = true; 604 ns->bpf_tc_accept = true;
602 debugfs_create_bool("bpf_tc_accept", 0600, ns->ddir, 605 debugfs_create_bool("bpf_tc_accept", 0600, ns->ddir,
@@ -619,9 +622,12 @@ int nsim_bpf_init(struct netdevsim *ns)
619 622
620void nsim_bpf_uninit(struct netdevsim *ns) 623void nsim_bpf_uninit(struct netdevsim *ns)
621{ 624{
622 WARN_ON(!list_empty(&ns->bpf_bound_progs));
623 WARN_ON(!list_empty(&ns->bpf_bound_maps));
624 WARN_ON(ns->xdp.prog); 625 WARN_ON(ns->xdp.prog);
625 WARN_ON(ns->xdp_hw.prog); 626 WARN_ON(ns->xdp_hw.prog);
626 WARN_ON(ns->bpf_offloaded); 627 WARN_ON(ns->bpf_offloaded);
628
629 if (ns->sdev->refcnt == 1) {
630 WARN_ON(!list_empty(&ns->sdev->bpf_bound_progs));
631 WARN_ON(!list_empty(&ns->sdev->bpf_bound_maps));
632 }
627} 633}