From 5c761238107cabe8db35c496de577d745f35362a Mon Sep 17 00:00:00 2001 From: Gregory Etelson Date: Mon, 8 Jun 2020 19:01:56 +0300 Subject: [PATCH] net/mlx5: fix flow memory allocation size In DV enabled MLX5 PMD build mlx5_ipool_cfg[MLX5_IPOOL_MLX5_FLOW].size was initiated for DV structure. If RTE initialization encountered MLX5 PCI function with disabled DV support mlx5_ipool_cfg[MLX5_IPOOL_MLX5_FLOW].size was reduced to match legacy verbs flow size. Since mlx5_ipool_cfg[MLX5_IPOOL_MLX5_FLOW] is a global variable that change reflected on DV enabled MLX5 PCI functions too. Running flow with invalid ipool size crashes PMD. The patch adjusts ipool flow size for each active PCI function. Fixes: b88341ca35fc ("net/mlx5: convert flow dev handle to indexed") Cc: stable@dpdk.org Signed-off-by: Gregory Etelson Acked-by: Matan Azrad --- drivers/net/mlx5/mlx5.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 7c5e23d9fc..6cb59bdc08 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -179,7 +179,7 @@ int mlx5_logtype; static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_ibv_list = LIST_HEAD_INITIALIZER(); static pthread_mutex_t mlx5_ibv_list_mutex = PTHREAD_MUTEX_INITIALIZER; -static struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = { +static const struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = { #ifdef HAVE_IBV_FLOW_DV_SUPPORT { .size = sizeof(struct mlx5_flow_dv_encap_decap_resource), @@ -271,7 +271,11 @@ static struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = { .type = "mlx5_hrxq_ipool", }, { - .size = sizeof(struct mlx5_flow_handle), + /* + * MLX5_IPOOL_MLX5_FLOW size varies for DV and VERBS flows. + * It set in run time according to PCI function configuration. + */ + .size = 0, .trunk_size = 64, .grow_trunk = 3, .grow_shift = 2, @@ -542,24 +546,29 @@ mlx5_flow_counters_mng_close(struct mlx5_dev_ctx_shared *sh) */ static void mlx5_flow_ipool_create(struct mlx5_dev_ctx_shared *sh, - const struct mlx5_dev_config *config __rte_unused) + const struct mlx5_dev_config *config) { uint8_t i; + struct mlx5_indexed_pool_config cfg; -#ifdef HAVE_IBV_FLOW_DV_SUPPORT - /* - * While DV is supported, user chooses the verbs mode, - * the mlx5 flow handle size is different with the - * MLX5_FLOW_HANDLE_VERBS_SIZE. - */ - if (!config->dv_flow_en) - mlx5_ipool_cfg[MLX5_IPOOL_MLX5_FLOW].size = - MLX5_FLOW_HANDLE_VERBS_SIZE; -#endif for (i = 0; i < MLX5_IPOOL_MAX; ++i) { + cfg = mlx5_ipool_cfg[i]; + switch (i) { + default: + break; + /* + * Set MLX5_IPOOL_MLX5_FLOW ipool size + * according to PCI function flow configuration. + */ + case MLX5_IPOOL_MLX5_FLOW: + cfg.size = config->dv_flow_en ? + sizeof(struct mlx5_flow_handle) : + MLX5_FLOW_HANDLE_VERBS_SIZE; + break; + } if (config->reclaim_mode) - mlx5_ipool_cfg[i].release_mem_en = 1; - sh->ipool[i] = mlx5_ipool_create(&mlx5_ipool_cfg[i]); + cfg.release_mem_en = 1; + sh->ipool[i] = mlx5_ipool_create(&cfg); } } -- 2.20.1