]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
Merge branch 'net-sched-support-replay-of-filter-offload-when-binding-to-block'
authorDavid S. Miller <davem@davemloft.net>
Tue, 26 Jun 2018 14:21:33 +0000 (23:21 +0900)
committerDavid S. Miller <davem@davemloft.net>
Tue, 26 Jun 2018 14:21:33 +0000 (23:21 +0900)
Jakub Kicinski says:

====================
net: sched: support replay of filter offload when binding to block

This series from John adds the ability to replay filter offload requests
when new offload callback is being registered on a TC block.  This is most
likely to take place for shared blocks today, when a block which already
has rules is bound to another interface.  Prior to this patch set if any
of the rules were offloaded the block bind would fail.

A new tcf_proto_op is added to generate a filter-specific offload request.
The new 'offload' op is supporting extack from day 0, hence we need to
propagate extack to .ndo_setup_tc TC_BLOCK_BIND/TC_BLOCK_UNBIND and
through tcf_block_cb_register() to tcf_block_playback_offloads().

The immediate use of this patch set is to simplify life of drivers which
require duplicating rules when sharing blocks.  Switch drivers (mlxsw)
can bind ports to rule lists dynamically, NIC drivers generally don't
have that ability and need the rules to be duplicated for each ingress
they match on.  In code terms this means that switch drivers don't
register multiple callbacks for each port.  NIC drivers do, and get a
separate request and hance rule per-port, as if the block was not shared.
The registration fails today, however, if some rules were already present.

As John notes in description of patch 7, drivers which register multiple
callbacks to shared blocks will likely need to flush the rules on block
unbind.  This set makes the core not only replay the the offload add
requests but also offload remove requests when callback is unregistered.

v2:
 - name parameters in patch 2;
 - use unsigned int instead of u32 for in_hw_coun;
 - improve extack message in patch 7.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
23 files changed:
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
drivers/net/ethernet/intel/i40e/i40e_main.c
drivers/net/ethernet/intel/i40evf/i40evf_main.c
drivers/net/ethernet/intel/igb/igb_main.c
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/netronome/nfp/bpf/main.c
drivers/net/ethernet/netronome/nfp/flower/offload.c
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
drivers/net/netdevsim/netdev.c
include/net/act_api.h
include/net/pkt_cls.h
include/net/sch_generic.h
net/dsa/slave.c
net/sched/cls_api.c
net/sched/cls_bpf.c
net/sched/cls_flower.c
net/sched/cls_matchall.c
net/sched/cls_u32.c

index 176fc9f4d7defe6a9d5b513902c97f56d732b323..b5fc6414a951300ad7021e47d060dba54ea7e619 100644 (file)
@@ -7984,7 +7984,7 @@ static int bnxt_setup_tc_block(struct net_device *dev,
        switch (f->command) {
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block, bnxt_setup_tc_block_cb,
-                                            bp, bp);
+                                            bp, bp, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, bnxt_setup_tc_block_cb, bp);
                return 0;
index 05d4059059062463ee8fa38d16a9a708f96cb411..0745f2dfc80c1a2f1079c20c3d8ac40310326a67 100644 (file)
@@ -173,7 +173,7 @@ static int bnxt_vf_rep_setup_tc_block(struct net_device *dev,
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block,
                                             bnxt_vf_rep_setup_tc_block_cb,
-                                            vf_rep, vf_rep);
+                                            vf_rep, vf_rep, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block,
                                        bnxt_vf_rep_setup_tc_block_cb, vf_rep);
index bc03c175a3cdf1440aca2269b4483f59cdb3a9dc..96bc177d54de00e55d445a5c82ad39c82c2422cb 100644 (file)
@@ -3016,7 +3016,7 @@ static int cxgb_setup_tc_block(struct net_device *dev,
        switch (f->command) {
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block, cxgb_setup_tc_block_cb,
-                                            pi, dev);
+                                            pi, dev, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, cxgb_setup_tc_block_cb, pi);
                return 0;
index 7ad2b1b0b1254302475423ed4cba465156f04417..426b0ccb1fc6c545bf4bac920c0026dd028b3dbf 100644 (file)
@@ -7554,7 +7554,7 @@ static int i40e_setup_tc_block(struct net_device *dev,
        switch (f->command) {
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block, i40e_setup_tc_block_cb,
-                                            np, np);
+                                            np, np, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, i40e_setup_tc_block_cb, np);
                return 0;
