From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonas Pfefferle Subject: [PATCH] vfio: noiommu check error handling Date: Tue, 31 Oct 2017 16:37:11 +0100 Message-ID: <1509464231-2073-1-git-send-email-jpf@zurich.ibm.com> Cc: anatoly.burakov@intel.com, Jonas Pfefferle To: dev@dpdk.org Return-path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by dpdk.org (Postfix) with ESMTP id 399D61B20E for ; Tue, 31 Oct 2017 16:37:18 +0100 (CET) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9VFXNsK122135 for ; Tue, 31 Oct 2017 11:37:18 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dxrv8n00n-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 31 Oct 2017 11:37:17 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 31 Oct 2017 15:37:15 -0000 List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Check and report errors on open/read in noiommu check. Signed-off-by: Jonas Pfefferle --- lib/librte_eal/linuxapp/eal/eal_vfio.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index 5bbcdf9..8f9d043 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -843,20 +843,34 @@ vfio_noiommu_dma_map(int __rte_unused vfio_container_fd) int vfio_noiommu_is_enabled(void) { - int fd, ret, cnt __rte_unused; + int fd; + ssize_t cnt; char c; - ret = -1; + if (access(VFIO_NOIOMMU_MODE, R_OK) == -1) { + /* + * file does not exist assume noiommu mode + * is not available i.e. not enabled + */ + return 0; + } + fd = open(VFIO_NOIOMMU_MODE, O_RDONLY); - if (fd < 0) + if (fd < 0) { + RTE_LOG(ERR, EAL, " cannot open vfio noiommu file %i (%s)\n", + errno, strerror(errno)); return -1; + } cnt = read(fd, &c, 1); - if (c == 'Y') - ret = 1; - close(fd); - return ret; + if (cnt != 1) { + RTE_LOG(ERR, EAL, " unable to read from vfio noiommu " + "file %i (%s)\n", errno, strerror(errno)); + return -1; + } + + return c == 'Y'; } #endif -- 2.7.4