get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 10128,
    "url": "https://patches.dpdk.org/api/patches/10128/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1453903474-18807-1-git-send-email-anatoly.burakov@intel.com/",
    "project": {
        "id": 1,
        "url": "https://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": "<1453903474-18807-1-git-send-email-anatoly.burakov@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1453903474-18807-1-git-send-email-anatoly.burakov@intel.com",
    "date": "2016-01-27T14:04:34",
    "name": "[dpdk-dev,v3] vfio: Support for no-IOMMU mode",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "2b2c209b9a30533ff9f18bc2043a3fedc5cf3a9c",
    "submitter": {
        "id": 4,
        "url": "https://patches.dpdk.org/api/people/4/?format=api",
        "name": "Burakov, Anatoly",
        "email": "anatoly.burakov@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1453903474-18807-1-git-send-email-anatoly.burakov@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/10128/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/10128/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 0DCB295BC;\n\tWed, 27 Jan 2016 15:04:42 +0100 (CET)",
            "from mga03.intel.com (mga03.intel.com [134.134.136.65])\n\tby dpdk.org (Postfix) with ESMTP id 33CF495BA\n\tfor <dev@dpdk.org>; Wed, 27 Jan 2016 15:04:40 +0100 (CET)",
            "from fmsmga003.fm.intel.com ([10.253.24.29])\n\tby orsmga103.jf.intel.com with ESMTP; 27 Jan 2016 06:04:38 -0800",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby FMSMGA003.fm.intel.com with ESMTP; 27 Jan 2016 06:04:35 -0800",
            "from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com\n\t[10.237.217.45])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tu0RE4YNv022983; Wed, 27 Jan 2016 14:04:34 GMT",
            "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id u0RE4Y0m018918;\n\tWed, 27 Jan 2016 14:04:34 GMT",
            "(from aburakov@localhost)\n\tby sivswdev01.ir.intel.com with  id u0RE4YKi018914;\n\tWed, 27 Jan 2016 14:04:34 GMT"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.22,354,1449561600\"; d=\"scan'208\";a=\"642199948\"",
        "From": "Anatoly Burakov <anatoly.burakov@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Wed, 27 Jan 2016 14:04:34 +0000",
        "Message-Id": "<1453903474-18807-1-git-send-email-anatoly.burakov@intel.com>",
        "X-Mailer": "git-send-email 1.7.4.1",
        "In-Reply-To": "<1452688569-14695-1-git-send-email-anatoly.burakov@intel.com>",
        "References": "<1452688569-14695-1-git-send-email-anatoly.burakov@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v3] 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>\nTested-by: Santosh Shukla <sshukla@mvista.com>\n---\nv3 changes:\n  Merging DMA mapping functions back into eal_pci_vfio.c\n  Fixing and adding comments\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/eal_pci_vfio.c | 205 +++++++++++++++++++++--------\n lib/librte_eal/linuxapp/eal/eal_vfio.h     |   5 +\n 2 files changed, 157 insertions(+), 53 deletions(-)",
    "diff": "diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c\nindex 74f91ba..fdf334b 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,11 +72,74 @@ 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 static struct vfio_config vfio_cfg;\n \n+/* DMA mapping function prototype.\n+ * Takes VFIO container fd as a parameter.\n+ * Returns 0 on success, -1 on error.\n+ * */\n+typedef  int (*vfio_dma_func_t)(int);\n+\n+struct vfio_iommu_type {\n+\tint type_id;\n+\tconst char *name;\n+\tvfio_dma_func_t dma_map_func;\n+};\n+\n+int vfio_iommu_type1_dma_map(int);\n+int vfio_iommu_noiommu_dma_map(int);\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+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 int\n pci_vfio_read_config(const struct rte_intr_handle *intr_handle,\n \t\t    void *buf, size_t len, off_t offs)\n@@ -208,42 +271,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 +451,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 +504,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 +515,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 +746,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 +980,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_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",
        "v3"
    ]
}