[dpdk-dev] net/i40e: fix unexpected mbuf free in vPMD

Message ID 20171010132205.72173-1-qi.z.zhang@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Qi Zhang Oct. 10, 2017, 1:22 p.m. UTC
  vPMD tx does not set sw_ring's mbuf to NULL after free it.
So to prevent same mbuf be free again, we need more carefully
check in i40e_tx_queue_release_mbufs.

Fixes: b4669bb95038 ("i40e: add vector Tx")
Cc: stable@dpdk.org

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---
v2:
- fix at i40e_tx_queue_release_mbufs so no performance impact.

 drivers/net/i40e/i40e_rxtx.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
  

Comments

Bruce Richardson Oct. 10, 2017, 8:48 a.m. UTC | #1
+Roger Melton

On Tue, Oct 10, 2017 at 09:22:05AM -0400, Qi Zhang wrote:
> vPMD tx does not set sw_ring's mbuf to NULL after free it.
> So to prevent same mbuf be free again, we need more carefully
> check in i40e_tx_queue_release_mbufs.
> 
> Fixes: b4669bb95038 ("i40e: add vector Tx")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
> ---
> v2:
> - fix at i40e_tx_queue_release_mbufs so no performance impact.
> 
This patch also supercedes this one, http://dpdk.org/dev/patchwork/patch/29814/
right?
Roger, can you please confirm that this alternative fix works in your
testing and that your patch is no longer necessary too.

Thanks,
/Bruce
  
Roger Melton Oct. 10, 2017, 11:05 a.m. UTC | #2
Hi Bruce,

I can.  It will take a day or 2 to get the results.

Regards,
Roger


On 10/10/17 4:48 AM, Bruce Richardson wrote:
> +Roger Melton
>
> On Tue, Oct 10, 2017 at 09:22:05AM -0400, Qi Zhang wrote:
>> vPMD tx does not set sw_ring's mbuf to NULL after free it.
>> So to prevent same mbuf be free again, we need more carefully
>> check in i40e_tx_queue_release_mbufs.
>>
>> Fixes: b4669bb95038 ("i40e: add vector Tx")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
>> ---
>> v2:
>> - fix at i40e_tx_queue_release_mbufs so no performance impact.
>>
> This patch also supercedes this one, http://dpdk.org/dev/patchwork/patch/29814/
> right?
> Roger, can you please confirm that this alternative fix works in your
> testing and that your patch is no longer necessary too.
>
> Thanks,
> /Bruce
>
> .
>
  
Bruce Richardson Oct. 10, 2017, 11:39 a.m. UTC | #3
On Tue, Oct 10, 2017 at 07:05:33AM -0400, Roger B. Melton wrote:
> Hi Bruce,
> 
> I can.  It will take a day or 2 to get the results.
> 
> Regards,
> Roger
> 

Thanks. Keep us posted. We want to ensure we have the best fix possible
for the issue in this release.

/Bruce

> 
> On 10/10/17 4:48 AM, Bruce Richardson wrote:
> > +Roger Melton
> > 
> > On Tue, Oct 10, 2017 at 09:22:05AM -0400, Qi Zhang wrote:
> > > vPMD tx does not set sw_ring's mbuf to NULL after free it.
> > > So to prevent same mbuf be free again, we need more carefully
> > > check in i40e_tx_queue_release_mbufs.
> > > 
> > > Fixes: b4669bb95038 ("i40e: add vector Tx")
> > > Cc: stable@dpdk.org
> > > 
> > > Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
> > > ---
> > > v2:
> > > - fix at i40e_tx_queue_release_mbufs so no performance impact.
> > > 
> > This patch also supercedes this one, http://dpdk.org/dev/patchwork/patch/29814/
> > right?
> > Roger, can you please confirm that this alternative fix works in your
> > testing and that your patch is no longer necessary too.
> > 
> > Thanks,
> > /Bruce
> > 
> > .
> > 
>
  
