get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 86686,
    "url": "http://patchwork.dpdk.org/api/patches/86686/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/9843593ce51003ea5e372a8107a96acdc01e8958.1610712939.git.anatoly.burakov@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.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": "<9843593ce51003ea5e372a8107a96acdc01e8958.1610712939.git.anatoly.burakov@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/9843593ce51003ea5e372a8107a96acdc01e8958.1610712939.git.anatoly.burakov@intel.com",
    "date": "2021-01-15T12:15:43",
    "name": "mem: improve parameter checking on memory hotplug",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "12fd6a345ddb5d5e86192e7f84e8df16d9e5230c",
    "submitter": {
        "id": 4,
        "url": "http://patchwork.dpdk.org/api/people/4/?format=api",
        "name": "Burakov, Anatoly",
        "email": "anatoly.burakov@intel.com"
    },
    "delegate": {
        "id": 24651,
        "url": "http://patchwork.dpdk.org/api/users/24651/?format=api",
        "username": "dmarchand",
        "first_name": "David",
        "last_name": "Marchand",
        "email": "david.marchand@redhat.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/9843593ce51003ea5e372a8107a96acdc01e8958.1610712939.git.anatoly.burakov@intel.com/mbox/",
    "series": [
        {
            "id": 14779,
            "url": "http://patchwork.dpdk.org/api/series/14779/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=14779",
            "date": "2021-01-15T12:15:43",
            "name": "mem: improve parameter checking on memory hotplug",
            "version": 1,
            "mbox": "http://patchwork.dpdk.org/series/14779/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/86686/comments/",
    "check": "fail",
    "checks": "http://patchwork.dpdk.org/api/patches/86686/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 881B0A0A02;\n\tFri, 15 Jan 2021 13:15:48 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 0C9C414102F;\n\tFri, 15 Jan 2021 13:15:48 +0100 (CET)",
            "from mga06.intel.com (mga06.intel.com [134.134.136.31])\n by mails.dpdk.org (Postfix) with ESMTP id 8FC3A14102E\n for <dev@dpdk.org>; Fri, 15 Jan 2021 13:15:46 +0100 (CET)",
            "from orsmga002.jf.intel.com ([10.7.209.21])\n by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 15 Jan 2021 04:15:45 -0800",
            "from silpixa00399498.ir.intel.com (HELO\n silpixa00399498.ger.corp.intel.com) ([10.237.222.179])\n by orsmga002.jf.intel.com with ESMTP; 15 Jan 2021 04:15:44 -0800"
        ],
        "IronPort-SDR": [
            "\n df7zLKXcy+j+pIvpqzcdvNWcSQ58xgWC3+EUbPBLxeIj6Oibdz8gIq6BilrUJT6s68RSJUCCdM\n 5KvbwXaFdk9g==",
            "\n nUH/FPt71Bxc3s1h8K6OFxMx3X/xK6Yym2r1ATIlBtGyH2qRcM8bjQzm3je4CrB87g4jE3wFo9\n Kh2UoZ82TxJQ=="
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6000,8403,9864\"; a=\"240084114\"",
            "E=Sophos;i=\"5.79,349,1602572400\"; d=\"scan'208\";a=\"240084114\"",
            "E=Sophos;i=\"5.79,349,1602572400\"; d=\"scan'208\";a=\"364563078\""
        ],
        "X-ExtLoop1": "1",
        "From": "Anatoly Burakov <anatoly.burakov@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Fri, 15 Jan 2021 12:15:43 +0000",
        "Message-Id": "\n <9843593ce51003ea5e372a8107a96acdc01e8958.1610712939.git.anatoly.burakov@intel.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[dpdk-dev] [PATCH] mem: improve parameter checking on memory hotplug",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Currently, we don't check anything that comes in through memory hotplug\nsubsystem using the IPC, because we always assume the data is correct.\nThis is okay as anyone having access to the IPC socket would also have\nrights to crash the DPDK process through other means, but it's still a\ngood practice to do parameter checking, so fix the code to do that.\n\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\n---\n lib/librte_eal/common/malloc_heap.c |  3 +-\n lib/librte_eal/common/malloc_mp.c   | 70 +++++++++++++++++++++++++----\n lib/librte_eal/common/malloc_mp.h   |  2 +-\n 3 files changed, 65 insertions(+), 10 deletions(-)",
    "diff": "diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c\nindex 5a09247a65..ee400f38ec 100644\n--- a/lib/librte_eal/common/malloc_heap.c\n+++ b/lib/librte_eal/common/malloc_heap.c\n@@ -460,6 +460,7 @@ try_expand_heap_secondary(struct malloc_heap *heap, uint64_t pg_sz,\n \t\tsize_t elt_size, int socket, unsigned int flags, size_t align,\n \t\tsize_t bound, bool contig)\n {\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n \tstruct malloc_mp_req req;\n \tint req_result;\n \n@@ -473,7 +474,7 @@ try_expand_heap_secondary(struct malloc_heap *heap, uint64_t pg_sz,\n \treq.alloc_req.elt_size = elt_size;\n \treq.alloc_req.page_sz = pg_sz;\n \treq.alloc_req.socket = socket;\n-\treq.alloc_req.heap = heap; /* it's in shared memory */\n+\treq.alloc_req.malloc_heap_idx = heap - mcfg->malloc_heaps;\n \n \treq_result = request_to_primary(&req);\n \ndiff --git a/lib/librte_eal/common/malloc_mp.c b/lib/librte_eal/common/malloc_mp.c\nindex 1f212f8349..1b0e15b518 100644\n--- a/lib/librte_eal/common/malloc_mp.c\n+++ b/lib/librte_eal/common/malloc_mp.c\n@@ -11,6 +11,7 @@\n \n #include \"eal_memalloc.h\"\n #include \"eal_memcfg.h\"\n+#include \"eal_private.h\"\n \n #include \"malloc_elem.h\"\n #include \"malloc_mp.h\"\n@@ -175,10 +176,49 @@ handle_sync(const struct rte_mp_msg *msg, const void *peer)\n \treturn 0;\n }\n \n+static int\n+handle_free_request(const struct malloc_mp_req *m)\n+{\n+\tconst struct rte_memseg_list *msl;\n+\tvoid *start, *end;\n+\tuint64_t len;\n+\n+\tlen = m->free_req.len;\n+\tstart = m->free_req.addr;\n+\tend = RTE_PTR_ADD(start, len - 1);\n+\n+\t/* check if the requested memory actually exists */\n+\tmsl = rte_mem_virt2memseg_list(start);\n+\tif (msl == NULL) {\n+\t\tRTE_LOG(ERR, EAL, \"Requested to free unknown memory\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\t/* check if end is within the same memory region */\n+\tif (rte_mem_virt2memseg_list(end) != msl) {\n+\t\tRTE_LOG(ERR, EAL, \"Requested to free memory spanning multiple regions\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\t/* we're supposed to only free memory that's not external */\n+\tif (msl->external) {\n+\t\tRTE_LOG(ERR, EAL, \"Requested to free external memory\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\t/* now that we've validated the request, time for a PSA */\n+\teal_memalloc_mem_event_notify(RTE_MEM_EVENT_FREE,\n+\t\t\tm->free_req.addr, m->free_req.len);\n+\n+\t/* now, do the actual freeing */\n+\treturn malloc_heap_free_pages(m->free_req.addr, m->free_req.len);\n+}\n+\n static int\n handle_alloc_request(const struct malloc_mp_req *m,\n \t\tstruct mp_request *req)\n {\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n \tconst struct malloc_req_alloc *ar = &m->alloc_req;\n \tstruct malloc_heap *heap;\n \tstruct malloc_elem *elem;\n@@ -187,17 +227,35 @@ handle_alloc_request(const struct malloc_mp_req *m,\n \tint n_segs;\n \tvoid *map_addr;\n \n+\t/* this is checked by the API, but we need to prevent divide by zero */\n+\tif (ar->page_sz == 0 || !rte_is_power_of_2(ar->page_sz)) {\n+\t\tRTE_LOG(ERR, EAL, \"Attempting to allocate with page size\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\t/* heap idx is index into the heap array, not socket ID */\n+\tif (ar->malloc_heap_idx >= RTE_MAX_HEAPS) {\n+\t\tRTE_LOG(ERR, EAL, \"Attempting to allocate from invalid heap\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\theap = &mcfg->malloc_heaps[ar->malloc_heap_idx];\n+\n+\t/* for allocations, we must only use internal heaps */\n+\tif (rte_malloc_heap_socket_is_external(heap->socket_id)) {\n+\t\tRTE_LOG(ERR, EAL, \"Attempting to allocate from external heap\\n\");\n+\t\treturn -1;\n+\t}\n+\n \talloc_sz = RTE_ALIGN_CEIL(ar->align + ar->elt_size +\n \t\t\tMALLOC_ELEM_TRAILER_LEN, ar->page_sz);\n \tn_segs = alloc_sz / ar->page_sz;\n \n-\theap = ar->heap;\n-\n \t/* we can't know in advance how many pages we'll need, so we malloc */\n \tms = malloc(sizeof(*ms) * n_segs);\n \tif (ms == NULL) {\n \t\tRTE_LOG(ERR, EAL, \"Couldn't allocate memory for request state\\n\");\n-\t\tgoto fail;\n+\t\treturn -1;\n \t}\n \tmemset(ms, 0, sizeof(*ms) * n_segs);\n \n@@ -261,11 +319,7 @@ handle_request(const struct rte_mp_msg *msg, const void *peer __rte_unused)\n \tif (m->t == REQ_TYPE_ALLOC) {\n \t\tret = handle_alloc_request(m, entry);\n \t} else if (m->t == REQ_TYPE_FREE) {\n-\t\teal_memalloc_mem_event_notify(RTE_MEM_EVENT_FREE,\n-\t\t\t\tm->free_req.addr, m->free_req.len);\n-\n-\t\tret = malloc_heap_free_pages(m->free_req.addr,\n-\t\t\t\tm->free_req.len);\n+\t\tret = handle_free_request(m);\n \t} else {\n \t\tRTE_LOG(ERR, EAL, \"Unexpected request from secondary\\n\");\n \t\tgoto fail;\ndiff --git a/lib/librte_eal/common/malloc_mp.h b/lib/librte_eal/common/malloc_mp.h\nindex 2b86b76f68..015b7ec393 100644\n--- a/lib/librte_eal/common/malloc_mp.h\n+++ b/lib/librte_eal/common/malloc_mp.h\n@@ -30,7 +30,7 @@ enum malloc_req_result {\n };\n \n struct malloc_req_alloc {\n-\tstruct malloc_heap *heap;\n+\tuint32_t malloc_heap_idx;\n \tuint64_t page_sz;\n \tsize_t elt_size;\n \tint socket;\n",
    "prefixes": []
}