Show a patch.

GET /api/patches/44048/
Content-Type: application/json
Vary: Accept

    "id": 44048,
    "url": "",
    "web_url": "",
    "project": {
        "id": 1,
        "url": "",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "",
        "list_email": "",
        "web_url": "",
        "scm_url": "git://",
        "webscm_url": ""
    "msgid": "<>",
    "date": "2018-08-30T15:21:28",
    "name": "[1/5] mem: add function for checking memsegs IOVAs addresses",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": true,
    "hash": "4dcc8738214ee38f7f1d49ee373ba2456443c6f9",
    "submitter": {
        "id": 270,
        "url": "",
        "name": "Alejandro Lucero",
        "email": ""
    "delegate": null,
    "mbox": "",
    "series": [
            "id": 1117,
            "url": "",
            "web_url": "",
            "date": "2018-08-30T15:21:27",
            "name": "use IOVAs check based on DMA mask",
            "version": 1,
            "mbox": ""
    "comments": "",
    "check": "fail",
    "checks": "",
    "tags": {},
    "headers": {
        "X-Mailman-Version": "2.1.15",
        "In-Reply-To": "<>",
        "Errors-To": "",
        "X-Mailer": "git-send-email 1.9.1",
        "Received": [
            "from [] (localhost [])\n\tby (Postfix) with ESMTP id 384725398;\n\tThu, 30 Aug 2018 17:22:32 +0200 (CEST)",
            "from (\n\t[]) by (Postfix) with ESMTP id AFDC54CBD;\n\tThu, 30 Aug 2018 17:22:27 +0200 (CEST)",
            "from (localhost [])\n\tby (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id\n\tw7UFLZcv021911; Thu, 30 Aug 2018 16:21:35 +0100",
            "(from alucero@localhost)\n\tby (8.14.4/8.14.4/Submit) id w7UFLZti021910;\n\tThu, 30 Aug 2018 16:21:35 +0100"
        "References": "<>",
        "Delivered-To": "",
        "X-BeenThere": "",
        "Message-Id": "<>",
        "List-Post": "<>",
        "Precedence": "list",
        "From": "Alejandro Lucero <>",
        "X-Original-To": "",
        "Return-Path": "<>",
        "Sender": "\"dev\" <>",
        "List-Help": "<>",
        "List-Subscribe": "<>,\n\t<>",
        "To": "",
        "List-Id": "DPDK patches and discussions <>",
        "List-Unsubscribe": "<>,\n\t<>",
        "Date": "Thu, 30 Aug 2018 16:21:28 +0100",
        "Cc": "",
        "List-Archive": "<>",
        "Subject": "[dpdk-dev] [PATCH 1/5] mem: add function for checking memsegs IOVAs\n\taddresses"
    "content": "A device can suffer addressing limitations. This functions checks\nmemsegs have iovas within the supported range based on dma mask.\n\nPMD should use this during initialization if supported devices\nsuffer addressing limitations, returning an error if this function\nreturns memsegs out of range.\n\nAnother potential usage is for emulated IOMMU hardware with addressing\nlimitations.\n\nIt is necessary to save the most restricted dma mask for checking\nmemory allocated dynamically after initialization.\n\nSigned-off-by: Alejandro Lucero <>\n---\n lib/librte_eal/common/eal_common_memory.c         | 56 +++++++++++++++++++++++\n lib/librte_eal/common/include/rte_eal_memconfig.h |  3 ++\n lib/librte_eal/common/include/rte_memory.h        |  3 ++\n lib/librte_eal/common/malloc_heap.c               | 12 +++++\n lib/librte_eal/linuxapp/eal/eal.c                 |  2 +\n lib/librte_eal/                |  1 +\n 6 files changed, 77 insertions(+)",
    "diff": "diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c\nindex fbfb1b0..1e8312b 100644\n--- a/lib/librte_eal/common/eal_common_memory.c\n+++ b/lib/librte_eal/common/eal_common_memory.c\n@@ -383,6 +383,62 @@ struct virtiova {\n \trte_memseg_walk(dump_memseg, f);\n }\n \n+static int\n+check_iova(const struct rte_memseg_list *msl __rte_unused,\n+\t\tconst struct rte_memseg *ms, void *arg)\n+{\n+\tuint64_t *mask = arg;\n+\trte_iova_t iova;\n+\n+\t/* higher address within segment */\n+\tiova = (ms->iova + ms->len) - 1;\n+\tif (!(iova & *mask))\n+\t\treturn 0;\n+\n+\tRTE_LOG(INFO, EAL, \"memseg iova %\"PRIx64\", len %zx, out of range\\n\",\n+\t\t\t   ms->iova, ms->len);\n+\n+\tRTE_LOG(INFO, EAL, \"\\tusing dma mask %\"PRIx64\"\\n\", *mask);\n+\t/* Stop the walk and change mask */\n+\t*mask = 0;\n+\treturn 1;\n+}\n+\n+#if defined(RTE_ARCH_64)\n+#define X86_VA_WIDTH 63\n+#else\n+#define MAX_DMA_MASK_BITS 31\n+#endif\n+\n+/* check memseg iovas are within the required range based on dma mask */\n+int __rte_experimental\n+rte_eal_check_dma_mask(uint8_t maskbits)\n+{\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tuint64_t mask;\n+\n+\t/* sanity check */\n+\tif (maskbits > MAX_DMA_MASK_BITS) {\n+\t\tRTE_LOG(INFO, EAL, \"wrong dma mask size %u (Max: %u)\\n\",\n+\t\t\t\t   maskbits, MAX_DMA_MASK_BITS);\n+\t\treturn -1;\n+\t}\n+\n+\t/* keep the more restricted maskbit */\n+\tif (!mcfg->dma_maskbits || maskbits < mcfg->dma_maskbits)\n+\t\tmcfg->dma_maskbits = maskbits;\n+\n+\t/* create dma mask */\n+\tmask = ~((1ULL << maskbits) - 1);\n+\n+\trte_memseg_walk(check_iova, &mask);\n+\n+\tif (!mask)\n+\t\treturn -1;\n+\n+\treturn 0;\n+}\n+\n /* return the number of memory channels */\n unsigned rte_memory_get_nchannel(void)\n {\ndiff --git a/lib/librte_eal/common/include/rte_eal_memconfig.h b/lib/librte_eal/common/include/rte_eal_memconfig.h\nindex aff0688..aea44cb 100644\n--- a/lib/librte_eal/common/include/rte_eal_memconfig.h\n+++ b/lib/librte_eal/common/include/rte_eal_memconfig.h\n@@ -77,6 +77,9 @@ struct rte_mem_config {\n \t * exact same address the primary process maps it.\n \t */\n \tuint64_t mem_cfg_addr;\n+\n+\t/* keeps the more restricted dma mask */\n+\tuint8_t dma_maskbits;\n } __attribute__((__packed__));\n \n \ndiff --git a/lib/librte_eal/common/include/rte_memory.h b/lib/librte_eal/common/include/rte_memory.h\nindex c4b7f4c..cd439e3 100644\n--- a/lib/librte_eal/common/include/rte_memory.h\n+++ b/lib/librte_eal/common/include/rte_memory.h\n@@ -357,6 +357,9 @@ typedef int (*rte_memseg_list_walk_t)(const struct rte_memseg_list *msl,\n  */\n unsigned rte_memory_get_nrank(void);\n \n+/* check memsegs iovas are within a range based on dma mask */\n+int rte_eal_check_dma_mask(uint8_t maskbits);\n+\n /**\n  * Drivers based on uio will not load unless physical\n  * addresses are obtainable. It is only possible to get\ndiff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c\nindex 12aaf2d..255d717 100644\n--- a/lib/librte_eal/common/malloc_heap.c\n+++ b/lib/librte_eal/common/malloc_heap.c\n@@ -259,11 +259,13 @@ struct malloc_elem *\n \t\tint socket, unsigned int flags, size_t align, size_t bound,\n \t\tbool contig, struct rte_memseg **ms, int n_segs)\n {\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n \tstruct rte_memseg_list *msl;\n \tstruct malloc_elem *elem = NULL;\n \tsize_t alloc_sz;\n \tint allocd_pages;\n \tvoid *ret, *map_addr;\n+\tuint64_t mask;\n \n \talloc_sz = (size_t)pg_sz * n_segs;\n \n@@ -291,6 +293,16 @@ struct malloc_elem *\n \t\tgoto fail;\n \t}\n \n+\tif (mcfg->dma_maskbits) {\n+\t\tmask = ~((1ULL << mcfg->dma_maskbits) - 1);\n+\t\tif (rte_eal_check_dma_mask(mask)) {\n+\t\t\tRTE_LOG(DEBUG, EAL,\n+\t\t\t\t\"%s(): couldn't allocate memory due to DMA mask\\n\",\n+\t\t\t\t__func__);\n+\t\t\tgoto fail;\n+\t\t}\n+\t}\n+\n \t/* add newly minted memsegs to malloc heap */\n \telem = malloc_heap_add_memory(heap, msl, map_addr, alloc_sz);\n \ndiff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c\nindex e59ac65..616723e 100644\n--- a/lib/librte_eal/linuxapp/eal/eal.c\n+++ b/lib/librte_eal/linuxapp/eal/eal.c\n@@ -263,6 +263,8 @@ enum rte_iova_mode\n \t * processes could later map the config into this exact location */\n \trte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;\n \n+\trte_config.mem_config->dma_maskbits = 0;\n+\n }\n \n /* attach to an existing shared memory config */\ndiff --git a/lib/librte_eal/ b/lib/librte_eal/\nindex 344a43d..85e6212 100644\n--- a/lib/librte_eal/\n+++ b/lib/librte_eal/\n@@ -284,6 +284,7 @@ EXPERIMENTAL {\n \trte_devargs_parsef;\n \trte_devargs_remove;\n \trte_devargs_type_count;\n+\trte_eal_check_dma_mask;\n \trte_eal_cleanup;\n \trte_eal_hotplug_add;\n \trte_eal_hotplug_remove;\n",
    "prefixes": [