From: Takeshi Yoshimura Date: Fri, 7 Jun 2019 02:28:29 +0000 (+0900) Subject: vfio: retry creating sPAPR DMA window X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=db90b4969e2e2e5df88fb993779bf6a03e9cae39;p=dpdk.git vfio: retry creating sPAPR DMA window sPAPR allows only page_shift from VFIO_IOMMU_SPAPR_TCE_GET_INFO ioctl. However, Linux 4.17 or before returns incorrect page_shift for Power9. I added the code for retrying creation of sPAPR DMA window. Signed-off-by: Takeshi Yoshimura Acked-by: Anatoly Burakov --- diff --git a/lib/librte_eal/linux/eal/eal_vfio.c b/lib/librte_eal/linux/eal/eal_vfio.c index fdc884f70b..7053ebe7d5 100644 --- a/lib/librte_eal/linux/eal/eal_vfio.c +++ b/lib/librte_eal/linux/eal/eal_vfio.c @@ -1445,9 +1445,29 @@ vfio_spapr_create_new_dma_window(int vfio_container_fd, /* create new DMA window */ ret = ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_CREATE, create); if (ret) { - RTE_LOG(ERR, EAL, " cannot create new DMA window, " - "error %i (%s)\n", errno, strerror(errno)); - return -1; + /* try possible page_shift and levels for workaround */ + uint32_t levels; + + for (levels = 1; levels <= info.ddw.levels; levels++) { + uint32_t pgsizes = info.ddw.pgsizes; + + while (pgsizes != 0) { + create->page_shift = 31 - __builtin_clz(pgsizes); + create->levels = levels; + ret = ioctl(vfio_container_fd, + VFIO_IOMMU_SPAPR_TCE_CREATE, create); + if (!ret) + break; + pgsizes &= ~(1 << create->page_shift); + } + if (!ret) + break; + } + if (ret) { + RTE_LOG(ERR, EAL, " cannot create new DMA window, " + "error %i (%s)\n", errno, strerror(errno)); + return -1; + } } if (create->start_addr != 0) {