[v2] net/ice: fix ice dcf control thread crash

Message ID 20230213071648.326123-1-ke1x.zhang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Qi Zhang
Headers
Series [v2] net/ice: fix ice dcf control thread crash |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS

Commit Message

Zhang, Ke1X Feb. 13, 2023, 7:16 a.m. UTC
  The control thread accesses the hardware resources after the
resources were released, resulting in a segment error.

This commit fixes the bug by exiting thread before resource released.

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
---
v2: add pthread_exit() for windows
---
 drivers/net/ice/ice_dcf.c         | 4 ++++
 lib/eal/windows/include/pthread.h | 5 +++++
 2 files changed, 9 insertions(+)
  

Comments

Thomas Monjalon Feb. 14, 2023, 11:03 a.m. UTC | #1
13/02/2023 08:16, Ke Zhang:
> --- a/lib/eal/windows/include/pthread.h
> +++ b/lib/eal/windows/include/pthread.h
> +static inline void
> +pthread_exit(__rte_unused void *__retval)
> +{
> +}

Please don't add more shim layer.
There is a new layer rte_thread_* in lib/eal/include/rte_thread.h
  
Zhang, Ke1X Feb. 16, 2023, 7:53 a.m. UTC | #2
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Tuesday, February 14, 2023 7:03 PM
> To: Zhang, Ke1X <ke1x.zhang@intel.com>
> Cc: Zhang, Qi Z <qi.z.zhang@intel.com>; Yang, Qiming
> <qiming.yang@intel.com>; dev@dpdk.org; Tyler Retzlaff
> <roretzla@linux.microsoft.com>
> Subject: Re: [PATCH v2] net/ice: fix ice dcf control thread crash
> 
> 13/02/2023 08:16, Ke Zhang:
> > --- a/lib/eal/windows/include/pthread.h
> > +++ b/lib/eal/windows/include/pthread.h
> > +static inline void
> > +pthread_exit(__rte_unused void *__retval) { }
> 
> Please don't add more shim layer.
> There is a new layer rte_thread_* in lib/eal/include/rte_thread.h
> 
Thanks for your comments.
Do I need add a function like rte_thread_exit() in in lib/eal/include/rte_thread.h?
There is no function for supporting pthread_exit.
  
Thomas Monjalon Feb. 20, 2023, 12:30 a.m. UTC | #3
16/02/2023 08:53, Zhang, Ke1X:
> From: Thomas Monjalon <thomas@monjalon.net>
> > 13/02/2023 08:16, Ke Zhang:
> > > --- a/lib/eal/windows/include/pthread.h
> > > +++ b/lib/eal/windows/include/pthread.h
> > > +static inline void
> > > +pthread_exit(__rte_unused void *__retval) { }
> > 
> > Please don't add more shim layer.
> > There is a new layer rte_thread_* in lib/eal/include/rte_thread.h
> > 
> Thanks for your comments.
> Do I need add a function like rte_thread_exit() in in lib/eal/include/rte_thread.h?

I guess yes.

> There is no function for supporting pthread_exit.

Tyler, how would you achieve the equivalent of pthread_exit?
  
Zhang, Ke1X March 1, 2023, 1:54 a.m. UTC | #4
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Monday, February 20, 2023 8:30 AM
> To: Tyler Retzlaff <roretzla@linux.microsoft.com>; Zhang, Ke1X
> <ke1x.zhang@intel.com>
> Cc: dev@dpdk.org; Zhang, Qi Z <qi.z.zhang@intel.com>; Yang, Qiming
> <qiming.yang@intel.com>; dev@dpdk.org; david.marchand@redhat.com
> Subject: Re: [PATCH v2] net/ice: fix ice dcf control thread crash
> 
> 16/02/2023 08:53, Zhang, Ke1X:
> > From: Thomas Monjalon <thomas@monjalon.net>
> > > 13/02/2023 08:16, Ke Zhang:
> > > > --- a/lib/eal/windows/include/pthread.h
> > > > +++ b/lib/eal/windows/include/pthread.h
> > > > +static inline void
> > > > +pthread_exit(__rte_unused void *__retval) { }
> > >
> > > Please don't add more shim layer.
> > > There is a new layer rte_thread_* in lib/eal/include/rte_thread.h
> > >
> > Thanks for your comments.
> > Do I need add a function like rte_thread_exit() in in
> lib/eal/include/rte_thread.h?
> 
> I guess yes.
> 
> > There is no function for supporting pthread_exit.
> 
> Tyler, how would you achieve the equivalent of pthread_exit?
> 
@ Tyler, would you please share any idea?
  
