From: Matan Azrad <ma...@nvidia.com> Currently, the list memory was allocated by the list API caller.
Move it to be allocated by the create API in order to save consistence with the hlist utility. Signed-off-by: Matan Azrad <ma...@nvidia.com> Acked-by: Suanming Mou <suanmi...@nvidia.com> --- drivers/net/mlx5/linux/mlx5_os.c | 105 ++++++++++++++++++++--------- drivers/net/mlx5/mlx5.c | 3 +- drivers/net/mlx5/mlx5.h | 10 +-- drivers/net/mlx5/mlx5_flow.h | 2 +- drivers/net/mlx5/mlx5_flow_dv.c | 56 ++++++++------- drivers/net/mlx5/mlx5_rxq.c | 6 +- drivers/net/mlx5/mlx5_utils.c | 19 ++++-- drivers/net/mlx5/mlx5_utils.h | 15 ++--- drivers/net/mlx5/windows/mlx5_os.c | 2 +- 9 files changed, 137 insertions(+), 81 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 8a043526da..87b63d852b 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -274,36 +274,44 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv) #ifdef HAVE_IBV_FLOW_DV_SUPPORT /* Init port id action list. */ snprintf(s, sizeof(s), "%s_port_id_action_list", sh->ibdev_name); - mlx5_list_create(&sh->port_id_action_list, s, sh, - flow_dv_port_id_create_cb, - flow_dv_port_id_match_cb, - flow_dv_port_id_remove_cb, - flow_dv_port_id_clone_cb, - flow_dv_port_id_clone_free_cb); + sh->port_id_action_list = mlx5_list_create(s, sh, + flow_dv_port_id_create_cb, + flow_dv_port_id_match_cb, + flow_dv_port_id_remove_cb, + flow_dv_port_id_clone_cb, + flow_dv_port_id_clone_free_cb); + if (!sh->port_id_action_list) + goto error; /* Init push vlan action list. */ snprintf(s, sizeof(s), "%s_push_vlan_action_list", sh->ibdev_name); - mlx5_list_create(&sh->push_vlan_action_list, s, sh, - flow_dv_push_vlan_create_cb, - flow_dv_push_vlan_match_cb, - flow_dv_push_vlan_remove_cb, - flow_dv_push_vlan_clone_cb, - flow_dv_push_vlan_clone_free_cb); + sh->push_vlan_action_list = mlx5_list_create(s, sh, + flow_dv_push_vlan_create_cb, + flow_dv_push_vlan_match_cb, + flow_dv_push_vlan_remove_cb, + flow_dv_push_vlan_clone_cb, + flow_dv_push_vlan_clone_free_cb); + if (!sh->push_vlan_action_list) + goto error; /* Init sample action list. */ snprintf(s, sizeof(s), "%s_sample_action_list", sh->ibdev_name); - mlx5_list_create(&sh->sample_action_list, s, sh, - flow_dv_sample_create_cb, - flow_dv_sample_match_cb, - flow_dv_sample_remove_cb, - flow_dv_sample_clone_cb, - flow_dv_sample_clone_free_cb); + sh->sample_action_list = mlx5_list_create(s, sh, + flow_dv_sample_create_cb, + flow_dv_sample_match_cb, + flow_dv_sample_remove_cb, + flow_dv_sample_clone_cb, + flow_dv_sample_clone_free_cb); + if (!sh->sample_action_list) + goto error; /* Init dest array action list. */ snprintf(s, sizeof(s), "%s_dest_array_list", sh->ibdev_name); - mlx5_list_create(&sh->dest_array_list, s, sh, - flow_dv_dest_array_create_cb, - flow_dv_dest_array_match_cb, - flow_dv_dest_array_remove_cb, - flow_dv_dest_array_clone_cb, - flow_dv_dest_array_clone_free_cb); + sh->dest_array_list = mlx5_list_create(s, sh, + flow_dv_dest_array_create_cb, + flow_dv_dest_array_match_cb, + flow_dv_dest_array_remove_cb, + flow_dv_dest_array_clone_cb, + flow_dv_dest_array_clone_free_cb); + if (!sh->dest_array_list) + goto error; /* Create tags hash list table. */ snprintf(s, sizeof(s), "%s_tags", sh->ibdev_name); sh->tag_table = mlx5_hlist_create(s, MLX5_TAGS_HLIST_ARRAY_SIZE, 0, @@ -447,6 +455,22 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv) sh->tunnel_hub = NULL; } mlx5_free_table_hash_list(priv); + if (sh->port_id_action_list) { + mlx5_list_destroy(sh->port_id_action_list); + sh->port_id_action_list = NULL; + } + if (sh->push_vlan_action_list) { + mlx5_list_destroy(sh->push_vlan_action_list); + sh->push_vlan_action_list = NULL; + } + if (sh->sample_action_list) { + mlx5_list_destroy(sh->sample_action_list); + sh->sample_action_list = NULL; + } + if (sh->dest_array_list) { + mlx5_list_destroy(sh->dest_array_list); + sh->dest_array_list = NULL; + } return err; } @@ -508,9 +532,23 @@ mlx5_os_free_shared_dr(struct mlx5_priv *priv) mlx5_release_tunnel_hub(sh, priv->dev_port); sh->tunnel_hub = NULL; } - mlx5_list_destroy(&sh->port_id_action_list); - mlx5_list_destroy(&sh->push_vlan_action_list); mlx5_free_table_hash_list(priv); + if (sh->port_id_action_list) { + mlx5_list_destroy(sh->port_id_action_list); + sh->port_id_action_list = NULL; + } + if (sh->push_vlan_action_list) { + mlx5_list_destroy(sh->push_vlan_action_list); + sh->push_vlan_action_list = NULL; + } + if (sh->sample_action_list) { + mlx5_list_destroy(sh->sample_action_list); + sh->sample_action_list = NULL; + } + if (sh->dest_array_list) { + mlx5_list_destroy(sh->dest_array_list); + sh->dest_array_list = NULL; + } } /** @@ -1710,11 +1748,13 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err = ENOTSUP; goto error; } - mlx5_list_create(&priv->hrxqs, "hrxq", eth_dev, mlx5_hrxq_create_cb, - mlx5_hrxq_match_cb, - mlx5_hrxq_remove_cb, - mlx5_hrxq_clone_cb, - mlx5_hrxq_clone_free_cb); + priv->hrxqs = mlx5_list_create("hrxq", eth_dev, mlx5_hrxq_create_cb, + mlx5_hrxq_match_cb, + mlx5_hrxq_remove_cb, + mlx5_hrxq_clone_cb, + mlx5_hrxq_clone_free_cb); + if (!priv->hrxqs) + goto error; rte_rwlock_init(&priv->ind_tbls_lock); /* Query availability of metadata reg_c's. */ err = mlx5_flow_discover_mreg_c(eth_dev); @@ -1771,7 +1811,8 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, mlx5_drop_action_destroy(eth_dev); if (own_domain_id) claim_zero(rte_eth_switch_domain_free(priv->domain_id)); - mlx5_list_destroy(&priv->hrxqs); + if (priv->hrxqs) + mlx5_list_destroy(priv->hrxqs); mlx5_free(priv); if (eth_dev != NULL) eth_dev->data->dev_private = NULL; diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 9aade013c5..775ea15adb 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1611,7 +1611,8 @@ mlx5_dev_close(struct rte_eth_dev *dev) if (ret) DRV_LOG(WARNING, "port %u some flows still remain", dev->data->port_id); - mlx5_list_destroy(&priv->hrxqs); + if (priv->hrxqs) + mlx5_list_destroy(priv->hrxqs); /* * Free the shared context in last turn, because the cleanup * routines above may use some shared fields, like diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 546bee761e..df5cba3d45 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1114,10 +1114,10 @@ struct mlx5_dev_ctx_shared { struct mlx5_hlist *encaps_decaps; /* Encap/decap action hash list. */ struct mlx5_hlist *modify_cmds; struct mlx5_hlist *tag_table; - struct mlx5_list port_id_action_list; /* Port ID action list. */ - struct mlx5_list push_vlan_action_list; /* Push VLAN actions. */ - struct mlx5_list sample_action_list; /* List of sample actions. */ - struct mlx5_list dest_array_list; + struct mlx5_list *port_id_action_list; /* Port ID action list. */ + struct mlx5_list *push_vlan_action_list; /* Push VLAN actions. */ + struct mlx5_list *sample_action_list; /* List of sample actions. */ + struct mlx5_list *dest_array_list; /* List of destination array actions. */ struct mlx5_flow_counter_mng cmng; /* Counters management structure. */ void *default_miss_action; /* Default miss action. */ @@ -1359,7 +1359,7 @@ struct mlx5_priv { struct mlx5_obj_ops obj_ops; /* HW objects operations. */ LIST_HEAD(rxq, mlx5_rxq_ctrl) rxqsctrl; /* DPDK Rx queues. */ LIST_HEAD(rxqobj, mlx5_rxq_obj) rxqsobj; /* Verbs/DevX Rx queues. */ - struct mlx5_list hrxqs; /* Hash Rx queues. */ + struct mlx5_list *hrxqs; /* Hash Rx queues. */ LIST_HEAD(txq, mlx5_txq_ctrl) txqsctrl; /* DPDK Tx queues. */ LIST_HEAD(txqobj, mlx5_txq_obj) txqsobj; /* Verbs/DevX Tx queues. */ /* Indirection tables. */ diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index ce363355c1..ce4d205e86 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -590,7 +590,7 @@ struct mlx5_flow_tbl_data_entry { /**< hash list entry, 64-bits key inside. */ struct mlx5_flow_tbl_resource tbl; /**< flow table resource. */ - struct mlx5_list matchers; + struct mlx5_list *matchers; /**< matchers' header associated with the flow table. */ struct mlx5_flow_dv_jump_tbl_resource jump; /**< jump resource, at most one for each table created. */ diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index 68a9e70a98..d588e6fd37 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -3883,7 +3883,7 @@ flow_dv_port_id_action_resource_register .data = ref, }; - entry = mlx5_list_register(&priv->sh->port_id_action_list, &ctx); + entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx); if (!entry) return -rte_errno; resource = container_of(entry, typeof(*resource), entry); @@ -4008,7 +4008,7 @@ flow_dv_push_vlan_action_resource_register .data = ref, }; - entry = mlx5_list_register(&priv->sh->push_vlan_action_list, &ctx); + entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx); if (!entry) return -rte_errno; resource = container_of(entry, typeof(*resource), entry); @@ -10010,12 +10010,22 @@ flow_dv_tbl_create_cb(struct mlx5_hlist *list, uint64_t key64, void *cb_ctx) MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list", key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress", key.level, key.id); - mlx5_list_create(&tbl_data->matchers, matcher_name, sh, - flow_dv_matcher_create_cb, - flow_dv_matcher_match_cb, - flow_dv_matcher_remove_cb, - flow_dv_matcher_clone_cb, - flow_dv_matcher_clone_free_cb); + tbl_data->matchers = mlx5_list_create(matcher_name, sh, + flow_dv_matcher_create_cb, + flow_dv_matcher_match_cb, + flow_dv_matcher_remove_cb, + flow_dv_matcher_clone_cb, + flow_dv_matcher_clone_free_cb); + if (!tbl_data->matchers) { + rte_flow_error_set(error, ENOMEM, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "cannot create tbl matcher list"); + mlx5_flow_os_destroy_flow_action(tbl_data->jump.action); + mlx5_flow_os_destroy_flow_tbl(tbl->obj); + mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx); + return NULL; + } return &tbl_data->entry; } @@ -10143,7 +10153,7 @@ flow_dv_tbl_remove_cb(struct mlx5_hlist *list, tbl_data->tunnel->tunnel_id : 0, tbl_data->group_id); } - mlx5_list_destroy(&tbl_data->matchers); + mlx5_list_destroy(tbl_data->matchers); mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx); } @@ -10275,7 +10285,7 @@ flow_dv_matcher_register(struct rte_eth_dev *dev, return -rte_errno; /* No need to refill the error info */ tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl); ref->tbl = tbl; - entry = mlx5_list_register(&tbl_data->matchers, &ctx); + entry = mlx5_list_register(tbl_data->matchers, &ctx); if (!entry) { flow_dv_tbl_resource_release(MLX5_SH(dev), tbl); return rte_flow_error_set(error, ENOMEM, @@ -10872,7 +10882,7 @@ flow_dv_sample_resource_register(struct rte_eth_dev *dev, .data = ref, }; - entry = mlx5_list_register(&priv->sh->sample_action_list, &ctx); + entry = mlx5_list_register(priv->sh->sample_action_list, &ctx); if (!entry) return -rte_errno; resource = container_of(entry, typeof(*resource), entry); @@ -11087,7 +11097,7 @@ flow_dv_dest_array_resource_register(struct rte_eth_dev *dev, .data = ref, }; - entry = mlx5_list_register(&priv->sh->dest_array_list, &ctx); + entry = mlx5_list_register(priv->sh->dest_array_list, &ctx); if (!entry) return -rte_errno; resource = container_of(entry, typeof(*resource), entry); @@ -13553,7 +13563,7 @@ flow_dv_matcher_release(struct rte_eth_dev *dev, int ret; MLX5_ASSERT(matcher->matcher_object); - ret = mlx5_list_unregister(&tbl->matchers, &matcher->entry); + ret = mlx5_list_unregister(tbl->matchers, &matcher->entry); flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl); return ret; } @@ -13696,7 +13706,7 @@ flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev, if (!resource) return 0; MLX5_ASSERT(resource->action); - return mlx5_list_unregister(&priv->sh->port_id_action_list, + return mlx5_list_unregister(priv->sh->port_id_action_list, &resource->entry); } @@ -13754,7 +13764,7 @@ flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev, if (!resource) return 0; MLX5_ASSERT(resource->action); - return mlx5_list_unregister(&priv->sh->push_vlan_action_list, + return mlx5_list_unregister(priv->sh->push_vlan_action_list, &resource->entry); } @@ -13835,7 +13845,7 @@ flow_dv_sample_resource_release(struct rte_eth_dev *dev, if (!resource) return 0; MLX5_ASSERT(resource->verbs_action); - return mlx5_list_unregister(&priv->sh->sample_action_list, + return mlx5_list_unregister(priv->sh->sample_action_list, &resource->entry); } @@ -13883,7 +13893,7 @@ flow_dv_dest_array_resource_release(struct rte_eth_dev *dev, if (!resource) return 0; MLX5_ASSERT(resource->action); - return mlx5_list_unregister(&priv->sh->dest_array_list, + return mlx5_list_unregister(priv->sh->dest_array_list, &resource->entry); } @@ -14727,7 +14737,7 @@ __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev, if (sub_policy->color_matcher[i]) { tbl = container_of(sub_policy->color_matcher[i]->tbl, typeof(*tbl), tbl); - mlx5_list_unregister(&tbl->matchers, + mlx5_list_unregister(tbl->matchers, &sub_policy->color_matcher[i]->entry); sub_policy->color_matcher[i] = NULL; } @@ -15461,7 +15471,7 @@ flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev) if (mtrmng->def_matcher[i]) { tbl = container_of(mtrmng->def_matcher[i]->tbl, struct mlx5_flow_tbl_data_entry, tbl); - mlx5_list_unregister(&tbl->matchers, + mlx5_list_unregister(tbl->matchers, &mtrmng->def_matcher[i]->entry); mtrmng->def_matcher[i] = NULL; } @@ -15471,7 +15481,7 @@ flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev) container_of(mtrmng->drop_matcher[i][j]->tbl, struct mlx5_flow_tbl_data_entry, tbl); - mlx5_list_unregister(&tbl->matchers, + mlx5_list_unregister(tbl->matchers, &mtrmng->drop_matcher[i][j]->entry); mtrmng->drop_matcher[i][j] = NULL; } @@ -15604,7 +15614,7 @@ __flow_dv_create_policy_matcher(struct rte_eth_dev *dev, matcher.priority = priority; matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf, matcher.mask.size); - entry = mlx5_list_register(&tbl_data->matchers, &ctx); + entry = mlx5_list_register(tbl_data->matchers, &ctx); if (!entry) { DRV_LOG(ERR, "Failed to register meter drop matcher."); return -1; @@ -16013,7 +16023,7 @@ flow_dv_create_mtr_tbls(struct rte_eth_dev *dev, matcher.crc = rte_raw_cksum ((const void *)matcher.mask.buf, matcher.mask.size); - entry = mlx5_list_register(&tbl_data->matchers, &ctx); + entry = mlx5_list_register(tbl_data->matchers, &ctx); if (!entry) { DRV_LOG(ERR, "Failed to register meter " "drop default matcher."); @@ -16050,7 +16060,7 @@ flow_dv_create_mtr_tbls(struct rte_eth_dev *dev, matcher.crc = rte_raw_cksum ((const void *)matcher.mask.buf, matcher.mask.size); - entry = mlx5_list_register(&tbl_data->matchers, &ctx); + entry = mlx5_list_register(tbl_data->matchers, &ctx); if (!entry) { DRV_LOG(ERR, "Failed to register meter drop matcher."); diff --git a/drivers/net/mlx5/mlx5_rxq.c b/drivers/net/mlx5/mlx5_rxq.c index f8769da8dc..aa9e973d10 100644 --- a/drivers/net/mlx5/mlx5_rxq.c +++ b/drivers/net/mlx5/mlx5_rxq.c @@ -2385,7 +2385,7 @@ uint32_t mlx5_hrxq_get(struct rte_eth_dev *dev, if (rss_desc->shared_rss) { hrxq = __mlx5_hrxq_create(dev, rss_desc); } else { - entry = mlx5_list_register(&priv->hrxqs, &ctx); + entry = mlx5_list_register(priv->hrxqs, &ctx); if (!entry) return 0; hrxq = container_of(entry, typeof(*hrxq), entry); @@ -2415,7 +2415,7 @@ int mlx5_hrxq_release(struct rte_eth_dev *dev, uint32_t hrxq_idx) if (!hrxq) return 0; if (!hrxq->standalone) - return mlx5_list_unregister(&priv->hrxqs, &hrxq->entry); + return mlx5_list_unregister(priv->hrxqs, &hrxq->entry); __mlx5_hrxq_remove(dev, hrxq); return 0; } @@ -2503,7 +2503,7 @@ mlx5_hrxq_verify(struct rte_eth_dev *dev) { struct mlx5_priv *priv = dev->data->dev_private; - return mlx5_list_get_entry_num(&priv->hrxqs); + return mlx5_list_get_entry_num(priv->hrxqs); } /** diff --git a/drivers/net/mlx5/mlx5_utils.c b/drivers/net/mlx5/mlx5_utils.c index 29248c80ed..a4526444f9 100644 --- a/drivers/net/mlx5/mlx5_utils.c +++ b/drivers/net/mlx5/mlx5_utils.c @@ -11,20 +11,25 @@ /********************* mlx5 list ************************/ -int -mlx5_list_create(struct mlx5_list *list, const char *name, void *ctx, +struct mlx5_list * +mlx5_list_create(const char *name, void *ctx, mlx5_list_create_cb cb_create, mlx5_list_match_cb cb_match, mlx5_list_remove_cb cb_remove, mlx5_list_clone_cb cb_clone, mlx5_list_clone_free_cb cb_clone_free) { + struct mlx5_list *list; int i; - MLX5_ASSERT(list); if (!cb_match || !cb_create || !cb_remove || !cb_clone || - !cb_clone_free) - return -1; + !cb_clone_free) { + rte_errno = EINVAL; + return NULL; + } + list = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*list), 0, SOCKET_ID_ANY); + if (!list) + return NULL; if (name) snprintf(list->name, sizeof(list->name), "%s", name); list->ctx = ctx; @@ -37,7 +42,7 @@ mlx5_list_create(struct mlx5_list *list, const char *name, void *ctx, DRV_LOG(DEBUG, "mlx5 list %s initialized.", list->name); for (i = 0; i <= RTE_MAX_LCORE; i++) LIST_INIT(&list->cache[i].h); - return 0; + return list; } static struct mlx5_list_entry * @@ -244,7 +249,7 @@ mlx5_list_destroy(struct mlx5_list *list) } } } - memset(list, 0, sizeof(*list)); + mlx5_free(list); } uint32_t diff --git a/drivers/net/mlx5/mlx5_utils.h b/drivers/net/mlx5/mlx5_utils.h index ffa9cd5142..0bf2f5f5ca 100644 --- a/drivers/net/mlx5/mlx5_utils.h +++ b/drivers/net/mlx5/mlx5_utils.h @@ -419,15 +419,14 @@ struct mlx5_list { * @param cb_remove * Callback function for entry remove. * @return - * 0 on success, otherwise failure. + * List pointer on success, otherwise NULL. */ -int mlx5_list_create(struct mlx5_list *list, - const char *name, void *ctx, - mlx5_list_create_cb cb_create, - mlx5_list_match_cb cb_match, - mlx5_list_remove_cb cb_remove, - mlx5_list_clone_cb cb_clone, - mlx5_list_clone_free_cb cb_clone_free); +struct mlx5_list *mlx5_list_create(const char *name, void *ctx, + mlx5_list_create_cb cb_create, + mlx5_list_match_cb cb_match, + mlx5_list_remove_cb cb_remove, + mlx5_list_clone_cb cb_clone, + mlx5_list_clone_free_cb cb_clone_free); /** * Search an entry matching the key. diff --git a/drivers/net/mlx5/windows/mlx5_os.c b/drivers/net/mlx5/windows/mlx5_os.c index f6cf1928b2..97a8f04e39 100644 --- a/drivers/net/mlx5/windows/mlx5_os.c +++ b/drivers/net/mlx5/windows/mlx5_os.c @@ -608,7 +608,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err = ENOTSUP; goto error; } - mlx5_list_create(&priv->hrxqs, "hrxq", eth_dev, + priv->hrxqs = mlx5_list_create("hrxq", eth_dev, mlx5_hrxq_create_cb, mlx5_hrxq_match_cb, mlx5_hrxq_remove_cb, mlx5_hrxq_clone_cb, mlx5_hrxq_clone_free_cb); -- 2.25.1