driver/net/pcap fix: pcap fd leak

Message ID ME3P282MB166871BA48AF990B7FACBD22D19D9@ME3P282MB1668.AUSP282.PROD.OUTLOOK.COM (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series driver/net/pcap fix: pcap fd leak |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot success github build: passed
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS

Commit Message

Tengfei Zhang Feb. 26, 2021, 4:20 p.m. UTC
  pcap fd was opend when vdev probed,
but not closed when vdev removed.
This bug appears in dpdk-pdump

Signed-off-by: ZhangTengfei <zypscode@outlook.com>
---
 drivers/net/pcap/rte_eth_pcap.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Ferruh Yigit Feb. 26, 2021, 4:46 p.m. UTC | #1
On 2/26/2021 4:20 PM, ZhangTengfei wrote:
> pcap fd was opend when vdev probed,
> but not closed when vdev removed.
> This bug appears in dpdk-pdump
> 
> Signed-off-by: ZhangTengfei <zypscode@outlook.com>
> ---
>   drivers/net/pcap/rte_eth_pcap.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
> index 90f5d75ea..fb01ea924 100644
> --- a/drivers/net/pcap/rte_eth_pcap.c
> +++ b/drivers/net/pcap/rte_eth_pcap.c
> @@ -1597,6 +1597,7 @@ pmd_pcap_remove(struct rte_vdev_device *dev)
>   	if (eth_dev == NULL)
>   		return 0; /* port already released */
>   
> +	eth_dev_stop(eth_dev);
>   	eth_dev_close(eth_dev);
>   	rte_eth_dev_release_port(eth_dev);
>   
> 

Thanks for the fix,
the cleanup seems missing in 'eth_dev_close()' too, what do you think moving 
'eth_dev_stop(eth_dev);' inside the 'eth_dev_close()'?
So both 'close' and 'remove' will be covered.


Btw, you have same patch with both "ZhangTengfei <zhangtengfei@oppo.com>" sign 
and "ZhangTengfei <zypscode@outlook.com>" sign (this one), can you please 
clarify which one do you prefer?
  
Tengfei Zhang Feb. 26, 2021, 5:47 p.m. UTC | #2
I think your idea is fine

What do you think just record file path in "pmd_pcap_probe()",
Perform an open operation only in "eth_dev_start()"?

When the secondary process add pcap vdev,
it send the request to primary process,
the primary process probe pcap vdev too ,
Both the two process open the same file (in function "pmd_pcap_probe()")
It's not necessary

I prefer "ZhangTengfei <zypscode@outlook.com>" sign (this one)


发送自 Windows 10 版邮件<https://go.microsoft.com/fwlink/?LinkId=550986>应用

发件人: Ferruh Yigit<mailto:ferruh.yigit@intel.com>
发送时间: 2021年2月27日 0:46
收件人: ZhangTengfei<mailto:zypscode@outlook.com>
抄送: dev@dpdk.org<mailto:dev@dpdk.org>
主题: Re: [PATCH] driver/net/pcap fix: pcap fd leak

On 2/26/2021 4:20 PM, ZhangTengfei wrote:
> pcap fd was opend when vdev probed,
> but not closed when vdev removed.
> This bug appears in dpdk-pdump
>
> Signed-off-by: ZhangTengfei <zypscode@outlook.com>
> ---
>   drivers/net/pcap/rte_eth_pcap.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
> index 90f5d75ea..fb01ea924 100644
> --- a/drivers/net/pcap/rte_eth_pcap.c
> +++ b/drivers/net/pcap/rte_eth_pcap.c
> @@ -1597,6 +1597,7 @@ pmd_pcap_remove(struct rte_vdev_device *dev)
>        if (eth_dev == NULL)
>                return 0; /* port already released */
>
> +     eth_dev_stop(eth_dev);
>        eth_dev_close(eth_dev);
>        rte_eth_dev_release_port(eth_dev);
>
>

Thanks for the fix,
the cleanup seems missing in 'eth_dev_close()' too, what do you think moving
'eth_dev_stop(eth_dev);' inside the 'eth_dev_close()'?
So both 'close' and 'remove' will be covered.


Btw, you have same patch with both "ZhangTengfei <zhangtengfei@oppo.com>" sign
and "ZhangTengfei <zypscode@outlook.com>" sign (this one), can you please
clarify which one do you prefer?
  
Ferruh Yigit March 1, 2021, 11:40 a.m. UTC | #3
Please do not top post, message moved down.

On 2/26/2021 5:47 PM, 张 杨 wrote:
>> I think your idea is fine
>> 
>> What do you think just record file path in "pmd_pcap_probe()",
>> 
>> Perform an open operation only in "eth_dev_start()"?
>> 
>> When the secondary process add pcap vdev,
>> 
>> it send the request to primary process,
>> 
>> the primary process probe pcap vdev too ,
>> 
>> Both the two process open the same file (in function "pmd_pcap_probe()")
>> 
>> It's not necessary
>> 
>> I prefer "ZhangTengfei <zypscode@outlook.com>" sign (this one)
>> 
>> 发送自Windows 10 版邮件 <https://go.microsoft.com/fwlink/?LinkId=550986>应用
>> 
>> *发件人: *Ferruh Yigit <mailto:ferruh.yigit@intel.com>
>> *发送时间: *2021年2月27日0:46
>> *收件人: *ZhangTengfei <mailto:zypscode@outlook.com>
>> *抄送: *dev@dpdk.org <mailto:dev@dpdk.org>
>> *主题: *Re: [PATCH] driver/net/pcap fix: pcap fd leak
>> 
>> On 2/26/2021 4:20 PM, ZhangTengfei wrote:
>>> pcap fd was opend when vdev probed,
>>> but not closed when vdev removed.
>>> This bug appears in dpdk-pdump
>>> 
>>> Signed-off-by: ZhangTengfei <zypscode@outlook.com>
>>> ---
>>>   drivers/net/pcap/rte_eth_pcap.c | 1 +
>>>   1 file changed, 1 insertion(+)
>>> 
>>> diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
>>> index 90f5d75ea..fb01ea924 100644
>>> --- a/drivers/net/pcap/rte_eth_pcap.c
>>> +++ b/drivers/net/pcap/rte_eth_pcap.c
>>> @@ -1597,6 +1597,7 @@ pmd_pcap_remove(struct rte_vdev_device *dev)
>>>        if (eth_dev == NULL)
>>>                return 0; /* port already released */
>>>   
>>> +     eth_dev_stop(eth_dev);
>>>        eth_dev_close(eth_dev);
>>>        rte_eth_dev_release_port(eth_dev);
>>>   
>>> 
>> 
>> Thanks for the fix,
>> the cleanup seems missing in 'eth_dev_close()' too, what do you think moving
>> 'eth_dev_stop(eth_dev);' inside the 'eth_dev_close()'?
>> So both 'close' and 'remove' will be covered.
>> 
>> 
>> Btw, you have same patch with both "ZhangTengfei <zhangtengfei@oppo.com>" sign
>> and "ZhangTengfei <zypscode@outlook.com>" sign (this one), can you please
>> clarify which one do you prefer?
>> 
 >
 > I think your idea is fine
 >
 > What do you think just record file path in "pmd_pcap_probe()",
 > Perform an open operation only in "eth_dev_start()"?
 >
 > When the secondary process add pcap vdev,
 > it send the request to primary process,
 > the primary process probe pcap vdev too ,>
 > Both the two process open the same file (in function "pmd_pcap_probe()")
 > It's not necessary
 >

Opening pcap helps us fail early in probe() if something is wrong, otherwise the 
driver probed and the problem detected in the start() when it is too late.
start() also opens pcap if it is not already opened.

In your usecase, if the pcap added by the secondary with the intention to use 
only by the secondary, yes primary process also opens the pcap unnecessarily, 
but that shouldn't be really a concern, this is one time cost in probe().

 > I prefer "ZhangTengfei <zypscode@outlook.com>" sign (this one)

OK, also can you please use "Name Surname <email@address.com>" format, to be 
consistent, I guess for you it means as following:
Tengfei Zhang <zypscode@outlook.com>
  
Tengfei Zhang March 1, 2021, 3:18 p.m. UTC | #4
On 2021/3/1 下午7:40, Ferruh Yigit wrote:
> Please do not top post, message moved down.
>
> On 2/26/2021 5:47 PM, 张 杨 wrote:
>>> I think your idea is fine
>>>
>>> What do you think just record file path in "pmd_pcap_probe()",
>>>
>>> Perform an open operation only in "eth_dev_start()"?
>>>
>>> When the secondary process add pcap vdev,
>>>
>>> it send the request to primary process,
>>>
>>> the primary process probe pcap vdev too ,
>>>
>>> Both the two process open the same file (in function 
>>> "pmd_pcap_probe()")
>>>
>>> It's not necessary
>>>
>>> I prefer "ZhangTengfei <zypscode@outlook.com>" sign (this one)
>>>
>>> 发送自Windows 10 版邮件 
>>> <https://go.microsoft.com/fwlink/?LinkId=550986>应用
>>>
>>> *发件人: *Ferruh Yigit <mailto:ferruh.yigit@intel.com>
>>> *发送时间: *2021年2月27日0:46
>>> *收件人: *ZhangTengfei <mailto:zypscode@outlook.com>
>>> *抄送: *dev@dpdk.org <mailto:dev@dpdk.org>
>>> *主题: *Re: [PATCH] driver/net/pcap fix: pcap fd leak
>>>
>>> On 2/26/2021 4:20 PM, ZhangTengfei wrote:
>>>> pcap fd was opend when vdev probed,
>>>> but not closed when vdev removed.
>>>> This bug appears in dpdk-pdump
>>>>
>>>> Signed-off-by: ZhangTengfei <zypscode@outlook.com>
>>>> ---
>>>>   drivers/net/pcap/rte_eth_pcap.c | 1 +
>>>>   1 file changed, 1 insertion(+)
>>>>
>>>> diff --git a/drivers/net/pcap/rte_eth_pcap.c 
>>>> b/drivers/net/pcap/rte_eth_pcap.c
>>>> index 90f5d75ea..fb01ea924 100644
>>>> --- a/drivers/net/pcap/rte_eth_pcap.c
>>>> +++ b/drivers/net/pcap/rte_eth_pcap.c
>>>> @@ -1597,6 +1597,7 @@ pmd_pcap_remove(struct rte_vdev_device *dev)
>>>>        if (eth_dev == NULL)
>>>>                return 0; /* port already released */
>>>>   +     eth_dev_stop(eth_dev);
>>>>        eth_dev_close(eth_dev);
>>>>        rte_eth_dev_release_port(eth_dev);
>>>>
>>>
>>> Thanks for the fix,
>>> the cleanup seems missing in 'eth_dev_close()' too, what do you 
>>> think moving
>>> 'eth_dev_stop(eth_dev);' inside the 'eth_dev_close()'?
>>> So both 'close' and 'remove' will be covered.
>>>
>>>
>>> Btw, you have same patch with both "ZhangTengfei 
>>> <zhangtengfei@oppo.com>" sign
>>> and "ZhangTengfei <zypscode@outlook.com>" sign (this one), can you 
>>> please
>>> clarify which one do you prefer?
>>>
> >
> > I think your idea is fine
> >
> > What do you think just record file path in "pmd_pcap_probe()",
> > Perform an open operation only in "eth_dev_start()"?
> >
> > When the secondary process add pcap vdev,
> > it send the request to primary process,
> > the primary process probe pcap vdev too ,>
> > Both the two process open the same file (in function 
> "pmd_pcap_probe()")
> > It's not necessary
> >
>
> Opening pcap helps us fail early in probe() if something is wrong, 
> otherwise the driver probed and the problem detected in the start() 
> when it is too late.
> start() also opens pcap if it is not already opened.
>
> In your usecase, if the pcap added by the secondary with the intention 
> to use only by the secondary, yes primary process also opens the pcap 
> unnecessarily, but that shouldn't be really a concern, this is one 
> time cost in probe().
>
> > I prefer "ZhangTengfei <zypscode@outlook.com>" sign (this one)
>
> OK, also can you please use "Name Surname <email@address.com>" format, 
> to be consistent, I guess for you it means as following:
> Tengfei Zhang <zypscode@outlook.com>

Rarely submit code to the open source community. Thank you for your advice.

I quite agree with your  view "fail early".

I will update the patch
  

Patch

diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 90f5d75ea..fb01ea924 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -1597,6 +1597,7 @@  pmd_pcap_remove(struct rte_vdev_device *dev)
 	if (eth_dev == NULL)
 		return 0; /* port already released */
 
+	eth_dev_stop(eth_dev);
 	eth_dev_close(eth_dev);
 	rte_eth_dev_release_port(eth_dev);