vfio: do not needlessly check for IOVA mode
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_vfio.c
index 5371ec2..2421d51 100644 (file)
@@ -681,10 +681,7 @@ vfio_type1_dma_map(int vfio_container_fd)
                dma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map);
                dma_map.vaddr = ms[i].addr_64;
                dma_map.size = ms[i].len;
-               if (rte_eal_iova_mode() == RTE_IOVA_VA)
-                       dma_map.iova = dma_map.vaddr;
-               else
-                       dma_map.iova = ms[i].iova;
+               dma_map.iova = ms[i].iova;
                dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
 
                ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map);
@@ -784,10 +781,7 @@ vfio_spapr_dma_map(int vfio_container_fd)
                dma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map);
                dma_map.vaddr = ms[i].addr_64;
                dma_map.size = ms[i].len;
-               if (rte_eal_iova_mode() == RTE_IOVA_VA)
-                       dma_map.iova = dma_map.vaddr;
-               else
-                       dma_map.iova = ms[i].iova;
+               dma_map.iova = ms[i].iova;
                dma_map.flags = VFIO_DMA_MAP_FLAG_READ |
                                 VFIO_DMA_MAP_FLAG_WRITE;
 
@@ -814,20 +808,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