Show a patch.

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

{
    "id": 44048,
    "url": "http://patches.dpdk.org/api/patches/44048/",
    "web_url": "http://patches.dpdk.org/patch/44048/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/",
        "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"
    },
    "msgid": "<1535642492-21831-2-git-send-email-alejandro.lucero@netronome.com>",
    "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": "http://patches.dpdk.org/api/people/270/",
        "name": "Alejandro Lucero",
        "email": "alejandro.lucero@netronome.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/patch/44048/mbox/",
    "series": [
        {
            "id": 1117,
            "url": "http://patches.dpdk.org/api/series/1117/",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1117",
            "date": "2018-08-30T15:21:27",
            "name": "use IOVAs check based on DMA mask",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/1117/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/44048/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/44048/checks/",
    "tags": {},
    "headers": {
        "X-Mailman-Version": "2.1.15",
        "In-Reply-To": "<1535642492-21831-1-git-send-email-alejandro.lucero@netronome.com>",
        "Errors-To": "dev-bounces@dpdk.org",
        "X-Mailer": "git-send-email 1.9.1",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 384725398;\n\tThu, 30 Aug 2018 17:22:32 +0200 (CEST)",
            "from netronome.com (host-79-78-33-110.static.as9105.net\n\t[79.78.33.110]) by dpdk.org (Postfix) with ESMTP id AFDC54CBD;\n\tThu, 30 Aug 2018 17:22:27 +0200 (CEST)",
            "from netronome.com (localhost [127.0.0.1])\n\tby netronome.com (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 netronome.com (8.14.4/8.14.4/Submit) id w7UFLZti021910;\n\tThu, 30 Aug 2018 16:21:35 +0100"
        ],
        "References": "<1535642492-21831-1-git-send-email-alejandro.lucero@netronome.com>",
        "Delivered-To": "patchwork@dpdk.org",
        "X-BeenThere": "dev@dpdk.org",
        "Message-Id": "<1535642492-21831-2-git-send-email-alejandro.lucero@netronome.com>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "Precedence": "list",
        "From": "Alejandro Lucero <alejandro.lucero@netronome.com>",
        "X-Original-To": "patchwork@dpdk.org",
        "Return-Path": "<dev-bounces@dpdk.org>",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "To": "dev@dpdk.org",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "Date": "Thu, 30 Aug 2018 16:21:28 +0100",
        "Cc": "stable@dpdk.org",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "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 <alejandro.lucero@netronome.com>\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/rte_eal_version.map                |  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/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map\nindex 344a43d..85e6212 100644\n--- a/lib/librte_eal/rte_eal_version.map\n+++ b/lib/librte_eal/rte_eal_version.map\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": [
        "1/5"
    ]
}