graph: fix node shrink

Message ID 20230119103234.841173-1-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series graph: fix node shrink |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

David Marchand Jan. 19, 2023, 10:32 a.m. UTC
  If the node id check failed, graph_lock was not taken before releasing.

Fixes: c59dac2ca14a ("graph: implement node operations")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/graph/node.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Kiran Kumar Kokkilagadda Jan. 19, 2023, 1:57 p.m. UTC | #1
> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: 19 January 2023 04:03 PM
> To: dev@dpdk.org
> Cc: stable@dpdk.org; Jerin Jacob Kollanukkaran <jerinj@marvell.com>; Kiran
> Kumar Kokkilagadda <kirankumark@marvell.com>; Nithin Kumar Dabilpuram
> <ndabilpuram@marvell.com>; Pavan Nikhilesh Bhagavatula
> <pbhagavatula@marvell.com>
> Subject: [EXT] [PATCH] graph: fix node shrink
> 
> External Email
> 
> ----------------------------------------------------------------------
> If the node id check failed, graph_lock was not taken before releasing.
> 
> Fixes: c59dac2ca14a ("graph: implement node operations")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Acked-by: Kiran Kumar Kokkilagadda <kirankumark@marvell.com>

> ---
>  lib/graph/node.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/graph/node.c b/lib/graph/node.c index fc6345de07..149414dcd9
> 100644
> --- a/lib/graph/node.c
> +++ b/lib/graph/node.c
> @@ -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
  
Jerin Jacob Jan. 23, 2023, 1:32 p.m. UTC | #2
On Thu, Jan 19, 2023 at 4:02 PM David Marchand
<david.marchand@redhat.com> wrote:
>
> 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
diff --git a/lib/graph/node.c b/lib/graph/node.c
index fc6345de07..89cdcf0207 100644
--- a/lib/graph/node.c
+++ b/lib/graph/node.c
@@ -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) {


>
> Fixes: c59dac2ca14a ("graph: implement node operations")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  lib/graph/node.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/lib/graph/node.c b/lib/graph/node.c
> index fc6345de07..149414dcd9 100644
> --- a/lib/graph/node.c
> +++ b/lib/graph/node.c
> @@ -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
>
  
David Marchand Jan. 23, 2023, 1:50 p.m. UTC | #3
On Mon, Jan 23, 2023 at 2:33 PM Jerin Jacob <jerinjacobk@gmail.com> wrote:
>
> On Thu, Jan 19, 2023 at 4:02 PM David Marchand
> <david.marchand@redhat.com> wrote:
> >
> > 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
> diff --git a/lib/graph/node.c b/lib/graph/node.c
> index fc6345de07..89cdcf0207 100644
> --- a/lib/graph/node.c
> +++ b/lib/graph/node.c
> @@ -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.
  
Jerin Jacob Jan. 23, 2023, 1:53 p.m. UTC | #4
On Mon, Jan 23, 2023 at 7:21 PM David Marchand
<david.marchand@redhat.com> wrote:
>
> On Mon, Jan 23, 2023 at 2:33 PM Jerin Jacob <jerinjacobk@gmail.com> wrote:
> >
> > On Thu, Jan 19, 2023 at 4:02 PM David Marchand
> > <david.marchand@redhat.com> wrote:
> > >
> > > 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
> > diff --git a/lib/graph/node.c b/lib/graph/node.c
> > index fc6345de07..89cdcf0207 100644
> > --- a/lib/graph/node.c
> > +++ b/lib/graph/node.c
> > @@ -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.


Acked-by: Jerin Jacob <jerinj@marvell.com>


>
> --
> David Marchand
>
  
David Marchand Jan. 31, 2023, 10:13 a.m. UTC | #5
On Thu, Jan 19, 2023 at 11:32 AM David Marchand
<david.marchand@redhat.com> wrote:
>
> If the node id check failed, graph_lock was not taken before releasing.
>
> Fixes: c59dac2ca14a ("graph: implement node operations")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

> If the node id check failed, graph_lock was not taken before releasing.
>
> Fixes: c59dac2ca14a ("graph: implement node operations")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Kiran Kumar Kokkilagadda <kirankumark@marvell.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>

Applied, thanks.
  

Patch

diff --git a/lib/graph/node.c b/lib/graph/node.c
index fc6345de07..149414dcd9 100644
--- a/lib/graph/node.c
+++ b/lib/graph/node.c
@@ -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;
 }