net: flow_offload: add flow_block_cb_is_busy() and use it
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 9 Jul 2019 20:55:48 +0000 (22:55 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 9 Jul 2019 21:38:50 +0000 (14:38 -0700)
This patch adds a function to check if flow block callback is already in
use.  Call this new function from flow_block_cb_setup_simple() and from
drivers.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mscc/ocelot_tc.c
drivers/net/ethernet/netronome/nfp/flower/offload.c
include/net/flow_offload.h
net/core/flow_offload.c
net/dsa/slave.c

index 7ca6b64720176674099bbbd3fc1b25ddaa267d95..62cb5408424c5393c89244da3954884e41dec9bc 100644 (file)
@@ -722,6 +722,10 @@ mlx5e_rep_indr_setup_tc_block(struct net_device *netdev,
                if (indr_priv)
                        return -EEXIST;
 
+               if (flow_block_cb_is_busy(mlx5e_rep_indr_setup_block_cb,
+                                         indr_priv, &mlx5e_block_cb_list))
+                       return -EBUSY;
+
                indr_priv = kmalloc(sizeof(*indr_priv), GFP_KERNEL);
                if (!indr_priv)
                        return -ENOMEM;
index 65bea6be84d68bfed074edb95176ddb0580928f4..35adc174f277a74b6064fd20c072bbe566f1a4e5 100644 (file)
@@ -1698,6 +1698,10 @@ static int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port,
 
        switch (f->command) {
        case FLOW_BLOCK_BIND:
+               if (flow_block_cb_is_busy(cb, mlxsw_sp_port,
+                                         &mlxsw_sp_block_cb_list))
+                       return -EBUSY;
+
                block_cb = flow_block_cb_alloc(f->net, cb, mlxsw_sp_port,
                                               mlxsw_sp_port, NULL);
                if (IS_ERR(block_cb))
index 935a774cb291bdf936e077a656a36e88ce9f4165..9e6464ffae5d1d6d4a9490119071d92e0281f86c 100644 (file)
@@ -153,6 +153,9 @@ static int ocelot_setup_tc_block(struct ocelot_port *port,
 
        switch (f->command) {
        case FLOW_BLOCK_BIND:
+               if (flow_block_cb_is_busy(cb, port, &ocelot_block_cb_list))
+                       return -EBUSY;
+
                block_cb = flow_block_cb_alloc(f->net, cb, port, port, NULL);
                if (IS_ERR(block_cb))
                        return PTR_ERR(block_cb);
index ddd6b509f27e663d62c933f2ccfb7fc3031f3f4e..1b38cfeb646c4d25c137e8ecb30f01d028758fa9 100644 (file)
@@ -1320,6 +1320,10 @@ static int nfp_flower_setup_tc_block(struct net_device *netdev,
 
        switch (f->command) {
        case FLOW_BLOCK_BIND:
+               if (flow_block_cb_is_busy(nfp_flower_setup_tc_block_cb, repr,
+                                         &nfp_block_cb_list))
+                       return -EBUSY;
+
                block_cb = flow_block_cb_alloc(f->net,
                                               nfp_flower_setup_tc_block_cb,
                                               repr, repr, NULL);
index 377ba0004370bb87960c56147c23eb17d7bb73bd..42a36a34600342415819efdfca36f6a9db315889 100644 (file)
@@ -296,6 +296,9 @@ static inline void flow_block_cb_remove(struct flow_block_cb *block_cb,
        list_move(&block_cb->list, &offload->cb_list);
 }
 
+bool flow_block_cb_is_busy(tc_setup_cb_t *cb, void *cb_ident,
+                          struct list_head *driver_block_list);
+
 int flow_block_cb_setup_simple(struct flow_block_offload *f,
                               struct list_head *driver_list, tc_setup_cb_t *cb,
                               void *cb_ident, void *cb_priv, bool ingress_only);
index a1b36b47dd89a9aed4b650fbcdc7a0647173e7a3..76f8db3841d7a3ebe0ee2ab40dff08b30d8a1a34 100644 (file)
@@ -228,6 +228,21 @@ unsigned int flow_block_cb_decref(struct flow_block_cb *block_cb)
 }
 EXPORT_SYMBOL(flow_block_cb_decref);
 
+bool flow_block_cb_is_busy(tc_setup_cb_t *cb, void *cb_ident,
+                          struct list_head *driver_block_list)
+{
+       struct flow_block_cb *block_cb;
+
+       list_for_each_entry(block_cb, driver_block_list, driver_list) {
+               if (block_cb->cb == cb &&
+                   block_cb->cb_ident == cb_ident)
+                       return true;
+       }
+
+       return false;
+}
+EXPORT_SYMBOL(flow_block_cb_is_busy);
+
 int flow_block_cb_setup_simple(struct flow_block_offload *f,
                               struct list_head *driver_block_list,
                               tc_setup_cb_t *cb, void *cb_ident, void *cb_priv,
@@ -243,6 +258,9 @@ int flow_block_cb_setup_simple(struct flow_block_offload *f,
 
        switch (f->command) {
        case FLOW_BLOCK_BIND:
+               if (flow_block_cb_is_busy(cb, cb_ident, driver_block_list))
+                       return -EBUSY;
+
                block_cb = flow_block_cb_alloc(f->net, cb, cb_ident,
                                               cb_priv, NULL);
                if (IS_ERR(block_cb))
index 90c32fd680dbc7981d6fb092b7998c908ef2022b..9bcb598fc84037d737e84621ccedc8f3819cbd4d 100644 (file)
@@ -961,6 +961,9 @@ static int dsa_slave_setup_tc_block(struct net_device *dev,
 
        switch (f->command) {
        case FLOW_BLOCK_BIND:
+               if (flow_block_cb_is_busy(cb, dev, &dsa_slave_block_cb_list))
+                       return -EBUSY;
+
                block_cb = flow_block_cb_alloc(f->net, cb, dev, dev, NULL);
                if (IS_ERR(block_cb))
                        return PTR_ERR(block_cb);