app/testpmd: fix crash on cleanup

Message ID 20230206154946.750829-1-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series app/testpmd: fix crash on cleanup |

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-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/github-robot: build fail github build: failed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS

Commit Message

David Marchand Feb. 6, 2023, 3:49 p.m. UTC
  If allocating the ports[] array fails, a crash will occur when shutting
down testpmd since ethdev emits RTE_ETH_EVENT_DESTROY events.
Move init_port() before registering ethdev event handler.

Fixes: 85c6571c9103 ("app/testpmd: reset port status on close notification")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/testpmd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Singh, Aman Deep Feb. 17, 2023, 7:14 a.m. UTC | #1
On 2/6/2023 9:19 PM, David Marchand wrote:
> If allocating the ports[] array fails, a crash will occur when shutting
> down testpmd since ethdev emits RTE_ETH_EVENT_DESTROY events.
> Move init_port() before registering ethdev event handler.

Looks ok to me. Avoids seg_fault, due to Null pointer access.

>
> Fixes: 85c6571c9103 ("app/testpmd: reset port status on close notification")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Acked-by: Aman Singh <aman.deep.singh@intel.com>

> ---
>   app/test-pmd/testpmd.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
> index e366f81a0f..de3017fd62 100644
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c
> @@ -4385,6 +4385,9 @@ main(int argc, char** argv)
>   		rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
>   			 rte_strerror(rte_errno));
>   
> +	/* allocate port structures, and init them */
> +	init_port();
> +
>   	ret = register_eth_event_callback();
>   	if (ret != 0)
>   		rte_exit(EXIT_FAILURE, "Cannot register for ethdev events");
> @@ -4403,9 +4406,6 @@ main(int argc, char** argv)
>   	if (nb_ports == 0)
>   		TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
>   
> -	/* allocate port structures, and init them */
> -	init_port();
> -
>   	set_def_fwd_config();
>   	if (nb_lcores == 0)
>   		rte_exit(EXIT_FAILURE, "No cores defined for forwarding\n"
  
Ferruh Yigit Feb. 17, 2023, 4:18 p.m. UTC | #2
On 2/17/2023 7:14 AM, Singh, Aman Deep wrote:
> 
> On 2/6/2023 9:19 PM, David Marchand wrote:
>> If allocating the ports[] array fails, a crash will occur when shutting
>> down testpmd since ethdev emits RTE_ETH_EVENT_DESTROY events.
>> Move init_port() before registering ethdev event handler.
> 
> Looks ok to me. Avoids seg_fault, due to Null pointer access.
> 
>>
>> Fixes: 85c6571c9103 ("app/testpmd: reset port status on close
>> notification")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: David Marchand <david.marchand@redhat.com>
> 
> Acked-by: Aman Singh <aman.deep.singh@intel.com>
> 

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

Patch

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index e366f81a0f..de3017fd62 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -4385,6 +4385,9 @@  main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
 			 rte_strerror(rte_errno));
 
+	/* allocate port structures, and init them */
+	init_port();
+
 	ret = register_eth_event_callback();
 	if (ret != 0)
 		rte_exit(EXIT_FAILURE, "Cannot register for ethdev events");
@@ -4403,9 +4406,6 @@  main(int argc, char** argv)
 	if (nb_ports == 0)
 		TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
 
-	/* allocate port structures, and init them */
-	init_port();
-
 	set_def_fwd_config();
 	if (nb_lcores == 0)
 		rte_exit(EXIT_FAILURE, "No cores defined for forwarding\n"