* Re: [dpdk-stable] [PATCH] app/test: fix reorder test failure
2018-05-03 15:42 [dpdk-stable] [PATCH] app/test: fix reorder test failure Reshma Pattan
@ 2018-05-03 15:49 ` Hunt, David
2018-05-03 15:53 ` Pattan, Reshma
2018-05-03 16:03 ` Hunt, David
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Hunt, David @ 2018-05-03 15:49 UTC (permalink / raw)
To: Reshma Pattan, dev; +Cc: stable
Hi Reshma,
On 3/5/2018 4:42 PM, Reshma Pattan wrote:
> Inside test_reorder_insert()
> rte_mempool_get_bulk() and rte_mempool_put_bulk() are used
> to allocate and free the mbufs and then rte_reorder_free()
> is called which again freeing the mbufs using rte_pktmbuf_free().
>
> The mixed use of rte_mempool_put_bulk() and rte_pktmbuf_free()
> causing duplicate mbufs to be created when rte_mempool_get_bulk()
> is called next in test_reorder_drain().
>
> Since reorder library is taking care of freeing the mbufs
> using rte_pktmbuf_free() change UT to allocate mbufs using
> rte_pktmbuf_alloc().
>
> Do not mix and match the bulk get/put APIs with
> alloc/free APIs which can cause undefined behavior.
>
> Fixes: d0c9b58d71 ("app/test: new reorder unit test")
> Cc: stable@dpdk.org
> Cc: david.hunt@intel.com
> Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
> ---
> test/test/test_reorder.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/test/test/test_reorder.c b/test/test/test_reorder.c
> index 65e4f38b2..b79b00961 100644
> --- a/test/test/test_reorder.c
> +++ b/test/test/test_reorder.c
> @@ -146,11 +146,11 @@ test_reorder_insert(void)
> b = rte_reorder_create("test_insert", rte_socket_id(), size);
> TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
>
> - ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
> - TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
> -
> - for (i = 0; i < num_bufs; i++)
> + for (i = 0; i < num_bufs; i++) {
> + bufs[i] = rte_pktmbuf_alloc(p);
> + TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
> bufs[i]->seqn = i;
> + }
>
> /* This should fill up order buffer:
> * reorder_seq = 0
> @@ -202,7 +202,6 @@ test_reorder_insert(void)
>
> ret = 0;
> exit:
> - rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
> rte_reorder_free(b);
> return ret;
> }
> @@ -227,9 +226,6 @@ test_reorder_drain(void)
> b = rte_reorder_create("test_drain", rte_socket_id(), size);
> TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
>
> - ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
> - TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
> -
> /* Check no drained packets if reorder is empty */
> cnt = rte_reorder_drain(b, robufs, 1);
> if (cnt != 0) {
> @@ -239,8 +235,11 @@ test_reorder_drain(void)
> goto exit;
> }
>
> - for (i = 0; i < num_bufs; i++)
> + for (i = 0; i < num_bufs; i++) {
> + bufs[i] = rte_pktmbuf_alloc(p);
> + TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
> bufs[i]->seqn = i;
> + }
>
> /* Insert packet with seqn 1:
> * reorder_seq = 0
> @@ -298,7 +297,6 @@ test_reorder_drain(void)
> }
> ret = 0;
> exit:
> - rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
> rte_reorder_free(b);
> return ret;
> }
I have one question. While the rte_reorder_free() takes care of freeing
up any mbufs that were inserted into the reorder buffer, should there
be rte_pktmbuf_free() calls for any remaining unused mbufs left in the
bufs[] array?
Regards,
Dave.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH] app/test: fix reorder test failure
2018-05-03 15:49 ` Hunt, David
@ 2018-05-03 15:53 ` Pattan, Reshma
2018-05-03 15:58 ` Hunt, David
0 siblings, 1 reply; 11+ messages in thread
From: Pattan, Reshma @ 2018-05-03 15:53 UTC (permalink / raw)
To: Hunt, David, dev; +Cc: stable
Hi,
> -----Original Message-----
> From: Hunt, David
> Sent: Thursday, May 3, 2018 4:50 PM
> To: Pattan, Reshma <reshma.pattan@intel.com>; dev@dpdk.org
> Cc: stable@dpdk.org
> Subject: Re: [PATCH] app/test: fix reorder test failure
>
> Hi Reshma,
>
> On 3/5/2018 4:42 PM, Reshma Pattan wrote:
> > Inside test_reorder_insert()
> > rte_mempool_get_bulk() and rte_mempool_put_bulk() are used to allocate
> > and free the mbufs and then rte_reorder_free() is called which again
> > freeing the mbufs using rte_pktmbuf_free().
> >
> > The mixed use of rte_mempool_put_bulk() and rte_pktmbuf_free() causing
> > duplicate mbufs to be created when rte_mempool_get_bulk() is called
> > next in test_reorder_drain().
> >
> > Since reorder library is taking care of freeing the mbufs using
> > rte_pktmbuf_free() change UT to allocate mbufs using
> > rte_pktmbuf_alloc().
> >
> > Do not mix and match the bulk get/put APIs with alloc/free APIs which
> > can cause undefined behavior.
> >
> > Fixes: d0c9b58d71 ("app/test: new reorder unit test")
> > Cc: stable@dpdk.org
> > Cc: david.hunt@intel.com
> > Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
> > ---
> > test/test/test_reorder.c | 18 ++++++++----------
> > 1 file changed, 8 insertions(+), 10 deletions(-)
> >
> > diff --git a/test/test/test_reorder.c b/test/test/test_reorder.c index
> > 65e4f38b2..b79b00961 100644
> > --- a/test/test/test_reorder.c
> > +++ b/test/test/test_reorder.c
> > @@ -146,11 +146,11 @@ test_reorder_insert(void)
> > b = rte_reorder_create("test_insert", rte_socket_id(), size);
> > TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
> >
> > - ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
> > - TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
> > -
> > - for (i = 0; i < num_bufs; i++)
> > + for (i = 0; i < num_bufs; i++) {
> > + bufs[i] = rte_pktmbuf_alloc(p);
> > + TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation
> failed\n");
> > bufs[i]->seqn = i;
> > + }
> >
> > /* This should fill up order buffer:
> > * reorder_seq = 0
> > @@ -202,7 +202,6 @@ test_reorder_insert(void)
> >
> > ret = 0;
> > exit:
> > - rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
> > rte_reorder_free(b);
> > return ret;
> > }
> > @@ -227,9 +226,6 @@ test_reorder_drain(void)
> > b = rte_reorder_create("test_drain", rte_socket_id(), size);
> > TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
> >
> > - ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
> > - TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
> > -
> > /* Check no drained packets if reorder is empty */
> > cnt = rte_reorder_drain(b, robufs, 1);
> > if (cnt != 0) {
> > @@ -239,8 +235,11 @@ test_reorder_drain(void)
> > goto exit;
> > }
> >
> > - for (i = 0; i < num_bufs; i++)
> > + for (i = 0; i < num_bufs; i++) {
> > + bufs[i] = rte_pktmbuf_alloc(p);
> > + TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation
> failed\n");
> > bufs[i]->seqn = i;
> > + }
> >
> > /* Insert packet with seqn 1:
> > * reorder_seq = 0
> > @@ -298,7 +297,6 @@ test_reorder_drain(void)
> > }
> > ret = 0;
> > exit:
> > - rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
> > rte_reorder_free(b);
> > return ret;
> > }
>
> I have one question. While the rte_reorder_free() takes care of freeing up any
> mbufs that were inserted into the reorder buffer, should there be
> rte_pktmbuf_free() calls for any remaining unused mbufs left in the bufs[]
> array?
>
Hmm, test teardown has rte_mempool_free() will that not be sufficient to free the pool and hence the mbufs?
> Regards,
> Dave.
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH] app/test: fix reorder test failure
2018-05-03 15:53 ` Pattan, Reshma
@ 2018-05-03 15:58 ` Hunt, David
0 siblings, 0 replies; 11+ messages in thread
From: Hunt, David @ 2018-05-03 15:58 UTC (permalink / raw)
To: Pattan, Reshma, dev; +Cc: stable
On 3/5/2018 4:53 PM, Pattan, Reshma wrote:
> Hi,
>
>> -----Original Message-----
>> From: Hunt, David
>> Sent: Thursday, May 3, 2018 4:50 PM
>> To: Pattan, Reshma <reshma.pattan@intel.com>; dev@dpdk.org
>> Cc: stable@dpdk.org
>> Subject: Re: [PATCH] app/test: fix reorder test failure
>>
>> Hi Reshma,
>>
>> On 3/5/2018 4:42 PM, Reshma Pattan wrote:
>>> Inside test_reorder_insert()
>>> rte_mempool_get_bulk() and rte_mempool_put_bulk() are used to allocate
>>> and free the mbufs and then rte_reorder_free() is called which again
>>> freeing the mbufs using rte_pktmbuf_free().
>>>
>>> The mixed use of rte_mempool_put_bulk() and rte_pktmbuf_free() causing
>>> duplicate mbufs to be created when rte_mempool_get_bulk() is called
>>> next in test_reorder_drain().
>>>
>>> Since reorder library is taking care of freeing the mbufs using
>>> rte_pktmbuf_free() change UT to allocate mbufs using
>>> rte_pktmbuf_alloc().
>>>
>>> Do not mix and match the bulk get/put APIs with alloc/free APIs which
>>> can cause undefined behavior.
>>>
>>> Fixes: d0c9b58d71 ("app/test: new reorder unit test")
>>> Cc: stable@dpdk.org
>>> Cc: david.hunt@intel.com
>>> Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
>>> ---
>>> test/test/test_reorder.c | 18 ++++++++----------
>>> 1 file changed, 8 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/test/test/test_reorder.c b/test/test/test_reorder.c index
>>> 65e4f38b2..b79b00961 100644
>>> --- a/test/test/test_reorder.c
>>> +++ b/test/test/test_reorder.c
>>> @@ -146,11 +146,11 @@ test_reorder_insert(void)
>>> b = rte_reorder_create("test_insert", rte_socket_id(), size);
>>> TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
>>>
>>> - ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
>>> - TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
>>> -
>>> - for (i = 0; i < num_bufs; i++)
>>> + for (i = 0; i < num_bufs; i++) {
>>> + bufs[i] = rte_pktmbuf_alloc(p);
>>> + TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation
>> failed\n");
>>> bufs[i]->seqn = i;
>>> + }
>>>
>>> /* This should fill up order buffer:
>>> * reorder_seq = 0
>>> @@ -202,7 +202,6 @@ test_reorder_insert(void)
>>>
>>> ret = 0;
>>> exit:
>>> - rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
>>> rte_reorder_free(b);
>>> return ret;
>>> }
>>> @@ -227,9 +226,6 @@ test_reorder_drain(void)
>>> b = rte_reorder_create("test_drain", rte_socket_id(), size);
>>> TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
>>>
>>> - ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
>>> - TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
>>> -
>>> /* Check no drained packets if reorder is empty */
>>> cnt = rte_reorder_drain(b, robufs, 1);
>>> if (cnt != 0) {
>>> @@ -239,8 +235,11 @@ test_reorder_drain(void)
>>> goto exit;
>>> }
>>>
>>> - for (i = 0; i < num_bufs; i++)
>>> + for (i = 0; i < num_bufs; i++) {
>>> + bufs[i] = rte_pktmbuf_alloc(p);
>>> + TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation
>> failed\n");
>>> bufs[i]->seqn = i;
>>> + }
>>>
>>> /* Insert packet with seqn 1:
>>> * reorder_seq = 0
>>> @@ -298,7 +297,6 @@ test_reorder_drain(void)
>>> }
>>> ret = 0;
>>> exit:
>>> - rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
>>> rte_reorder_free(b);
>>> return ret;
>>> }
>> I have one question. While the rte_reorder_free() takes care of freeing up any
>> mbufs that were inserted into the reorder buffer, should there be
>> rte_pktmbuf_free() calls for any remaining unused mbufs left in the bufs[]
>> array?
>>
>
> Hmm, test teardown has rte_mempool_free() will that not be sufficient to free the pool and hence the mbufs?
>
That may happen to work today, but it's not very clean, and may cause
problems in the future
if management of underlying mbuf allocation/free changes. I think would
be better to explicitly
call free for each mbuf before tearing down the mempool.
Rgds,
Dave.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH] app/test: fix reorder test failure
2018-05-03 15:42 [dpdk-stable] [PATCH] app/test: fix reorder test failure Reshma Pattan
2018-05-03 15:49 ` Hunt, David
@ 2018-05-03 16:03 ` Hunt, David
2018-05-03 16:30 ` [dpdk-stable] [PATCH v2] " Reshma Pattan
2018-05-03 16:35 ` [dpdk-stable] [PATCH v3] " Reshma Pattan
3 siblings, 0 replies; 11+ messages in thread
From: Hunt, David @ 2018-05-03 16:03 UTC (permalink / raw)
To: Reshma Pattan, dev; +Cc: stable
On 3/5/2018 4:42 PM, Reshma Pattan wrote:
> Inside test_reorder_insert()
> rte_mempool_get_bulk() and rte_mempool_put_bulk() are used
> to allocate and free the mbufs and then rte_reorder_free()
> is called which again freeing the mbufs using rte_pktmbuf_free().
>
> The mixed use of rte_mempool_put_bulk() and rte_pktmbuf_free()
> causing duplicate mbufs to be created when rte_mempool_get_bulk()
> is called next in test_reorder_drain().
>
> Since reorder library is taking care of freeing the mbufs
> using rte_pktmbuf_free() change UT to allocate mbufs using
> rte_pktmbuf_alloc().
>
> Do not mix and match the bulk get/put APIs with
> alloc/free APIs which can cause undefined behavior.
>
> Fixes: d0c9b58d71 ("app/test: new reorder unit test")
>
--snip--
Could I also suggest the following text for the commit message:
app/test: fix reorder test failure
mbufs are being freed twice in error, once in rte_mempool_put_bulk()
and then in rte_reorder_free(). Refactor the code so that we use
rte_reorder_free() to free mbufs in the reorder buffer, and
use rte_pktmbuf_free() to free any unused or drained mbufs.
Rgds,
Dave.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [dpdk-stable] [PATCH v2] app/test: fix reorder test failure
2018-05-03 15:42 [dpdk-stable] [PATCH] app/test: fix reorder test failure Reshma Pattan
2018-05-03 15:49 ` Hunt, David
2018-05-03 16:03 ` Hunt, David
@ 2018-05-03 16:30 ` Reshma Pattan
2018-05-03 16:36 ` [dpdk-stable] [PATCH v3] " Reshma Pattan
2018-05-03 16:35 ` [dpdk-stable] [PATCH v3] " Reshma Pattan
3 siblings, 1 reply; 11+ messages in thread
From: Reshma Pattan @ 2018-05-03 16:30 UTC (permalink / raw)
To: david.hunt, dev; +Cc: stable
mbufs are being freed twice in error, once in rte_mempool_put_bulk()
and then in rte_reorder_free(). Refactor the code so that we use
rte_reorder_free() to free mbufs in the reorder buffer, and use
rte_pktmbuf_free() to free any unused or drained mbufs.
Fixes: d0c9b58d71 ("app/test: new reorder unit test")
Cc: stable@dpdk.org backport
Cc: david.hunt@intel.com
Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
V2:
set mbufs to NULL after reorder insert.
simplified the commit message.
---
test/test/test_reorder.c | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/test/test/test_reorder.c b/test/test/test_reorder.c
index 65e4f38b2..7eff718c1 100644
--- a/test/test/test_reorder.c
+++ b/test/test/test_reorder.c
@@ -146,11 +146,11 @@ test_reorder_insert(void)
b = rte_reorder_create("test_insert", rte_socket_id(), size);
TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
- ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
- TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
-
- for (i = 0; i < num_bufs; i++)
+ for (i = 0; i < num_bufs; i++) {
+ bufs[i] = rte_pktmbuf_alloc(p);
+ TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
bufs[i]->seqn = i;
+ }
/* This should fill up order buffer:
* reorder_seq = 0
@@ -165,6 +165,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[i] = NULL;
}
/* early packet - should move mbufs to ready buf and move sequence window
@@ -179,6 +180,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[4] = NULL;
/* early packet from current sequence window - full ready buffer */
bufs[5]->seqn = 2 * size;
@@ -189,6 +191,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[5] = NULL;
/* late packet */
bufs[6]->seqn = 3 * size;
@@ -199,11 +202,15 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[6] = NULL;
ret = 0;
exit:
- rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
rte_reorder_free(b);
+ for (i = 0; i < num_bufs; i++) {
+ if (bufs[i] != NULL)
+ rte_pktmbuf_free(bufs[i]);
+ }
return ret;
}
@@ -227,9 +234,6 @@ test_reorder_drain(void)
b = rte_reorder_create("test_drain", rte_socket_id(), size);
TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
- ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
- TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
-
/* Check no drained packets if reorder is empty */
cnt = rte_reorder_drain(b, robufs, 1);
if (cnt != 0) {
@@ -239,8 +243,11 @@ test_reorder_drain(void)
goto exit;
}
- for (i = 0; i < num_bufs; i++)
+ for (i = 0; i < num_bufs; i++) {
+ bufs[i] = rte_pktmbuf_alloc(p);
+ TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
bufs[i]->seqn = i;
+ }
/* Insert packet with seqn 1:
* reorder_seq = 0
@@ -248,6 +255,7 @@ test_reorder_drain(void)
* OB[] = {1, NULL, NULL, NULL}
*/
rte_reorder_insert(b, bufs[1]);
+ bufs[1] = NULL;
cnt = rte_reorder_drain(b, robufs, 1);
if (cnt != 1) {
@@ -263,18 +271,22 @@ test_reorder_drain(void)
*/
rte_reorder_insert(b, bufs[2]);
rte_reorder_insert(b, bufs[3]);
+ bufs[2] = NULL;
+ bufs[3] = NULL;
/* Insert more packets
* RB[] = {NULL, NULL, NULL, NULL}
* OB[] = {NULL, 2, 3, 4}
*/
rte_reorder_insert(b, bufs[4]);
+ bufs[4] = NULL;
/* Insert more packets
* RB[] = {2, 3, 4, NULL}
* OB[] = {NULL, NULL, 7, NULL}
*/
rte_reorder_insert(b, bufs[7]);
+ bufs[7] = NULL;
/* drained expected packets */
cnt = rte_reorder_drain(b, robufs, 4);
@@ -298,8 +310,12 @@ test_reorder_drain(void)
}
ret = 0;
exit:
- rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
+
rte_reorder_free(b);
+ for (i = 0; i < num_bufs; i++) {
+ if (bufs[i] != NULL)
+ rte_pktmbuf_free(bufs[i]);
+ }
return ret;
}
--
2.14.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [dpdk-stable] [PATCH v3] app/test: fix reorder test failure
2018-05-03 16:30 ` [dpdk-stable] [PATCH v2] " Reshma Pattan
@ 2018-05-03 16:36 ` Reshma Pattan
2018-05-03 17:02 ` Hunt, David
2018-05-04 10:47 ` [dpdk-stable] [PATCH v4] " Reshma Pattan
0 siblings, 2 replies; 11+ messages in thread
From: Reshma Pattan @ 2018-05-03 16:36 UTC (permalink / raw)
To: david.hunt, dev; +Cc: stable
mbufs are being freed twice in error, once in rte_mempool_put_bulk()
and then in rte_reorder_free(). Refactor the code so that we use
rte_reorder_free() to free mbufs in the reorder buffer, and use
rte_pktmbuf_free() to free any unused or drained mbufs.
Fixes: d0c9b58d71 ("app/test: new reorder unit test")
Cc: stable@dpdk.org backport
Cc: david.hunt@intel.com
Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
v3
fix the indentation
---
test/test/test_reorder.c | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/test/test/test_reorder.c b/test/test/test_reorder.c
index 65e4f38b2..b7f664f66 100644
--- a/test/test/test_reorder.c
+++ b/test/test/test_reorder.c
@@ -146,11 +146,11 @@ test_reorder_insert(void)
b = rte_reorder_create("test_insert", rte_socket_id(), size);
TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
- ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
- TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
-
- for (i = 0; i < num_bufs; i++)
+ for (i = 0; i < num_bufs; i++) {
+ bufs[i] = rte_pktmbuf_alloc(p);
+ TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
bufs[i]->seqn = i;
+ }
/* This should fill up order buffer:
* reorder_seq = 0
@@ -165,6 +165,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[i] = NULL;
}
/* early packet - should move mbufs to ready buf and move sequence window
@@ -179,6 +180,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[4] = NULL;
/* early packet from current sequence window - full ready buffer */
bufs[5]->seqn = 2 * size;
@@ -189,6 +191,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[5] = NULL;
/* late packet */
bufs[6]->seqn = 3 * size;
@@ -199,11 +202,15 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[6] = NULL;
ret = 0;
exit:
- rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
rte_reorder_free(b);
+ for (i = 0; i < num_bufs; i++) {
+ if (bufs[i] != NULL)
+ rte_pktmbuf_free(bufs[i]);
+ }
return ret;
}
@@ -227,9 +234,6 @@ test_reorder_drain(void)
b = rte_reorder_create("test_drain", rte_socket_id(), size);
TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
- ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
- TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
-
/* Check no drained packets if reorder is empty */
cnt = rte_reorder_drain(b, robufs, 1);
if (cnt != 0) {
@@ -239,8 +243,11 @@ test_reorder_drain(void)
goto exit;
}
- for (i = 0; i < num_bufs; i++)
+ for (i = 0; i < num_bufs; i++) {
+ bufs[i] = rte_pktmbuf_alloc(p);
+ TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
bufs[i]->seqn = i;
+ }
/* Insert packet with seqn 1:
* reorder_seq = 0
@@ -248,6 +255,7 @@ test_reorder_drain(void)
* OB[] = {1, NULL, NULL, NULL}
*/
rte_reorder_insert(b, bufs[1]);
+ bufs[1] = NULL;
cnt = rte_reorder_drain(b, robufs, 1);
if (cnt != 1) {
@@ -263,18 +271,22 @@ test_reorder_drain(void)
*/
rte_reorder_insert(b, bufs[2]);
rte_reorder_insert(b, bufs[3]);
+ bufs[2] = NULL;
+ bufs[3] = NULL;
/* Insert more packets
* RB[] = {NULL, NULL, NULL, NULL}
* OB[] = {NULL, 2, 3, 4}
*/
rte_reorder_insert(b, bufs[4]);
+ bufs[4] = NULL;
/* Insert more packets
* RB[] = {2, 3, 4, NULL}
* OB[] = {NULL, NULL, 7, NULL}
*/
rte_reorder_insert(b, bufs[7]);
+ bufs[7] = NULL;
/* drained expected packets */
cnt = rte_reorder_drain(b, robufs, 4);
@@ -298,8 +310,11 @@ test_reorder_drain(void)
}
ret = 0;
exit:
- rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
rte_reorder_free(b);
+ for (i = 0; i < num_bufs; i++) {
+ if (bufs[i] != NULL)
+ rte_pktmbuf_free(bufs[i]);
+ }
return ret;
}
--
2.14.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH v3] app/test: fix reorder test failure
2018-05-03 16:36 ` [dpdk-stable] [PATCH v3] " Reshma Pattan
@ 2018-05-03 17:02 ` Hunt, David
2018-05-04 10:47 ` [dpdk-stable] [PATCH v4] " Reshma Pattan
1 sibling, 0 replies; 11+ messages in thread
From: Hunt, David @ 2018-05-03 17:02 UTC (permalink / raw)
To: Reshma Pattan, dev; +Cc: stable
Hi Reshma,
On 3/5/2018 5:36 PM, Reshma Pattan wrote:
> mbufs are being freed twice in error, once in rte_mempool_put_bulk()
> and then in rte_reorder_free(). Refactor the code so that we use
> rte_reorder_free() to free mbufs in the reorder buffer, and use
> rte_pktmbuf_free() to free any unused or drained mbufs.
>
> Fixes: d0c9b58d71 ("app/test: new reorder unit test")
> Cc: stable@dpdk.org backport
> Cc: david.hunt@intel.com
> Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
> ---
> v3
> fix the indentation
> ---
> test/test/test_reorder.c | 35 +++++++++++++++++++++++++----------
> 1 file changed, 25 insertions(+), 10 deletions(-)
>
> diff --git a/test/test/test_reorder.c b/test/test/test_reorder.c
> index 65e4f38b2..b7f664f66 100644
> --- a/test/test/test_reorder.c
> +++ b/test/test/test_reorder.c
> @@ -146,11 +146,11 @@ test_reorder_insert(void)
> b = rte_reorder_create("test_insert", rte_socket_id(), size);
> TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
>
> - ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
> - TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
> -
> - for (i = 0; i < num_bufs; i++)
> + for (i = 0; i < num_bufs; i++) {
> + bufs[i] = rte_pktmbuf_alloc(p);
> + TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
> bufs[i]->seqn = i;
> + }
>
> /* This should fill up order buffer:
> * reorder_seq = 0
> @@ -165,6 +165,7 @@ test_reorder_insert(void)
> ret = -1;
> goto exit;
> }
> + bufs[i] = NULL;
> }
>
> /* early packet - should move mbufs to ready buf and move sequence window
> @@ -179,6 +180,7 @@ test_reorder_insert(void)
> ret = -1;
> goto exit;
> }
> + bufs[4] = NULL;
>
> /* early packet from current sequence window - full ready buffer */
> bufs[5]->seqn = 2 * size;
> @@ -189,6 +191,7 @@ test_reorder_insert(void)
> ret = -1;
> goto exit;
> }
> + bufs[5] = NULL;
>
> /* late packet */
> bufs[6]->seqn = 3 * size;
> @@ -199,11 +202,15 @@ test_reorder_insert(void)
> ret = -1;
> goto exit;
> }
> + bufs[6] = NULL;
>
> ret = 0;
> exit:
> - rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
> rte_reorder_free(b);
> + for (i = 0; i < num_bufs; i++) {
> + if (bufs[i] != NULL)
> + rte_pktmbuf_free(bufs[i]);
> + }
> return ret;
> }
>
> @@ -227,9 +234,6 @@ test_reorder_drain(void)
> b = rte_reorder_create("test_drain", rte_socket_id(), size);
> TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
>
> - ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
> - TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
> -
> /* Check no drained packets if reorder is empty */
> cnt = rte_reorder_drain(b, robufs, 1);
> if (cnt != 0) {
> @@ -239,8 +243,11 @@ test_reorder_drain(void)
> goto exit;
> }
>
> - for (i = 0; i < num_bufs; i++)
> + for (i = 0; i < num_bufs; i++) {
> + bufs[i] = rte_pktmbuf_alloc(p);
> + TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
> bufs[i]->seqn = i;
> + }
>
> /* Insert packet with seqn 1:
> * reorder_seq = 0
> @@ -248,6 +255,7 @@ test_reorder_drain(void)
> * OB[] = {1, NULL, NULL, NULL}
> */
> rte_reorder_insert(b, bufs[1]);
> + bufs[1] = NULL;
>
> cnt = rte_reorder_drain(b, robufs, 1);
I think we need a loop here to pktmbuf_free() each of the mbufs in the
robufs array that was populated by the drain() function.
> if (cnt != 1) {
> @@ -263,18 +271,22 @@ test_reorder_drain(void)
> */
> rte_reorder_insert(b, bufs[2]);
> rte_reorder_insert(b, bufs[3]);
> + bufs[2] = NULL;
> + bufs[3] = NULL;
>
> /* Insert more packets
> * RB[] = {NULL, NULL, NULL, NULL}
> * OB[] = {NULL, 2, 3, 4}
> */
> rte_reorder_insert(b, bufs[4]);
> + bufs[4] = NULL;
>
> /* Insert more packets
> * RB[] = {2, 3, 4, NULL}
> * OB[] = {NULL, NULL, 7, NULL}
> */
> rte_reorder_insert(b, bufs[7]);
> + bufs[7] = NULL;
>
> /* drained expected packets */
> cnt = rte_reorder_drain(b, robufs, 4);
And again here.
> @@ -298,8 +310,11 @@ test_reorder_drain(void)
> }
> ret = 0;
> exit:
> - rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
> rte_reorder_free(b);
> + for (i = 0; i < num_bufs; i++) {
> + if (bufs[i] != NULL)
> + rte_pktmbuf_free(bufs[i]);
> + }
> return ret;
> }
>
Reviewed-by: David Hunt <david.hunt@intel.com>
Thanks,
Dave.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [dpdk-stable] [PATCH v4] app/test: fix reorder test failure
2018-05-03 16:36 ` [dpdk-stable] [PATCH v3] " Reshma Pattan
2018-05-03 17:02 ` Hunt, David
@ 2018-05-04 10:47 ` Reshma Pattan
2018-05-13 21:17 ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
1 sibling, 1 reply; 11+ messages in thread
From: Reshma Pattan @ 2018-05-04 10:47 UTC (permalink / raw)
To: david.hunt, dev; +Cc: stable
mbufs are being freed twice in error, once in rte_mempool_put_bulk()
and then in rte_reorder_free(). Refactor the code so that we use
rte_reorder_free() to free mbufs in the reorder buffer, and use
rte_pktmbuf_free() to free any unused or drained mbufs.
Fixes: d0c9b58d71 ("app/test: new reorder unit test")
Cc: stable@dpdk.org backport
Cc: david.hunt@intel.com
Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
Reviewed-by: David Hunt <david.hunt@intel.com>
---
v4: free the mbufs after reorder drain.
---
test/test/test_reorder.c | 47 +++++++++++++++++++++++++++++++++++++----------
1 file changed, 37 insertions(+), 10 deletions(-)
diff --git a/test/test/test_reorder.c b/test/test/test_reorder.c
index 65e4f38b2..ccee4d086 100644
--- a/test/test/test_reorder.c
+++ b/test/test/test_reorder.c
@@ -146,11 +146,11 @@ test_reorder_insert(void)
b = rte_reorder_create("test_insert", rte_socket_id(), size);
TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
- ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
- TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
-
- for (i = 0; i < num_bufs; i++)
+ for (i = 0; i < num_bufs; i++) {
+ bufs[i] = rte_pktmbuf_alloc(p);
+ TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
bufs[i]->seqn = i;
+ }
/* This should fill up order buffer:
* reorder_seq = 0
@@ -165,6 +165,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[i] = NULL;
}
/* early packet - should move mbufs to ready buf and move sequence window
@@ -179,6 +180,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[4] = NULL;
/* early packet from current sequence window - full ready buffer */
bufs[5]->seqn = 2 * size;
@@ -189,6 +191,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[5] = NULL;
/* late packet */
bufs[6]->seqn = 3 * size;
@@ -199,11 +202,15 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[6] = NULL;
ret = 0;
exit:
- rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
rte_reorder_free(b);
+ for (i = 0; i < num_bufs; i++) {
+ if (bufs[i] != NULL)
+ rte_pktmbuf_free(bufs[i]);
+ }
return ret;
}
@@ -219,6 +226,10 @@ test_reorder_drain(void)
int ret = 0;
unsigned i, cnt;
+ /* initialize all robufs to NULL */
+ for (i = 0; i < num_bufs; i++)
+ robufs[i] = NULL;
+
/* This would create a reorder buffer instance consisting of:
* reorder_seq = 0
* ready_buf: RB[size] = {NULL, NULL, NULL, NULL}
@@ -227,9 +238,6 @@ test_reorder_drain(void)
b = rte_reorder_create("test_drain", rte_socket_id(), size);
TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
- ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
- TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
-
/* Check no drained packets if reorder is empty */
cnt = rte_reorder_drain(b, robufs, 1);
if (cnt != 0) {
@@ -239,8 +247,11 @@ test_reorder_drain(void)
goto exit;
}
- for (i = 0; i < num_bufs; i++)
+ for (i = 0; i < num_bufs; i++) {
+ bufs[i] = rte_pktmbuf_alloc(p);
+ TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
bufs[i]->seqn = i;
+ }
/* Insert packet with seqn 1:
* reorder_seq = 0
@@ -248,6 +259,7 @@ test_reorder_drain(void)
* OB[] = {1, NULL, NULL, NULL}
*/
rte_reorder_insert(b, bufs[1]);
+ bufs[1] = NULL;
cnt = rte_reorder_drain(b, robufs, 1);
if (cnt != 1) {
@@ -256,6 +268,8 @@ test_reorder_drain(void)
ret = -1;
goto exit;
}
+ if (robufs[0] != NULL)
+ rte_pktmbuf_free(robufs[i]);
/* Insert more packets
* RB[] = {NULL, NULL, NULL, NULL}
@@ -263,18 +277,22 @@ test_reorder_drain(void)
*/
rte_reorder_insert(b, bufs[2]);
rte_reorder_insert(b, bufs[3]);
+ bufs[2] = NULL;
+ bufs[3] = NULL;
/* Insert more packets
* RB[] = {NULL, NULL, NULL, NULL}
* OB[] = {NULL, 2, 3, 4}
*/
rte_reorder_insert(b, bufs[4]);
+ bufs[4] = NULL;
/* Insert more packets
* RB[] = {2, 3, 4, NULL}
* OB[] = {NULL, NULL, 7, NULL}
*/
rte_reorder_insert(b, bufs[7]);
+ bufs[7] = NULL;
/* drained expected packets */
cnt = rte_reorder_drain(b, robufs, 4);
@@ -284,6 +302,10 @@ test_reorder_drain(void)
ret = -1;
goto exit;
}
+ for (i = 0; i < 3; i++) {
+ if (robufs[i] != NULL)
+ rte_pktmbuf_free(robufs[i]);
+ }
/*
* RB[] = {NULL, NULL, NULL, NULL}
@@ -298,8 +320,13 @@ test_reorder_drain(void)
}
ret = 0;
exit:
- rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
rte_reorder_free(b);
+ for (i = 0; i < num_bufs; i++) {
+ if (bufs[i] != NULL)
+ rte_pktmbuf_free(bufs[i]);
+ if (robufs[i] != NULL)
+ rte_pktmbuf_free(robufs[i]);
+ }
return ret;
}
--
2.14.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [dpdk-dev] [PATCH v4] app/test: fix reorder test failure
2018-05-04 10:47 ` [dpdk-stable] [PATCH v4] " Reshma Pattan
@ 2018-05-13 21:17 ` Thomas Monjalon
0 siblings, 0 replies; 11+ messages in thread
From: Thomas Monjalon @ 2018-05-13 21:17 UTC (permalink / raw)
To: Reshma Pattan; +Cc: dev, david.hunt, stable
04/05/2018 12:47, Reshma Pattan:
> mbufs are being freed twice in error, once in rte_mempool_put_bulk()
> and then in rte_reorder_free(). Refactor the code so that we use
> rte_reorder_free() to free mbufs in the reorder buffer, and use
> rte_pktmbuf_free() to free any unused or drained mbufs.
>
> Fixes: d0c9b58d71 ("app/test: new reorder unit test")
> Cc: stable@dpdk.org backport
> Cc: david.hunt@intel.com
> Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
> Reviewed-by: David Hunt <david.hunt@intel.com>
Applied, thanks
^ permalink raw reply [flat|nested] 11+ messages in thread
* [dpdk-stable] [PATCH v3] app/test: fix reorder test failure
2018-05-03 15:42 [dpdk-stable] [PATCH] app/test: fix reorder test failure Reshma Pattan
` (2 preceding siblings ...)
2018-05-03 16:30 ` [dpdk-stable] [PATCH v2] " Reshma Pattan
@ 2018-05-03 16:35 ` Reshma Pattan
3 siblings, 0 replies; 11+ messages in thread
From: Reshma Pattan @ 2018-05-03 16:35 UTC (permalink / raw)
To: david.hunt, dev; +Cc: stable
mbufs are being freed twice in error, once in rte_mempool_put_bulk()
and then in rte_reorder_free(). Refactor the code so that we use
rte_reorder_free() to free mbufs in the reorder buffer, and use
rte_pktmbuf_free() to free any unused or drained mbufs.
Fixes: d0c9b58d71 ("app/test: new reorder unit test")
Cc: stable@dpdk.org backport
Cc: david.hunt@intel.com
Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
v3
fix the indentation
---
test/test/test_reorder.c | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/test/test/test_reorder.c b/test/test/test_reorder.c
index 65e4f38b2..b7f664f66 100644
--- a/test/test/test_reorder.c
+++ b/test/test/test_reorder.c
@@ -146,11 +146,11 @@ test_reorder_insert(void)
b = rte_reorder_create("test_insert", rte_socket_id(), size);
TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
- ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
- TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
-
- for (i = 0; i < num_bufs; i++)
+ for (i = 0; i < num_bufs; i++) {
+ bufs[i] = rte_pktmbuf_alloc(p);
+ TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
bufs[i]->seqn = i;
+ }
/* This should fill up order buffer:
* reorder_seq = 0
@@ -165,6 +165,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[i] = NULL;
}
/* early packet - should move mbufs to ready buf and move sequence window
@@ -179,6 +180,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[4] = NULL;
/* early packet from current sequence window - full ready buffer */
bufs[5]->seqn = 2 * size;
@@ -189,6 +191,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[5] = NULL;
/* late packet */
bufs[6]->seqn = 3 * size;
@@ -199,11 +202,15 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
+ bufs[6] = NULL;
ret = 0;
exit:
- rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
rte_reorder_free(b);
+ for (i = 0; i < num_bufs; i++) {
+ if (bufs[i] != NULL)
+ rte_pktmbuf_free(bufs[i]);
+ }
return ret;
}
@@ -227,9 +234,6 @@ test_reorder_drain(void)
b = rte_reorder_create("test_drain", rte_socket_id(), size);
TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
- ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
- TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");
-
/* Check no drained packets if reorder is empty */
cnt = rte_reorder_drain(b, robufs, 1);
if (cnt != 0) {
@@ -239,8 +243,11 @@ test_reorder_drain(void)
goto exit;
}
- for (i = 0; i < num_bufs; i++)
+ for (i = 0; i < num_bufs; i++) {
+ bufs[i] = rte_pktmbuf_alloc(p);
+ TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
bufs[i]->seqn = i;
+ }
/* Insert packet with seqn 1:
* reorder_seq = 0
@@ -248,6 +255,7 @@ test_reorder_drain(void)
* OB[] = {1, NULL, NULL, NULL}
*/
rte_reorder_insert(b, bufs[1]);
+ bufs[1] = NULL;
cnt = rte_reorder_drain(b, robufs, 1);
if (cnt != 1) {
@@ -263,18 +271,22 @@ test_reorder_drain(void)
*/
rte_reorder_insert(b, bufs[2]);
rte_reorder_insert(b, bufs[3]);
+ bufs[2] = NULL;
+ bufs[3] = NULL;
/* Insert more packets
* RB[] = {NULL, NULL, NULL, NULL}
* OB[] = {NULL, 2, 3, 4}
*/
rte_reorder_insert(b, bufs[4]);
+ bufs[4] = NULL;
/* Insert more packets
* RB[] = {2, 3, 4, NULL}
* OB[] = {NULL, NULL, 7, NULL}
*/
rte_reorder_insert(b, bufs[7]);
+ bufs[7] = NULL;
/* drained expected packets */
cnt = rte_reorder_drain(b, robufs, 4);
@@ -298,8 +310,11 @@ test_reorder_drain(void)
}
ret = 0;
exit:
- rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
rte_reorder_free(b);
+ for (i = 0; i < num_bufs; i++) {
+ if (bufs[i] != NULL)
+ rte_pktmbuf_free(bufs[i]);
+ }
return ret;
}
--
2.14.3
^ permalink raw reply [flat|nested] 11+ messages in thread