app/test-crypto-perf: fix invalid mbuf next operation

Message ID 20240103035357.720016-1-suanmingm@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series app/test-crypto-perf: fix invalid mbuf next operation |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

Suanming Mou Jan. 3, 2024, 3:53 a.m. UTC
  In fill_multi_seg_mbuf(), when remaining_segments is 0,
rte_mbuf m's next should pointer to NULL instead of a
new rte_mbuf, that casues setting m->next as NULL out
of the while loop to the invalid mbuf.

This commit fixes the invalid mbuf next operation.

Fixes: bf9d6702eca9 ("app/crypto-perf: use single mempool")

Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
---
 app/test-crypto-perf/cperf_test_common.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

Anoob Joseph Jan. 3, 2024, 11:21 a.m. UTC | #1
Hi Suanming,

Good catch. Please see inline.

Thanks,
Anoob

> -----Original Message-----
> From: Suanming Mou <suanmingm@nvidia.com>
> Sent: Wednesday, January 3, 2024 9:24 AM
> To: Ciara Power <ciara.power@intel.com>
> Cc: dev@dpdk.org
> Subject: [EXT] [PATCH] app/test-crypto-perf: fix invalid mbuf next operation
> 
> External Email
> 
> ----------------------------------------------------------------------
> In fill_multi_seg_mbuf(), when remaining_segments is 0, rte_mbuf m's next
> should pointer to NULL instead of a new rte_mbuf, that casues setting m->next
> as NULL out of the while loop to the invalid mbuf.
> 
> This commit fixes the invalid mbuf next operation.
> 
> Fixes: bf9d6702eca9 ("app/crypto-perf: use single mempool")
> 
> Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> ---
>  app/test-crypto-perf/cperf_test_common.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/app/test-crypto-perf/cperf_test_common.c b/app/test-crypto-
> perf/cperf_test_common.c
> index 932aab16df..ad2076dd2e 100644
> --- a/app/test-crypto-perf/cperf_test_common.c
> +++ b/app/test-crypto-perf/cperf_test_common.c
> @@ -72,13 +72,15 @@ fill_multi_seg_mbuf(struct rte_mbuf *m, struct
> rte_mempool *mp,
>  		rte_mbuf_refcnt_set(m, 1);
>  		next_mbuf = (struct rte_mbuf *) ((uint8_t *) m +
>  					mbuf_hdr_size + segment_sz);
> -		m->next = next_mbuf;
> -		m = next_mbuf;
> -		remaining_segments--;
> 
> +		remaining_segments--;
> +		if (remaining_segments > 0) {

[Anoob] Would it make sense to move assignment of next_mbuf also to here? That way, the checks will become self explanatory.
  		next_mbuf = (struct rte_mbuf *) ((uint8_t *) m +
  					mbuf_hdr_size + segment_sz);

> +			m->next = next_mbuf;
> +			m = next_mbuf;
> +		} else {
> +			m->next = NULL;
> +		}
>  	} while (remaining_segments > 0);
> -
> -	m->next = NULL;
>  }
> 
>  static void
> --
> 2.34.1
  
Suanming Mou Jan. 3, 2024, 12:35 p.m. UTC | #2
Hi,