index dc56a866749507ef30c1ca5016e58f4bfb8ec764..5906c1c1d19d82d7e37b0a891e457fea792b4153 100644 (file)
@@ -2926,7 +2926,7 @@ static int i40evf_setup_tc_block(struct net_device *dev,
        switch (f->command) {
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block, i40evf_setup_tc_block_cb,
-                                            adapter, adapter);
+                                            adapter, adapter, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, i40evf_setup_tc_block_cb,
                                        adapter);
index 6a78d8272eb2cc925f15897a9f3767fafb3acd4f..f1e3397bd405a0bb8cd819f95c9355d3fce2c9ac 100644 (file)
@@ -2728,7 +2728,7 @@ static int igb_setup_tc_block(struct igb_adapter *adapter,
        switch (f->command) {
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block, igb_setup_tc_block_cb,
-                                            adapter, adapter);
+                                            adapter, adapter, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, igb_setup_tc_block_cb,
                                        adapter);
index 3e87dbbc90246dba3a59e3f8ccded5885b441ae2..d29bd8fc3ff38a55ffd61a704efcf8cd6ce04968 100644 (file)
@@ -9325,7 +9325,7 @@ static int ixgbe_setup_tc_block(struct net_device *dev,
        switch (f->command) {
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb,
-                                            adapter, adapter);
+                                            adapter, adapter, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb,
                                        adapter);
index 56c1b6f5593e053d4629b15635bacf1ece9d6a88..134f20a182b5a842389bd4073db957d8af2d7c72 100644 (file)
@@ -3371,7 +3371,7 @@ static int mlx5e_setup_tc_block(struct net_device *dev,
        switch (f->command) {
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block, mlx5e_setup_tc_block_cb,
-                                            priv, priv);
+                                            priv, priv, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, mlx5e_setup_tc_block_cb,
                                        priv);
index 57987f6546e8357bdfaeb3e657e0f07fe47d940a..3f2fe95e01d9b4d1ad7be43b28b3eb6bc6218d6c 100644 (file)
@@ -797,7 +797,7 @@ static int mlx5e_rep_setup_tc_block(struct net_device *dev,
        switch (f->command) {
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block, mlx5e_rep_setup_tc_cb,
-                                            priv, priv);
+                                            priv, priv, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, mlx5e_rep_setup_tc_cb, priv);
                return 0;
