This commit creates the global default miss action instead of maintain
it in flow insertion time. This makes the action to be thread safe.

Signed-off-by: Suanming Mou <suanmi...@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_os.c |  7 ++++
 drivers/net/mlx5/mlx5.c          |  2 +
 drivers/net/mlx5/mlx5.h          |  1 +
 drivers/net/mlx5/mlx5_flow_dv.c  | 86 ++--------------------------------------
 4 files changed, 14 insertions(+), 82 deletions(-)

diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index 63ea55b..f0470a2 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -1317,6 +1317,10 @@
                err = mlx5_alloc_shared_dr(priv);
                if (err)
                        goto error;
+               priv->default_miss_action =
+                               mlx5_glue->dr_create_flow_action_default_miss();
+               if (!priv->default_miss_action)
+                       DRV_LOG(WARNING, "Default miss action not supported.");
        }
        if (config->devx && config->dv_flow_en && config->dest_tir) {
                priv->obj_ops = devx_obj_ops;
@@ -1397,6 +1401,9 @@
                        close(priv->nl_socket_rdma);
                if (priv->vmwa_context)
                        mlx5_vlan_vmwa_exit(priv->vmwa_context);
+               if (priv->default_miss_action)
+                       mlx5_glue->destroy_flow_action
+                                       (priv->default_miss_action);
                if (own_domain_id)
                        claim_zero(rte_eth_switch_domain_free(priv->domain_id));
                mlx5_cache_list_destroy(&priv->hrxqs);
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index fc9c5a9..1d57d16 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -1203,6 +1203,8 @@ struct mlx5_dev_ctx_shared *
                priv->txqs = NULL;
        }
        mlx5_proc_priv_uninit(dev);
+       if (priv->default_miss_action)
+               mlx5_glue->destroy_flow_action(priv->default_miss_action);
        if (priv->mreg_cp_tbl)
                mlx5_hlist_destroy(priv->mreg_cp_tbl);
        mlx5_mprq_free_mp(dev);
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index b2312cf..944db8d 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -841,6 +841,7 @@ struct mlx5_priv {
        uint8_t skip_default_rss_reta; /* Skip configuration of default reta. */
        uint8_t fdb_def_rule; /* Whether fdb jump to table 1 is configured. */
        struct mlx5_mp_id mp_id; /* ID of a multi-process process */
+       void *default_miss_action;
        LIST_HEAD(fdir, mlx5_fdir_flow) fdir_flows; /* fdir flows. */
 };
 
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index a2cb9ed..80df066 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -73,9 +73,6 @@
 flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
                             struct mlx5_flow_tbl_resource *tbl);
 
-static int
-flow_dv_default_miss_resource_release(struct rte_eth_dev *dev);
-
 /**
  * Initialize flow attributes structure according to flow items' types.
  *
@@ -2770,42 +2767,6 @@ struct mlx5_cache_entry *
 }
 
 /**
- * Find existing default miss resource or create and register a new one.
- *
- * @param[in, out] dev
- *   Pointer to rte_eth_dev structure.
- * @param[out] error
- *   pointer to error structure.
- *
- * @return
- *   0 on success otherwise -errno and errno is set.
- */
-static int
-flow_dv_default_miss_resource_register(struct rte_eth_dev *dev,
-               struct rte_flow_error *error)
-{
-       struct mlx5_priv *priv = dev->data->dev_private;
-       struct mlx5_dev_ctx_shared *sh = priv->sh;
-       struct mlx5_flow_default_miss_resource *cache_resource =
-                       &sh->default_miss;
-       int cnt = rte_atomic32_read(&cache_resource->refcnt);
-
-       if (!cnt) {
-               MLX5_ASSERT(cache_resource->action);
-               cache_resource->action =
-               mlx5_glue->dr_create_flow_action_default_miss();
-               if (!cache_resource->action)
-                       return rte_flow_error_set(error, ENOMEM,
-                                       RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-                                       "cannot create default miss action");
-               DRV_LOG(DEBUG, "new default miss resource %p: refcnt %d++",
-                               (void *)cache_resource->action, cnt);
-       }
-       rte_atomic32_inc(&cache_resource->refcnt);
-       return 0;
-}
-
-/**
  * Find existing table port ID resource or create and register a new one.
  *
  * @param[in, out] dev
@@ -9033,15 +8994,13 @@ struct mlx5_hlist_entry *
                        dh->rix_hrxq = hrxq_idx;
                        dv->actions[n++] = hrxq->action;
                } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
-                       if (flow_dv_default_miss_resource_register
-                                       (dev, error)) {
+                       if (!priv->sh->default_miss.action) {
                                rte_flow_error_set
                                        (error, rte_errno,
                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-                                        "cannot create default miss resource");
-                               goto error_default_miss;
+                                        "default miss action not be created.");
+                               goto error;
                        }
-                       dh->rix_default_fate =  MLX5_FLOW_FATE_DEFAULT_MISS;
                        dv->actions[n++] = priv->sh->default_miss.action;
                }
                err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
@@ -9067,9 +9026,6 @@ struct mlx5_hlist_entry *
        }
        return 0;
 error:
-       if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS)
-               flow_dv_default_miss_resource_release(dev);
-error_default_miss:
        err = rte_errno; /* Save rte_errno before cleanup. */
        SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
                       handle_idx, dh, next) {
@@ -9198,36 +9154,6 @@ struct mlx5_hlist_entry *
        return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
 }
 
-/**
- * Release a default miss resource.
- *
- * @param dev
- *   Pointer to Ethernet device.
- * @return
- *   1 while a reference on it exists, 0 when freed.
- */
-static int
-flow_dv_default_miss_resource_release(struct rte_eth_dev *dev)
-{
-       struct mlx5_priv *priv = dev->data->dev_private;
-       struct mlx5_dev_ctx_shared *sh = priv->sh;
-       struct mlx5_flow_default_miss_resource *cache_resource =
-                       &sh->default_miss;
-
-       MLX5_ASSERT(cache_resource->action);
-       DRV_LOG(DEBUG, "default miss resource %p: refcnt %d--",
-                       (void *)cache_resource->action,
-                       rte_atomic32_read(&cache_resource->refcnt));
-       if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
-               claim_zero(mlx5_glue->destroy_flow_action
-                               (cache_resource->action));
-               DRV_LOG(DEBUG, "default miss resource %p: removed",
-                               (void *)cache_resource->action);
-               return 0;
-       }
-       return 1;
-}
-
 void
 flow_dv_modify_remove_cb(struct mlx5_hlist *list __rte_unused,
                         struct mlx5_hlist_entry *entry)
@@ -9366,9 +9292,6 @@ struct mlx5_hlist_entry *
        case MLX5_FLOW_FATE_PORT_ID:
                flow_dv_port_id_action_resource_release(dev, handle);
                break;
-       case MLX5_FLOW_FATE_DEFAULT_MISS:
-               flow_dv_default_miss_resource_release(dev);
-               break;
        default:
                DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
                break;
@@ -9405,8 +9328,7 @@ struct mlx5_hlist_entry *
                        dh->drv_flow = NULL;
                }
                if (dh->fate_action == MLX5_FLOW_FATE_DROP ||
-                   dh->fate_action == MLX5_FLOW_FATE_QUEUE ||
-                   dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS)
+                   dh->fate_action == MLX5_FLOW_FATE_QUEUE)
                        flow_dv_fate_resource_release(dev, dh);
                if (dh->vf_vlan.tag && dh->vf_vlan.created)
                        mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
-- 
1.8.3.1

Reply via email to