net/mlx5: fix meter policy ID table container
authorShun Hao <shunh@nvidia.com>
Fri, 2 Jul 2021 09:14:44 +0000 (12:14 +0300)
committerRaslan Darawsheh <rasland@nvidia.com>
Thu, 8 Jul 2021 20:09:25 +0000 (22:09 +0200)
The meter policy handlers are managed by user IDs and the driver used l3
table in order to map the user ID to the internal driver handler of the
policy.

The l3 table was wrongly saved in the shared device structure which
manages all the switch domain ports what made the user IDs shared
between different ethdev ports.

Move the policy l3 table to be per port by saving it in the port private
structure.

Fixes: afb4aa4f122 ("net/mlx5: support meter policy operations")
Cc: stable@dpdk.org
Signed-off-by: Shun Hao <shunh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_flow_meter.c

index d0faa45..abd573e 100644 (file)
@@ -600,8 +600,6 @@ mlx5_aso_flow_mtrs_mng_init(struct mlx5_dev_ctx_shared *sh)
                if (sh->meter_aso_en) {
                        rte_spinlock_init(&sh->mtrmng->pools_mng.mtrsl);
                        LIST_INIT(&sh->mtrmng->pools_mng.meters);
-                       sh->mtrmng->policy_idx_tbl =
-                               mlx5_l3t_create(MLX5_L3T_TYPE_DWORD);
                }
                sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
        }
