From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.tuxdriver.com (charlotte.tuxdriver.com [70.61.120.58]) by dpdk.org (Postfix) with ESMTP id 5B9F9AFDC for ; Tue, 17 Jun 2014 21:03:52 +0200 (CEST) Received: from hmsreliant.think-freely.org ([2001:470:8:a08:7aac:c0ff:fec2:933b] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63) (envelope-from ) id 1Wwyfn-0004aC-GI; Tue, 17 Jun 2014 15:04:01 -0400 From: Neil Horman To: dev@dpdk.org Date: Tue, 17 Jun 2014 15:03:52 -0400 Message-Id: <1403031832-28540-1-git-send-email-nhorman@tuxdriver.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Score: -2.9 (--) X-Spam-Status: No Subject: [dpdk-dev] [PATCH] vfio: correct system call error checking X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jun 2014 19:03:52 -0000 Noticed today that ioctl error code return checking was incorrect in some of the vfio code. ioctl can return a negative value if the system detects an error before the target device/driver can produce a return code. The dpdk vfio code only checks specfically for the values that it expects, which leaves it open to accepting unexpected error codes as success. For instance, if the vfio layer noted that the iommu driver hadn't finished registering yet, it would return an -EINVAL error code, but the dpdk would accept that as success, becuase it wasn't 0. Fix this to specifically check for < 0 error codes Signed-off-by: Neil Horman CC: Thomas Monjalon --- lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index 4de6061..65aa8ad 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -319,16 +319,16 @@ pci_vfio_get_container_fd(void) /* check VFIO API version */ ret = ioctl(vfio_container_fd, VFIO_GET_API_VERSION); - if (ret != VFIO_API_VERSION) { - RTE_LOG(ERR, EAL, " unknown VFIO API version!\n"); + if ((ret < 0) || (ret != VFIO_API_VERSION)) { + RTE_LOG(ERR, EAL, " unknown VFIO API version! errno = %d\n", errno); close(vfio_container_fd); return -1; } /* check if we support IOMMU type 1 */ ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU); - if (!ret) { - RTE_LOG(ERR, EAL, " unknown IOMMU driver!\n"); + if (ret <= 0) { + RTE_LOG(ERR, EAL, " unknown IOMMU driver! errno = %d\n", errno); close(vfio_container_fd); return -1; } -- 1.8.3.1