Roger Melton Oct. 10, 2017, 11:47 a.m. UTC | #4
On 10/10/17 7:39 AM, Bruce Richardson wrote:
> On Tue, Oct 10, 2017 at 07:05:33AM -0400, Roger B. Melton wrote:
>> Hi Bruce,
>>
>> I can.  It will take a day or 2 to get the results.
>>
>> Regards,
>> Roger
>>
> Thanks. Keep us posted. We want to ensure we have the best fix possible
> for the issue in this release.

Thanks for finding a better solution ;-).  I'll let you know the results 
when I have them, just wanted you to know it may take a couple of days 
to turn around.

-Roger

>
> /Bruce
>
>> On 10/10/17 4:48 AM, Bruce Richardson wrote:
>>> +Roger Melton
>>>
>>> On Tue, Oct 10, 2017 at 09:22:05AM -0400, Qi Zhang wrote:
>>>> vPMD tx does not set sw_ring's mbuf to NULL after free it.
>>>> So to prevent same mbuf be free again, we need more carefully
>>>> check in i40e_tx_queue_release_mbufs.
>>>>
>>>> Fixes: b4669bb95038 ("i40e: add vector Tx")
>>>> Cc: stable@dpdk.org
>>>>
>>>> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
>>>> ---
>>>> v2:
>>>> - fix at i40e_tx_queue_release_mbufs so no performance impact.
>>>>
>>> This patch also supercedes this one, http://dpdk.org/dev/patchwork/patch/29814/
>>> right?
>>> Roger, can you please confirm that this alternative fix works in your
>>> testing and that your patch is no longer necessary too.
>>>
>>> Thanks,
>>> /Bruce
>>>
>>> .
>>>
> .
>
  
Roger Melton Oct. 12, 2017, 11:15 a.m. UTC | #5
On 10/10/17 7:47 AM, Roger B. Melton wrote:
> On 10/10/17 7:39 AM, Bruce Richardson wrote:
>> On Tue, Oct 10, 2017 at 07:05:33AM -0400, Roger B. Melton wrote:
>>> Hi Bruce,
>>>
>>> I can.  It will take a day or 2 to get the results.
>>>
>>> Regards,
>>> Roger
>>>
>> Thanks. Keep us posted. We want to ensure we have the best fix possible
>> for the issue in this release.
>
> Thanks for finding a better solution ;-).  I'll let you know the 
> results when I have them, just wanted you to know it may take a couple 
> of days to turn around.
>
> -Roger

Confirmed that this patch does address the issue.  Thanks again Bruce/Qi 
for finding a better alternative.

Regards, Roger
>
>>
>> /Bruce
>>
>>> On 10/10/17 4:48 AM, Bruce Richardson wrote:
>>>> +Roger Melton
>>>>
>>>> On Tue, Oct 10, 2017 at 09:22:05AM -0400, Qi Zhang wrote:
>>>>> vPMD tx does not set sw_ring's mbuf to NULL after free it.
>>>>> So to prevent same mbuf be free again, we need more carefully
>>>>> check in i40e_tx_queue_release_mbufs.
>>>>>
>>>>> Fixes: b4669bb95038 ("i40e: add vector Tx")
>>>>> Cc: stable@dpdk.org
>>>>>
>>>>> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
>>>>> ---
>>>>> v2:
>>>>> - fix at i40e_tx_queue_release_mbufs so no performance impact.
>>>>>
>>>> This patch also supercedes this one, 
>>>> http://dpdk.org/dev/patchwork/patch/29814/
>>>> right?
>>>> Roger, can you please confirm that this alternative fix works in your
>>>> testing and that your patch is no longer necessary too.
>>>>
>>>> Thanks,
>>>> /Bruce
>>>>
>>>> .
>>>>
>> .
>>
>
> .
>
  
Bruce Richardson Oct. 12, 2017, 11:30 a.m. UTC | #6
> -----Original Message-----

> From: Roger B. Melton [mailto:rmelton@cisco.com]

> Sent: Thursday, October 12, 2017 12:15 PM

> To: Richardson, Bruce <bruce.richardson@intel.com>

> Cc: Zhang, Qi Z <qi.z.zhang@intel.com>; Ananyev, Konstantin

> <konstantin.ananyev@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>;

