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 0E9B845BAE; Wed, 23 Oct 2024 10:30:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C32EB427B0; Wed, 23 Oct 2024 10:29:19 +0200 (CEST) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 580C540E3B for ; Wed, 23 Oct 2024 10:28:57 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4XYMc469Rtz1jBC4; Wed, 23 Oct 2024 16:27:32 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id B7D741A0188; Wed, 23 Oct 2024 16:28:55 +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; Wed, 23 Oct 2024 16:28:55 +0800 From: Dengdui Huang To: CC: , , , , , , , , Subject: [PATCH v4 13/42] bus/pci: use rte strerror Date: Wed, 23 Oct 2024 16:28:23 +0800 Message-ID: <20241023082852.2780488-14-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241023082852.2780488-1-huangdengdui@huawei.com> References: <20231114082539.1858594-44-huangdengdui@huawei.com> <20241023082852.2780488-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: dggems705-chm.china.huawei.com (10.3.19.182) 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 rte_strerror() to replace it. Cc: stable@dpdk.org Signed-off-by: Dengdui Huang Acked-by: Chengwen Feng Acked-by: Morten Brørup --- drivers/bus/pci/bsd/pci.c | 8 ++++---- drivers/bus/pci/linux/pci.c | 7 ++++--- drivers/bus/pci/linux/pci_uio.c | 23 ++++++++++++----------- drivers/bus/pci/linux/pci_vfio.c | 23 ++++++++++++----------- drivers/bus/pci/pci_common_uio.c | 3 ++- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c index 2f88252418..cf10a3b66a 100644 --- a/drivers/bus/pci/bsd/pci.c +++ b/drivers/bus/pci/bsd/pci.c @@ -122,7 +122,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, } if (rte_intr_fd_get(dev->intr_handle) < 0) { - PCI_LOG(ERR, "Cannot open %s: %s", devname, strerror(errno)); + PCI_LOG(ERR, "Cannot open %s: %s", devname, rte_strerror(errno)); goto error; } @@ -164,7 +164,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, /* allocate memory to keep path */ maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0); if (maps[map_idx].path == NULL) { - PCI_LOG(ERR, "Cannot allocate memory for path: %s", strerror(errno)); + PCI_LOG(ERR, "Cannot allocate memory for path: %s", rte_strerror(errno)); return -1; } @@ -173,7 +173,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, */ fd = open(devname, O_RDWR); if (fd < 0) { - PCI_LOG(ERR, "Cannot open %s: %s", devname, strerror(errno)); + PCI_LOG(ERR, "Cannot open %s: %s", devname, rte_strerror(errno)); goto error; } @@ -347,7 +347,7 @@ rte_pci_scan(void) unsigned i; if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) { PCI_LOG(ERR, "%s(): error with ioctl on /dev/pci: %s", - __func__, strerror(errno)); + __func__, rte_strerror(errno)); goto error; } diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c index 9056035b33..1350412610 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "eal_filesystem.h" @@ -449,7 +450,7 @@ rte_pci_scan(void) dir = opendir(rte_pci_get_sysfs_path()); if (dir == NULL) { - PCI_LOG(ERR, "%s(): opendir failed: %s", __func__, strerror(errno)); + PCI_LOG(ERR, "%s(): opendir failed: %s", __func__, rte_strerror(errno)); return -1; } @@ -500,7 +501,7 @@ pci_device_iommu_support_va(const struct rte_pci_device *dev) return true; PCI_LOG(ERR, "%s(): can't open %s: %s", - __func__, filename, strerror(errno)); + __func__, filename, rte_strerror(errno)); return false; } @@ -551,7 +552,7 @@ pci_device_iommu_support_va(__rte_unused const struct rte_pci_device *dev) if (fp == NULL) { PCI_LOG(ERR, "%s(): can't open %s: %s", - __func__, filename, strerror(errno)); + __func__, filename, rte_strerror(errno)); return ret; } diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c index 4c1d3327a9..58039176ce 100644 --- a/drivers/bus/pci/linux/pci_uio.c +++ b/drivers/bus/pci/linux/pci_uio.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "eal_filesystem.h" #include "pci_init.h" @@ -108,7 +109,7 @@ pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num) dev = makedev(major, minor); ret = mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, dev); if (ret != 0) { - PCI_LOG(ERR, "%s(): mknod() failed %s", __func__, strerror(errno)); + PCI_LOG(ERR, "%s(): mknod() failed %s", __func__, rte_strerror(errno)); return -1; } @@ -237,7 +238,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, /* save fd */ fd = open(devname, O_RDWR); if (fd < 0) { - PCI_LOG(ERR, "Cannot open %s: %s", devname, strerror(errno)); + PCI_LOG(ERR, "Cannot open %s: %s", devname, rte_strerror(errno)); goto error; } @@ -249,7 +250,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, uio_cfg_fd = open(cfgname, O_RDWR); if (uio_cfg_fd < 0) { - PCI_LOG(ERR, "Cannot open %s: %s", cfgname, strerror(errno)); + PCI_LOG(ERR, "Cannot open %s: %s", cfgname, rte_strerror(errno)); goto error; } @@ -310,7 +311,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, /* allocate memory to keep path */ maps[map_idx].path = rte_malloc(NULL, sizeof(devname), 0); if (maps[map_idx].path == NULL) { - PCI_LOG(ERR, "Cannot allocate memory for path: %s", strerror(errno)); + PCI_LOG(ERR, "Cannot allocate memory for path: %s", rte_strerror(errno)); return -1; } @@ -342,7 +343,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, /* then try to map resource file */ fd = open(devname, O_RDWR); if (fd < 0) { - PCI_LOG(ERR, "Cannot open %s: %s", devname, strerror(errno)); + PCI_LOG(ERR, "Cannot open %s: %s", devname, rte_strerror(errno)); goto error; } } @@ -397,7 +398,7 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, dev->addr.devid, dev->addr.function); f = fopen(filename, "r"); if (f == NULL) { - PCI_LOG(ERR, "%s(): Cannot open sysfs resource: %s", __func__, strerror(errno)); + PCI_LOG(ERR, "%s(): Cannot open sysfs resource: %s", __func__, rte_strerror(errno)); return -1; } @@ -438,14 +439,14 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, RTE_INTR_HANDLE_UNKNOWN) { int uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname), 0); if (uio_num < 0) { - PCI_LOG(ERR, "cannot open %s: %s", dirname, strerror(errno)); + PCI_LOG(ERR, "cannot open %s: %s", dirname, rte_strerror(errno)); goto error; } snprintf(filename, sizeof(filename), "/dev/uio%u", uio_num); fd = open(filename, O_RDWR); if (fd < 0) { - PCI_LOG(ERR, "Cannot open %s: %s", filename, strerror(errno)); + PCI_LOG(ERR, "Cannot open %s: %s", filename, rte_strerror(errno)); goto error; } if (rte_intr_fd_set(dev->intr_handle, fd)) @@ -484,7 +485,7 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, dev->addr.devid, dev->addr.function); f = fopen(filename, "r"); if (f == NULL) { - PCI_LOG(ERR, "Cannot open sysfs resource: %s", strerror(errno)); + PCI_LOG(ERR, "Cannot open sysfs resource: %s", rte_strerror(errno)); return -1; } for (i = 0; i < bar + 1; i++) { @@ -507,14 +508,14 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, /* mmap the pci resource */ fd = open(filename, O_RDWR); if (fd < 0) { - PCI_LOG(ERR, "Cannot open %s: %s", filename, strerror(errno)); + PCI_LOG(ERR, "Cannot open %s: %s", filename, rte_strerror(errno)); goto error; } addr = mmap(NULL, end_addr + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close(fd); if (addr == MAP_FAILED) { - PCI_LOG(ERR, "Cannot mmap IO port resource: %s", strerror(errno)); + PCI_LOG(ERR, "Cannot mmap IO port resource: %s", rte_strerror(errno)); goto error; } diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index 5317170231..6ccf097fb7 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "eal_filesystem.h" @@ -223,7 +224,7 @@ pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd) ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_IRQ_INFO, &irq); if (ret < 0) { PCI_LOG(ERR, "Cannot get VFIO IRQ info, error %i (%s)", - errno, strerror(errno)); + errno, rte_strerror(errno)); return -1; } @@ -249,7 +250,7 @@ pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd) fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (fd < 0) { PCI_LOG(ERR, "Cannot set up eventfd, error %i (%s)", - errno, strerror(errno)); + errno, rte_strerror(errno)); return -1; } @@ -330,7 +331,7 @@ pci_vfio_enable_notifier(struct rte_pci_device *dev, int vfio_dev_fd) fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (fd < 0) { PCI_LOG(ERR, "Cannot set up eventfd, error %i (%s)", - errno, strerror(errno)); + errno, rte_strerror(errno)); return -1; } @@ -451,7 +452,7 @@ pci_rte_vfio_setup_device(struct rte_pci_device *dev, int vfio_dev_fd) * then it updates errno as EINVAL. */ if (ioctl(vfio_dev_fd, VFIO_DEVICE_RESET) && errno != EINVAL) { - PCI_LOG(ERR, "Unable to reset device! Error: %d (%s)", errno, strerror(errno)); + PCI_LOG(ERR, "Unable to reset device! Error: %d (%s)", errno, rte_strerror(errno)); return -1; } @@ -724,7 +725,7 @@ pci_vfio_fill_regions(struct rte_pci_device *dev, int vfio_dev_fd, ret = pci_vfio_get_region_info(vfio_dev_fd, ®, i); if (ret < 0) { PCI_LOG(DEBUG, "%s cannot get device region info error %i (%s)", - dev->name, errno, strerror(errno)); + dev->name, errno, rte_strerror(errno)); return -1; } @@ -792,7 +793,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) VFIO_PCI_CONFIG_REGION_INDEX); if (ret < 0) { PCI_LOG(ERR, "%s cannot get device region info error %i (%s)", - dev->name, errno, strerror(errno)); + dev->name, errno, rte_strerror(errno)); goto err_vfio_res; } pdev->region[VFIO_PCI_CONFIG_REGION_INDEX].size = reg->size; @@ -830,7 +831,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) ret = pci_vfio_get_region_info(vfio_dev_fd, ®, i); if (ret < 0) { PCI_LOG(ERR, "%s cannot get device region info error %i (%s)", - pci_addr, errno, strerror(errno)); + pci_addr, errno, rte_strerror(errno)); goto err_map; } @@ -891,7 +892,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) ret = pci_vfio_sparse_mmap_bar(vfio_dev_fd, vfio_res, i, 0); if (ret < 0) { PCI_LOG(ERR, "%s sparse mapping BAR%i failed: %s", - pci_addr, i, strerror(errno)); + pci_addr, i, rte_strerror(errno)); free(reg); goto err_map; } @@ -899,7 +900,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) ret = pci_vfio_mmap_bar(vfio_dev_fd, vfio_res, i, 0); if (ret < 0) { PCI_LOG(ERR, "%s mapping BAR%i failed: %s", - pci_addr, i, strerror(errno)); + pci_addr, i, rte_strerror(errno)); free(reg); goto err_map; } @@ -995,14 +996,14 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev) ret = pci_vfio_sparse_mmap_bar(vfio_dev_fd, vfio_res, i, MAP_FIXED); if (ret < 0) { PCI_LOG(ERR, "%s sparse mapping BAR%i failed: %s", - pci_addr, i, strerror(errno)); + pci_addr, i, rte_strerror(errno)); goto err_vfio_dev_fd; } } else { ret = pci_vfio_mmap_bar(vfio_dev_fd, vfio_res, i, MAP_FIXED); if (ret < 0) { PCI_LOG(ERR, "%s mapping BAR%i failed: %s", - pci_addr, i, strerror(errno)); + pci_addr, i, rte_strerror(errno)); goto err_vfio_dev_fd; } } diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c index 30503bd23a..b2b0ba798d 100644 --- a/drivers/bus/pci/pci_common_uio.c +++ b/drivers/bus/pci/pci_common_uio.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "private.h" @@ -52,7 +53,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev) fd = open(uio_res->maps[i].path, O_RDWR); if (fd < 0) { PCI_LOG(ERR, "Cannot open %s: %s", - uio_res->maps[i].path, strerror(errno)); + uio_res->maps[i].path, rte_strerror(errno)); return -1; } -- 2.33.0