index 968b88af2ef5ea93077186ff72d41d95aae60803..52437363766a8a7b72522cdba10bdb8f6430f309 100644 (file)
@@ -1503,7 +1503,8 @@ static int mlxsw_sp_setup_tc_block_cb_flower(enum tc_setup_type type,
 
 static int
 mlxsw_sp_setup_tc_block_flower_bind(struct mlxsw_sp_port *mlxsw_sp_port,
-                                   struct tcf_block *block, bool ingress)
+                                   struct tcf_block *block, bool ingress,
+                                   struct netlink_ext_ack *extack)
 {
        struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
        struct mlxsw_sp_acl_block *acl_block;
@@ -1518,7 +1519,7 @@ mlxsw_sp_setup_tc_block_flower_bind(struct mlxsw_sp_port *mlxsw_sp_port,
                        return -ENOMEM;
                block_cb = __tcf_block_cb_register(block,
                                                   mlxsw_sp_setup_tc_block_cb_flower,
-                                                  mlxsw_sp, acl_block);
+                                                  mlxsw_sp, acl_block, extack);
                if (IS_ERR(block_cb)) {
                        err = PTR_ERR(block_cb);
                        goto err_cb_register;
@@ -1541,7 +1542,7 @@ mlxsw_sp_setup_tc_block_flower_bind(struct mlxsw_sp_port *mlxsw_sp_port,
 
 err_block_bind:
        if (!tcf_block_cb_decref(block_cb)) {
-               __tcf_block_cb_unregister(block_cb);
+               __tcf_block_cb_unregister(block, block_cb);
 err_cb_register:
                mlxsw_sp_acl_block_destroy(acl_block);
        }
@@ -1571,7 +1572,7 @@ mlxsw_sp_setup_tc_block_flower_unbind(struct mlxsw_sp_port *mlxsw_sp_port,
        err = mlxsw_sp_acl_block_unbind(mlxsw_sp, acl_block,
                                        mlxsw_sp_port, ingress);
        if (!err && !tcf_block_cb_decref(block_cb)) {
-               __tcf_block_cb_unregister(block_cb);
+               __tcf_block_cb_unregister(block, block_cb);
                mlxsw_sp_acl_block_destroy(acl_block);
        }
 }
@@ -1596,11 +1597,12 @@ static int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port,
        switch (f->command) {
        case TC_BLOCK_BIND:
                err = tcf_block_cb_register(f->block, cb, mlxsw_sp_port,
-                                           mlxsw_sp_port);
+                                           mlxsw_sp_port, f->extack);
                if (err)
                        return err;
                err = mlxsw_sp_setup_tc_block_flower_bind(mlxsw_sp_port,
-                                                         f->block, ingress);
+                                                         f->block, ingress,
+                                                         f->extack);
                if (err) {
                        tcf_block_cb_unregister(f->block, cb, mlxsw_sp_port);
                        return err;
index fcdfb8e7fdeab0b9dcb353f4cd4a7d76370c9817..bf46f7bff912df180fabd0f9c25df1973ac110a9 100644 (file)
@@ -206,7 +206,7 @@ static int nfp_bpf_setup_tc_block(struct net_device *netdev,
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block,
                                             nfp_bpf_setup_tc_block_cb,
-                                            nn, nn);
+                                            nn, nn, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block,
                                        nfp_bpf_setup_tc_block_cb,
index c0e74aa4cb5e5e90ef9dea8508a8d27ec28b8857..a427dab4bf49707bc1aee822ad28f0f3cfc17a7e 100644 (file)
@@ -627,7 +627,7 @@ static int nfp_flower_setup_tc_block(struct net_device *netdev,
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block,
                                             nfp_flower_setup_tc_block_cb,
-                                            repr, repr);
+                                            repr, repr, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block,
                                        nfp_flower_setup_tc_block_cb,
index cba46b62a1cdd9571c9b82bb35503bc652c2782e..2354e30caa78cfc6d2c711c3819d45408da14840 100644 (file)
@@ -3776,7 +3776,7 @@ static int stmmac_setup_tc_block(struct stmmac_priv *priv,
        switch (f->command) {
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block, stmmac_setup_tc_block_cb,
-                               priv, priv);
+                               priv, priv, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, stmmac_setup_tc_block_cb, priv);
                return 0;
index ec68f38213d9c31e4049893020e1dc2bb97eea3b..c9dacc6fcd5970ca56b41dd80289c8b296862912 100644 (file)
@@ -260,7 +260,7 @@ nsim_setup_tc_block(struct net_device *dev, struct tc_block_offload *f)
        switch (f->command) {
        case TC_BLOCK_BIND:
                return tcf_block_cb_register(f->block, nsim_setup_tc_block_cb,
-                                            ns, ns);
+                                            ns, ns, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, nsim_setup_tc_block_cb, ns);
                return 0;
index 9e59ebfded625426c2c3764225d58081b704cf0a..5ff11adbe2a69e8eca51a053cb7d24b820b6e48a 100644 (file)
@@ -190,9 +190,6 @@ static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes,
 #endif
 }
 
-typedef int tc_setup_cb_t(enum tc_setup_type type,
-                         void *type_data, void *cb_priv);
-
 #ifdef CONFIG_NET_CLS_ACT
 int tc_setup_cb_egdev_register(const struct net_device *dev,
                               tc_setup_cb_t *cb, void *cb_priv);
index a3c1a2c47cd4bfd868004548cdf1ef7a361fa4c6..4070b8eb6d14f95c014e1740ffcfb25191da8332 100644 (file)
@@ -73,11 +73,13 @@ void tcf_block_cb_incref(struct tcf_block_cb *block_cb);
 unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb);
 struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block,
                                             tc_setup_cb_t *cb, void *cb_ident,
-                                            void *cb_priv);
+                                            void *cb_priv,
+                                            struct netlink_ext_ack *extack);
 int tcf_block_cb_register(struct tcf_block *block,
                          tc_setup_cb_t *cb, void *cb_ident,
-                         void *cb_priv);
-void __tcf_block_cb_unregister(struct tcf_block_cb *block_cb);
+                         void *cb_priv, struct netlink_ext_ack *extack);
+void __tcf_block_cb_unregister(struct tcf_block *block,
+                              struct tcf_block_cb *block_cb);
 void tcf_block_cb_unregister(struct tcf_block *block,
                             tc_setup_cb_t *cb, void *cb_ident);
 
@@ -161,7 +163,8 @@ unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb)
 static inline
 struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block,
                                             tc_setup_cb_t *cb, void *cb_ident,
-                                            void *cb_priv)
+                                            void *cb_priv,
+                                            struct netlink_ext_ack *extack)
 {
        return NULL;
 }
@@ -169,13 +172,14 @@ struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block,
 static inline
 int tcf_block_cb_register(struct tcf_block *block,
                          tc_setup_cb_t *cb, void *cb_ident,
-                         void *cb_priv)
+                         void *cb_priv, struct netlink_ext_ack *extack)
 {
        return 0;
 }
 
 static inline
