bpf: pass destroy() as a callback and remove its ndo_bpf subcommand
authorQuentin Monnet <quentin.monnet@netronome.com>
Fri, 9 Nov 2018 13:03:30 +0000 (13:03 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 10 Nov 2018 23:39:54 +0000 (15:39 -0800)
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 program destruction to the struct and remove the
subcommand that was used to call them through the NDO.

Remove function __bpf_offload_ndo(), which is no longer used.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
drivers/net/ethernet/netronome/nfp/bpf/offload.c
drivers/net/netdevsim/bpf.c
include/linux/bpf.h
include/linux/netdevice.h
kernel/bpf/offload.c

index 8653a2189c1904ad56daedbedd9db4bcba7283ec..91085cc3c843b61565a10e3e974b9d52d116acdc 100644 (file)
@@ -238,15 +238,13 @@ static int nfp_bpf_translate(struct net_device *netdev, struct bpf_prog *prog)
        return nfp_map_ptrs_record(nfp_prog->bpf, nfp_prog, prog);
 }
 
-static int nfp_bpf_destroy(struct nfp_net *nn, struct bpf_prog *prog)
+static void nfp_bpf_destroy(struct bpf_prog *prog)
 {
        struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv;
 
        kvfree(nfp_prog->prog);
        nfp_map_ptrs_forget(nfp_prog->bpf, nfp_prog);
        nfp_prog_free(nfp_prog);
-
-       return 0;
 }
 
 /* Atomic engine requires values to be in big endian, we need to byte swap
@@ -418,8 +416,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)
 {
        switch (bpf->command) {
-       case BPF_OFFLOAD_DESTROY:
-               return nfp_bpf_destroy(nn, bpf->offload.prog);
        case BPF_OFFLOAD_MAP_ALLOC:
                return nfp_bpf_map_alloc(app->priv, bpf->offmap);
        case BPF_OFFLOAD_MAP_FREE:
@@ -599,4 +595,5 @@ const struct bpf_prog_offload_ops nfp_bpf_dev_ops = {
        .finalize       = nfp_bpf_finalize,
        .prepare        = nfp_bpf_verifier_prep,
        .translate      = nfp_bpf_translate,
+       .destroy        = nfp_bpf_destroy,
 };
index 30c2cd516d1c67930177f1e0634c42c19c5cb710..33e3d54c3a0a8341f2a57955b4d9368de05fa2f6 100644 (file)
@@ -294,6 +294,7 @@ static const struct bpf_prog_offload_ops nsim_bpf_dev_ops = {
        .finalize       = nsim_bpf_finalize,
        .prepare        = nsim_bpf_verifier_prep,
        .translate      = nsim_bpf_translate,
+       .destroy        = nsim_bpf_destroy_prog,
 };
 
 static int nsim_setup_prog_checks(struct netdevsim *ns, struct netdev_bpf *bpf)
@@ -560,9 +561,6 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
        ASSERT_RTNL();
 
        switch (bpf->command) {
-       case BPF_OFFLOAD_DESTROY:
-               nsim_bpf_destroy_prog(bpf->offload.prog);
-               return 0;
        case XDP_QUERY_PROG:
                return xdp_attachment_query(&ns->xdp, bpf);
        case XDP_QUERY_PROG_HW:
index d1eb3c8a3fa9a4f7df75ff9dc54ad6ea6348a6c3..867d2801db645db02f55e4f03f04470bf05bfe80 100644 (file)
@@ -270,6 +270,7 @@ struct bpf_prog_offload_ops {
        int (*finalize)(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);
+       void (*destroy)(struct bpf_prog *prog);
 };
 
 struct bpf_prog_offload {
index 27499127e0385cd050e311286f4f0cdd8e463ee1..17d52a647fe5746abc013fae7cc9000045755013 100644 (file)
@@ -863,7 +863,6 @@ enum bpf_netdev_command {
        XDP_QUERY_PROG,
        XDP_QUERY_PROG_HW,
        /* BPF program for offload callbacks, invoked at program load time. */
-       BPF_OFFLOAD_DESTROY,
        BPF_OFFLOAD_MAP_ALLOC,
        BPF_OFFLOAD_MAP_FREE,
        XDP_QUERY_XSK_UMEM,
@@ -889,10 +888,6 @@ struct netdev_bpf {
                        /* flags with which program was installed */
                        u32 prog_flags;
                };
-               /* BPF_OFFLOAD_DESTROY */
-               struct {
-                       struct bpf_prog *prog;
-               } offload;
                /* BPF_OFFLOAD_MAP_ALLOC, BPF_OFFLOAD_MAP_FREE */
                struct {
                        struct bpf_offloaded_map *offmap;
index ae0167366c12f1d6f21ad2acc80b832d7e3e31f3..d665e75a0ac3ba420a6c6d45f5095fa1ec202ab2 100644 (file)
@@ -123,23 +123,6 @@ err_maybe_put:
        return err;
 }
 
-static int __bpf_offload_ndo(struct bpf_prog *prog, enum bpf_netdev_command cmd,
-                            struct netdev_bpf *data)
-{
-       struct bpf_prog_offload *offload = prog->aux->offload;
-       struct net_device *netdev;
-
-       ASSERT_RTNL();
-
-       if (!offload)
-               return -ENODEV;
-       netdev = offload->netdev;
-
-       data->command = cmd;
-
-       return netdev->netdev_ops->ndo_bpf(netdev, data);
-}
-
 int bpf_prog_offload_verifier_prep(struct bpf_verifier_env *env)
 {
        struct bpf_prog_offload *offload;
@@ -192,12 +175,9 @@ int bpf_prog_offload_finalize(struct bpf_verifier_env *env)
 static void __bpf_prog_offload_destroy(struct bpf_prog *prog)
 {
        struct bpf_prog_offload *offload = prog->aux->offload;
-       struct netdev_bpf data = {};
-
-       data.offload.prog = prog;
 
        if (offload->dev_state)
-               WARN_ON(__bpf_offload_ndo(prog, BPF_OFFLOAD_DESTROY, &data));
+               offload->offdev->ops->destroy(prog);
 
        /* Make sure BPF_PROG_GET_NEXT_ID can't find this dead program */
        bpf_prog_free_id(prog, true);
@@ -209,12 +189,10 @@ static void __bpf_prog_offload_destroy(struct bpf_prog *prog)
 
 void bpf_prog_offload_destroy(struct bpf_prog *prog)
 {
-       rtnl_lock();
        down_write(&bpf_devs_lock);
        if (prog->aux->offload)
                __bpf_prog_offload_destroy(prog);
        up_write(&bpf_devs_lock);
-       rtnl_unlock();
 }
 
 static int bpf_prog_offload_translate(struct bpf_prog *prog)