From de4a79cf56bec0623f7f73ca82a2cff15f1f38e3 Mon Sep 17 00:00:00 2001 From: Jonas Pfefferle Date: Tue, 31 Oct 2017 16:59:46 +0100 Subject: [PATCH] vfio: improve noiommu check error handling Kernels v4.4 and earlier does have vfio, but not the noiommu mode, so the file does not exist. Check and report errors on open/read in noiommu check. Signed-off-by: Jonas Pfefferle Acked-by: Anatoly Burakov Acked-by: Maxime Coquelin --- lib/librte_eal/linuxapp/eal/eal_vfio.c | 29 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index 5371ec23b3..e44ae4d04a 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -814,20 +814,33 @@ vfio_noiommu_dma_map(int __rte_unused vfio_container_fd) int rte_vfio_noiommu_is_enabled(void) { - int fd, ret, cnt __rte_unused; + int fd; + ssize_t cnt; char c; - ret = -1; fd = open(VFIO_NOIOMMU_MODE, O_RDONLY); - if (fd < 0) - return -1; + if (fd < 0) { + if (errno != ENOENT) { + RTE_LOG(ERR, EAL, " cannot open vfio noiommu file %i (%s)\n", + errno, strerror(errno)); + return -1; + } + /* + * else the file does not exists + * i.e. noiommu is not enabled + */ + return 0; + } 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.20.1