-void __tcf_block_cb_unregister(struct tcf_block_cb *block_cb)
+void __tcf_block_cb_unregister(struct tcf_block *block,
+                              struct tcf_block_cb *block_cb)
 {
 }
 
@@ -596,6 +600,7 @@ struct tc_block_offload {
        enum tc_block_command command;
        enum tcf_block_binder_type binder_type;
        struct tcf_block *block;
+       struct netlink_ext_ack *extack;
 };
 
 struct tc_cls_common_offload {
index 6488daa32f829563c3d26ffe075022f3c9ededf5..7432100027b7f14d4bbd4109901bd8b144a39415 100644 (file)
@@ -20,6 +20,9 @@ struct qdisc_walker;
 struct tcf_walker;
 struct module;
 
+typedef int tc_setup_cb_t(enum tc_setup_type type,
+                         void *type_data, void *cb_priv);
+
 struct qdisc_rate_table {
        struct tc_ratespec rate;
        u32             data[256];
@@ -256,6 +259,9 @@ struct tcf_proto_ops {
                                          bool *last,
                                          struct netlink_ext_ack *);
        void                    (*walk)(struct tcf_proto*, struct tcf_walker *arg);
+       int                     (*reoffload)(struct tcf_proto *tp, bool add,
+                                            tc_setup_cb_t *cb, void *cb_priv,
+                                            struct netlink_ext_ack *extack);
        void                    (*bind_class)(void *, u32, unsigned long);
 
        /* rtnetlink specific */
@@ -330,6 +336,21 @@ static inline void tcf_block_offload_dec(struct tcf_block *block, u32 *flags)
        block->offloadcnt--;
 }
 
+static inline void
+tc_cls_offload_cnt_update(struct tcf_block *block, unsigned int *cnt,
+                         u32 *flags, bool add)
+{
+       if (add) {
+               if (!*cnt)
+                       tcf_block_offload_inc(block, flags);
+               (*cnt)++;
+       } else {
+               (*cnt)--;
+               if (!*cnt)
+                       tcf_block_offload_dec(block, flags);
+       }
+}
+
 static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz)
 {
        struct qdisc_skb_cb *qcb;
index 1e3b6a6d8a40dcf69200ead186a6ab8919e63db6..71536c4351327e426a4e901bf84edfd94e07afd7 100644 (file)
@@ -900,7 +900,7 @@ static int dsa_slave_setup_tc_block(struct net_device *dev,
 
        switch (f->command) {
        case TC_BLOCK_BIND:
-               return tcf_block_cb_register(f->block, cb, dev, dev);
+               return tcf_block_cb_register(f->block, cb, dev, dev, f->extack);
        case TC_BLOCK_UNBIND:
                tcf_block_cb_unregister(f->block, cb, dev);
                return 0;
index cdc3c87c53e62d4db4bb18fa5f59d7889b9866cb..bbf8dda96b0e65b46db4ba1429135c24c22227b2 100644 (file)
@@ -277,18 +277,21 @@ static bool tcf_block_offload_in_use(struct tcf_block *block)
 static int tcf_block_offload_cmd(struct tcf_block *block,
                                 struct net_device *dev,
                                 struct tcf_block_ext_info *ei,
-                                enum tc_block_command command)
+                                enum tc_block_command command,
+                                struct netlink_ext_ack *extack)
 {
        struct tc_block_offload bo = {};
 
        bo.command = command;
        bo.binder_type = ei->binder_type;
        bo.block = block;
+       bo.extack = extack;
        return dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_BLOCK, &bo);
 }
 
 static int tcf_block_offload_bind(struct tcf_block *block, struct Qdisc *q,
-                                 struct tcf_block_ext_info *ei)
+                                 struct tcf_block_ext_info *ei,
+                                 struct netlink_ext_ack *extack)
 {
        struct net_device *dev = q->dev_queue->dev;
        int err;
@@ -299,10 +302,12 @@ static int tcf_block_offload_bind(struct tcf_block *block, struct Qdisc *q,
        /* If tc offload feature is disabled and the block we try to bind
         * to already has some offloaded filters, forbid to bind.
         */
-       if (!tc_can_offload(dev) && tcf_block_offload_in_use(block))
+       if (!tc_can_offload(dev) && tcf_block_offload_in_use(block)) {
+               NL_SET_ERR_MSG(extack, "Bind to offloaded block failed as dev has offload disabled");
                return -EOPNOTSUPP;
+       }
 
-       err = tcf_block_offload_cmd(block, dev, ei, TC_BLOCK_BIND);
+       err = tcf_block_offload_cmd(block, dev, ei, TC_BLOCK_BIND, extack);
        if (err == -EOPNOTSUPP)
                goto no_offload_dev_inc;
        return err;
@@ -322,7 +327,7 @@ static void tcf_block_offload_unbind(struct tcf_block *block, struct Qdisc *q,
 
        if (!dev->netdev_ops->ndo_setup_tc)
                goto no_offload_dev_dec;
-       err = tcf_block_offload_cmd(block, dev, ei, TC_BLOCK_UNBIND);
+       err = tcf_block_offload_cmd(block, dev, ei, TC_BLOCK_UNBIND, NULL);
        if (err == -EOPNOTSUPP)
                goto no_offload_dev_dec;
        return;
@@ -612,7 +617,7 @@ int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
        if (err)
                goto err_chain_head_change_cb_add;
 
-       err = tcf_block_offload_bind(block, q, ei);
+       err = tcf_block_offload_bind(block, q, ei, extack);
        if (err)
                goto err_block_offload_bind;
 
@@ -746,18 +751,53 @@ unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb)
 }
 EXPORT_SYMBOL(tcf_block_cb_decref);
 
+static int
+tcf_block_playback_offloads(struct tcf_block *block, tc_setup_cb_t *cb,
+                           void *cb_priv, bool add, bool offload_in_use,
+                           struct netlink_ext_ack *extack)
+{
+       struct tcf_chain *chain;
+       struct tcf_proto *tp;
+       int err;
+
+       list_for_each_entry(chain, &block->chain_list, list) {
+               for (tp = rtnl_dereference(chain->filter_chain); tp;
+                    tp = rtnl_dereference(tp->next)) {
+                       if (tp->ops->reoffload) {
+                               err = tp->ops->reoffload(tp, add, cb, cb_priv,
+                                                        extack);
+                               if (err && add)
+                                       goto err_playback_remove;
+                       } else if (add && offload_in_use) {
+                               err = -EOPNOTSUPP;
+                               NL_SET_ERR_MSG(extack, "Filter HW offload failed - classifier without re-offloading support");
+                               goto err_playback_remove;
+                       }
+               }
+       }
+
+       return 0;
+
+err_playback_remove:
+       tcf_block_playback_offloads(block, cb, cb_priv, false, offload_in_use,
+                                   extack);
+       return err;
+}
+
 struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block,
                                             tc_setup_cb_t *cb, void *cb_ident,
-                                            void *cb_priv)
+                                            void *cb_priv,
+                                            struct netlink_ext_ack *extack)
 {
        struct tcf_block_cb *block_cb;
+       int err;
 
-       /* At this point, playback of previous block cb calls is not supported,
-        * so forbid to register to block which already has some offloaded
-        * filters present.
-        */
-       if (tcf_block_offload_in_use(block))
-               return ERR_PTR(-EOPNOTSUPP);
+       /* Replay any already present rules */
+       err = tcf_block_playback_offloads(block, cb, cb_priv, true,
+                                         tcf_block_offload_in_use(block),
+                                         extack);
+       if (err)
+               return ERR_PTR(err);
 
        block_cb = kzalloc(sizeof(*block_cb), GFP_KERNEL);
        if (!block_cb)
@@ -772,17 +812,22 @@ EXPORT_SYMBOL(__tcf_block_cb_register);
 
 int tcf_block_cb_register(struct tcf_block *block,
                          tc_setup_cb_t *cb, void *cb_ident,
-                         void *cb_priv)
+                         void *cb_priv, struct netlink_ext_ack *extack)
 {
        struct tcf_block_cb *block_cb;
 
-       block_cb = __tcf_block_cb_register(block, cb, cb_ident, cb_priv);
+       block_cb = __tcf_block_cb_register(block, cb, cb_ident, cb_priv,
+                                          extack);
        return IS_ERR(block_cb) ? PTR_ERR(block_cb) : 0;
 }
 EXPORT_SYMBOL(tcf_block_cb_register);
 
