get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/9834/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 9834,
    "url": "http://patches.dpdk.org/api/patches/9834/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1452688569-14695-1-git-send-email-anatoly.burakov@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1452688569-14695-1-git-send-email-anatoly.burakov@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1452688569-14695-1-git-send-email-anatoly.burakov@intel.com",
    "date": "2016-01-13T12:36:09",
    "name": "[dpdk-dev,v2] vfio: Support for no-IOMMU mode",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "257fa27aee5234d9bf81bc3c4313addef9f1d669",
    "submitter": {
        "id": 4,
        "url": "http://patches.dpdk.org/api/people/4/?format=api",
        "name": "Anatoly Burakov",
        "email": "anatoly.burakov@intel.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1452688569-14695-1-git-send-email-anatoly.burakov@intel.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/9834/comments/",
    "check": "pending",
    "checks": "http://patches.dpdk.org/api/patches/9834/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id A29A78E74;\n\tWed, 13 Jan 2016 13:36:14 +0100 (CET)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id B77E18E62\n\tfor <dev@dpdk.org>; Wed, 13 Jan 2016 13:36:12 +0100 (CET)",
            "from orsmga003.jf.intel.com ([10.7.209.27])\n\tby orsmga102.jf.intel.com with ESMTP; 13 Jan 2016 04:36:11 -0800",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby orsmga003.jf.intel.com with ESMTP; 13 Jan 2016 04:36:10 -0800",
            "from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com\n\t[10.237.217.46])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tu0DCa9jv007760; Wed, 13 Jan 2016 12:36:09 GMT",
            "from sivswdev02.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev02.ir.intel.com with ESMTP id u0DCa9PQ014736;\n\tWed, 13 Jan 2016 12:36:09 GMT",
            "(from aburakov@localhost)\n\tby sivswdev02.ir.intel.com with  id u0DCa9ZW014732;\n\tWed, 13 Jan 2016 12:36:09 GMT"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.22,289,1449561600\"; d=\"scan'208\";a=\"726113941\"",
        "From": "Anatoly Burakov <anatoly.burakov@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Wed, 13 Jan 2016 12:36:09 +0000",
        "Message-Id": "<1452688569-14695-1-git-send-email-anatoly.burakov@intel.com>",
        "X-Mailer": "git-send-email 1.7.4.1",
        "In-Reply-To": "<1450728967-9686-1-git-send-email-anatoly.burakov@intel.com>",
        "References": "<1450728967-9686-1-git-send-email-anatoly.burakov@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2] vfio: Support for no-IOMMU mode",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "This commit is adding a generic mechanism to support multiple IOMMU\ntypes. For now, it's only type 1 (x86 IOMMU) and no-IOMMU (a special\nVFIO mode that doesn't use IOMMU at all), but it's easily extended\nby adding necessary definitions into eal_pci_init.h and a DMA\nmapping function to eal_pci_vfio_dma.c.\n\nSince type 1 IOMMU module is no longer necessary to have VFIO,\nwe fix the module check to check for vfio-pci instead. It's not\nideal and triggers VFIO checks more often (and thus produces more\nerror output, which was the reason behind the module check in the\nfirst place), so we compensate for that by providing more verbose\nlogging, indicating whether VFIO initialization has succeeded or\nfailed.\n\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\nSigned-off-by: Santosh Shukla <sshukla@mvista.com>\nTested-by: Santosh Shukla <sshukla@mvista.com>\n---\nv2 changes:\n  Compile fix (hat-tip to Santosh Shukla)\n  Tested-by is provisional, since only superficial testing was done\n---\n lib/librte_eal/linuxapp/eal/Makefile           |   1 +\n lib/librte_eal/linuxapp/eal/eal_pci_init.h     |  22 ++++\n lib/librte_eal/linuxapp/eal/eal_pci_vfio.c     | 143 ++++++++++++++++---------\n lib/librte_eal/linuxapp/eal/eal_pci_vfio_dma.c |  84 +++++++++++++++\n lib/librte_eal/linuxapp/eal/eal_vfio.h         |   5 +\n 5 files changed, 202 insertions(+), 53 deletions(-)\n create mode 100644 lib/librte_eal/linuxapp/eal/eal_pci_vfio_dma.c",
    "diff": "diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile\nindex 26eced5..5c9e9d9 100644\n--- a/lib/librte_eal/linuxapp/eal/Makefile\n+++ b/lib/librte_eal/linuxapp/eal/Makefile\n@@ -59,6 +59,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_log.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci_uio.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci_vfio.c\n+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci_vfio_dma.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci_vfio_mp_sync.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_debug.c\n SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_lcore.c\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h\nindex a17c708..da1c431 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h\n+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h\n@@ -106,6 +106,28 @@ struct vfio_config {\n \tstruct vfio_group vfio_groups[VFIO_MAX_GROUPS];\n };\n \n+/* function pointer typedef for DMA mapping functions */\n+typedef  int (*vfio_dma_func_t)(int);\n+\n+/* Structure to hold supported IOMMU types */\n+struct vfio_iommu_type {\n+\tint type_id;\n+\tconst char *name;\n+\tvfio_dma_func_t dma_map_func;\n+};\n+\n+/* function prototypes for different IOMMU types */\n+int vfio_iommu_type1_dma_map(int container_fd);\n+int vfio_iommu_noiommu_dma_map(int container_fd);\n+\n+/* IOMMU types we support */\n+static const struct vfio_iommu_type iommu_types[] = {\n+\t\t/* x86 IOMMU, otherwise known as type 1 */\n+\t\t{ VFIO_TYPE1_IOMMU, \"Type 1\", &vfio_iommu_type1_dma_map},\n+\t\t/* IOMMU-less mode */\n+\t\t{ VFIO_NOIOMMU_IOMMU, \"No-IOMMU\", &vfio_iommu_noiommu_dma_map},\n+};\n+\n #endif\n \n #endif /* EAL_PCI_INIT_H_ */\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c\nindex 74f91ba..5eb6cd0 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c\n@@ -72,6 +72,7 @@ EAL_REGISTER_TAILQ(rte_vfio_tailq)\n #define VFIO_DIR \"/dev/vfio\"\n #define VFIO_CONTAINER_PATH \"/dev/vfio/vfio\"\n #define VFIO_GROUP_FMT \"/dev/vfio/%u\"\n+#define VFIO_NOIOMMU_GROUP_FMT \"/dev/vfio/noiommu-%u\"\n #define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL)\n \n /* per-process VFIO config */\n@@ -208,42 +209,58 @@ pci_vfio_set_bus_master(int dev_fd)\n \treturn 0;\n }\n \n-/* set up DMA mappings */\n-static int\n-pci_vfio_setup_dma_maps(int vfio_container_fd)\n-{\n-\tconst struct rte_memseg *ms = rte_eal_get_physmem_layout();\n-\tint i, ret;\n-\n-\tret = ioctl(vfio_container_fd, VFIO_SET_IOMMU,\n-\t\t\tVFIO_TYPE1_IOMMU);\n-\tif (ret) {\n-\t\tRTE_LOG(ERR, EAL, \"  cannot set IOMMU type, \"\n-\t\t\t\t\"error %i (%s)\\n\", errno, strerror(errno));\n-\t\treturn -1;\n+/* pick IOMMU type. returns a pointer to vfio_iommu_type or NULL for error */\n+static const struct vfio_iommu_type *\n+pci_vfio_set_iommu_type(int vfio_container_fd) {\n+\tunsigned idx;\n+\tfor (idx = 0; idx < RTE_DIM(iommu_types); idx++) {\n+\t\tconst struct vfio_iommu_type *t = &iommu_types[idx];\n+\n+\t\tint ret = ioctl(vfio_container_fd, VFIO_SET_IOMMU,\n+\t\t\t\tt->type_id);\n+\t\tif (!ret) {\n+\t\t\tRTE_LOG(NOTICE, EAL, \"  using IOMMU type %d (%s)\\n\",\n+\t\t\t\t\tt->type_id, t->name);\n+\t\t\treturn t;\n+\t\t}\n+\t\t/* not an error, there may be more supported IOMMU types */\n+\t\tRTE_LOG(DEBUG, EAL, \"  set IOMMU type %d (%s) failed, \"\n+\t\t\t\t\"error %i (%s)\\n\", t->type_id, t->name, errno,\n+\t\t\t\tstrerror(errno));\n \t}\n+\t/* if we didn't find a suitable IOMMU type, fail */\n+\treturn NULL;\n+}\n \n-\t/* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */\n-\tfor (i = 0; i < RTE_MAX_MEMSEG; i++) {\n-\t\tstruct vfio_iommu_type1_dma_map dma_map;\n-\n-\t\tif (ms[i].addr == NULL)\n-\t\t\tbreak;\n-\n-\t\tmemset(&dma_map, 0, sizeof(dma_map));\n-\t\tdma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map);\n-\t\tdma_map.vaddr = ms[i].addr_64;\n-\t\tdma_map.size = ms[i].len;\n-\t\tdma_map.iova = ms[i].phys_addr;\n-\t\tdma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;\n-\n-\t\tret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map);\n+/* check if we have any supported extensions */\n+static int\n+pci_vfio_has_supported_extensions(int vfio_container_fd) {\n+\tint ret;\n+\tunsigned idx, n_extensions = 0;\n+\tfor (idx = 0; idx < RTE_DIM(iommu_types); idx++) {\n+\t\tconst struct vfio_iommu_type *t = &iommu_types[idx];\n \n-\t\tif (ret) {\n-\t\t\tRTE_LOG(ERR, EAL, \"  cannot set up DMA remapping, \"\n-\t\t\t\t\t\"error %i (%s)\\n\", errno, strerror(errno));\n+\t\tret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,\n+\t\t\t\tt->type_id);\n+\t\tif (ret < 0) {\n+\t\t\tRTE_LOG(ERR, EAL, \"  could not get IOMMU type, \"\n+\t\t\t\t\"error %i (%s)\\n\", errno,\n+\t\t\t\tstrerror(errno));\n+\t\t\tclose(vfio_container_fd);\n \t\t\treturn -1;\n+\t\t} else if (ret == 1) {\n+\t\t\t/* we found a supported extension */\n+\t\t\tn_extensions++;\n \t\t}\n+\t\tRTE_LOG(DEBUG, EAL, \"  IOMMU type %d (%s) is %s\\n\",\n+\t\t\t\tt->type_id, t->name,\n+\t\t\t\tret ? \"supported\" : \"not supported\");\n+\t}\n+\n+\t/* if we didn't find any supported IOMMU types, fail */\n+\tif (!n_extensions) {\n+\t\tclose(vfio_container_fd);\n+\t\treturn -1;\n \t}\n \n \treturn 0;\n@@ -372,17 +389,10 @@ pci_vfio_get_container_fd(void)\n \t\t\treturn -1;\n \t\t}\n \n-\t\t/* check if we support IOMMU type 1 */\n-\t\tret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU);\n-\t\tif (ret != 1) {\n-\t\t\tif (ret < 0)\n-\t\t\t\tRTE_LOG(ERR, EAL, \"  could not get IOMMU type, \"\n-\t\t\t\t\t\"error %i (%s)\\n\", errno,\n-\t\t\t\t\tstrerror(errno));\n-\t\t\telse\n-\t\t\t\tRTE_LOG(ERR, EAL, \"  unsupported IOMMU type \"\n-\t\t\t\t\t\"detected in VFIO\\n\");\n-\t\t\tclose(vfio_container_fd);\n+\t\tret = pci_vfio_has_supported_extensions(vfio_container_fd);\n+\t\tif (ret) {\n+\t\t\tRTE_LOG(ERR, EAL, \"  no supported IOMMU \"\n+\t\t\t\t\t\"extensions found!\\n\");\n \t\t\treturn -1;\n \t\t}\n \n@@ -432,6 +442,7 @@ pci_vfio_get_group_fd(int iommu_group_no)\n \n \t/* if primary, try to open the group */\n \tif (internal_config.process_type == RTE_PROC_PRIMARY) {\n+\t\t/* try regular group format */\n \t\tsnprintf(filename, sizeof(filename),\n \t\t\t\t VFIO_GROUP_FMT, iommu_group_no);\n \t\tvfio_group_fd = open(filename, O_RDWR);\n@@ -442,7 +453,20 @@ pci_vfio_get_group_fd(int iommu_group_no)\n \t\t\t\t\t\tstrerror(errno));\n \t\t\t\treturn -1;\n \t\t\t}\n-\t\t\treturn 0;\n+\n+\t\t\t/* special case: try no-IOMMU path as well */\n+\t\t\tsnprintf(filename, sizeof(filename),\n+\t\t\t\t\tVFIO_NOIOMMU_GROUP_FMT, iommu_group_no);\n+\t\t\tvfio_group_fd = open(filename, O_RDWR);\n+\t\t\tif (vfio_group_fd < 0) {\n+\t\t\t\tif (errno != ENOENT) {\n+\t\t\t\t\tRTE_LOG(ERR, EAL, \"Cannot open %s: %s\\n\", filename,\n+\t\t\t\t\t\t\tstrerror(errno));\n+\t\t\t\t\treturn -1;\n+\t\t\t\t}\n+\t\t\t\treturn 0;\n+\t\t\t}\n+\t\t\t/* noiommu group found */\n \t\t}\n \n \t\t/* if the fd is valid, create a new group for it */\n@@ -660,14 +684,21 @@ pci_vfio_map_resource(struct rte_pci_device *dev)\n \t}\n \n \t/*\n-\t * set up DMA mappings for container\n+\t * pick an IOMMU type and set up DMA mappings for container\n \t *\n \t * needs to be done only once, only when at least one group is assigned to\n \t * a container and only in primary process\n \t */\n \tif (internal_config.process_type == RTE_PROC_PRIMARY &&\n \t\t\tvfio_cfg.vfio_container_has_dma == 0) {\n-\t\tret = pci_vfio_setup_dma_maps(vfio_cfg.vfio_container_fd);\n+\t\t/* select an IOMMU type which we will be using */\n+\t\tconst struct vfio_iommu_type *t =\n+\t\t\t\tpci_vfio_set_iommu_type(vfio_cfg.vfio_container_fd);\n+\t\tif (!t) {\n+\t\t\tRTE_LOG(ERR, EAL, \"  %s failed to select IOMMU type\\n\", pci_addr);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tret = t->dma_map_func(vfio_cfg.vfio_container_fd);\n \t\tif (ret) {\n \t\t\tRTE_LOG(ERR, EAL, \"  %s DMA remapping failed, \"\n \t\t\t\t\t\"error %i (%s)\\n\", pci_addr, errno, strerror(errno));\n@@ -887,35 +918,41 @@ pci_vfio_enable(void)\n {\n \t/* initialize group list */\n \tint i;\n-\tint module_vfio_type1;\n+\tint vfio_available;\n \n \tfor (i = 0; i < VFIO_MAX_GROUPS; i++) {\n \t\tvfio_cfg.vfio_groups[i].fd = -1;\n \t\tvfio_cfg.vfio_groups[i].group_no = -1;\n \t}\n \n-\tmodule_vfio_type1 = rte_eal_check_module(\"vfio_iommu_type1\");\n+\t/* inform the user that we are probing for VFIO */\n+\tRTE_LOG(INFO, EAL, \"Probing VFIO support...\\n\");\n+\n+\t/* check if vfio-pci module is loaded */\n+\tvfio_available = rte_eal_check_module(\"vfio_pci\");\n \n \t/* return error directly */\n-\tif (module_vfio_type1 == -1) {\n+\tif (vfio_available == -1) {\n \t\tRTE_LOG(INFO, EAL, \"Could not get loaded module details!\\n\");\n \t\treturn -1;\n \t}\n \n \t/* return 0 if VFIO modules not loaded */\n-\tif (module_vfio_type1 == 0) {\n-\t\tRTE_LOG(INFO, EAL, \"VFIO modules not all loaded, \"\n-\t\t\t\"skip VFIO support...\\n\");\n+\tif (vfio_available == 0) {\n+\t\tRTE_LOG(INFO, EAL, \"VFIO modules not loaded, \"\n+\t\t\t\"skipping VFIO support...\\n\");\n \t\treturn 0;\n \t}\n \n \tvfio_cfg.vfio_container_fd = pci_vfio_get_container_fd();\n \n \t/* check if we have VFIO driver enabled */\n-\tif (vfio_cfg.vfio_container_fd != -1)\n+\tif (vfio_cfg.vfio_container_fd != -1) {\n+\t\tRTE_LOG(NOTICE, EAL, \"VFIO support initialized\\n\");\n \t\tvfio_cfg.vfio_enabled = 1;\n-\telse\n+\t} else {\n \t\tRTE_LOG(NOTICE, EAL, \"VFIO support could not be initialized\\n\");\n+\t}\n \n \treturn 0;\n }\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_dma.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_dma.c\nnew file mode 100644\nindex 0000000..50d3563\n--- /dev/null\n+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_dma.c\n@@ -0,0 +1,84 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <string.h>\n+#include <sys/ioctl.h>\n+\n+#include <rte_log.h>\n+#include <rte_pci.h>\n+#include <rte_eal_memconfig.h>\n+\n+#include \"eal_pci_init.h\"\n+\n+#ifdef VFIO_PRESENT\n+\n+int\n+vfio_iommu_type1_dma_map(int vfio_container_fd)\n+{\n+\tconst struct rte_memseg *ms = rte_eal_get_physmem_layout();\n+\tint i, ret;\n+\n+\t/* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */\n+\tfor (i = 0; i < RTE_MAX_MEMSEG; i++) {\n+\t\tstruct vfio_iommu_type1_dma_map dma_map;\n+\n+\t\tif (ms[i].addr == NULL)\n+\t\t\tbreak;\n+\n+\t\tmemset(&dma_map, 0, sizeof(dma_map));\n+\t\tdma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map);\n+\t\tdma_map.vaddr = ms[i].addr_64;\n+\t\tdma_map.size = ms[i].len;\n+\t\tdma_map.iova = ms[i].phys_addr;\n+\t\tdma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;\n+\n+\t\tret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map);\n+\n+\t\tif (ret) {\n+\t\t\tRTE_LOG(ERR, EAL, \"  cannot set up DMA remapping, \"\n+\t\t\t\t\t\"error %i (%s)\\n\", errno, strerror(errno));\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int\n+vfio_iommu_noiommu_dma_map(int __rte_unused vfio_container_fd)\n+{\n+\t/* No-IOMMU mode does not need DMA mapping */\n+\treturn 0;\n+}\n+\n+#endif\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h\nindex 72ec3f6..638ee31 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h\n+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h\n@@ -52,6 +52,11 @@\n #define RTE_PCI_MSIX_FLAGS_QSIZE  PCI_MSIX_FLAGS_QSIZE\n #endif\n \n+/* older kernels may not have no-IOMMU mode */\n+#ifndef VFIO_NOIOMMU_IOMMU\n+#define VFIO_NOIOMMU_IOMMU 8\n+#endif\n+\n #define VFIO_PRESENT\n #endif /* kernel version */\n #endif /* RTE_EAL_VFIO */\n",
    "prefixes": [
        "dpdk-dev",
        "v2"
    ]
}