]> git.droids-corp.org - dpdk.git/commitdiff
net/mlx5: fix errno update in shared context creation
authorMichael Baum <michaelba@nvidia.com>
Mon, 14 Feb 2022 09:34:55 +0000 (11:34 +0200)
committerRaslan Darawsheh <rasland@nvidia.com>
Mon, 21 Feb 2022 10:36:40 +0000 (11:36 +0100)
The mlx5_alloc_shared_dev_ctx() function has a local variable named
"err" which contains the errno value in case of failure.

When functions called by this function are failed, this variable is
updated with their return value (that should be a positive errno value).
However, some functions doesn't update errno value by themselves or
return negative errno value. If one of them fails, the "err" variable
contains negative value what cause to assertion failure.

This patch updates all functions uses by mlx5_alloc_shared_dev_ctx()
function to update rte_errno and take this value instead of "err" value.

Fixes: 5dfa003db53f ("common/mlx5: fix post doorbell barrier")
Fixes: 5d55a494f4e6 ("net/mlx5: split multi-thread flow handling per OS")
Cc: stable@dpdk.org
Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
drivers/net/mlx5/linux/mlx5_flow_os.c
drivers/net/mlx5/linux/mlx5_os.c
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/windows/mlx5_flow_os.c
drivers/net/mlx5/windows/mlx5_os.c

index 893f00b82404ebedfe1b3f541fb420dda29f8688..a5956c255af228975e9e814e58bf0ea7d09fe348 100644 (file)
@@ -14,7 +14,8 @@ mlx5_flow_os_init_workspace_once(void)
 {
        if (rte_thread_key_create(&key_workspace, flow_release_workspace)) {
                DRV_LOG(ERR, "Can't create flow workspace data thread key.");
-               return -ENOMEM;
+               rte_errno = ENOMEM;
+               return -rte_errno;
        }
        return 0;
 }
index 69d3e1e3adb0d2c6a5438d1bc841800eff6306c9..faab310b11501f7e632c3499515860f9d1ee81d3 100644 (file)
@@ -138,7 +138,7 @@ mlx5_os_set_nonblock_channel_fd(int fd)
  *   Pointer to mlx5 device attributes.
  *
  * @return