-void __tcf_block_cb_unregister(struct tcf_block_cb *block_cb)
+void __tcf_block_cb_unregister(struct tcf_block *block,
+                              struct tcf_block_cb *block_cb)
 {
+       tcf_block_playback_offloads(block, block_cb->cb, block_cb->cb_priv,
+                                   false, tcf_block_offload_in_use(block),
+                                   NULL);
        list_del(&block_cb->list);
        kfree(block_cb);
 }
@@ -796,7 +841,7 @@ void tcf_block_cb_unregister(struct tcf_block *block,
        block_cb = tcf_block_cb_lookup(block, cb, cb_ident);
        if (!block_cb)
                return;
-       __tcf_block_cb_unregister(block_cb);
+       __tcf_block_cb_unregister(block, block_cb);
 }
 EXPORT_SYMBOL(tcf_block_cb_unregister);
 
index 1aa7f6511065a1d1da3eda4a409c66c5ce0bc773..66e0ac9811f9e3811a9b3b19bb453022c7004879 100644 (file)
@@ -43,6 +43,7 @@ struct cls_bpf_prog {
        struct tcf_result res;
        bool exts_integrated;
        u32 gen_flags;
+       unsigned int in_hw_count;
        struct tcf_exts exts;
        u32 handle;
        u16 bpf_num_ops;
@@ -174,6 +175,7 @@ static int cls_bpf_offload_cmd(struct tcf_proto *tp, struct cls_bpf_prog *prog,
                        cls_bpf_offload_cmd(tp, oldprog, prog, extack);
                        return err;
                } else if (err > 0) {
+                       prog->in_hw_count = err;
                        tcf_block_offload_inc(block, &prog->gen_flags);
                }
        }
