get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 124491,
    "url": "http://patches.dpdk.org/api/patches/124491/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20230224081642.2566619-2-david.marchand@redhat.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": "<20230224081642.2566619-2-david.marchand@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20230224081642.2566619-2-david.marchand@redhat.com",
    "date": "2023-02-24T08:16:29",
    "name": "[01/14] malloc: rework heap lock handling",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "a590c1353007f2f86e743d0213324a24b3898992",
    "submitter": {
        "id": 1173,
        "url": "http://patches.dpdk.org/api/people/1173/?format=api",
        "name": "David Marchand",
        "email": "david.marchand@redhat.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20230224081642.2566619-2-david.marchand@redhat.com/mbox/",
    "series": [
        {
            "id": 27167,
            "url": "http://patches.dpdk.org/api/series/27167/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=27167",
            "date": "2023-02-24T08:16:28",
            "name": "Enable lock annotations on most libraries and drivers",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/27167/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/124491/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/124491/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 F13A841D5D;\n\tFri, 24 Feb 2023 09:17:01 +0100 (CET)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 6822940EF1;\n\tFri, 24 Feb 2023 09:17:01 +0100 (CET)",
            "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by mails.dpdk.org (Postfix) with ESMTP id 2E4DE40693\n for <dev@dpdk.org>; Fri, 24 Feb 2023 09:17:00 +0100 (CET)",
            "from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com\n [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n us-mta-669-eAVmm8YxPV6srYQOjMJzDQ-1; Fri, 24 Feb 2023 03:16:55 -0500",
            "from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com\n [10.11.54.9])\n (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n (No client certificate requested)\n by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CB2D9800B23;\n Fri, 24 Feb 2023 08:16:54 +0000 (UTC)",
            "from dmarchan.redhat.com (unknown [10.45.224.55])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 03B8B492B07;\n Fri, 24 Feb 2023 08:16:53 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1677226619;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=pys5mz0G2mUZukXwaKteJY89qQfoORUAaHkqtbFYt4A=;\n b=hVMDxBnr7rSFX7BBtxoRRpJwzYVNX3doTYQqYsoTvC3O2pVsDq/rdb96XExqksfx1zSMeB\n im9gg09Ad5EfFP5G2IW87SqqXzpMrYDIXXuI7GqW47QB2s82K9FECzTeyQEYxPac1GOClS\n ++2JQZK7wPNI2lfpDwksz0y9YSoF1us=",
        "X-MC-Unique": "eAVmm8YxPV6srYQOjMJzDQ-1",
        "From": "David Marchand <david.marchand@redhat.com>",
        "To": "dev@dpdk.org",
        "Cc": "thomas@monjalon.net,\n\tAnatoly Burakov <anatoly.burakov@intel.com>",
        "Subject": "[PATCH 01/14] malloc: rework heap lock handling",
        "Date": "Fri, 24 Feb 2023 09:16:29 +0100",
        "Message-Id": "<20230224081642.2566619-2-david.marchand@redhat.com>",
        "In-Reply-To": "<20230224081642.2566619-1-david.marchand@redhat.com>",
        "References": "<20230224081642.2566619-1-david.marchand@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.1 on 10.11.54.9",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "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"
    },
    "content": "Move all heap->lock manipulation to malloc_heap.c to have a single\nlocation where to look at and make higher level code unaware of this\nlocking constraint.\n\nThe destroy helper has been reworked to zero all the heap object but\nleave the lock untouched. The heap lock is then released through the\nstandard API.\nThis makes the code less scary even though, at this point of its life,\nthe heap object is probably referenced only by the caller.\n\nSigned-off-by: David Marchand <david.marchand@redhat.com>\n---\n lib/eal/common/malloc_heap.c | 45 +++++++++++++++++++++++++++---------\n lib/eal/common/rte_malloc.c  | 10 --------\n 2 files changed, 34 insertions(+), 21 deletions(-)",
    "diff": "diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c\nindex d7c410b786..cc84dce672 100644\n--- a/lib/eal/common/malloc_heap.c\n+++ b/lib/eal/common/malloc_heap.c\n@@ -1292,6 +1292,8 @@ int\n malloc_heap_add_external_memory(struct malloc_heap *heap,\n \t\tstruct rte_memseg_list *msl)\n {\n+\trte_spinlock_lock(&heap->lock);\n+\n \t/* erase contents of new memory */\n \tmemset(msl->base_va, 0, msl->len);\n \n@@ -1308,6 +1310,11 @@ malloc_heap_add_external_memory(struct malloc_heap *heap,\n \teal_memalloc_mem_event_notify(RTE_MEM_EVENT_ALLOC,\n \t\t\tmsl->base_va, msl->len);\n \n+\t/* mark it as heap segment */\n+\tmsl->heap = 1;\n+\n+\trte_spinlock_unlock(&heap->lock);\n+\n \treturn 0;\n }\n \n@@ -1315,7 +1322,12 @@ int\n malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr,\n \t\tsize_t len)\n {\n-\tstruct malloc_elem *elem = heap->first;\n+\tstruct malloc_elem *elem;\n+\tint ret = -1;\n+\n+\trte_spinlock_lock(&heap->lock);\n+\n+\telem = heap->first;\n \n \t/* find element with specified va address */\n \twhile (elem != NULL && elem != va_addr) {\n@@ -1323,20 +1335,24 @@ malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr,\n \t\t/* stop if we've blown past our VA */\n \t\tif (elem > (struct malloc_elem *)va_addr) {\n \t\t\trte_errno = ENOENT;\n-\t\t\treturn -1;\n+\t\t\tgoto out;\n \t\t}\n \t}\n \t/* check if element was found */\n \tif (elem == NULL || elem->msl->len != len) {\n \t\trte_errno = ENOENT;\n-\t\treturn -1;\n+\t\tgoto out;\n \t}\n \t/* if element's size is not equal to segment len, segment is busy */\n \tif (elem->state == ELEM_BUSY || elem->size != len) {\n \t\trte_errno = EBUSY;\n-\t\treturn -1;\n+\t\tgoto out;\n \t}\n-\treturn destroy_elem(elem, len);\n+\tret = destroy_elem(elem, len);\n+\n+out:\n+\trte_spinlock_unlock(&heap->lock);\n+\treturn ret;\n }\n \n int\n@@ -1372,23 +1388,30 @@ malloc_heap_create(struct malloc_heap *heap, const char *heap_name)\n int\n malloc_heap_destroy(struct malloc_heap *heap)\n {\n+\tint ret = -1;\n+\n+\trte_spinlock_lock(&heap->lock);\n+\n \tif (heap->alloc_count != 0) {\n \t\tRTE_LOG(ERR, EAL, \"Heap is still in use\\n\");\n \t\trte_errno = EBUSY;\n-\t\treturn -1;\n+\t\tgoto fail;\n \t}\n \tif (heap->first != NULL || heap->last != NULL) {\n \t\tRTE_LOG(ERR, EAL, \"Heap still contains memory segments\\n\");\n \t\trte_errno = EBUSY;\n-\t\treturn -1;\n+\t\tgoto fail;\n \t}\n \tif (heap->total_size != 0)\n \t\tRTE_LOG(ERR, EAL, \"Total size not zero, heap is likely corrupt\\n\");\n \n-\t/* after this, the lock will be dropped */\n-\tmemset(heap, 0, sizeof(*heap));\n-\n-\treturn 0;\n+\tRTE_BUILD_BUG_ON(offsetof(struct malloc_heap, lock) != 0);\n+\tmemset(RTE_PTR_ADD(heap, sizeof(heap->lock)), 0,\n+\t\tsizeof(*heap) - sizeof(heap->lock));\n+\tret = 0;\n+fail:\n+\trte_spinlock_unlock(&heap->lock);\n+\treturn ret;\n }\n \n int\ndiff --git a/lib/eal/common/rte_malloc.c b/lib/eal/common/rte_malloc.c\nindex d39870bf3c..4f500892f2 100644\n--- a/lib/eal/common/rte_malloc.c\n+++ b/lib/eal/common/rte_malloc.c\n@@ -436,10 +436,7 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,\n \t\tgoto unlock;\n \t}\n \n-\trte_spinlock_lock(&heap->lock);\n \tret = malloc_heap_add_external_memory(heap, msl);\n-\tmsl->heap = 1; /* mark it as heap segment */\n-\trte_spinlock_unlock(&heap->lock);\n \n unlock:\n \trte_mcfg_mem_write_unlock();\n@@ -482,9 +479,7 @@ rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len)\n \t\tgoto unlock;\n \t}\n \n-\trte_spinlock_lock(&heap->lock);\n \tret = malloc_heap_remove_external_memory(heap, va_addr, len);\n-\trte_spinlock_unlock(&heap->lock);\n \tif (ret != 0)\n \t\tgoto unlock;\n \n@@ -655,12 +650,7 @@ rte_malloc_heap_destroy(const char *heap_name)\n \t\tgoto unlock;\n \t}\n \t/* sanity checks done, now we can destroy the heap */\n-\trte_spinlock_lock(&heap->lock);\n \tret = malloc_heap_destroy(heap);\n-\n-\t/* if we failed, lock is still active */\n-\tif (ret < 0)\n-\t\trte_spinlock_unlock(&heap->lock);\n unlock:\n \trte_mcfg_mem_write_unlock();\n \n",
    "prefixes": [
        "01/14"
    ]
}