get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 138811,
    "url": "http://patchwork.dpdk.org/api/patches/138811/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20240326154936.1132201-1-rjarry@redhat.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": "<20240326154936.1132201-1-rjarry@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20240326154936.1132201-1-rjarry@redhat.com",
    "date": "2024-03-26T15:49:36",
    "name": "[v2] graph: avoid id collisions",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "f47fe661986b6672ff028e53b0bf135e77920e8e",
    "submitter": {
        "id": 2850,
        "url": "http://patchwork.dpdk.org/api/people/2850/?format=api",
        "name": "Robin Jarry",
        "email": "rjarry@redhat.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20240326154936.1132201-1-rjarry@redhat.com/mbox/",
    "series": [
        {
            "id": 31620,
            "url": "http://patchwork.dpdk.org/api/series/31620/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=31620",
            "date": "2024-03-26T15:49:36",
            "name": "[v2] graph: avoid id collisions",
            "version": 2,
            "mbox": "http://patchwork.dpdk.org/series/31620/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/138811/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/138811/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 EA98E43D56;\n\tTue, 26 Mar 2024 16:50:00 +0100 (CET)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 6FBA04029F;\n\tTue, 26 Mar 2024 16:50:00 +0100 (CET)",
            "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by mails.dpdk.org (Postfix) with ESMTP id 8B0E64013F\n for <dev@dpdk.org>; Tue, 26 Mar 2024 16:49:59 +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.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-688-bHi2c5jmNUawH58gNU2HNA-1; Tue, 26 Mar 2024 11:49:54 -0400",
            "from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com\n [10.11.54.6])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4605D8007A3;\n Tue, 26 Mar 2024 15:49:54 +0000 (UTC)",
            "from localhost.localdomain (unknown [10.39.208.31])\n by smtp.corp.redhat.com (Postfix) with ESMTP id EF0C02166B31;\n Tue, 26 Mar 2024 15:49:52 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1711468199;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to: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=agKD7ZiBcbnbnyH9yh8sjiPiomvL3KgkCvyGoSAXKL4=;\n b=M21PN7xyvtYoDoqtJY4qOhyvrWA4v7zeZ2xpbE1V/3xZe3EDiq0+Ix3No0/agi0AoAoXF2\n FRVWNZeElrcBsNAoIlNKO1naTsVaokEUbw8zv3OEXP3r/acsy/gyNWd2J3yphw7C79Cwvl\n skRsDwj2ZlQTuBTe3QB4XV0BsdlZTGs=",
        "X-MC-Unique": "bHi2c5jmNUawH58gNU2HNA-1",
        "From": "Robin Jarry <rjarry@redhat.com>",
        "To": "dev@dpdk.org, Jerin Jacob <jerinj@marvell.com>,\n Kiran Kumar K <kirankumark@marvell.com>,\n Nithin Dabilpuram <ndabilpuram@marvell.com>,\n Zhirun Yan <yanzhirun_163@163.com>",
        "Subject": "[PATCH v2] graph: avoid id collisions",
        "Date": "Tue, 26 Mar 2024 16:49:36 +0100",
        "Message-ID": "<20240326154936.1132201-1-rjarry@redhat.com>",
        "In-Reply-To": "<20240325155354.770676-2-rjarry@redhat.com>",
        "References": "<20240325155354.770676-2-rjarry@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.4.1 on 10.11.54.6",
        "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": "The graph id is determined based on a global variable that is\nincremented every time a graph is created, and decremented every time\na graph is destroyed. This only works if graphs are destroyed in the\nreverse order in which they have been created.\n\nThe following code produces duplicate graph IDs which can lead to\nuse-after-free bugs and other undefined behaviours:\n\n  a = rte_graph_create(...); // id=0 graph_id=1\n  b = rte_graph_create(...); // id=1 graph_id=2\n  rte_graph_destroy(a);      // graph_id=1\n  c = rte_graph_create(...); // id=1 graph_id=2 (duplicate with b)\n  rte_graph_destroy(c);      // frees memory still used by b\n\nRemove the global counter. Make sure that the graph list is always\nordered by increasing graph ids. When creating a new graph, pick a free\nid which is not allocated.\n\nUpdate unit tests to ensure it works as expected.\n\nSigned-off-by: Robin Jarry <rjarry@redhat.com>\n---\n\nNotes:\n    v2: Added unit test\n\n app/test/test_graph.c | 63 +++++++++++++++++++++++++++++++\n lib/graph/graph.c     | 86 ++++++++++++++++++++++++++++++++++---------\n 2 files changed, 132 insertions(+), 17 deletions(-)",
    "diff": "diff --git a/app/test/test_graph.c b/app/test/test_graph.c\nindex b8409bc60497..c650ac4f57b7 100644\n--- a/app/test/test_graph.c\n+++ b/app/test/test_graph.c\n@@ -696,6 +696,68 @@ test_graph_clone(void)\n \treturn ret;\n }\n \n+static int\n+test_graph_id_collisions(void)\n+{\n+\tstatic const char *node_patterns[] = {\"test_node_source1\", \"test_node00\"};\n+\tstruct rte_graph_param gconf = {\n+\t\t.socket_id = SOCKET_ID_ANY,\n+\t\t.nb_node_patterns = 2,\n+\t\t.node_patterns = node_patterns,\n+\t};\n+\trte_graph_t g1, g2, g3;\n+\n+\tg1 = rte_graph_create(\"worker1\", &gconf);\n+\tif (g1 == RTE_GRAPH_ID_INVALID) {\n+\t\tprintf(\"Graph 1 creation failed with error = %d\\n\", rte_errno);\n+\t\treturn -1;\n+\t}\n+\tg2 = rte_graph_create(\"worker2\", &gconf);\n+\tif (g2 == RTE_GRAPH_ID_INVALID) {\n+\t\tprintf(\"Graph 2 creation failed with error = %d\\n\", rte_errno);\n+\t\treturn -1;\n+\t}\n+\tif (g1 == g2) {\n+\t\tprintf(\"Graph ids should be different\\n\");\n+\t\treturn -1;\n+\t}\n+\tif (rte_graph_destroy(g1) < 0) {\n+\t\tprintf(\"Graph 1 suppression failed\\n\");\n+\t\treturn -1;\n+\t}\n+\tg3 = rte_graph_create(\"worker3\", &gconf);\n+\tif (g3 == RTE_GRAPH_ID_INVALID) {\n+\t\tprintf(\"Graph 3 creation failed with error = %d\\n\", rte_errno);\n+\t\treturn -1;\n+\t}\n+\tif (g3 == g2) {\n+\t\tprintf(\"Graph ids should be different\\n\");\n+\t\treturn -1;\n+\t}\n+\tg1 = rte_graph_clone(g2, \"worker1\", &gconf);\n+\tif (g1 == RTE_GRAPH_ID_INVALID) {\n+\t\tprintf(\"Graph 2 clone failed with error = %d\\n\", rte_errno);\n+\t\treturn -1;\n+\t}\n+\tif (g1 == g2 || g2 == g3 || g1 == g3) {\n+\t\tprintf(\"Graph ids should be different\\n\");\n+\t\treturn -1;\n+\t}\n+\tif (rte_graph_destroy(g1) < 0) {\n+\t\tprintf(\"Graph 1 suppression failed\\n\");\n+\t\treturn -1;\n+\t}\n+\tif (rte_graph_destroy(g2) < 0) {\n+\t\tprintf(\"Graph 2 suppression failed\\n\");\n+\t\treturn -1;\n+\t}\n+\tif (rte_graph_destroy(g3) < 0) {\n+\t\tprintf(\"Graph 3 suppression failed\\n\");\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\n+\n static int\n test_graph_model_mcore_dispatch_node_lcore_affinity_set(void)\n {\n@@ -977,6 +1039,7 @@ static struct unit_test_suite graph_testsuite = {\n \t\tTEST_CASE(test_lookup_functions),\n \t\tTEST_CASE(test_create_graph),\n \t\tTEST_CASE(test_graph_clone),\n+\t\tTEST_CASE(test_graph_id_collisions),\n \t\tTEST_CASE(test_graph_model_mcore_dispatch_node_lcore_affinity_set),\n \t\tTEST_CASE(test_graph_model_mcore_dispatch_core_bind_unbind),\n \t\tTEST_CASE(test_graph_worker_model_set_get),\ndiff --git a/lib/graph/graph.c b/lib/graph/graph.c\nindex 147bc6c685c5..50616580d06b 100644\n--- a/lib/graph/graph.c\n+++ b/lib/graph/graph.c\n@@ -19,11 +19,54 @@\n \n static struct graph_head graph_list = STAILQ_HEAD_INITIALIZER(graph_list);\n static rte_spinlock_t graph_lock = RTE_SPINLOCK_INITIALIZER;\n-static rte_graph_t graph_id;\n-\n-#define GRAPH_ID_CHECK(id) ID_CHECK(id, graph_id)\n \n /* Private functions */\n+static struct graph *\n+graph_from_id(rte_graph_t id)\n+{\n+\tstruct graph *graph;\n+\tSTAILQ_FOREACH(graph, &graph_list, next) {\n+\t\tif (graph->id == id)\n+\t\t\treturn graph;\n+\t}\n+\trte_errno = EINVAL;\n+\treturn NULL;\n+}\n+\n+static rte_graph_t\n+graph_next_free_id(void)\n+{\n+\tstruct graph *graph;\n+\trte_graph_t id = 0;\n+\n+\tSTAILQ_FOREACH(graph, &graph_list, next) {\n+\t\tif (id < graph->id)\n+\t\t\tbreak;\n+\t\tid = graph->id + 1;\n+\t}\n+\n+\treturn id;\n+}\n+\n+static void\n+graph_insert_ordered(struct graph *graph)\n+{\n+\tstruct graph *after, *g;\n+\n+\tafter = NULL;\n+\tSTAILQ_FOREACH(g, &graph_list, next) {\n+\t\tif (g->id < graph->id) {\n+\t\t\tafter = g;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tif (after == NULL) {\n+\t\tSTAILQ_INSERT_TAIL(&graph_list, graph, next);\n+\t} else {\n+\t\tSTAILQ_INSERT_AFTER(&graph_list, after, graph, next);\n+\t}\n+}\n+\n struct graph_head *\n graph_list_head_get(void)\n {\n@@ -279,7 +322,8 @@ rte_graph_model_mcore_dispatch_core_bind(rte_graph_t id, int lcore)\n {\n \tstruct graph *graph;\n \n-\tGRAPH_ID_CHECK(id);\n+\tif (graph_from_id(id) == NULL)\n+\t\tgoto fail;\n \tif (!rte_lcore_is_enabled(lcore))\n \t\tSET_ERR_JMP(ENOLINK, fail, \"lcore %d not enabled\", lcore);\n \n@@ -309,7 +353,8 @@ rte_graph_model_mcore_dispatch_core_unbind(rte_graph_t id)\n {\n \tstruct graph *graph;\n \n-\tGRAPH_ID_CHECK(id);\n+\tif (graph_from_id(id) == NULL)\n+\t\tgoto fail;\n \tSTAILQ_FOREACH(graph, &graph_list, next)\n \t\tif (graph->id == id)\n \t\t\tbreak;\n@@ -406,7 +451,7 @@ rte_graph_create(const char *name, struct rte_graph_param *prm)\n \tgraph->socket = prm->socket_id;\n \tgraph->src_node_count = src_node_count;\n \tgraph->node_count = graph_nodes_count(graph);\n-\tgraph->id = graph_id;\n+\tgraph->id = graph_next_free_id();\n \tgraph->parent_id = RTE_GRAPH_ID_INVALID;\n \tgraph->lcore_id = RTE_MAX_LCORE;\n \tgraph->num_pkt_to_capture = prm->num_pkt_to_capture;\n@@ -422,8 +467,7 @@ rte_graph_create(const char *name, struct rte_graph_param *prm)\n \t\tgoto graph_mem_destroy;\n \n \t/* All good, Lets add the graph to the list */\n-\tgraph_id++;\n-\tSTAILQ_INSERT_TAIL(&graph_list, graph, next);\n+\tgraph_insert_ordered(graph);\n \n \tgraph_spinlock_unlock();\n \treturn graph->id;\n@@ -467,7 +511,6 @@ rte_graph_destroy(rte_graph_t id)\n \t\t\tgraph_cleanup(graph);\n \t\t\tSTAILQ_REMOVE(&graph_list, graph, graph, next);\n \t\t\tfree(graph);\n-\t\t\tgraph_id--;\n \t\t\tgoto done;\n \t\t}\n \t\tgraph = tmp;\n@@ -520,7 +563,7 @@ graph_clone(struct graph *parent_graph, const char *name, struct rte_graph_param\n \tgraph->parent_id = parent_graph->id;\n \tgraph->lcore_id = parent_graph->lcore_id;\n \tgraph->socket = parent_graph->socket;\n-\tgraph->id = graph_id;\n+\tgraph->id = graph_next_free_id();\n \n \t/* Allocate the Graph fast path memory and populate the data */\n \tif (graph_fp_mem_create(graph))\n@@ -539,8 +582,7 @@ graph_clone(struct graph *parent_graph, const char *name, struct rte_graph_param\n \t\tgoto graph_mem_destroy;\n \n \t/* All good, Lets add the graph to the list */\n-\tgraph_id++;\n-\tSTAILQ_INSERT_TAIL(&graph_list, graph, next);\n+\tgraph_insert_ordered(graph);\n \n \tgraph_spinlock_unlock();\n \treturn graph->id;\n@@ -561,7 +603,8 @@ rte_graph_clone(rte_graph_t id, const char *name, struct rte_graph_param *prm)\n {\n \tstruct graph *graph;\n \n-\tGRAPH_ID_CHECK(id);\n+\tif (graph_from_id(id) == NULL)\n+\t\tgoto fail;\n \tSTAILQ_FOREACH(graph, &graph_list, next)\n \t\tif (graph->id == id)\n \t\t\treturn graph_clone(graph, name, prm);\n@@ -587,7 +630,8 @@ rte_graph_id_to_name(rte_graph_t id)\n {\n \tstruct graph *graph;\n \n-\tGRAPH_ID_CHECK(id);\n+\tif (graph_from_id(id) == NULL)\n+\t\tgoto fail;\n \tSTAILQ_FOREACH(graph, &graph_list, next)\n \t\tif (graph->id == id)\n \t\t\treturn graph->name;\n@@ -604,7 +648,8 @@ rte_graph_node_get(rte_graph_t gid, uint32_t nid)\n \trte_graph_off_t off;\n \trte_node_t count;\n \n-\tGRAPH_ID_CHECK(gid);\n+\tif (graph_from_id(gid) == NULL)\n+\t\tgoto fail;\n \tSTAILQ_FOREACH(graph, &graph_list, next)\n \t\tif (graph->id == gid) {\n \t\t\trte_graph_foreach_node(count, off, graph->graph,\n@@ -747,7 +792,8 @@ graph_scan_dump(FILE *f, rte_graph_t id, bool all)\n \tstruct graph *graph;\n \n \tRTE_VERIFY(f);\n-\tGRAPH_ID_CHECK(id);\n+\tif (graph_from_id(id) == NULL)\n+\t\tgoto fail;\n \n \tSTAILQ_FOREACH(graph, &graph_list, next) {\n \t\tif (all == true) {\n@@ -776,7 +822,13 @@ rte_graph_list_dump(FILE *f)\n rte_graph_t\n rte_graph_max_count(void)\n {\n-\treturn graph_id;\n+\tstruct graph *graph;\n+\trte_graph_t count = 0;\n+\n+\tSTAILQ_FOREACH(graph, &graph_list, next)\n+\t\tcount++;\n+\n+\treturn count;\n }\n \n RTE_LOG_REGISTER_DEFAULT(rte_graph_logtype, INFO);\n",
    "prefixes": [
        "v2"
    ]
}