Kevin Traynor March 1, 2023, 2:53 p.m. UTC | #5
On 13/02/2023 07:16, Ke Zhang wrote:
> The control thread accesses the hardware resources after the
> resources were released, resulting in a segment error.
> 
> This commit fixes the bug by exiting thread before resource released.
> 

Please add the "Fixes: xyz" tag for the commit that introduced this bug 
so the fix can be backported to the appropriate stable branches.

> Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
> ---
> v2: add pthread_exit() for windows
> ---
>   drivers/net/ice/ice_dcf.c         | 4 ++++
>   lib/eal/windows/include/pthread.h | 5 +++++
>   2 files changed, 9 insertions(+)
> 
> diff --git a/drivers/net/ice/ice_dcf.c b/drivers/net/ice/ice_dcf.c
> index 1c3d22ae0f..e58908caf5 100644
> --- a/drivers/net/ice/ice_dcf.c
> +++ b/drivers/net/ice/ice_dcf.c
> @@ -543,6 +543,8 @@ ice_dcf_handle_vsi_update_event(struct ice_dcf_hw *hw)
>   	ice_dcf_disable_irq0(hw);
>   
>   	for (;;) {
> +		if (hw->vc_event_msg_cb == NULL)
> +			pthread_exit(NULL);
>   		if (ice_dcf_get_vf_resource(hw) == 0 &&
>   		    ice_dcf_get_vf_vsi_map(hw) >= 0) {
>   			err = 0;
> @@ -760,6 +762,8 @@ ice_dcf_uninit_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw)
>   	rte_intr_callback_unregister(intr_handle,
>   				     ice_dcf_dev_interrupt_handler, hw);
>   
> +	hw->vc_event_msg_cb = NULL;
> +
>   	ice_dcf_mode_disable(hw);
>   	iavf_shutdown_adminq(&hw->avf);
>   
> diff --git a/lib/eal/windows/include/pthread.h b/lib/eal/windows/include/pthread.h
> index 27fd2cca52..f0068ebd73 100644
> --- a/lib/eal/windows/include/pthread.h
> +++ b/lib/eal/windows/include/pthread.h
> @@ -149,6 +149,11 @@ pthread_detach(__rte_unused pthread_t thread)
>   	return 0;
>   }
>   
> +static inline void
> +pthread_exit(__rte_unused void *__retval)
> +{
> +}
> +
>   static inline int
>   pthread_join(__rte_unused pthread_t thread,
>   	__rte_unused void **value_ptr)
  

Patch

diff --git a/drivers/net/ice/ice_dcf.c b/drivers/net/ice/ice_dcf.c
index 1c3d22ae0f..e58908caf5 100644
--- a/drivers/net/ice/ice_dcf.c
+++ b/drivers/net/ice/ice_dcf.c
@@ -543,6 +543,8 @@  ice_dcf_handle_vsi_update_event(struct ice_dcf_hw *hw)
 	ice_dcf_disable_irq0(hw);
 
 	for (;;) {
+		if (hw->vc_event_msg_cb == NULL)
+			pthread_exit(NULL);
 		if (ice_dcf_get_vf_resource(hw) == 0 &&
 		    ice_dcf_get_vf_vsi_map(hw) >= 0) {
 			err = 0;
@@ -760,6 +762,8 @@  ice_dcf_uninit_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw)
 	rte_intr_callback_unregister(intr_handle,
 				     ice_dcf_dev_interrupt_handler, hw);
 
+	hw->vc_event_msg_cb = NULL;
+
 	ice_dcf_mode_disable(hw);
 	iavf_shutdown_adminq(&hw->avf);
 
diff --git a/lib/eal/windows/include/pthread.h b/lib/eal/windows/include/pthread.h
index 27fd2cca52..f0068ebd73 100644
--- a/lib/eal/windows/include/pthread.h
+++ b/lib/eal/windows/include/pthread.h
@@ -149,6 +149,11 @@  pthread_detach(__rte_unused pthread_t thread)
 	return 0;
 }
 
+static inline void
+pthread_exit(__rte_unused void *__retval)
+{
+}
+
 static inline int
 pthread_join(__rte_unused pthread_t thread,
 	__rte_unused void **value_ptr)