> -----Original Message-----
> From: Anoob Joseph <anoobj@marvell.com>
> Sent: Wednesday, January 3, 2024 7:22 PM
> To: Suanming Mou <suanmingm@nvidia.com>
> Cc: dev@dpdk.org; Ciara Power <ciara.power@intel.com>
> Subject: RE: [EXT] [PATCH] app/test-crypto-perf: fix invalid mbuf next operation
> 
> Hi Suanming,
> 
> Good catch. Please see inline.
> 
> Thanks,
> Anoob
> 
> > -----Original Message-----
> > From: Suanming Mou <suanmingm@nvidia.com>
> > Sent: Wednesday, January 3, 2024 9:24 AM
> > To: Ciara Power <ciara.power@intel.com>
> > Cc: dev@dpdk.org
> > Subject: [EXT] [PATCH] app/test-crypto-perf: fix invalid mbuf next
> > operation
> >
> > External Email
> >
> > ----------------------------------------------------------------------
> > In fill_multi_seg_mbuf(), when remaining_segments is 0, rte_mbuf m's
> > next should pointer to NULL instead of a new rte_mbuf, that casues
> > setting m->next as NULL out of the while loop to the invalid mbuf.
> >
> > This commit fixes the invalid mbuf next operation.
> >
> > Fixes: bf9d6702eca9 ("app/crypto-perf: use single mempool")
> >
> > Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> > ---
> >  app/test-crypto-perf/cperf_test_common.c | 12 +++++++-----
> >  1 file changed, 7 insertions(+), 5 deletions(-)
> >
> > diff --git a/app/test-crypto-perf/cperf_test_common.c
> > b/app/test-crypto- perf/cperf_test_common.c index
> > 932aab16df..ad2076dd2e 100644
> > --- a/app/test-crypto-perf/cperf_test_common.c
> > +++ b/app/test-crypto-perf/cperf_test_common.c
> > @@ -72,13 +72,15 @@ fill_multi_seg_mbuf(struct rte_mbuf *m, struct
> > rte_mempool *mp,
> >  		rte_mbuf_refcnt_set(m, 1);
> >  		next_mbuf = (struct rte_mbuf *) ((uint8_t *) m +
> >  					mbuf_hdr_size + segment_sz);
> > -		m->next = next_mbuf;
> > -		m = next_mbuf;
> > -		remaining_segments--;
> >
> > +		remaining_segments--;
> > +		if (remaining_segments > 0) {
> 
> [Anoob] Would it make sense to move assignment of next_mbuf also to here?
> That way, the checks will become self explanatory.
>   		next_mbuf = (struct rte_mbuf *) ((uint8_t *) m +
>   					mbuf_hdr_size + segment_sz);
> 

Make sense. Maybe just like that:
  		m->next = (struct rte_mbuf *) ((uint8_t *) m +
  					mbuf_hdr_size + segment_sz);
		m = m->next;

What do you think?

> > +			m->next = next_mbuf;
> > +			m = next_mbuf;
> > +		} else {
> > +			m->next = NULL;
> > +		}
> >  	} while (remaining_segments > 0);
> > -
> > -	m->next = NULL;
> >  }
> >
> >  static void
> > --
> > 2.34.1
  
Anoob Joseph Jan. 3, 2024, 3:42 p.m. UTC | #3
Hi Suanming,

Please see inline.

Thanks,
Anoob

