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 5109343FEF for ; Fri, 10 May 2024 08:28:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 411B3402ED; Fri, 10 May 2024 08:28:34 +0200 (CEST) Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01olkn2048.outbound.protection.outlook.com [40.92.99.48]) by mails.dpdk.org (Postfix) with ESMTP id 07B834025F; Fri, 10 May 2024 08:28:31 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fvj4mrX43joHSxITSTzyf8gUGH3C5B9yEfwBczxF3+yZZTawJoVODKlWgU/agrRP0okqOpZUSZ+fZkuulGBQsNI3h+bqb00Wtfndx2tYAAy1noKtWg29AoqjEB2Z/jANSWA7ycCR27b+xeZPrPgFFpGixNW80jzaVgfBY32mnDQjJyCvJzwT6LaK5ba987zyZMEoUz8QBsMXeyn+Qzk7wwr+apDPuKZqSwPGgFR0dq19bzwnFPsA0lDj8Iv0c9835toem6mAGFELZE4l92SXstyxlWh1vVbw1RMEbY5/MS7NyQGgSqtP77ByCev4qIrt149qr3EiZuzq6DU0c24C8g== 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=JBwyI1RZNvsJJ47MWpqAum9mzY7irD6V91655gG3Ltc=; b=QknYnQbFsUKBfJILXXey5T61iq7O2G0ef6dUGf/kCs0P/bqSg+ZmQmn2GbbkRDKji1txrnvAlaUv946ucBqfm0iGPbPCvl/N63vKuLrRIRPB0i5BVWrwPFQvVEx+JQV3p0NR9N4/YIfi1C3jMF5Igau/KETDkZ8QFFTxHBXx+hf1TOQaEF1aE3ZulM7O8SqLzhr88fDLfdEEzDpVDdCueu4L1lRlCkGbK0Xz+l1HXGvwtaEYiYePwcYip2cYLI1G4xiDh1ELHh3Prnrxdldiu/tGSXUCNlIsK+dw1hImM8oIiKXdomCqT6gXOoyELsp5E4C+MHQR/pHnOmVl0LREuA== 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=JBwyI1RZNvsJJ47MWpqAum9mzY7irD6V91655gG3Ltc=; b=DDVNUfmqYROjKbye6x+d05YmoPq4gV9x7JIGwzdQ3AIWeXzWTJ/7jzhgcUkGoRzO8DwEGf4Q/qFzMUXOXgREnXfCE0FoYE7VM0Ohi5Qh9VMa/7MlKPxiuNRL77OeY/CMJxrJ+jFhX+AU80sDQ1xqhYTIDm6JazjappDJpgqrTBHQjmCQE07BlNtDXokh6r2N0FVu9TlM8a/LIXIx7EpsdGBHyS9OvtSeCIUiEC8Y8n4Ia9mehwzcYjFkKp11L1wcrw6sOr6rnadZkjD76bP2f62Q/BTOoFwLtFvkQOodkDXrm/JCgdY8WWg+8RAGm6R50ITmvLxYC9Wy5GCT2Tvgxw== Received: from TYAP286MB0649.JPNP286.PROD.OUTLOOK.COM (2603:1096:402:38::13) by OS9P286MB4317.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:2c2::8) 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:28:28 +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:28:28 +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] graph: fix does not return the unique id when create graph Date: Fri, 10 May 2024 14:28:00 +0800 Message-ID: X-Mailer: git-send-email 2.32.1 (Apple Git-133) Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [WnKYP2u0aEJErv+B0xhlQQMJZQqLqJzo] X-ClientProxiedBy: TY2PR02CA0016.apcprd02.prod.outlook.com (2603:1096:404:56::28) To TYAP286MB0649.JPNP286.PROD.OUTLOOK.COM (2603:1096:402:38::13) X-Microsoft-Original-Message-ID: <20240510062800.16739-1-chengongming1900@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYAP286MB0649:EE_|OS9P286MB4317:EE_ X-MS-Office365-Filtering-Correlation-Id: 5dc7b46f-2c30-4e1d-9314-08dc70ba6729 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|3430499023|3412199016|440099019; X-Microsoft-Antispam-Message-Info: r0o2HDol9SX9sRSrhCYNWPrBUyZGp89gif2pV7z11H4EEJWdfukAjPT5r5ssWJ3+HUdWPLl6589lcmnWkI+aVDdwizETkIP0y+CS67luQDo6piSUiJlQvS2dbzgBnPRorfXoaFlJZYvD8X+mcKfufN7UBAXlz11jcYNyrbyp+xaUD0WEu25Kvgoc1FRF+OrfodMAl5AVW0ZqtmybEvXB+e9w0NTu3Rau/7tao30aBsVCIc4A7jB9jBWF0Y0mm8XY+DZqT93ZqlZ958GwK7ExHaiQ4rqEvmkxy9Mnggx+sf79SPeAs/jnYgKFLJvYNo75hXxBeI2m5PsovOGXaSsvQlzpBFWCpXzvwyvzqbCRMB4A5zomwReZCUrHVKdJzGIpKD3oAGSQnJgo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94xA3XNXHi1m2xgjtdBHAkpedBKvbnZivqkMcnefoxUTpZGV8SqzI?= =?us-ascii?Q?UT30mQRzIQfVVTQiZQDM3FJeDNWHqaLOjnsF1EpA7qA8z8aI+5Nz3UVLLoW2?= =?us-ascii?Q?lHTQ+M/rPghQn3FodGfx+/rZp+dpZRKoOfEbbEPAYLpUgx4P6xCD/f7ogbUP?= =?us-ascii?Q?KatDQzvWdvTelRBB19S5bxMXn0kydj5UaRzvzRJdVpw2LNqT0Gq2oy8t5bcF?= =?us-ascii?Q?yCQsDIwtRi5kchmMP6xVsnMAafZsUz44V/HTjvQ95U77eEU31DEUJPgmcp2R?= =?us-ascii?Q?abFTOC1xDTmM0hqS7QH5au3Q1bOJmkz1DKL9kO3YNKnY9RnISPmjvLEtHYaw?= =?us-ascii?Q?RGYO9mbE9vMA2djB+DYjVbmXc8a7lE/KCqDiNdr61yG4l54ceRFc1gG2s93R?= =?us-ascii?Q?mo6g2LpTMcDt3SudJvn+rm2rmuXF/hxKLXJivlnDP8JYxPpgVLlSBDmbTfdO?= =?us-ascii?Q?63qrUMdFaXG0wtmmv4nfwOStq/9ate0A63amIjLo1G/+5Kd/m7UrCRi9pzZL?= =?us-ascii?Q?Q0WjmkVd9IsZWD3Fgr/Qhr3jgWNVli/KHAU6hp+Z9JAT3hjbVQfQI615FwYq?= =?us-ascii?Q?fO4a1smEk0I8y2qWG+VA?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5dc7b46f-2c30-4e1d-9314-08dc70ba6729 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:28:28.0457 (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: OS9P286MB4317 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, 93 insertions(+), 70 deletions(-) diff --git a/lib/graph/graph.c b/lib/graph/graph.c index 26f0968a97..1e7895e02b 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 = 0; + 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(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,14 @@ 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) { - graph_dump(f, graph); - return; - } + } else if ((graph = graph_find_by_id(id))) { + graph_dump(f, graph); } -fail: + return; } @@ -758,7 +772,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)