> Xing, Beilei <beilei.xing@intel.com>; dev@dpdk.org; stable@dpdk.org

> Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH] net/i40e: fix unexpected

> mbuf free in vPMD

> 

> On 10/10/17 7:47 AM, Roger B. Melton wrote:

> > On 10/10/17 7:39 AM, Bruce Richardson wrote:

> >> On Tue, Oct 10, 2017 at 07:05:33AM -0400, Roger B. Melton wrote:

> >>> Hi Bruce,

> >>>

> >>> I can.  It will take a day or 2 to get the results.

> >>>

> >>> Regards,

> >>> Roger

> >>>

> >> Thanks. Keep us posted. We want to ensure we have the best fix

> >> possible for the issue in this release.

> >

> > Thanks for finding a better solution ;-).  I'll let you know the

> > results when I have them, just wanted you to know it may take a couple

> > of days to turn around.

> >

> > -Roger

> 

> Confirmed that this patch does address the issue.  Thanks again Bruce/Qi

> for finding a better alternative.

> 

> Regards, Roger

> >

Great.

Acked-by: Bruce Richardson <bruce.richardson@intel.com>


See also comment below.

> >>

> >> /Bruce

> >>

> >>> On 10/10/17 4:48 AM, Bruce Richardson wrote:

> >>>> +Roger Melton

> >>>>

> >>>> On Tue, Oct 10, 2017 at 09:22:05AM -0400, Qi Zhang wrote:

> >>>>> vPMD tx does not set sw_ring's mbuf to NULL after free it.

> >>>>> So to prevent same mbuf be free again, we need more carefully

> >>>>> check in i40e_tx_queue_release_mbufs.

> >>>>>

Maybe this commit message could be reworded to be a bit more detailed.

"vPMD tx does not set sw_ring's mbuf to NULL after free.
Therefore, in cases where the vector transmit function is in
use, we must use the appropriate index and threshold values
for the queue to only free the unreleased mbufs"
  
Ferruh Yigit Oct. 12, 2017, 5:28 p.m. UTC | #7
On 10/10/2017 2:22 PM, Qi Zhang wrote:
> vPMD tx does not set sw_ring's mbuf to NULL after free it.
> So to prevent same mbuf be free again, we need more carefully
> check in i40e_tx_queue_release_mbufs.
> 
> Fixes: b4669bb95038 ("i40e: add vector Tx")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>

> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied to dpdk-next-net/master, thanks.

(Used suggested commit log, thanks.)
  

Patch

diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
index 3a8d32c..f21c1c5 100644
--- a/drivers/net/i40e/i40e_rxtx.c
+++ b/drivers/net/i40e/i40e_rxtx.c
@@ -2305,18 +2305,40 @@  i40e_reset_rx_queue(struct i40e_rx_queue *rxq)
 void
 i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq)
 {
+	struct rte_eth_dev *dev;
 	uint16_t i;
 
+	dev = &rte_eth_devices[txq->port_id];
+
 	if (!txq || !txq->sw_ring) {
 		PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
 		return;
 	}
 
-	for (i = 0; i < txq->nb_tx_desc; i++) {
-		if (txq->sw_ring[i].mbuf) {
+	/**
+	 *  vPMD tx will not set sw_ring's mbuf to NULL after free,
+	 *  so need to free remains more carefully.
+	 */
+	if (dev->tx_pkt_burst == i40e_xmit_pkts_vec) {
+		i = txq->tx_next_dd - txq->tx_rs_thresh + 1;
+		if (txq->tx_tail < i) {
+			for (; i < txq->nb_tx_desc; i++) {
+				rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
+				txq->sw_ring[i].mbuf = NULL;
+			}
+			i = 0;
+		}
+		for (; i < txq->tx_tail; i++) {
 			rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
 			txq->sw_ring[i].mbuf = NULL;
 		}
+	} else {
+		for (i = 0; i < txq->nb_tx_desc; i++) {
+			if (txq->sw_ring[i].mbuf) {
+				rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
+				txq->sw_ring[i].mbuf = NULL;
+			}
+		}
 	}
 }