@@ -652,6 +654,42 @@ static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg)
        }
 }
 
+static int cls_bpf_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb,
+                            void *cb_priv, struct netlink_ext_ack *extack)
+{
+       struct cls_bpf_head *head = rtnl_dereference(tp->root);
+       struct tcf_block *block = tp->chain->block;
+       struct tc_cls_bpf_offload cls_bpf = {};
+       struct cls_bpf_prog *prog;
+       int err;
+
+       list_for_each_entry(prog, &head->plist, link) {
+               if (tc_skip_hw(prog->gen_flags))
+                       continue;
+
+               tc_cls_common_offload_init(&cls_bpf.common, tp, prog->gen_flags,
+                                          extack);
+               cls_bpf.command = TC_CLSBPF_OFFLOAD;
+               cls_bpf.exts = &prog->exts;
+               cls_bpf.prog = add ? prog->filter : NULL;
+               cls_bpf.oldprog = add ? NULL : prog->filter;
+               cls_bpf.name = prog->bpf_name;
+               cls_bpf.exts_integrated = prog->exts_integrated;
+
+               err = cb(TC_SETUP_CLSBPF, &cls_bpf, cb_priv);
+               if (err) {
+                       if (add && tc_skip_sw(prog->gen_flags))
+                               return err;
+                       continue;
+               }
+
+               tc_cls_offload_cnt_update(block, &prog->in_hw_count,
+                                         &prog->gen_flags, add);
+       }
+
+       return 0;
+}
+
 static struct tcf_proto_ops cls_bpf_ops __read_mostly = {
        .kind           =       "bpf",
        .owner          =       THIS_MODULE,
@@ -662,6 +700,7 @@ static struct tcf_proto_ops cls_bpf_ops __read_mostly = {
        .change         =       cls_bpf_change,
        .delete         =       cls_bpf_delete,
        .walk           =       cls_bpf_walk,
+       .reoffload      =       cls_bpf_reoffload,
        .dump           =       cls_bpf_dump,
        .bind_class     =       cls_bpf_bind_class,
 };
index 9e8b26a80fb3ea9e57b6b22d259eaefe171eca09..352876bb901b7af5076bf3a5930dde979fc0a861 100644 (file)
@@ -87,6 +87,7 @@ struct cls_fl_filter {
        struct list_head list;
        u32 handle;
        u32 flags;
+       unsigned int in_hw_count;
        struct rcu_work rwork;
        struct net_device *hw_dev;
 };
@@ -289,6 +290,7 @@ static int fl_hw_replace_filter(struct tcf_proto *tp,
                fl_hw_destroy_filter(tp, f, NULL);
                return err;
        } else if (err > 0) {
+               f->in_hw_count = err;
                tcf_block_offload_inc(block, &f->flags);
        }
 
@@ -1087,6 +1089,47 @@ static void fl_walk(struct tcf_proto *tp, struct tcf_walker *arg)
        }
 }
 
