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 76A7B45C76; Mon, 4 Nov 2024 12:16:00 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D606E427E2; Mon, 4 Nov 2024 12:11:39 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id F2B3140A72 for ; Mon, 4 Nov 2024 12:10:47 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Xhpct2vPvzyVQ6; Mon, 4 Nov 2024 19:09:02 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id EDBCA140137; Mon, 4 Nov 2024 19:10:46 +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:46 +0800 From: Dengdui Huang To: CC: , , , , , , , , , , Subject: [PATCH v5 50/52] vdpa/ifc: replace strerror with reentrant version Date: Mon, 4 Nov 2024 19:10:35 +0800 Message-ID: <20241104111037.3632161-51-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/vdpa/ifc/ifcvf_vdpa.c | 57 ++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index 65de383b95..170614d8ce 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "base/ifcvf.h" @@ -407,6 +408,7 @@ vdpa_enable_vfio_intr(struct ifcvf_internal *internal, bool m_rx) int ret; uint32_t i, nr_vring; char irq_set_buf[MSIX_IRQ_SET_BUF_LEN]; + char errmsg[RTE_STRERR_BUFSIZE]; struct vfio_irq_set *irq_set; int *fd_ptr; struct rte_vhost_vring vring; @@ -445,8 +447,9 @@ vdpa_enable_vfio_intr(struct ifcvf_internal *internal, bool m_rx) */ fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (fd < 0) { - DRV_LOG(ERR, "can't setup eventfd: %s", - strerror(errno)); + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); + DRV_LOG(ERR, "can't setup eventfd: %s", errmsg); return -1; } internal->intr_fd[i] = fd; @@ -456,8 +459,9 @@ vdpa_enable_vfio_intr(struct ifcvf_internal *internal, bool m_rx) ret = ioctl(internal->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set); if (ret) { - DRV_LOG(ERR, "Error enabling MSI-X interrupts: %s", - strerror(errno)); + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); + DRV_LOG(ERR, "Error enabling MSI-X interrupts: %s", errmsg); return -1; } @@ -470,6 +474,7 @@ vdpa_disable_vfio_intr(struct ifcvf_internal *internal) int ret; uint32_t i, nr_vring; char irq_set_buf[MSIX_IRQ_SET_BUF_LEN]; + char errmsg[RTE_STRERR_BUFSIZE]; struct vfio_irq_set *irq_set; irq_set = (struct vfio_irq_set *)irq_set_buf; @@ -488,8 +493,9 @@ vdpa_disable_vfio_intr(struct ifcvf_internal *internal) ret = ioctl(internal->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set); if (ret) { - DRV_LOG(ERR, "Error disabling MSI-X interrupts: %s", - strerror(errno)); + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); + DRV_LOG(ERR, "Error disabling MSI-X interrupts: %s", errmsg); return -1; } @@ -502,6 +508,7 @@ notify_relay(void *arg) int i, kickfd, epfd, nfds = 0; uint32_t qid, q_num; struct epoll_event events[IFCVF_MAX_QUEUES * 2]; + char errmsg[RTE_STRERR_BUFSIZE]; struct epoll_event ev; uint64_t buf; int nbytes; @@ -526,7 +533,9 @@ notify_relay(void *arg) rte_vhost_get_vhost_vring(internal->vid, qid, &vring); ev.data.u64 = qid | (uint64_t)vring.kickfd << 32; if (epoll_ctl(epfd, EPOLL_CTL_ADD, vring.kickfd, &ev) < 0) { - DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); + DRV_LOG(ERR, "epoll add error: %s", errmsg); return 1; } } @@ -550,9 +559,12 @@ notify_relay(void *arg) errno == EWOULDBLOCK || errno == EAGAIN) continue; + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), + "Unknown error %d", errno); DRV_LOG(INFO, "Error reading " "kickfd: %s", - strerror(errno)); + errmsg); } break; } while (1); @@ -612,6 +624,7 @@ static uint32_t intr_relay(void *arg) { struct ifcvf_internal *internal = (struct ifcvf_internal *)arg; + char errmsg[RTE_STRERR_BUFSIZE]; struct epoll_event csc_event; struct epoll_event ev; uint64_t buf; @@ -628,7 +641,9 @@ intr_relay(void *arg) ev.data.fd = rte_intr_fd_get(internal->pdev->intr_handle); if (epoll_ctl(csc_epfd, EPOLL_CTL_ADD, rte_intr_fd_get(internal->pdev->intr_handle), &ev) < 0) { - DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); + DRV_LOG(ERR, "epoll add error: %s", errmsg); goto out; } @@ -651,9 +666,11 @@ intr_relay(void *arg) errno == EWOULDBLOCK || errno == EAGAIN) continue; + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); DRV_LOG(ERR, "Error reading from file descriptor %d: %s", csc_event.data.fd, - strerror(errno)); + errmsg); goto out; } else if (nbytes == 0) { DRV_LOG(ERR, "Read nothing from file descriptor %d", @@ -926,6 +943,7 @@ vring_relay(void *arg) struct rte_vhost_vring vring; uint16_t qid, q_num; struct epoll_event events[IFCVF_MAX_QUEUES * 4]; + char errmsg[RTE_STRERR_BUFSIZE]; struct epoll_event ev; int nbytes; uint64_t buf; @@ -947,7 +965,9 @@ vring_relay(void *arg) rte_vhost_get_vhost_vring(vid, qid, &vring); ev.data.u64 = qid << 1 | (uint64_t)vring.kickfd << 32; if (epoll_ctl(epfd, EPOLL_CTL_ADD, vring.kickfd, &ev) < 0) { - DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); + DRV_LOG(ERR, "epoll add error: %s", errmsg); return 1; } } @@ -961,7 +981,9 @@ vring_relay(void *arg) (uint64_t)internal->intr_fd[qid] << 32; if (epoll_ctl(epfd, EPOLL_CTL_ADD, internal->intr_fd[qid], &ev) < 0) { - DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); + DRV_LOG(ERR, "epoll add error: %s", errmsg); return 1; } update_used_ring(internal, qid); @@ -990,9 +1012,12 @@ vring_relay(void *arg) errno == EWOULDBLOCK || errno == EAGAIN) continue; + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), + "Unknown error %d", errno); DRV_LOG(INFO, "Error reading " "kickfd: %s", - strerror(errno)); + errmsg); } break; } while (1); @@ -1250,6 +1275,7 @@ ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) struct internal_list *list; struct ifcvf_internal *internal; struct vfio_region_info reg = { .argsz = sizeof(reg) }; + char errmsg[RTE_STRERR_BUFSIZE]; int ret; vdev = rte_vhost_get_vdpa_device(vid); @@ -1264,8 +1290,9 @@ ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) reg.index = ifcvf_get_notify_region(&internal->hw); ret = ioctl(internal->vfio_dev_fd, VFIO_DEVICE_GET_REGION_INFO, ®); if (ret) { - DRV_LOG(ERR, "Get not get device region info: %s", - strerror(errno)); + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); + DRV_LOG(ERR, "Get not get device region info: %s", errmsg); return -1; } -- 2.33.0