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 9E8F245BAE; Wed, 23 Oct 2024 10:32:30 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B064242D91; Wed, 23 Oct 2024 10:29:43 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 0C69840E5A for ; Wed, 23 Oct 2024 10:29:01 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XYMZs4rM8zfdY7; Wed, 23 Oct 2024 16:26:29 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id EA0451800D9; Wed, 23 Oct 2024 16:28:59 +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:59 +0800 From: Dengdui Huang To: CC: , , , , , , , , Subject: [PATCH v4 38/42] net/virtio: use rte strerror Date: Wed, 23 Oct 2024 16:28:48 +0800 Message-ID: <20241023082852.2780488-39-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/net/virtio/virtio_user/vhost_kernel.c | 8 +++--- .../net/virtio/virtio_user/vhost_kernel_tap.c | 25 ++++++++++--------- drivers/net/virtio/virtio_user/vhost_user.c | 20 +++++++-------- drivers/net/virtio/virtio_user/vhost_vdpa.c | 12 ++++----- .../net/virtio/virtio_user/virtio_user_dev.c | 8 +++--- drivers/net/virtio/virtio_user_ethdev.c | 6 ++--- 6 files changed, 40 insertions(+), 39 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c index e42bb35935..b1dec119fc 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c @@ -92,7 +92,7 @@ vhost_kernel_ioctl(int fd, uint64_t request, void *arg) ret = ioctl(fd, request, arg); if (ret) { PMD_DRV_LOG(ERR, "Vhost-kernel ioctl %"PRIu64" failed (%s)", - request, strerror(errno)); + request, rte_strerror(errno)); return -1; } @@ -428,7 +428,7 @@ vhost_kernel_setup(struct virtio_user_dev *dev) for (i = 0; i < dev->max_queue_pairs; ++i) { vhostfd = open(dev->path, O_RDWR); if (vhostfd < 0) { - PMD_DRV_LOG(ERR, "fail to open %s, %s", dev->path, strerror(errno)); + PMD_DRV_LOG(ERR, "fail to open %s, %s", dev->path, rte_strerror(errno)); goto err_tapfds; } data->vhostfds[i] = vhostfd; @@ -511,14 +511,14 @@ vhost_kernel_set_backend(int vhostfd, int tapfd) f.index = 0; if (ioctl(vhostfd, VHOST_NET_SET_BACKEND, &f) < 0) { PMD_DRV_LOG(ERR, "VHOST_NET_SET_BACKEND fails, %s", - strerror(errno)); + rte_strerror(errno)); return -1; } f.index = 1; if (ioctl(vhostfd, VHOST_NET_SET_BACKEND, &f) < 0) { PMD_DRV_LOG(ERR, "VHOST_NET_SET_BACKEND fails, %s", - strerror(errno)); + rte_strerror(errno)); return -1; } diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c index 611e2e25ec..4542ccbf04 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c @@ -13,6 +13,7 @@ #include #include +#include #include "vhost_kernel_tap.h" #include "../virtio_logs.h" @@ -27,12 +28,12 @@ tap_support_features(unsigned int *tap_features) tapfd = open(PATH_NET_TUN, O_RDWR); if (tapfd < 0) { PMD_DRV_LOG(ERR, "fail to open %s: %s", - PATH_NET_TUN, strerror(errno)); + PATH_NET_TUN, rte_strerror(errno)); return -1; } if (ioctl(tapfd, TUNGETFEATURES, tap_features) == -1) { - PMD_DRV_LOG(ERR, "TUNGETFEATURES failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNGETFEATURES failed: %s", rte_strerror(errno)); close(tapfd); return -1; } @@ -49,11 +50,11 @@ tap_open(const char *ifname, unsigned int r_flags, bool multi_queue) tapfd = open(PATH_NET_TUN, O_RDWR); if (tapfd < 0) { - PMD_DRV_LOG(ERR, "fail to open %s: %s", PATH_NET_TUN, strerror(errno)); + PMD_DRV_LOG(ERR, "fail to open %s: %s", PATH_NET_TUN, rte_strerror(errno)); return -1; } if (fcntl(tapfd, F_SETFL, O_NONBLOCK) < 0) { - PMD_DRV_LOG(ERR, "fcntl tapfd failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "fcntl tapfd failed: %s", rte_strerror(errno)); close(tapfd); return -1; } @@ -68,12 +69,12 @@ tap_open(const char *ifname, unsigned int r_flags, bool multi_queue) if (multi_queue) { PMD_DRV_LOG(DEBUG, "TUNSETIFF failed (will retry without IFF_MULTI_QUEUE): %s", - strerror(errno)); + rte_strerror(errno)); multi_queue = false; goto retry_mono_q; } - PMD_DRV_LOG(ERR, "TUNSETIFF failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNSETIFF failed: %s", rte_strerror(errno)); close(tapfd); tapfd = -1; } @@ -88,7 +89,7 @@ tap_get_name(int tapfd, char **name) memset(&ifr, 0, sizeof(ifr)); if (ioctl(tapfd, TUNGETIFF, (void *)&ifr) == -1) { - PMD_DRV_LOG(ERR, "TUNGETIFF failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNGETIFF failed: %s", rte_strerror(errno)); return -1; } ret = asprintf(name, "%s", ifr.ifr_name); @@ -104,7 +105,7 @@ tap_get_flags(int tapfd, unsigned int *tap_flags) memset(&ifr, 0, sizeof(ifr)); if (ioctl(tapfd, TUNGETIFF, (void *)&ifr) == -1) { - PMD_DRV_LOG(ERR, "TUNGETIFF failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNGETIFF failed: %s", rte_strerror(errno)); return -1; } *tap_flags = ifr.ifr_flags; @@ -120,7 +121,7 @@ tap_set_mac(int tapfd, uint8_t *mac) ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; memcpy(ifr.ifr_hwaddr.sa_data, mac, RTE_ETHER_ADDR_LEN); if (ioctl(tapfd, SIOCSIFHWADDR, (void *)&ifr) == -1) { - PMD_DRV_LOG(ERR, "SIOCSIFHWADDR failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "SIOCSIFHWADDR failed: %s", rte_strerror(errno)); return -1; } return 0; @@ -155,7 +156,7 @@ vhost_kernel_tap_set_offload(int fd, uint64_t features) offload &= ~TUN_F_UFO; if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) { PMD_DRV_LOG(ERR, "TUNSETOFFLOAD ioctl() failed: %s", - strerror(errno)); + rte_strerror(errno)); return -1; } } @@ -175,12 +176,12 @@ vhost_kernel_tap_setup(int tapfd, int hdr_size, uint64_t features) * max_mem_regions, supported in newer version linux kernel */ if (ioctl(tapfd, TUNSETVNETHDRSZ, &hdr_size) < 0) { - PMD_DRV_LOG(ERR, "TUNSETVNETHDRSZ failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNSETVNETHDRSZ failed: %s", rte_strerror(errno)); return -1; } if (ioctl(tapfd, TUNSETSNDBUF, &sndbuf) < 0) { - PMD_DRV_LOG(ERR, "TUNSETSNDBUF failed: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "TUNSETSNDBUF failed: %s", rte_strerror(errno)); return -1; } diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index c10252506b..d3742c6c62 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -136,7 +136,7 @@ vhost_user_write(int fd, struct vhost_user_msg *msg, int *fds, int fd_num) } while (r < 0 && errno == EINTR); if (r < 0) - PMD_DRV_LOG(ERR, "Failed to send msg: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "Failed to send msg: %s", rte_strerror(errno)); return r; } @@ -149,7 +149,7 @@ vhost_user_read(int fd, struct vhost_user_msg *msg) ret = recv(fd, (void *)msg, sz_hdr, 0); if (ret < 0) { - PMD_DRV_LOG(ERR, "Failed to recv msg header: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "Failed to recv msg header: %s", rte_strerror(errno)); return -1; } else if (ret < sz_hdr) { PMD_DRV_LOG(ERR, "Failed to recv msg hdr: %d instead of %d.", @@ -175,7 +175,7 @@ vhost_user_read(int fd, struct vhost_user_msg *msg) if (sz_payload) { ret = recv(fd, (void *)((char *)msg + sz_hdr), sz_payload, 0); if (ret < 0) { - PMD_DRV_LOG(ERR, "Failed to recv msg payload: %s", strerror(errno)); + PMD_DRV_LOG(ERR, "Failed to recv msg payload: %s", rte_strerror(errno)); return -1; } else if (ret < sz_payload) { PMD_DRV_LOG(ERR, "Failed to recv msg payload: %d instead of %u.", @@ -750,7 +750,7 @@ vhost_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un) ret = bind(fd, (struct sockaddr *)un, sizeof(*un)); if (ret < 0) { PMD_DRV_LOG(ERR, "failed to bind to %s: %s; remove it and try again", - dev->path, strerror(errno)); + dev->path, rte_strerror(errno)); return -1; } ret = listen(fd, MAX_VIRTIO_USER_BACKLOG); @@ -761,13 +761,13 @@ vhost_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un) data->vhostfd = accept(fd, NULL, NULL); if (data->vhostfd < 0) { PMD_DRV_LOG(ERR, "Failed to accept initial client connection (%s)", - strerror(errno)); + rte_strerror(errno)); return -1; } flag = fcntl(fd, F_GETFL); if (fcntl(fd, F_SETFL, flag | O_NONBLOCK) < 0) { - PMD_DRV_LOG(ERR, "fcntl failed, %s", strerror(errno)); + PMD_DRV_LOG(ERR, "fcntl failed, %s", rte_strerror(errno)); return -1; } @@ -835,15 +835,15 @@ vhost_user_setup(struct virtio_user_dev *dev) fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { - PMD_DRV_LOG(ERR, "socket() error, %s", strerror(errno)); + PMD_DRV_LOG(ERR, "socket() error, %s", rte_strerror(errno)); goto err_data; } flag = fcntl(fd, F_GETFD); if (flag == -1) - PMD_DRV_LOG(WARNING, "fcntl get fd failed, %s", strerror(errno)); + PMD_DRV_LOG(WARNING, "fcntl get fd failed, %s", rte_strerror(errno)); else if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0) - PMD_DRV_LOG(WARNING, "fcntl set fd failed, %s", strerror(errno)); + PMD_DRV_LOG(WARNING, "fcntl set fd failed, %s", rte_strerror(errno)); memset(&un, 0, sizeof(un)); un.sun_family = AF_UNIX; @@ -857,7 +857,7 @@ vhost_user_setup(struct virtio_user_dev *dev) } } else { if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) { - PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno)); + PMD_DRV_LOG(ERR, "connect error, %s", rte_strerror(errno)); goto err_socket; } data->vhostfd = fd; diff --git a/drivers/net/virtio/virtio_user/vhost_vdpa.c b/drivers/net/virtio/virtio_user/vhost_vdpa.c index bc3e2a9af5..f8c883ee64 100644 --- a/drivers/net/virtio/virtio_user/vhost_vdpa.c +++ b/drivers/net/virtio/virtio_user/vhost_vdpa.c @@ -93,7 +93,7 @@ vhost_vdpa_ioctl(int fd, uint64_t request, void *arg) ret = ioctl(fd, request, arg); if (ret) { PMD_DRV_LOG(ERR, "Vhost-vDPA ioctl %"PRIu64" failed (%s)", - request, strerror(errno)); + request, rte_strerror(errno)); return -1; } @@ -187,7 +187,7 @@ vhost_vdpa_iotlb_batch_begin(struct virtio_user_dev *dev) if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB batch begin (%s)", - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -213,7 +213,7 @@ vhost_vdpa_iotlb_batch_end(struct virtio_user_dev *dev) if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB batch end (%s)", - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -244,7 +244,7 @@ vhost_vdpa_dma_map(struct virtio_user_dev *dev, void *addr, if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB update (%s)", - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -273,7 +273,7 @@ vhost_vdpa_dma_unmap(struct virtio_user_dev *dev, __rte_unused void *addr, if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB invalidate (%s)", - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -531,7 +531,7 @@ vhost_vdpa_setup(struct virtio_user_dev *dev) data->vhostfd = open(dev->path, O_RDWR); if (data->vhostfd < 0) { PMD_DRV_LOG(ERR, "Failed to open %s: %s", - dev->path, strerror(errno)); + dev->path, rte_strerror(errno)); free(data); return -1; } diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 2997d2bd26..33389c702e 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -60,13 +60,13 @@ virtio_user_init_notify_queue(struct virtio_user_dev *dev, uint32_t queue_sel) dev->callfds[queue_sel] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (dev->callfds[queue_sel] < 0) { PMD_DRV_LOG(ERR, "(%s) Failed to setup callfd for queue %u: %s", - dev->path, queue_sel, strerror(errno)); + dev->path, queue_sel, rte_strerror(errno)); return -1; } dev->kickfds[queue_sel] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (dev->kickfds[queue_sel] < 0) { PMD_DRV_LOG(ERR, "(%s) Failed to setup kickfd for queue %u: %s", - dev->path, queue_sel, strerror(errno)); + dev->path, queue_sel, rte_strerror(errno)); return -1; } @@ -1113,7 +1113,7 @@ virtio_user_control_queue_notify(struct virtqueue *vq, void *cookie) if (!dev->notify_area) { if (write(dev->kickfds[vq->vq_queue_index], ¬ify_data, sizeof(notify_data)) < 0) PMD_DRV_LOG(ERR, "failed to kick backend: %s", - strerror(errno)); + rte_strerror(errno)); return; } else if (!virtio_with_feature(&dev->hw, VIRTIO_F_NOTIFICATION_DATA)) { rte_write16(vq->vq_queue_index, vq->notify_addr); @@ -1358,7 +1358,7 @@ virtio_user_dev_server_reconnect(struct virtio_user_dev *dev) if (dev->ops->get_features(dev, &dev->device_features) < 0) { PMD_INIT_LOG(ERR, "get_features failed: %s", - strerror(errno)); + rte_strerror(errno)); return -1; } diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 747dddeb2e..5a23d63012 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -285,7 +285,7 @@ virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq) if (write(dev->kickfds[vq->vq_queue_index], ¬ify_data, sizeof(notify_data)) < 0) PMD_DRV_LOG(ERR, "failed to kick backend: %s", - strerror(errno)); + rte_strerror(errno)); return; } else if (!virtio_with_feature(hw, VIRTIO_F_NOTIFICATION_DATA)) { rte_write16(vq->vq_queue_index, vq->notify_addr); @@ -417,7 +417,7 @@ vdpa_dynamic_major_num(void) fp = fopen("/proc/devices", "r"); if (fp == NULL) { PMD_INIT_LOG(ERR, "Cannot open /proc/devices: %s", - strerror(errno)); + rte_strerror(errno)); return UNNAMED_MAJOR; } @@ -444,7 +444,7 @@ virtio_user_backend_type(const char *path) return VIRTIO_USER_BACKEND_VHOST_USER; PMD_INIT_LOG(ERR, "Stat fails: %s (%s)", path, - strerror(errno)); + rte_strerror(errno)); return VIRTIO_USER_BACKEND_UNKNOWN; } -- 2.33.0