> -----Original Message-----
> From: Suanming Mou <suanmingm@nvidia.com>
> Sent: Wednesday, January 3, 2024 6:06 PM
> To: Anoob Joseph <anoobj@marvell.com>
> Cc: dev@dpdk.org; Ciara Power <ciara.power@intel.com>
> Subject: RE: [EXT] [PATCH] app/test-crypto-perf: fix invalid mbuf next operation
> 
> Hi,
> 
> > -----Original Message-----
> > From: Anoob Joseph <anoobj@marvell.com>
> > Sent: Wednesday, January 3, 2024 7:22 PM
> > To: Suanming Mou <suanmingm@nvidia.com>
> > Cc: dev@dpdk.org; Ciara Power <ciara.power@intel.com>
> > Subject: RE: [EXT] [PATCH] app/test-crypto-perf: fix invalid mbuf next
> > operation
> >
> > Hi Suanming,
> >
> > Good catch. Please see inline.
> >
> > Thanks,
> > Anoob
> >
> > > -----Original Message-----
> > > From: Suanming Mou <suanmingm@nvidia.com>
> > > Sent: Wednesday, January 3, 2024 9:24 AM
> > > To: Ciara Power <ciara.power@intel.com>
> > > Cc: dev@dpdk.org
> > > Subject: [EXT] [PATCH] app/test-crypto-perf: fix invalid mbuf next
> > > operation
> > >
> > > External Email
> > >
> > > --------------------------------------------------------------------
> > > -- In fill_multi_seg_mbuf(), when remaining_segments is 0, rte_mbuf
> > > m's next should pointer to NULL instead of a new rte_mbuf, that
> > > casues setting m->next as NULL out of the while loop to the invalid
> > > mbuf.
> > >
> > > This commit fixes the invalid mbuf next operation.
> > >
> > > Fixes: bf9d6702eca9 ("app/crypto-perf: use single mempool")
> > >
> > > Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> > > ---
> > >  app/test-crypto-perf/cperf_test_common.c | 12 +++++++-----
> > >  1 file changed, 7 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/app/test-crypto-perf/cperf_test_common.c
> > > b/app/test-crypto- perf/cperf_test_common.c index
> > > 932aab16df..ad2076dd2e 100644
> > > --- a/app/test-crypto-perf/cperf_test_common.c
> > > +++ b/app/test-crypto-perf/cperf_test_common.c
> > > @@ -72,13 +72,15 @@ fill_multi_seg_mbuf(struct rte_mbuf *m, struct
> > > rte_mempool *mp,
> > >  		rte_mbuf_refcnt_set(m, 1);
> > >  		next_mbuf = (struct rte_mbuf *) ((uint8_t *) m +
> > >  					mbuf_hdr_size + segment_sz);
> > > -		m->next = next_mbuf;
> > > -		m = next_mbuf;
> > > -		remaining_segments--;
> > >
> > > +		remaining_segments--;
> > > +		if (remaining_segments > 0) {
> >
> > [Anoob] Would it make sense to move assignment of next_mbuf also to here?
> > That way, the checks will become self explanatory.
> >   		next_mbuf = (struct rte_mbuf *) ((uint8_t *) m +
> >   					mbuf_hdr_size + segment_sz);
> >
> 
> Make sense. Maybe just like that:
>   		m->next = (struct rte_mbuf *) ((uint8_t *) m +
>   					mbuf_hdr_size + segment_sz);
> 		m = m->next;
> 
> What do you think?

[Anoob] Yes. That's even better. 

I think we can have line lengths upto 100 characters now. In case you find it easier to put in single line.

> 
> > > +			m->next = next_mbuf;
> > > +			m = next_mbuf;
> > > +		} else {
> > > +			m->next = NULL;
> > > +		}
> > >  	} while (remaining_segments > 0);
> > > -
> > > -	m->next = NULL;
> > >  }
> > >
> > >  static void
> > > --
> > > 2.34.1
  
