From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9CD0643FEF for ; Fri, 10 May 2024 08:48:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8A634402F0; Fri, 10 May 2024 08:48:12 +0200 (CEST) Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01olkn2086.outbound.protection.outlook.com [40.92.98.86]) by mails.dpdk.org (Postfix) with ESMTP id ADAF34025F; Fri, 10 May 2024 08:48:09 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OyfBRBesgPF+CcoChx5UnVzhCwoSJceM13tMgWxiiMyrS/pqzOlQ7YzCw+wuw26NjYGmujP2ep1ID7ilx//1aEzpNfmcwSh8y0EOqD8UcfI3eoxLqI7k7BIffDjt/cbJlxdYojBWAqBkj59180Xm+FDPXNLHcp8FKphaJV69ZNB8MHyh8MwtBGwpi2ctw0DeQiWYwPJ6cb8Peqyk2nO9ONa+PGr5FHSZIGvKrRIht4ikcuiST2xrD9/S9sllQDcy5B3/1uHiw6omm26BLJxULrizbwDlfkBmhqw07/Wi3dt1HuKWYAs9GEYcwPBRJhvcLnEiIffmFwQpIkwF+xvGIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iO3hd87BMZ9aVzeLAKk8HyYFILfveiEARDG/YvpoeBg=; b=IZYKUi72h4Sm1vA/rnStU3Qr8ZJPEz94p2YRmtv2br7Yp9AAk3AoYSGaICkPrQp6k+/8zpFWk0vKSe8/bBVReqq51Xmm+DPpHpk350wd0NcAJvKAQX/HyrOlHUdmdhf+mbOXAzwrlb8GJe4bB7OVVvR9XFmNaC70vScUJypkLaYgvvnxF3u1suCifo+TIqCnwxXZyA19tr3GNBk614tK37RXvbo6rhQPy13zvWexM68Bcf8H0xsCuN1uMsToa2OPVub9C1V9UIUqTcosxgmZASjCiJN/LXxiUf4A/MFp1tCg7DU7AenGeZvvbcSoQWUhXYpU+ZVkjSGxtJplLf2oSw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iO3hd87BMZ9aVzeLAKk8HyYFILfveiEARDG/YvpoeBg=; b=dggJHR77wNNh9wYP6AlEgar5Ll4ZoIcnhPSyBkX2z9etlHjqg+NbGI5kt4Kcz+jcDD9cs4Ef0Tp5aEgxvGQkoKTg1goUntj1Xhp1r/eobxR3sncX7jDDERx3RS1B86febRBOzYqhXPXMt6PTbfxJi/5Lz24nYj1V45qLx0s3RH0QXVDjIIdYesNyhp//waYLlu0mi44fgcKucfypO7qJUH+JpjUPmPrjtko3c5DntwY5ibqJr/5UVHeG2X34CA+LoyNIR4PTFqsHlQsRw/I66CZwmZAKf6QSXn8a7QWgDcuSgdWxdxm8zYeLQ1tFD1PRBbR2TSDI9rOiKdfOFCsVFQ== Received: from TYAP286MB0649.JPNP286.PROD.OUTLOOK.COM (2603:1096:402:38::13) by TYCP286MB3636.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3aa::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.49; Fri, 10 May 2024 06:48:06 +0000 Received: from TYAP286MB0649.JPNP286.PROD.OUTLOOK.COM ([fe80::a92e:74bb:6df2:7ea2]) by TYAP286MB0649.JPNP286.PROD.OUTLOOK.COM ([fe80::a92e:74bb:6df2:7ea2%5]) with mapi id 15.20.7544.048; Fri, 10 May 2024 06:48:06 +0000 From: Gongming Chen To: jerinj@marvell.com, kirankumark@marvell.com, ndabilpuram@marvell.com, yanzhirun_163@163.com Cc: dev@dpdk.org, Gongming Chen , stable@dpdk.org, Fan Yin Subject: [PATCH v2] graph: fix does not return the unique id when create graph Date: Fri, 10 May 2024 14:47:47 +0800 Message-ID: X-Mailer: git-send-email 2.32.1 (Apple Git-133) Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [zOw9JEcG3WC3Ee0HmKgkYkkdTUl51usv] X-ClientProxiedBy: TYCP286CA0314.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:38b::18) To TYAP286MB0649.JPNP286.PROD.OUTLOOK.COM (2603:1096:402:38::13) X-Microsoft-Original-Message-ID: <20240510064747.18051-1-chengongming1900@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYAP286MB0649:EE_|TYCP286MB3636:EE_ X-MS-Office365-Filtering-Correlation-Id: 3d98c6fd-be19-48ba-52d8-08dc70bd2597 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|440099019|3412199016|3430499023; X-Microsoft-Antispam-Message-Info: QxJZ9EZy6Mn7iDcN0S2tJNdIdEIiaaoNkDvZU4xn8ZlfYXA2Wn4FOkEY+rsDMmFoOKk6F/i/ZFkIi8A2QCvmmSreSV+ClvmvWD0G+ZKIIiHwmTMQ6VU6nVsPlgpTY7MjTKLCJYVjanDqcHDGVqmQIxMyoNp0ZaXQGEk8TnqKGmNkmKJqHv8+ab8FRX0Lqb3gNDIOlnkPEUN9sKPHj2mlP/y2lY++74+Y6tinv3RvrCc+zmmfTfMOp8SOw0OAUkEZJ7TnUsxmECUk+eVAoNBI6Lmpppi4qT9jiIl9q0C7EA0TWjYQgf5z5fSCaO26uDHTKlr97WF8sLaPgolJaCdKU79Q1ZdPcYwLhCDXcbk0K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cvUJmLbL6HXKXDWeiXx0?= =?us-ascii?Q?JyF8u+07sdppHXoKkj+7RA1wfoiKURkbtgI9yt7lMVjaXZDUU/TmKQj0SiOX?= =?us-ascii?Q?1a09yfnWWxUqfMyGjkbVB9NG15wj6qjWFoCC6HWa8kH/wpPSxOJPN/DagdeH?= =?us-ascii?Q?sJ8ajjcq1VNAr2mtg/wg+wyf7DzGbvdEo8Gt5WgEfZD9fLLdlDtjKx0upCIA?= =?us-ascii?Q?JZEQyTOxGihd9ZG0NXU09H2h2Mo3RAndJ7w+RUsK8b6WnIsypGEe+bXyRYhg?= =?us-ascii?Q?MHHTJrMeQUixuyJYluIZEYIKeno4mhIZgDVP2QXt0sjF74c1fphmFLcpQEIC?= =?us-ascii?Q?8PE5Koyp6+H/U3wdh2NTkMBd6qnMFEd0nSRDnnG2motU5va5ZCak/m8GVyIr?= =?us-ascii?Q?TlTqj8e9hN2VMTb4F05ws4O3a6h/CaslriScC8Vr2b9QjDdWuuyI+QCKBtsi?= =?us-ascii?Q?8uhUzV5YrA8HS795z8vaw/z5WUwQ1qLHlpufNMK3QgGn0sJ1PiWuWDhnWUie?= =?us-ascii?Q?S/cX2OryRK/1xHEqTHPi5tij2Ab3t3muJLvF5UAwMChwNvUl64CjLKsuN/E/?= =?us-ascii?Q?kh9UgYaulnrFpHSU+mqbGqp8vafDg9GSOFMZPnCKvmaVS8yIkclQjpGlPwAo?= =?us-ascii?Q?yVk8IpOrTQ7hISo7i1Gc?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3d98c6fd-be19-48ba-52d8-08dc70bd2597 X-MS-Exchange-CrossTenant-AuthSource: TYAP286MB0649.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 06:48:06.3829 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCP286MB3636 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org From: Gongming Chen When the order of graph destroy is not the reverse order of create, that is, when it is destroyed at will, the newly created graph id will be the same as the existing graph id, which is not the expected unique graph id. This graph id incorrectly corresponds to multiple graphs. Fixes: a91fecc19c5c ("graph: implement create and destroy") Cc: stable@dpdk.org Reported-by: Fan Yin Signed-off-by: Gongming Chen Signed-off-by: Fan Yin --- lib/graph/graph.c | 163 ++++++++++++++++++++++++++-------------------- 1 file changed, 94 insertions(+), 69 deletions(-) diff --git a/lib/graph/graph.c b/lib/graph/graph.c index 26f0968a97..b8fecd9c6a 100644 --- a/lib/graph/graph.c +++ b/lib/graph/graph.c @@ -19,9 +19,6 @@ static struct graph_head graph_list = STAILQ_HEAD_INITIALIZER(graph_list); static rte_spinlock_t graph_lock = RTE_SPINLOCK_INITIALIZER; -static rte_graph_t graph_id; - -#define GRAPH_ID_CHECK(id) ID_CHECK(id, graph_id) /* Private functions */ struct graph_head * @@ -217,6 +214,46 @@ graph_node_fini(struct graph *graph) graph_node->node->name)); } +static struct graph * +graph_find_by_id(rte_graph_t id) +{ + struct graph *graph; + + STAILQ_FOREACH(graph, &graph_list, next) + if (graph->id == id) + return graph; + return NULL; +} + +static struct graph * +graph_find_by_name(const char *name) +{ + struct graph *graph; + + STAILQ_FOREACH(graph, &graph_list, next) + if (strncmp(graph->name, name, RTE_GRAPH_NAMESIZE) == 0) + return graph; + return NULL; +} + +static rte_graph_t +graph_free_id_find(void) +{ + static rte_graph_t graph_id; + if (graph_id == RTE_GRAPH_ID_INVALID) + graph_id++; + + rte_graph_t end_id = graph_id; + do { + if (!graph_find_by_id(graph_id)) + return graph_id++; + if (++graph_id == RTE_GRAPH_ID_INVALID) + graph_id++; + } while (graph_id != end_id); + + return RTE_GRAPH_ID_INVALID; +} + static struct rte_graph * graph_mem_fixup_node_ctx(struct rte_graph *graph) { @@ -279,13 +316,12 @@ rte_graph_model_mcore_dispatch_core_bind(rte_graph_t id, int lcore) { struct graph *graph; - GRAPH_ID_CHECK(id); if (!rte_lcore_is_enabled(lcore)) SET_ERR_JMP(ENOLINK, fail, "lcore %d not enabled", lcore); - STAILQ_FOREACH(graph, &graph_list, next) - if (graph->id == id) - break; + graph = graph_find_by_id(id); + if (!graph) + goto fail; if (graph->graph->model != RTE_GRAPH_MODEL_MCORE_DISPATCH) goto fail; @@ -309,15 +345,12 @@ rte_graph_model_mcore_dispatch_core_unbind(rte_graph_t id) { struct graph *graph; - GRAPH_ID_CHECK(id); - STAILQ_FOREACH(graph, &graph_list, next) - if (graph->id == id) - break; + graph = graph_find_by_id(id); + if (!graph) + return; graph->lcore_id = RTE_MAX_LCORE; graph->graph->dispatch.lcore_id = RTE_MAX_LCORE; - -fail: return; } @@ -352,10 +385,8 @@ rte_graph_create(const char *name, struct rte_graph_param *prm) SET_ERR_JMP(EINVAL, fail, "Graph name should not be NULL"); /* Check for existence of duplicate graph */ - STAILQ_FOREACH(graph, &graph_list, next) - if (strncmp(name, graph->name, RTE_GRAPH_NAMESIZE) == 0) - SET_ERR_JMP(EEXIST, fail, "Found duplicate graph %s", - name); + if (graph_find_by_name(name)) + SET_ERR_JMP(EEXIST, fail, "Found duplicate graph %s", name); /* Create graph object */ graph = calloc(1, sizeof(*graph)); @@ -403,10 +434,12 @@ rte_graph_create(const char *name, struct rte_graph_param *prm) graph_pcap_enable(prm->pcap_enable); /* Initialize graph object */ + graph->id = graph_free_id_find(); + if (graph->id == RTE_GRAPH_ID_INVALID) + goto graph_cleanup; graph->socket = prm->socket_id; graph->src_node_count = src_node_count; graph->node_count = graph_nodes_count(graph); - graph->id = graph_id; graph->parent_id = RTE_GRAPH_ID_INVALID; graph->lcore_id = RTE_MAX_LCORE; graph->num_pkt_to_capture = prm->num_pkt_to_capture; @@ -422,7 +455,6 @@ rte_graph_create(const char *name, struct rte_graph_param *prm) goto graph_mem_destroy; /* All good, Lets add the graph to the list */ - graph_id++; STAILQ_INSERT_TAIL(&graph_list, graph, next); graph_spinlock_unlock(); @@ -467,7 +499,6 @@ rte_graph_destroy(rte_graph_t id) graph_cleanup(graph); STAILQ_REMOVE(&graph_list, graph, graph, next); free(graph); - graph_id--; goto done; } graph = tmp; @@ -515,12 +546,14 @@ graph_clone(struct graph *parent_graph, const char *name, struct rte_graph_param goto graph_cleanup; /* Initialize the graph object */ + graph->id = graph_free_id_find(); + if (graph->id == RTE_GRAPH_ID_INVALID) + goto graph_cleanup; graph->src_node_count = parent_graph->src_node_count; graph->node_count = parent_graph->node_count; graph->parent_id = parent_graph->id; graph->lcore_id = parent_graph->lcore_id; graph->socket = parent_graph->socket; - graph->id = graph_id; /* Allocate the Graph fast path memory and populate the data */ if (graph_fp_mem_create(graph)) @@ -539,7 +572,6 @@ graph_clone(struct graph *parent_graph, const char *name, struct rte_graph_param goto graph_mem_destroy; /* All good, Lets add the graph to the list */ - graph_id++; STAILQ_INSERT_TAIL(&graph_list, graph, next); graph_spinlock_unlock(); @@ -561,12 +593,10 @@ rte_graph_clone(rte_graph_t id, const char *name, struct rte_graph_param *prm) { struct graph *graph; - GRAPH_ID_CHECK(id); - STAILQ_FOREACH(graph, &graph_list, next) - if (graph->id == id) - return graph_clone(graph, name, prm); + graph = graph_find_by_id(id); + if (graph) + return graph_clone(graph, name, prm); -fail: return RTE_GRAPH_ID_INVALID; } @@ -575,9 +605,9 @@ rte_graph_from_name(const char *name) { struct graph *graph; - STAILQ_FOREACH(graph, &graph_list, next) - if (strncmp(graph->name, name, RTE_GRAPH_NAMESIZE) == 0) - return graph->id; + graph = graph_find_by_name(name); + if (graph) + return graph->id; return RTE_GRAPH_ID_INVALID; } @@ -587,12 +617,10 @@ rte_graph_id_to_name(rte_graph_t id) { struct graph *graph; - GRAPH_ID_CHECK(id); - STAILQ_FOREACH(graph, &graph_list, next) - if (graph->id == id) - return graph->name; + graph = graph_find_by_id(id); + if (graph) + return graph->name; -fail: return NULL; } @@ -604,17 +632,13 @@ rte_graph_node_get(rte_graph_t gid, uint32_t nid) rte_graph_off_t off; rte_node_t count; - GRAPH_ID_CHECK(gid); - STAILQ_FOREACH(graph, &graph_list, next) - if (graph->id == gid) { - rte_graph_foreach_node(count, off, graph->graph, - node) { - if (node->id == nid) - return node; - } - break; + graph = graph_find_by_id(gid); + if (graph) + rte_graph_foreach_node(count, off, graph->graph, node) { + if (node->id == nid) + return node; } -fail: + return NULL; } @@ -626,15 +650,11 @@ rte_graph_node_get_by_name(const char *graph_name, const char *node_name) rte_graph_off_t off; rte_node_t count; - STAILQ_FOREACH(graph, &graph_list, next) - if (!strncmp(graph->name, graph_name, RTE_GRAPH_NAMESIZE)) { - rte_graph_foreach_node(count, off, graph->graph, - node) { - if (!strncmp(node->name, node_name, - RTE_NODE_NAMESIZE)) - return node; - } - break; + graph = graph_find_by_name(graph_name); + if (graph) + rte_graph_foreach_node(count, off, graph->graph, node) { + if (!strncmp(node->name, node_name, RTE_NODE_NAMESIZE)) + return node; } return NULL; @@ -713,13 +733,10 @@ rte_graph_export(const char *name, FILE *f) struct graph *graph; int rc = ENOENT; - STAILQ_FOREACH(graph, &graph_list, next) { - if (strncmp(graph->name, name, RTE_GRAPH_NAMESIZE) == 0) { - rc = graph_to_dot(f, graph); - goto end; - } - } -end: + graph = graph_find_by_name(name); + if (graph) + rc = graph_to_dot(f, graph); + return -rc; } @@ -729,17 +746,16 @@ graph_scan_dump(FILE *f, rte_graph_t id, bool all) struct graph *graph; RTE_VERIFY(f); - GRAPH_ID_CHECK(id); - STAILQ_FOREACH(graph, &graph_list, next) { - if (all == true) { + if (all == true) { + STAILQ_FOREACH(graph, &graph_list, next) graph_dump(f, graph); - } else if (graph->id == id) { + } else { + graph = graph_find_by_id(id); + if (graph) graph_dump(f, graph); - return; - } } -fail: + return; } @@ -758,7 +774,16 @@ rte_graph_list_dump(FILE *f) rte_graph_t rte_graph_max_count(void) { - return graph_id; + struct graph *graph; + rte_graph_t count = 0; + + graph_spinlock_lock(); + + STAILQ_FOREACH(graph, &graph_list, next) + count++; + + graph_spinlock_unlock(); + return count; } RTE_LOG_REGISTER_DEFAULT(rte_graph_logtype, INFO); -- 2.32.1 (Apple Git-133)