+static int fl_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb,
+                       void *cb_priv, struct netlink_ext_ack *extack)
+{
+       struct cls_fl_head *head = rtnl_dereference(tp->root);
+       struct tc_cls_flower_offload cls_flower = {};
+       struct tcf_block *block = tp->chain->block;
+       struct fl_flow_mask *mask;
+       struct cls_fl_filter *f;
+       int err;
+
+       list_for_each_entry(mask, &head->masks, list) {
+               list_for_each_entry(f, &mask->filters, list) {
+                       if (tc_skip_hw(f->flags))
+                               continue;
+
+                       tc_cls_common_offload_init(&cls_flower.common, tp,
+                                                  f->flags, extack);
+                       cls_flower.command = add ?
+                               TC_CLSFLOWER_REPLACE : TC_CLSFLOWER_DESTROY;
+                       cls_flower.cookie = (unsigned long)f;
+                       cls_flower.dissector = &mask->dissector;
+                       cls_flower.mask = &f->mkey;
+                       cls_flower.key = &f->key;
+                       cls_flower.exts = &f->exts;
+                       cls_flower.classid = f->res.classid;
+
+                       err = cb(TC_SETUP_CLSFLOWER, &cls_flower, cb_priv);
+                       if (err) {
+                               if (add && tc_skip_sw(f->flags))
+                                       return err;
+                               continue;
+                       }
+
+                       tc_cls_offload_cnt_update(block, &f->in_hw_count,
+                                                 &f->flags, add);
+               }
+       }
+
+       return 0;
+}
+
 static int fl_dump_key_val(struct sk_buff *skb,
                           void *val, int val_type,
                           void *mask, int mask_type, int len)
@@ -1438,6 +1481,7 @@ static struct tcf_proto_ops cls_fl_ops __read_mostly = {
        .change         = fl_change,
        .delete         = fl_delete,
        .walk           = fl_walk,
+       .reoffload      = fl_reoffload,
        .dump           = fl_dump,
        .bind_class     = fl_bind_class,
        .owner          = THIS_MODULE,
index 47b207ef77620f8baa530a8bc8c44c35ecf2df78..af16f36ed578910824cac069dad85325e3271e0e 100644 (file)
@@ -21,6 +21,7 @@ struct cls_mall_head {
        struct tcf_result res;
        u32 handle;
        u32 flags;
+       unsigned int in_hw_count;
        struct rcu_work rwork;
 };
 
@@ -95,6 +96,7 @@ static int mall_replace_hw_filter(struct tcf_proto *tp,
                mall_destroy_hw_filter(tp, head, cookie, NULL);
                return err;
        } else if (err > 0) {
+               head->in_hw_count = err;
                tcf_block_offload_inc(block, &head->flags);
        }
 
@@ -235,6 +237,35 @@ static void mall_walk(struct tcf_proto *tp, struct tcf_walker *arg)
        arg->count++;
 }
 
+static int mall_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb,
+                         void *cb_priv, struct netlink_ext_ack *extack)
+{
+       struct cls_mall_head *head = rtnl_dereference(tp->root);
+       struct tc_cls_matchall_offload cls_mall = {};
+       struct tcf_block *block = tp->chain->block;
+       int err;
+
+       if (tc_skip_hw(head->flags))
+               return 0;
+
+       tc_cls_common_offload_init(&cls_mall.common, tp, head->flags, extack);
+       cls_mall.command = add ?
+               TC_CLSMATCHALL_REPLACE : TC_CLSMATCHALL_DESTROY;
+       cls_mall.exts = &head->exts;
+       cls_mall.cookie = (unsigned long)head;
+
+       err = cb(TC_SETUP_CLSMATCHALL, &cls_mall, cb_priv);
+       if (err) {
+               if (add && tc_skip_sw(head->flags))
+                       return err;
+               return 0;
+       }
+
+       tc_cls_offload_cnt_update(block, &head->in_hw_count, &head->flags, add);
+
+       return 0;
+}
+
 static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh,
                     struct sk_buff *skb, struct tcmsg *t)
 {
@@ -289,6 +320,7 @@ static struct tcf_proto_ops cls_mall_ops __read_mostly = {
        .change         = mall_change,
        .delete         = mall_delete,
        .walk           = mall_walk,
+       .reoffload      = mall_reoffload,
        .dump           = mall_dump,
        .bind_class     = mall_bind_class,
        .owner          = THIS_MODULE,
index fb861f90fde6610d7fa4f7b6908742b307a4b9d0..d5d2a6dc39216b0ca28bd11094f0b64fda5c5964 100644 (file)
@@ -62,6 +62,7 @@ struct tc_u_knode {
        struct tc_u32_pcnt __percpu *pf;
 #endif
        u32                     flags;
+       unsigned int            in_hw_count;
 #ifdef CONFIG_CLS_U32_MARK
        u32                     val;
        u32                     mask;
@@ -571,6 +572,7 @@ static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n,
                u32_remove_hw_knode(tp, n, NULL);
                return err;
        } else if (err > 0) {
+               n->in_hw_count = err;
                tcf_block_offload_inc(block, &n->flags);
        }
 
@@ -1199,6 +1201,114 @@ static void u32_walk(struct tcf_proto *tp, struct tcf_walker *arg)
        }
 }
 
