From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ferruh Yigit Subject: [PATCH] vfio: add no-iommu support Date: Mon, 21 Dec 2015 12:18:25 +0000 Message-ID: <1450700305-26453-1-git-send-email-ferruh.yigit@intel.com> References: <20151221114643.GA30129@sivlogin002.ir.intel.com> To: dev@dpdk.org Return-path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 5510ADE3 for ; Mon, 21 Dec 2015 13:18:35 +0100 (CET) In-Reply-To: <20151221114643.GA30129@sivlogin002.ir.intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This is based on patch from Alex Williamson: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=033291eccbdb plus http://dpdk.org/dev/patchwork/patch/9598/ This patch is intended to test above patches on DPDK rather than official patch to DPDK. Test result is DPDK successfully run on no-iommu environment. Signed-off-by: Ferruh Yigit --- lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index 74f91ba..90bba4a 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -61,6 +61,18 @@ #ifdef VFIO_PRESENT +/*#define VFIO_NOIOMMU*/ + +#ifndef VFIO_NOIOMMU_IOMMU +#define VFIO_NOIOMMU_IOMMU 8 +#endif + +#ifdef VFIO_NOIOMMU +#define VFIO_IOMMU_TYPE VFIO_NOIOMMU_IOMMU +#else +#define VFIO_IOMMU_TYPE VFIO_TYPE1_IOMMU +#endif + #define PAGE_SIZE (sysconf(_SC_PAGESIZE)) #define PAGE_MASK (~(PAGE_SIZE - 1)) @@ -71,7 +83,11 @@ EAL_REGISTER_TAILQ(rte_vfio_tailq) #define VFIO_DIR "/dev/vfio" #define VFIO_CONTAINER_PATH "/dev/vfio/vfio" +#ifdef VFIO_NOIOMMU +#define VFIO_GROUP_FMT "/dev/vfio/noiommu-%u" +#else #define VFIO_GROUP_FMT "/dev/vfio/%u" +#endif #define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL) /* per-process VFIO config */ @@ -212,17 +228,21 @@ pci_vfio_set_bus_master(int dev_fd) static int pci_vfio_setup_dma_maps(int vfio_container_fd) { +#ifndef VFIO_NOIOMMU const struct rte_memseg *ms = rte_eal_get_physmem_layout(); - int i, ret; + int i; +#endif + int ret; ret = ioctl(vfio_container_fd, VFIO_SET_IOMMU, - VFIO_TYPE1_IOMMU); + VFIO_IOMMU_TYPE); if (ret) { RTE_LOG(ERR, EAL, " cannot set IOMMU type, " "error %i (%s)\n", errno, strerror(errno)); return -1; } +#ifndef VFIO_NOIOMMU /* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */ for (i = 0; i < RTE_MAX_MEMSEG; i++) { struct vfio_iommu_type1_dma_map dma_map; @@ -245,6 +265,7 @@ pci_vfio_setup_dma_maps(int vfio_container_fd) return -1; } } +#endif return 0; } @@ -373,7 +394,8 @@ pci_vfio_get_container_fd(void) } /* check if we support IOMMU type 1 */ - ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU); + ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION, + VFIO_IOMMU_TYPE); if (ret != 1) { if (ret < 0) RTE_LOG(ERR, EAL, " could not get IOMMU type, " -- 2.5.0