- *   0 on success, non zero error number otherwise
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 int
 mlx5_os_get_dev_attr(struct mlx5_common_device *cdev,
@@ -150,8 +150,10 @@ mlx5_os_get_dev_attr(struct mlx5_common_device *cdev,
 
        memset(device_attr, 0, sizeof(*device_attr));
        err = mlx5_glue->query_device_ex(ctx, NULL, &attr_ex);
-       if (err)
-               return err;
+       if (err) {
+               rte_errno = errno;
+               return -rte_errno;
+       }
        device_attr->device_cap_flags_ex = attr_ex.device_cap_flags_ex;
        device_attr->max_qp_wr = attr_ex.orig_attr.max_qp_wr;
        device_attr->max_sge = attr_ex.orig_attr.max_sge;
@@ -170,8 +172,10 @@ mlx5_os_get_dev_attr(struct mlx5_common_device *cdev,
 
        struct mlx5dv_context dv_attr = { .comp_mask = 0 };
        err = mlx5_glue->dv_query_device(ctx, &dv_attr);
-       if (err)
-               return err;
+       if (err) {
+               rte_errno = errno;
+               return -rte_errno;
+       }
 
        device_attr->flags = dv_attr.flags;
        device_attr->comp_mask = dv_attr.comp_mask;
@@ -195,7 +199,7 @@ mlx5_os_get_dev_attr(struct mlx5_common_device *cdev,
        strlcpy(device_attr->fw_ver, attr_ex.orig_attr.fw_ver,
                sizeof(device_attr->fw_ver));
 
-       return err;
+       return 0;
 }
 
 /**
index cde8d022cd11bb197773a11a5c5e360322da04e8..0e154b88ed8b0ecd1c9be8aeaae6f194dca368d8 100644 (file)
@@ -1172,12 +1172,11 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
        MLX5_ASSERT(spawn->max_port);
        sh = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
                         sizeof(struct mlx5_dev_ctx_shared) +
-                        spawn->max_port *
-                        sizeof(struct mlx5_dev_shared_port),
+                        spawn->max_port * sizeof(struct mlx5_dev_shared_port),
                         RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
        if (!sh) {
-               DRV_LOG(ERR, "shared context allocation failure");
-               rte_errno  = ENOMEM;
+               DRV_LOG(ERR, "Shared context allocation failure.");
+               rte_errno = ENOMEM;
                goto exit;
        }
        pthread_mutex_init(&sh->txpp.mutex, NULL);
@@ -1199,9 +1198,8 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
        strncpy(sh->ibdev_path, mlx5_os_get_ctx_device_path(sh->cdev->ctx),
                sizeof(sh->ibdev_path) - 1);
        /*
-        * Setting port_id to max unallowed value means
-        * there is no interrupt subhandler installed for
-        * the given port index i.
+        * Setting port_id to max unallowed value means there is no interrupt
+        * subhandler installed for the given port index i.
         */
        for (i = 0; i < sh->max_port; i++) {
                sh->port[i].ih_port_id = RTE_MAX_ETHPORTS;
@@ -1211,12 +1209,12 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
                sh->td = mlx5_devx_cmd_create_td(sh->cdev->ctx);
                if (!sh->td) {
                        DRV_LOG(ERR, "TD allocation failure");
-                       err = ENOMEM;
+                       rte_errno = ENOMEM;
                        goto error;
                }
                if (mlx5_setup_tis(sh)) {
                        DRV_LOG(ERR, "TIS allocation failure");
-                       err = ENOMEM;
+                       rte_errno = ENOMEM;
                        goto error;
                }
                err = mlx5_rxtx_uars_prepare(sh);
@@ -1246,19 +1244,19 @@ exit:
        pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
        return sh;
 error:
+       err = rte_errno;
        pthread_mutex_destroy(&sh->txpp.mutex);
        pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
        MLX5_ASSERT(sh);
-       if (sh->td)
-               claim_zero(mlx5_devx_cmd_destroy(sh->td));
+       mlx5_rxtx_uars_release(sh);
        i = 0;
        do {
                if (sh->tis[i])
                        claim_zero(mlx5_devx_cmd_destroy(sh->tis[i]));
        } while (++i < (uint32_t)sh->bond.n_port);
-       mlx5_rxtx_uars_release(sh);
+       if (sh->td)
+               claim_zero(mlx5_devx_cmd_destroy(sh->td));
        mlx5_free(sh);
-       MLX5_ASSERT(err > 0);
        rte_errno = err;
        return NULL;
 }
index 7bb4c4590a88c92acfd2632bee1e1f98512cae81..f5e3893ed48970e5e603b22edbd7b6cb1206c59f 100644 (file)
@@ -372,7 +372,7 @@ mlx5_flow_os_init_workspace_once(void)
 
        if (err) {
                DRV_LOG(ERR, "Can't create flow workspace data thread key.");
-               return err;
+               return -rte_errno;
        }
        pthread_mutex_init(&lock_thread_list, NULL);
        return 0;
index 3db33cd0cfe4486fbe719d6d8bee548952395441..a9619e5bdae519864597397cf1cc17db0f4b47f2 100644 (file)
@@ -152,7 +152,7 @@ mlx5_init_once(void)
  *   Pointer to mlx5 device attributes.
  *
  * @return
- *   0 on success, non zero error number otherwise.
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 int
 mlx5_os_get_dev_attr(struct mlx5_common_device *cdev,
@@ -161,10 +161,11 @@ mlx5_os_get_dev_attr(struct mlx5_common_device *cdev,
        struct mlx5_context *mlx5_ctx;
        void *pv_iseg = NULL;
        u32 cb_iseg = 0;
-       int err = 0;
 
-       if (!cdev || !cdev->ctx)
-               return -EINVAL;
+       if (!cdev || !cdev->ctx) {
+               rte_errno = EINVAL;
+               return -rte_errno;
+       }
        mlx5_ctx = (struct mlx5_context *)cdev->ctx;
        memset(device_attr, 0, sizeof(*device_attr));
        device_attr->max_cq = 1 << cdev->config.hca_attr.log_max_cq;
@@ -187,15 +188,14 @@ mlx5_os_get_dev_attr(struct mlx5_common_device *cdev,
        pv_iseg = mlx5_glue->query_hca_iseg(mlx5_ctx, &cb_iseg);
        if (pv_iseg == NULL) {
                DRV_LOG(ERR, "Failed to get device hca_iseg");
-               return errno;
-       }
-       if (!err) {
-               snprintf(device_attr->fw_ver, 64, "%x.%x.%04x",
-                       MLX5_GET(initial_seg, pv_iseg, fw_rev_major),
-                       MLX5_GET(initial_seg, pv_iseg, fw_rev_minor),
-                       MLX5_GET(initial_seg, pv_iseg, fw_rev_subminor));
+               rte_errno = errno;
+               return -rte_errno;
        }
-       return err;
+       snprintf(device_attr->fw_ver, 64, "%x.%x.%04x",
+                MLX5_GET(initial_seg, pv_iseg, fw_rev_major),
+                MLX5_GET(initial_seg, pv_iseg, fw_rev_minor),
+                MLX5_GET(initial_seg, pv_iseg, fw_rev_subminor));
+       return 0;
 }
 
 /**