index 0226327..6eae7b6 100644 (file)
@@ -870,8 +870,6 @@ struct mlx5_flow_mtr_mng {
        /* Default policy id. */
        uint32_t def_policy_ref_cnt;
        /** def_policy meter use count. */
-       struct mlx5_l3t_tbl *policy_idx_tbl;
-       /* Policy index lookup table. */
        struct mlx5_flow_tbl_resource *drop_tbl[MLX5_MTR_DOMAIN_MAX];
        /* Meter drop table. */
        struct mlx5_flow_dv_matcher *
@@ -1375,6 +1373,7 @@ struct mlx5_priv {
        uint8_t mtr_color_reg; /* Meter color match REG_C. */
        struct mlx5_legacy_flow_meters flow_meters; /* MTR list. */
        struct mlx5_l3t_tbl *mtr_profile_tbl; /* Meter index lookup table. */
+       struct mlx5_l3t_tbl *policy_idx_tbl; /* Policy index lookup table. */
        struct mlx5_l3t_tbl *mtr_idx_tbl; /* Meter index lookup table. */
        uint8_t skip_default_rss_reta; /* Skip configuration of default reta. */
        uint8_t fdb_def_rule; /* Whether fdb jump to table 1 is configured. */
index 87c5782..6f962a8 100644 (file)
@@ -512,11 +512,9 @@ mlx5_flow_meter_policy_find(struct rte_eth_dev *dev,
        struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
        union mlx5_l3t_data data;
 
-       if (policy_id > MLX5_MAX_SUB_POLICY_TBL_NUM ||
-               !priv->sh->mtrmng->policy_idx_tbl)
+       if (policy_id > MLX5_MAX_SUB_POLICY_TBL_NUM || !priv->policy_idx_tbl)
                return NULL;
-       if (mlx5_l3t_get_entry(priv->sh->mtrmng->policy_idx_tbl,
-                               policy_id, &data) ||
+       if (mlx5_l3t_get_entry(priv->policy_idx_tbl, policy_id, &data) ||
                                !data.dword)
                return NULL;
        if (policy_idx)
@@ -524,8 +522,7 @@ mlx5_flow_meter_policy_find(struct rte_eth_dev *dev,
        sub_policy = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
                                        data.dword);
        /* Remove reference taken by the mlx5_l3t_get_entry. */
-       mlx5_l3t_clear_entry(priv->sh->mtrmng->policy_idx_tbl,
-                               policy_id);
+       mlx5_l3t_clear_entry(priv->policy_idx_tbl, policy_id);
        if (sub_policy)
                if (sub_policy->main_policy_id)
                        return sub_policy->main_policy;
@@ -605,9 +602,8 @@ __mlx5_flow_meter_policy_delete(struct rte_eth_dev *dev,
                        }
                }
        }
-       if (priv->sh->mtrmng->policy_idx_tbl && clear_l3t) {
-               if (mlx5_l3t_clear_entry(priv->sh->mtrmng->policy_idx_tbl,
-                                       policy_id)) {
+       if (priv->policy_idx_tbl && clear_l3t) {
+               if (mlx5_l3t_clear_entry(priv->policy_idx_tbl, policy_id)) {
                        rte_spinlock_unlock(&mtr_policy->sl);
                        return -rte_mtr_error_set(error, ENOTSUP,
                                RTE_MTR_ERROR_TYPE_METER_POLICY_ID, NULL,
@@ -770,14 +766,12 @@ mlx5_flow_meter_policy_add(struct rte_eth_dev *dev,
                        goto policy_add_err;
        }
        data.dword = policy_idx;
-       if (!priv->sh->mtrmng->policy_idx_tbl) {
-               priv->sh->mtrmng->policy_idx_tbl =
-                               mlx5_l3t_create(MLX5_L3T_TYPE_DWORD);
-               if (!priv->sh->mtrmng->policy_idx_tbl)
+       if (!priv->policy_idx_tbl) {
+               priv->policy_idx_tbl = mlx5_l3t_create(MLX5_L3T_TYPE_DWORD);
+               if (!priv->policy_idx_tbl)
                        goto policy_add_err;
        }
-       if (mlx5_l3t_set_entry(priv->sh->mtrmng->policy_idx_tbl,
-                               policy_id, &data))
+       if (mlx5_l3t_set_entry(priv->policy_idx_tbl, policy_id, &data))
                goto policy_add_err;
        return 0;
 policy_add_err:
@@ -1840,9 +1834,8 @@ mlx5_flow_meter_rxq_flush(struct rte_eth_dev *dev)
 
        if (!priv->mtr_en)
                return;
-       if (priv->sh->mtrmng->policy_idx_tbl && priv->sh->refcnt == 1) {
-               MLX5_L3T_FOREACH(priv->sh->mtrmng->policy_idx_tbl,
-                                       i, entry) {
+       if (priv->policy_idx_tbl) {
+               MLX5_L3T_FOREACH(priv->policy_idx_tbl, i, entry) {
                        policy_idx = *(uint32_t *)entry;
                        sub_policy = mlx5_ipool_get
                                (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
@@ -1908,9 +1901,8 @@ mlx5_flow_meter_flush(struct rte_eth_dev *dev, struct rte_mtr_error *error)
                                NULL, "MTR object meter profile invalid.");
                }
        }
-       if (priv->sh->mtrmng->policy_idx_tbl && priv->sh->refcnt == 1) {
-               MLX5_L3T_FOREACH(priv->sh->mtrmng->policy_idx_tbl,
-                                       i, entry) {
+       if (priv->policy_idx_tbl) {
+               MLX5_L3T_FOREACH(priv->policy_idx_tbl, i, entry) {
                        policy_idx = *(uint32_t *)entry;
                        sub_policy = mlx5_ipool_get
                                (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
@@ -1931,8 +1923,8 @@ mlx5_flow_meter_flush(struct rte_eth_dev *dev, struct rte_mtr_error *error)
                                                "meter policy invalid.");
                        mlx5_free(sub_policy->main_policy);
                }
-               mlx5_l3t_destroy(priv->sh->mtrmng->policy_idx_tbl);
-               priv->sh->mtrmng->policy_idx_tbl = NULL;
+               mlx5_l3t_destroy(priv->policy_idx_tbl);
+               priv->policy_idx_tbl = NULL;
        }
        if (priv->mtr_profile_tbl) {
                MLX5_L3T_FOREACH(priv->mtr_profile_tbl, i, entry) {