Suanming Mou Jan. 4, 2024, 2:23 a.m. UTC | #4
> -----Original Message-----
> From: Anoob Joseph <anoobj@marvell.com>
> Sent: Wednesday, January 3, 2024 11:43 PM
> To: Suanming Mou <suanmingm@nvidia.com>
> Cc: dev@dpdk.org; Ciara Power <ciara.power@intel.com>
> Subject: RE: [EXT] [PATCH] app/test-crypto-perf: fix invalid mbuf next operation
> 
> Hi Suanming,
> 
> Please see inline.
> 
> Thanks,
> Anoob
> 
> > -----Original Message-----
> > From: Suanming Mou <suanmingm@nvidia.com>
> > Sent: Wednesday, January 3, 2024 6:06 PM
> > To: Anoob Joseph <anoobj@marvell.com>
> > Cc: dev@dpdk.org; Ciara Power <ciara.power@intel.com>
> > Subject: RE: [EXT] [PATCH] app/test-crypto-perf: fix invalid mbuf next
> > operation
> >
> > Hi,
> >
> > > -----Original Message-----
> > > From: Anoob Joseph <anoobj@marvell.com>
> > > Sent: Wednesday, January 3, 2024 7:22 PM
> > > To: Suanming Mou <suanmingm@nvidia.com>
> > > Cc: dev@dpdk.org; Ciara Power <ciara.power@intel.com>
> > > Subject: RE: [EXT] [PATCH] app/test-crypto-perf: fix invalid mbuf
> > > next operation
> > >
> > > Hi Suanming,
> > >
> > > Good catch. Please see inline.
> > >
> > > Thanks,
> > > Anoob
> > >
> > > > -----Original Message-----
> > > > From: Suanming Mou <suanmingm@nvidia.com>
> > > > Sent: Wednesday, January 3, 2024 9:24 AM
> > > > To: Ciara Power <ciara.power@intel.com>
> > > > Cc: dev@dpdk.org
> > > > Subject: [EXT] [PATCH] app/test-crypto-perf: fix invalid mbuf next
> > > > operation
> > > >
> > > > External Email
> > > >
> > > > ------------------------------------------------------------------
> > > > --
> > > > -- In fill_multi_seg_mbuf(), when remaining_segments is 0,
> > > > rte_mbuf m's next should pointer to NULL instead of a new
> > > > rte_mbuf, that casues setting m->next as NULL out of the while
> > > > loop to the invalid mbuf.
> > > >
> > > > This commit fixes the invalid mbuf next operation.
> > > >
> > > > Fixes: bf9d6702eca9 ("app/crypto-perf: use single mempool")
> > > >
> > > > Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> > > > ---
> > > >  app/test-crypto-perf/cperf_test_common.c | 12 +++++++-----
> > > >  1 file changed, 7 insertions(+), 5 deletions(-)
> > > >
> > > > diff --git a/app/test-crypto-perf/cperf_test_common.c
> > > > b/app/test-crypto- perf/cperf_test_common.c index
> > > > 932aab16df..ad2076dd2e 100644
> > > > --- a/app/test-crypto-perf/cperf_test_common.c
> > > > +++ b/app/test-crypto-perf/cperf_test_common.c
> > > > @@ -72,13 +72,15 @@ fill_multi_seg_mbuf(struct rte_mbuf *m, struct
> > > > rte_mempool *mp,
> > > >  		rte_mbuf_refcnt_set(m, 1);
> > > >  		next_mbuf = (struct rte_mbuf *) ((uint8_t *) m +
> > > >  					mbuf_hdr_size + segment_sz);
> > > > -		m->next = next_mbuf;
> > > > -		m = next_mbuf;
> > > > -		remaining_segments--;
> > > >
> > > > +		remaining_segments--;
> > > > +		if (remaining_segments > 0) {
> > >
> > > [Anoob] Would it make sense to move assignment of next_mbuf also to here?
> > > That way, the checks will become self explanatory.
> > >   		next_mbuf = (struct rte_mbuf *) ((uint8_t *) m +
> > >   					mbuf_hdr_size + segment_sz);
> > >
> >
> > Make sense. Maybe just like that:
> >   		m->next = (struct rte_mbuf *) ((uint8_t *) m +
> >   					mbuf_hdr_size + segment_sz);
> > 		m = m->next;
> >
> > What do you think?
> 
> [Anoob] Yes. That's even better.
> 
> I think we can have line lengths upto 100 characters now. In case you find it
> easier to put in single line.

OK, thanks for the suggestion.

> 
> >
> > > > +			m->next = next_mbuf;
> > > > +			m = next_mbuf;
> > > > +		} else {
> > > > +			m->next = NULL;
> > > > +		}
> > > >  	} while (remaining_segments > 0);
> > > > -
> > > > -	m->next = NULL;
> > > >  }
> > > >
> > > >  static void
> > > > --
> > > > 2.34.1
  

Patch

diff --git a/app/test-crypto-perf/cperf_test_common.c b/app/test-crypto-perf/cperf_test_common.c
index 932aab16df..ad2076dd2e 100644
--- a/app/test-crypto-perf/cperf_test_common.c
+++ b/app/test-crypto-perf/cperf_test_common.c
@@ -72,13 +72,15 @@  fill_multi_seg_mbuf(struct rte_mbuf *m, struct rte_mempool *mp,
 		rte_mbuf_refcnt_set(m, 1);
 		next_mbuf = (struct rte_mbuf *) ((uint8_t *) m +
 					mbuf_hdr_size + segment_sz);
-		m->next = next_mbuf;
-		m = next_mbuf;
-		remaining_segments--;
 
+		remaining_segments--;
+		if (remaining_segments > 0) {
+			m->next = next_mbuf;
+			m = next_mbuf;
+		} else {
+			m->next = NULL;
+		}
 	} while (remaining_segments > 0);
-
-	m->next = NULL;
 }
 
 static void