[RFC,3/3] examples/bond: fix invalid use of trylock

Message ID 20220410135140.161842-3-mattias.ronnblom@ericsson.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series [RFC,1/3] eal: add macro to warn for unused function return values |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Mattias Rönnblom April 10, 2022, 1:51 p.m. UTC
  The conditional rte_spinlock_trylock() was used as if it is an
unconditional lock operation in a number of places.

Fixes: cc7e8ae84faa ("examples/bond: add example application for link bonding mode 6")
Cc: michalx.k.jastrzebski@intel.com

Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
---
 examples/bond/main.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
  

Comments

humin (Q) April 11, 2022, 1:01 a.m. UTC | #1
Acked-by: Min Hu (Connor) <humin29@huawei.com>

在 2022/4/10 21:51, Mattias Rönnblom 写道:
> The conditional rte_spinlock_trylock() was used as if it is an
> unconditional lock operation in a number of places.
> 
> Fixes: cc7e8ae84faa ("examples/bond: add example application for link bonding mode 6")
> Cc: michalx.k.jastrzebski@intel.com
> 
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
> ---
>   examples/bond/main.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/examples/bond/main.c b/examples/bond/main.c
> index 335bde5c8d..4efebb3902 100644
> --- a/examples/bond/main.c
> +++ b/examples/bond/main.c
> @@ -373,7 +373,7 @@ static int lcore_main(__rte_unused void *arg1)
>   	bond_ip = BOND_IP_1 | (BOND_IP_2 << 8) |
>   				(BOND_IP_3 << 16) | (BOND_IP_4 << 24);
>   
> -	rte_spinlock_trylock(&global_flag_stru_p->lock);
> +	rte_spinlock_lock(&global_flag_stru_p->lock);
>   
>   	while (global_flag_stru_p->LcoreMainIsRunning) {
>   		rte_spinlock_unlock(&global_flag_stru_p->lock);
> @@ -456,7 +456,7 @@ static int lcore_main(__rte_unused void *arg1)
>   			if (is_free == 0)
>   				rte_pktmbuf_free(pkts[i]);
>   		}
> -		rte_spinlock_trylock(&global_flag_stru_p->lock);
> +		rte_spinlock_lock(&global_flag_stru_p->lock);
>   	}
>   	rte_spinlock_unlock(&global_flag_stru_p->lock);
>   	printf("BYE lcore_main\n");
> @@ -571,7 +571,7 @@ static void cmd_start_parsed(__rte_unused void *parsed_result,
>   {
>   	int worker_core_id = rte_lcore_id();
>   
> -	rte_spinlock_trylock(&global_flag_stru_p->lock);
> +	rte_spinlock_lock(&global_flag_stru_p->lock);
>   	if (global_flag_stru_p->LcoreMainIsRunning == 0) {
>   		if (rte_eal_get_lcore_state(global_flag_stru_p->LcoreMainCore)
>   		    != WAIT) {
> @@ -591,7 +591,7 @@ static void cmd_start_parsed(__rte_unused void *parsed_result,
>   	if ((worker_core_id >= RTE_MAX_LCORE) || (worker_core_id == 0))
>   		return;
>   
> -	rte_spinlock_trylock(&global_flag_stru_p->lock);
> +	rte_spinlock_lock(&global_flag_stru_p->lock);
>   	global_flag_stru_p->LcoreMainIsRunning = 1;
>   	rte_spinlock_unlock(&global_flag_stru_p->lock);
>   	cmdline_printf(cl,
> @@ -659,7 +659,7 @@ static void cmd_stop_parsed(__rte_unused void *parsed_result,
>   			    struct cmdline *cl,
>   			    __rte_unused void *data)
>   {
> -	rte_spinlock_trylock(&global_flag_stru_p->lock);
> +	rte_spinlock_lock(&global_flag_stru_p->lock);
>   	if (global_flag_stru_p->LcoreMainIsRunning == 0)	{
>   		cmdline_printf(cl,
>   					"lcore_main not running on core:%d\n",
> @@ -700,7 +700,7 @@ static void cmd_quit_parsed(__rte_unused void *parsed_result,
>   			    struct cmdline *cl,
>   			    __rte_unused void *data)
>   {
> -	rte_spinlock_trylock(&global_flag_stru_p->lock);
> +	rte_spinlock_lock(&global_flag_stru_p->lock);
>   	if (global_flag_stru_p->LcoreMainIsRunning == 0)	{
>   		cmdline_printf(cl,
>   					"lcore_main not running on core:%d\n",
> @@ -762,7 +762,7 @@ static void cmd_show_parsed(__rte_unused void *parsed_result,
>   		printf("\n");
>   	}
>   
> -	rte_spinlock_trylock(&global_flag_stru_p->lock);
> +	rte_spinlock_lock(&global_flag_stru_p->lock);
>   	cmdline_printf(cl,
>   			"Active_slaves:%d "
>   			"packets received:Tot:%d Arp:%d IPv4:%d\n",
>
  
David Marchand April 11, 2022, 11:25 a.m. UTC | #2
On Sun, Apr 10, 2022 at 3:53 PM Mattias Rönnblom
<mattias.ronnblom@ericsson.com> wrote:
>
> The conditional rte_spinlock_trylock() was used as if it is an
> unconditional lock operation in a number of places.
>
> Fixes: cc7e8ae84faa ("examples/bond: add example application for link bonding mode 6")
> Cc: michalx.k.jastrzebski@intel.com

Any reason not to ask for backport in stable branches?

>
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>

Otherwise, this series looks good, thanks Mattias.
  
Mattias Rönnblom April 11, 2022, 2:32 p.m. UTC | #3
On 2022-04-11 03:01, Min Hu (Connor) wrote:
> Acked-by: Min Hu (Connor) <humin29@huawei.com>
> 

Thanks.

It was pretty obvious that something was wrong with this example's use 
of the spinlock, but after the brief look I had it was a little less 
obvious if this patch would fix the problem or not.

> 在 2022/4/10 21:51, Mattias Rönnblom 写道:
>> The conditional rte_spinlock_trylock() was used as if it is an
>> unconditional lock operation in a number of places.
>>
>> Fixes: cc7e8ae84faa ("examples/bond: add example application for link 
>> bonding mode 6")
>> Cc: michalx.k.jastrzebski@intel.com
>>
>> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
>> ---
>>   examples/bond/main.c | 14 +++++++-------
>>   1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/examples/bond/main.c b/examples/bond/main.c
>> index 335bde5c8d..4efebb3902 100644
>> --- a/examples/bond/main.c
>> +++ b/examples/bond/main.c
>> @@ -373,7 +373,7 @@ static int lcore_main(__rte_unused void *arg1)
>>       bond_ip = BOND_IP_1 | (BOND_IP_2 << 8) |
>>                   (BOND_IP_3 << 16) | (BOND_IP_4 << 24);
>> -    rte_spinlock_trylock(&global_flag_stru_p->lock);
>> +    rte_spinlock_lock(&global_flag_stru_p->lock);
>>       while (global_flag_stru_p->LcoreMainIsRunning) {
>>           rte_spinlock_unlock(&global_flag_stru_p->lock);
>> @@ -456,7 +456,7 @@ static int lcore_main(__rte_unused void *arg1)
>>               if (is_free == 0)
>>                   rte_pktmbuf_free(pkts[i]);
>>           }
>> -        rte_spinlock_trylock(&global_flag_stru_p->lock);
>> +        rte_spinlock_lock(&global_flag_stru_p->lock);
>>       }
>>       rte_spinlock_unlock(&global_flag_stru_p->lock);
>>       printf("BYE lcore_main\n");
>> @@ -571,7 +571,7 @@ static void cmd_start_parsed(__rte_unused void 
>> *parsed_result,
>>   {
>>       int worker_core_id = rte_lcore_id();
>> -    rte_spinlock_trylock(&global_flag_stru_p->lock);
>> +    rte_spinlock_lock(&global_flag_stru_p->lock);
>>       if (global_flag_stru_p->LcoreMainIsRunning == 0) {
>>           if (rte_eal_get_lcore_state(global_flag_stru_p->LcoreMainCore)
>>               != WAIT) {
>> @@ -591,7 +591,7 @@ static void cmd_start_parsed(__rte_unused void 
>> *parsed_result,
>>       if ((worker_core_id >= RTE_MAX_LCORE) || (worker_core_id == 0))
>>           return;
>> -    rte_spinlock_trylock(&global_flag_stru_p->lock);
>> +    rte_spinlock_lock(&global_flag_stru_p->lock);
>>       global_flag_stru_p->LcoreMainIsRunning = 1;
>>       rte_spinlock_unlock(&global_flag_stru_p->lock);
>>       cmdline_printf(cl,
>> @@ -659,7 +659,7 @@ static void cmd_stop_parsed(__rte_unused void 
>> *parsed_result,
>>                   struct cmdline *cl,
>>                   __rte_unused void *data)
>>   {
>> -    rte_spinlock_trylock(&global_flag_stru_p->lock);
>> +    rte_spinlock_lock(&global_flag_stru_p->lock);
>>       if (global_flag_stru_p->LcoreMainIsRunning == 0)    {
>>           cmdline_printf(cl,
>>                       "lcore_main not running on core:%d\n",
>> @@ -700,7 +700,7 @@ static void cmd_quit_parsed(__rte_unused void 
>> *parsed_result,
>>                   struct cmdline *cl,
>>                   __rte_unused void *data)
>>   {
>> -    rte_spinlock_trylock(&global_flag_stru_p->lock);
>> +    rte_spinlock_lock(&global_flag_stru_p->lock);
>>       if (global_flag_stru_p->LcoreMainIsRunning == 0)    {
>>           cmdline_printf(cl,
>>                       "lcore_main not running on core:%d\n",
>> @@ -762,7 +762,7 @@ static void cmd_show_parsed(__rte_unused void 
>> *parsed_result,
>>           printf("\n");
>>       }
>> -    rte_spinlock_trylock(&global_flag_stru_p->lock);
>> +    rte_spinlock_lock(&global_flag_stru_p->lock);
>>       cmdline_printf(cl,
>>               "Active_slaves:%d "
>>               "packets received:Tot:%d Arp:%d IPv4:%d\n",
>>
  
Mattias Rönnblom April 11, 2022, 2:33 p.m. UTC | #4
On 2022-04-11 13:25, David Marchand wrote:
> On Sun, Apr 10, 2022 at 3:53 PM Mattias Rönnblom
> <mattias.ronnblom@ericsson.com> wrote:
>>
>> The conditional rte_spinlock_trylock() was used as if it is an
>> unconditional lock operation in a number of places.
>>
>> Fixes: cc7e8ae84faa ("examples/bond: add example application for link bonding mode 6")
>> Cc: michalx.k.jastrzebski@intel.com
> 
> Any reason not to ask for backport in stable branches?
> 

No. Will do.

>>
>> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
> 
> Otherwise, this series looks good, thanks Mattias.
> 
>
  

Patch

diff --git a/examples/bond/main.c b/examples/bond/main.c
index 335bde5c8d..4efebb3902 100644
--- a/examples/bond/main.c
+++ b/examples/bond/main.c
@@ -373,7 +373,7 @@  static int lcore_main(__rte_unused void *arg1)
 	bond_ip = BOND_IP_1 | (BOND_IP_2 << 8) |
 				(BOND_IP_3 << 16) | (BOND_IP_4 << 24);
 
-	rte_spinlock_trylock(&global_flag_stru_p->lock);
+	rte_spinlock_lock(&global_flag_stru_p->lock);
 
 	while (global_flag_stru_p->LcoreMainIsRunning) {
 		rte_spinlock_unlock(&global_flag_stru_p->lock);
@@ -456,7 +456,7 @@  static int lcore_main(__rte_unused void *arg1)
 			if (is_free == 0)
 				rte_pktmbuf_free(pkts[i]);
 		}
-		rte_spinlock_trylock(&global_flag_stru_p->lock);
+		rte_spinlock_lock(&global_flag_stru_p->lock);
 	}
 	rte_spinlock_unlock(&global_flag_stru_p->lock);
 	printf("BYE lcore_main\n");
@@ -571,7 +571,7 @@  static void cmd_start_parsed(__rte_unused void *parsed_result,
 {
 	int worker_core_id = rte_lcore_id();
 
-	rte_spinlock_trylock(&global_flag_stru_p->lock);
+	rte_spinlock_lock(&global_flag_stru_p->lock);
 	if (global_flag_stru_p->LcoreMainIsRunning == 0) {
 		if (rte_eal_get_lcore_state(global_flag_stru_p->LcoreMainCore)
 		    != WAIT) {
@@ -591,7 +591,7 @@  static void cmd_start_parsed(__rte_unused void *parsed_result,
 	if ((worker_core_id >= RTE_MAX_LCORE) || (worker_core_id == 0))
 		return;
 
-	rte_spinlock_trylock(&global_flag_stru_p->lock);
+	rte_spinlock_lock(&global_flag_stru_p->lock);
 	global_flag_stru_p->LcoreMainIsRunning = 1;
 	rte_spinlock_unlock(&global_flag_stru_p->lock);
 	cmdline_printf(cl,
@@ -659,7 +659,7 @@  static void cmd_stop_parsed(__rte_unused void *parsed_result,
 			    struct cmdline *cl,
 			    __rte_unused void *data)
 {
-	rte_spinlock_trylock(&global_flag_stru_p->lock);
+	rte_spinlock_lock(&global_flag_stru_p->lock);
 	if (global_flag_stru_p->LcoreMainIsRunning == 0)	{
 		cmdline_printf(cl,
 					"lcore_main not running on core:%d\n",
@@ -700,7 +700,7 @@  static void cmd_quit_parsed(__rte_unused void *parsed_result,
 			    struct cmdline *cl,
 			    __rte_unused void *data)
 {
-	rte_spinlock_trylock(&global_flag_stru_p->lock);
+	rte_spinlock_lock(&global_flag_stru_p->lock);
 	if (global_flag_stru_p->LcoreMainIsRunning == 0)	{
 		cmdline_printf(cl,
 					"lcore_main not running on core:%d\n",
@@ -762,7 +762,7 @@  static void cmd_show_parsed(__rte_unused void *parsed_result,
 		printf("\n");
 	}
 
-	rte_spinlock_trylock(&global_flag_stru_p->lock);
+	rte_spinlock_lock(&global_flag_stru_p->lock);
 	cmdline_printf(cl,
 			"Active_slaves:%d "
 			"packets received:Tot:%d Arp:%d IPv4:%d\n",