[v2,2/2] net/ice: fix leak on thread termination

Message ID 20210511113358.2485-3-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series Thread termination leak fixes |

Checks

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

Commit Message

David Marchand May 11, 2021, 11:33 a.m. UTC
  A terminated pthread should be joined or detached so that its associated
resources are released.

The "ice-reset-<vf_id>" threads are used to service some reset task in the
background, but they are never joined by the thread that created them.
The easiest solution is to detach new threads.

The Windows EAL did not provide a pthread_detach wrapper but there is no
resource to release for Windows threads, so add an empty wrapper.

Fixes: 3b3757bda3c3 ("net/ice: get VF hardware index in DCF")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Haiyue Wang <haiyue.wang@intel.com>
---
Changes since v1:
- fixed build for net/ice on Windows

---
 drivers/net/ice/ice_dcf_parent.c  | 2 ++
 lib/eal/windows/include/pthread.h | 6 ++++++
 2 files changed, 8 insertions(+)
  

Comments

Dmitry Kozlyuk May 11, 2021, 5:34 p.m. UTC | #1
2021-05-11 13:33 (UTC+0200), David Marchand:
> A terminated pthread should be joined or detached so that its associated
> resources are released.
> 
> The "ice-reset-<vf_id>" threads are used to service some reset task in the
> background, but they are never joined by the thread that created them.
> The easiest solution is to detach new threads.
> 
> The Windows EAL did not provide a pthread_detach wrapper but there is no
> resource to release for Windows threads, so add an empty wrapper.
> 
> Fixes: 3b3757bda3c3 ("net/ice: get VF hardware index in DCF")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> Acked-by: Haiyue Wang <haiyue.wang@intel.com>
> ---
> Changes since v1:
> - fixed build for net/ice on Windows
> 
> ---
>  drivers/net/ice/ice_dcf_parent.c  | 2 ++
>  lib/eal/windows/include/pthread.h | 6 ++++++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/drivers/net/ice/ice_dcf_parent.c b/drivers/net/ice/ice_dcf_parent.c
> index c8e433239b..1d7aa8bc87 100644
> --- a/drivers/net/ice/ice_dcf_parent.c
> +++ b/drivers/net/ice/ice_dcf_parent.c
> @@ -121,6 +121,8 @@ ice_dcf_vsi_update_service_handler(void *param)
>  	struct ice_dcf_hw *hw = reset_param->dcf_hw;
>  	struct ice_dcf_adapter *adapter;
>  
> +	pthread_detach(pthread_self());
> +
>  	rte_delay_us(ICE_DCF_VSI_UPDATE_SERVICE_INTERVAL);
>  
>  	rte_spinlock_lock(&vsi_update_lock);
> diff --git a/lib/eal/windows/include/pthread.h b/lib/eal/windows/include/pthread.h
> index 1939b0121c..27fd2cca52 100644
> --- a/lib/eal/windows/include/pthread.h
> +++ b/lib/eal/windows/include/pthread.h
> @@ -143,6 +143,12 @@ pthread_create(void *threadid, const void *threadattr, void *threadfunc,
>  	return ((hThread != NULL) ? 0 : E_FAIL);
>  }
>  
> +static inline int
> +pthread_detach(__rte_unused pthread_t thread)
> +{
> +	return 0;
> +}
> +
>  static inline int
>  pthread_join(__rte_unused pthread_t thread,
>  	__rte_unused void **value_ptr)

For Windows part,
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
  

Patch

diff --git a/drivers/net/ice/ice_dcf_parent.c b/drivers/net/ice/ice_dcf_parent.c
index c8e433239b..1d7aa8bc87 100644
--- a/drivers/net/ice/ice_dcf_parent.c
+++ b/drivers/net/ice/ice_dcf_parent.c
@@ -121,6 +121,8 @@  ice_dcf_vsi_update_service_handler(void *param)
 	struct ice_dcf_hw *hw = reset_param->dcf_hw;
 	struct ice_dcf_adapter *adapter;
 
+	pthread_detach(pthread_self());
+
 	rte_delay_us(ICE_DCF_VSI_UPDATE_SERVICE_INTERVAL);
 
 	rte_spinlock_lock(&vsi_update_lock);
diff --git a/lib/eal/windows/include/pthread.h b/lib/eal/windows/include/pthread.h
index 1939b0121c..27fd2cca52 100644
--- a/lib/eal/windows/include/pthread.h
+++ b/lib/eal/windows/include/pthread.h
@@ -143,6 +143,12 @@  pthread_create(void *threadid, const void *threadattr, void *threadfunc,
 	return ((hThread != NULL) ? 0 : E_FAIL);
 }
 
+static inline int
+pthread_detach(__rte_unused pthread_t thread)
+{
+	return 0;
+}
+
 static inline int
 pthread_join(__rte_unused pthread_t thread,
 	__rte_unused void **value_ptr)