From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3130E45C76; Mon, 4 Nov 2024 12:16:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4B41A42D7D; Mon, 4 Nov 2024 12:11:45 +0100 (CET) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 6C7A840E26 for ; Mon, 4 Nov 2024 12:10:47 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4XhpYb1C4jz1JB6S; Mon, 4 Nov 2024 19:06:11 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id 273DA1400D2; Mon, 4 Nov 2024 19:10:45 +0800 (CST) Received: from localhost.huawei.com (10.50.165.33) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 4 Nov 2024 19:10:44 +0800 From: Dengdui Huang To: CC: , , , , , , , , , , Subject: [PATCH v5 39/52] net/mlx4: replace strerror with reentrant version Date: Mon, 4 Nov 2024 19:10:24 +0800 Message-ID: <20241104111037.3632161-40-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241104111037.3632161-1-huangdengdui@huawei.com> References: <20231114082539.1858594-1-huangdengdui@huawei.com> <20241104111037.3632161-1-huangdengdui@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500011.china.huawei.com (7.185.36.84) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The function strerror() is insecure in a multi-thread environment. This patch uses strerror_r() to replace it. Signed-off-by: Dengdui Huang Acked-by: Chengwen Feng Acked-by: Morten Brørup Acked-by: Huisong Li --- drivers/net/mlx4/mlx4.c | 27 +++++++++++++++++++++------ drivers/net/mlx4/mlx4_rxq.c | 14 +++++++++++--- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index 9c2872429f..e8872e105c 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -247,15 +247,18 @@ static int mlx4_dev_configure(struct rte_eth_dev *dev) { struct mlx4_priv *priv = dev->data->dev_private; + char errmsg[RTE_STRERR_BUFSIZE]; struct rte_flow_error error; int ret; /* Prepare internal flow rules. */ ret = mlx4_flow_sync(priv, &error); if (ret) { + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); ERROR("cannot set up internal flow rules (code %d, \"%s\")," " flow error type %d, cause %p, message: %s", - -ret, strerror(-ret), error.type, error.cause, + -ret, errmsg, error.type, error.cause, error.message ? error.message : "(unspecified)"); goto exit; } @@ -291,6 +294,7 @@ static int mlx4_dev_start(struct rte_eth_dev *dev) { struct mlx4_priv *priv = dev->data->dev_private; + char errmsg[RTE_STRERR_BUFSIZE]; struct rte_flow_error error; uint16_t i; int ret; @@ -301,8 +305,10 @@ mlx4_dev_start(struct rte_eth_dev *dev) priv->started = 1; ret = mlx4_rss_init(priv); if (ret) { + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); ERROR("%p: cannot initialize RSS resources: %s", - (void *)dev, strerror(-ret)); + (void *)dev, errmsg); goto err; } #ifdef RTE_LIBRTE_MLX4_DEBUG @@ -316,10 +322,12 @@ mlx4_dev_start(struct rte_eth_dev *dev) } ret = mlx4_flow_sync(priv, &error); if (ret) { + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); ERROR("%p: cannot attach flow rules (code %d, \"%s\")," " flow error type %d, cause %p, message: %s", (void *)dev, - -ret, strerror(-ret), error.type, error.cause, + -ret, errmsg, error.type, error.cause, error.message ? error.message : "(unspecified)"); goto err; } @@ -788,6 +796,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) unsigned int vf; int i; char ifname[IF_NAMESIZE]; + char errmsg[RTE_STRERR_BUFSIZE]; (void)pci_drv; err = mlx4_init_once(); @@ -946,7 +955,9 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) err = mlx4_glue->query_port(ctx, port, &port_attr); if (err) { err = ENODEV; - ERROR("port query failed: %s", strerror(err)); + if (strerror_r(err, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", err); + ERROR("port query failed: %s", errmsg); goto port_error; } if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) { @@ -962,8 +973,10 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) /* Make asynchronous FD non-blocking to handle interrupts. */ err = mlx4_fd_set_non_blocking(ctx->async_fd); if (err) { + if (strerror_r(err, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", err); ERROR("cannot make asynchronous FD non-blocking: %s", - strerror(err)); + errmsg); goto port_error; } /* Allocate protection domain. */ @@ -1023,8 +1036,10 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) /* Configure the first MAC address by default. */ err = mlx4_get_mac(priv, &mac.addr_bytes); if (err) { + if (strerror_r(err, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", err); ERROR("cannot get MAC address, is mlx4_en loaded?" - " (error: %s)", strerror(err)); + " (error: %s)", errmsg); goto port_error; } INFO("port %u MAC address is " RTE_ETHER_ADDR_PRT_FMT, diff --git a/drivers/net/mlx4/mlx4_rxq.c b/drivers/net/mlx4/mlx4_rxq.c index 781ee256df..d147bcad26 100644 --- a/drivers/net/mlx4/mlx4_rxq.c +++ b/drivers/net/mlx4/mlx4_rxq.c @@ -332,6 +332,7 @@ mlx4_rss_init(struct mlx4_priv *priv) { struct rte_eth_dev *dev = ETH_DEV(priv); uint8_t log2_range = rte_log2_u32(dev->data->nb_rx_queues); + char errmsg[RTE_STRERR_BUFSIZE]; uint32_t wq_num_prev = 0; const char *msg; unsigned int i; @@ -351,9 +352,11 @@ mlx4_rss_init(struct mlx4_priv *priv) MLX4DV_SET_CTX_ATTR_LOG_WQS_RANGE_SZ, &log2_range); if (ret) { + if (strerror_r(ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", ret); ERROR("cannot set up range size for RSS context to %u" " (for %u Rx queues), error: %s", - 1 << log2_range, dev->data->nb_rx_queues, strerror(ret)); + 1 << log2_range, dev->data->nb_rx_queues, errmsg); rte_errno = ret; return -ret; } @@ -430,8 +433,10 @@ mlx4_rss_init(struct mlx4_priv *priv) priv->rss_init = 1; return 0; error: + if (strerror_r(ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", ret); ERROR("cannot initialize common RSS resources (queue %u): %s: %s", - i, msg, strerror(ret)); + i, msg, errmsg); while (i--) { struct rxq *rxq = ETH_DEV(priv)->data->rx_queues[i]; @@ -508,6 +513,7 @@ mlx4_rxq_attach(struct rxq *rxq) uint32_t create_flags = 0; uint32_t comp_mask = 0; volatile struct mlx4_wqe_data_seg (*wqes)[]; + char errmsg[RTE_STRERR_BUFSIZE]; unsigned int i; int ret; @@ -630,8 +636,10 @@ mlx4_rxq_attach(struct rxq *rxq) claim_zero(mlx4_glue->destroy_cq(cq)); --rxq->usecnt; rte_errno = ret; + if (strerror_r(ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", ret); ERROR("error while attaching Rx queue %p: %s: %s", - (void *)rxq, msg, strerror(ret)); + (void *)rxq, msg, errmsg); priv->verbs_alloc_ctx.type = MLX4_VERBS_ALLOC_TYPE_NONE; return -ret; } -- 2.33.0