+static int u32_reoffload_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht,
+                              bool add, tc_setup_cb_t *cb, void *cb_priv,
+                              struct netlink_ext_ack *extack)
+{
+       struct tc_cls_u32_offload cls_u32 = {};
+       int err;
+
+       tc_cls_common_offload_init(&cls_u32.common, tp, ht->flags, extack);
+       cls_u32.command = add ? TC_CLSU32_NEW_HNODE : TC_CLSU32_DELETE_HNODE;
+       cls_u32.hnode.divisor = ht->divisor;
+       cls_u32.hnode.handle = ht->handle;
+       cls_u32.hnode.prio = ht->prio;
+
+       err = cb(TC_SETUP_CLSU32, &cls_u32, cb_priv);
+       if (err && add && tc_skip_sw(ht->flags))
+               return err;
+
+       return 0;
+}
+
+static int u32_reoffload_knode(struct tcf_proto *tp, struct tc_u_knode *n,
+                              bool add, tc_setup_cb_t *cb, void *cb_priv,
+                              struct netlink_ext_ack *extack)
+{
+       struct tc_u_hnode *ht = rtnl_dereference(n->ht_down);
+       struct tcf_block *block = tp->chain->block;
+       struct tc_cls_u32_offload cls_u32 = {};
+       int err;
+
+       tc_cls_common_offload_init(&cls_u32.common, tp, n->flags, extack);
+       cls_u32.command = add ?
+               TC_CLSU32_REPLACE_KNODE : TC_CLSU32_DELETE_KNODE;
+       cls_u32.knode.handle = n->handle;
+
+       if (add) {
+               cls_u32.knode.fshift = n->fshift;
+#ifdef CONFIG_CLS_U32_MARK
+               cls_u32.knode.val = n->val;
+               cls_u32.knode.mask = n->mask;
+#else
+               cls_u32.knode.val = 0;
+               cls_u32.knode.mask = 0;
+#endif
+               cls_u32.knode.sel = &n->sel;
+               cls_u32.knode.exts = &n->exts;
+               if (n->ht_down)
+                       cls_u32.knode.link_handle = ht->handle;
+       }
+
+       err = cb(TC_SETUP_CLSU32, &cls_u32, cb_priv);
+       if (err) {
+               if (add && tc_skip_sw(n->flags))
+                       return err;
+               return 0;
+       }
+
+       tc_cls_offload_cnt_update(block, &n->in_hw_count, &n->flags, add);
+
+       return 0;
+}
+
+static int u32_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb,
+                        void *cb_priv, struct netlink_ext_ack *extack)
+{
+       struct tc_u_common *tp_c = tp->data;
+       struct tc_u_hnode *ht;
+       struct tc_u_knode *n;
+       unsigned int h;
+       int err;
+
+       for (ht = rtnl_dereference(tp_c->hlist);
+            ht;
+            ht = rtnl_dereference(ht->next)) {
+               if (ht->prio != tp->prio)
+                       continue;
+
+               /* When adding filters to a new dev, try to offload the
+                * hashtable first. When removing, do the filters before the
+                * hashtable.
+                */
+               if (add && !tc_skip_hw(ht->flags)) {
+                       err = u32_reoffload_hnode(tp, ht, add, cb, cb_priv,
+                                                 extack);
+                       if (err)
+                               return err;
+               }
+
+               for (h = 0; h <= ht->divisor; h++) {
+                       for (n = rtnl_dereference(ht->ht[h]);
+                            n;
+                            n = rtnl_dereference(n->next)) {
+                               if (tc_skip_hw(n->flags))
+                                       continue;
+
+                               err = u32_reoffload_knode(tp, n, add, cb,
+                                                         cb_priv, extack);
+                               if (err)
+                                       return err;
+                       }
+               }
+
+               if (!add && !tc_skip_hw(ht->flags))
+                       u32_reoffload_hnode(tp, ht, add, cb, cb_priv, extack);
+       }
+
+       return 0;
+}
+
 static void u32_bind_class(void *fh, u32 classid, unsigned long cl)
 {
        struct tc_u_knode *n = fh;
@@ -1336,6 +1446,7 @@ static struct tcf_proto_ops cls_u32_ops __read_mostly = {
        .change         =       u32_change,
        .delete         =       u32_delete,
        .walk           =       u32_walk,
+       .reoffload      =       u32_reoffload,
        .dump           =       u32_dump,
        .bind_class     =       u32_bind_class,
        .owner          =       THIS_MODULE,