Skip to contentSkip to conversation

graph: fix node shrink

PATCH Applied David Marchand 3 participants 6 messages Jan 19, 2023 – Jan 31, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 graph: fix node shrink

If the node id check failed, graph_lock was not taken before releasing.

Fixes c59dac2ca14a ("graph: implement node operations")
---
 lib/graph/node.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/graph/node.c +4 -4
index fc6345de07..149414dcd9 100644
@@ -300,16 +300,16 @@ rte_node_edge_shrink(rte_node_t id, rte_edge_t size)
 		if (node->id == id) {
 			if (node->nb_edges < size) {
 				rte_errno = E2BIG;
-				goto fail;
+			} else {
+				node->nb_edges = size;
+				rc = size;
 			}
-			node->nb_edges = size;
-			rc = size;
 			break;
 		}
 	}
 
-fail:
 	graph_spinlock_unlock();
+fail:
 	return rc;
 }
 
Signature · 1 line
2.39.0
Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: 19 January 2023 04:03 PM
To: [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; Nithin Kumar Dabilpuram <[email protected]>; Pavan Nikhilesh Bhagavatula <[email protected]>
Subject: [EXT] [PATCH] graph: fix node shrink

External Email

Quoted 7 lines

----------------------------------------------------------------------
If the node id check failed, graph_lock was not taken before releasing.

Fixes c59dac2ca14a ("graph: implement node operations")
Quoted 32 lines
---
 lib/graph/node.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/graph/node.c index fc6345de07..149414dcd9 renamed from lib/graph/node.c +0 -0

100644

lib/graph/node.c +4 -5
@@ -300,16 +300,16 @@ rte_node_edge_shrink(rte_node_t id, rte_edge_t
 size)
 		if (node->id == id) {
 			if (node->nb_edges < size) {
 				rte_errno = E2BIG;
-				goto fail;
+			} else {
+				node->nb_edges = size;
+				rc = size;
 			}
-			node->nb_edges = size;
-			rc = size;
 			break;
 		}
 	}
 
-fail:
 	graph_spinlock_unlock();
+fail:
 	return rc;
 }
 
--

2.39.0

#2 lore raw
In reply to David Marchand
Quoted 2 lines · David Marchand

If the node id check failed, graph_lock was not taken before releasing.

Thanks for the fix.

Why not this oneline fix?

[main][dpdk.org] $ git diff

lib/graph/node.c +1 -1
index fc6345de07..89cdcf0207 100644
@@ -293,8 +293,8 @@ rte_node_edge_shrink(rte_node_t id, rte_edge_t size)
        rte_edge_t rc = RTE_EDGE_ID_INVALID;
        struct node *node;
 
-       NODE_ID_CHECK(id);
        graph_spinlock_lock();
+       NODE_ID_CHECK(id);
 
        STAILQ_FOREACH(node, &node_list, next) {
                if (node->id == id) {
Quoted 37 lines
Fixes c59dac2ca14a ("graph: implement node operations")
---
 lib/graph/node.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/graph/node.c +4 -5
index fc6345de07..149414dcd9 100644
@@ -300,16 +300,16 @@ rte_node_edge_shrink(rte_node_t id, rte_edge_t size)
                if (node->id == id) {
                        if (node->nb_edges < size) {
                                rte_errno = E2BIG;
-                               goto fail;
+                       } else {
+                               node->nb_edges = size;
+                               rc = size;
                        }
-                       node->nb_edges = size;
-                       rc = size;
                        break;
                }
        }
 
-fail:
        graph_spinlock_unlock();
+fail:
        return rc;
 }
 
--

2.39.0

#3 lore raw
Quoted 17 lines · Jerin Jacob
Quoted 2 lines · David Marchand

If the node id check failed, graph_lock was not taken before releasing.

Thanks for the fix.

Why not this oneline fix?

[main][dpdk.org] $ git diff

lib/graph/node.c +0 -0
index fc6345de07..89cdcf0207 100644

lib/graph/node.c rte_node_edge_shrink(rte_node_t id, rte_edge_t size) · line 300

Quoted 9 lines
lib/graph/node.c +1 -1
@@ -293,8 +293,8 @@ rte_node_edge_shrink(rte_node_t id, rte_edge_t size)
        rte_edge_t rc = RTE_EDGE_ID_INVALID;
        struct node *node;
 
-       NODE_ID_CHECK(id);
        graph_spinlock_lock();
+       NODE_ID_CHECK(id);
 
        STAILQ_FOREACH(node, &node_list, next) {
                if (node->id == id) {

Other calls to NODE_ID_CHECK input check are done out of the lock. And to keep consistency with the rest of this library code.

Signature · 1 line
David Marchand
Acked-by
#4 lore raw
Quoted 26 lines · David Marchand
Quoted 24 lines · Jerin Jacob
Quoted 2 lines · David Marchand

If the node id check failed, graph_lock was not taken before releasing.

Thanks for the fix.

Why not this oneline fix?

[main][dpdk.org] $ git diff

lib/graph/node.c +1 -1
index fc6345de07..89cdcf0207 100644
@@ -293,8 +293,8 @@ rte_node_edge_shrink(rte_node_t id, rte_edge_t size)
        rte_edge_t rc = RTE_EDGE_ID_INVALID;
        struct node *node;
 
-       NODE_ID_CHECK(id);
        graph_spinlock_lock();
+       NODE_ID_CHECK(id);
 
Quoted 5 lines

lib/graph/node.c rte_node_edge_shrink(rte_node_t id, rte_edge_t size) · line 300

Quoted 2 lines
lib/graph/node.c +0 -0
        STAILQ_FOREACH(node, &node_list, next) {
                if (node->id == id) {

Other calls to NODE_ID_CHECK input check are done out of the lock. And to keep consistency with the rest of this library code.

Quoted 4 lines

--
David Marchand

author Acked-by Kiran Kumar Kokkilagadda Acked-by Jerin Jacob on v1 1/1 Applied
#5 lore raw
In reply to David Marchand
Quoted 6 lines · David Marchand

If the node id check failed, graph_lock was not taken before releasing.

Fixes c59dac2ca14a ("graph: implement node operations")
Quoted 8 lines

If the node id check failed, graph_lock was not taken before releasing.

Fixes c59dac2ca14a ("graph: implement node operations")

Applied, thanks.

Signature · 1 line
David Marchand