examples/qos_sched: fix negative loop bound
PATCH v3 1/1 examples/qos_sched: fix negative loop bound
From: Slawomir Mrozowicz <[email protected]>
Fix issue reported by Coverity.
Coverity ID 30704: Negative loop boundnegative_returns: Using unsigned variable n_tokens in a loop exit condition.
--- examples/qos_sched/args.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
examples/qos_sched/args.c +1 -1
@@ -162,7 +162,7 @@ static int app_parse_opt_vals(const char *conf_str, char separator, uint32_t n_vals, uint32_t *opt_vals) { char *string; -uint32_t i, n_tokens; +int i, n_tokens;char *tokens[MAX_OPT_VALUES ];if (conf_str ==NULL || opt_vals ==NULL || n_vals ==0 || n_vals >MAX_OPT_VALUES )
Signature · 1 line
1.9.1
PATCH v3 1/1 examples/qos_sched: fix copy-paste error
From: Slawomir Mrozowicz <[email protected]>
Fix issue reported by Coverity.
Coverity ID 30699: Copy-paste error;rx_port in pconf->rx_port looks like a copy-paste error.
--- examples/qos_sched/args.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
examples/qos_sched/args.c +1 -1
@@ -270,7 +270,7 @@ app_parse_flow_conf(const char *conf_str) }if (pconf->tx_port >=RTE_MAX_ETHPORTS ) {RTE_LOG (ERR ,APP ,"pfc %u: invalid tx port %" PRIu8" index\n" , - nb_pfc, pconf->rx_port); + nb_pfc, pconf->tx_port);return -1 ; }
Signature · 1 line
1.9.1
Re: [PATCH v3] examples/qos_sched: fix copy-paste error
Quoted 40 lines
-----Original Message-----
From: Jastrzebski, MichalX K
Sent: Thursday, April 21, 2016 2:08 PM
To: Dumitrescu, Cristian <[email protected]>; Zhang, Roy Fan <[email protected]>; Singh, Jasvinder <[email protected]>
Cc: [email protected]; Mrozowicz, SlawomirX <[email protected]>
Subject: [PATCH v3] examples/qos_sched: fix copy-paste errorFrom: Slawomir Mrozowicz <[email protected]>
Fix issue reported by Coverity.
Coverity ID 30699: Copy-paste error;
rx_portinpconf->rx_portlooks like a copy-paste error.Fixes de3cfa2c9823 ("sched: initial import")Signed-off-by Slawomir Mrozowicz <[email protected]>--- examples/qos_sched/args.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)examples/qos_sched/args.c +1
-2@@ -270,7 +270,7 @@ app_parse_flow_conf(const char *conf_str) }if (pconf->tx_port >=RTE_MAX_ETHPORTS ) {RTE_LOG (ERR ,APP ,"pfc %u: invalid tx port %" PRIu8" index\n", - nb_pfc, pconf->rx_port); + nb_pfc, pconf->tx_port);return -1 ; } --
Quoted 1 line
1.9.1
Thomas Monjalon
AppliedRe: [PATCH v3] examples/qos_sched: fix copy-paste error
copy-paste is the cause of this error.
The headline should show which error is fixed (or briefly its impact area).
Here: "fix error message"
Quoted 10 lines
Quoted 8 lines
Fix issue reported by Coverity.
Coverity ID 30699: Copy-paste error;
rx_portinpconf->rx_portlooks like a copy-paste error.Fixes de3cfa2c9823 ("sched: initial import")Signed-off-by Slawomir Mrozowicz <[email protected]>
Applied, thanks
PATCH v3 1/1 examples/qos_sched: fix bad bit shift operation
In reply to Michal JastrzebskiFrom: Slawomir Mrozowicz <[email protected]>
Fix issue reported by Coverity.
Coverity ID 30690: Bad bit shift operationlarge_shift: In expression 1ULL << i, left shifting by more than 63 bits has undefined behavior. The shift amount, i, is as much as 127.
--- examples/qos_sched/args.c | 84 +++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 32 deletions(-)
examples/qos_sched/args.c +52 -32
@@ -53,7 +53,7 @@static uint32_t app_master_core =1 ;static uint32_t app_numa_mask; -static uint64_t app_used_core_mask =0 ; +static int app_used_core_mask[RTE_MAX_LCORE ];static uint64_t app_used_port_mask =0 ;static uint64_t app_used_rx_port_mask =0 ;static uint64_t app_used_tx_port_mask =0 ;
@@ -115,22 +115,23 @@ static inline int str_is(const char *str, const char *is)return strcmp (str, is) ==0 ; } -/* returns core mask used by DPDK */ -static uint64_t -app_eal_core_mask (void ) +/* compare used core with eal configuration, +returns: +1 if equal +0 if differ */ +static int +app_eal_core_check (void ) { -uint32_t i; -uint64_t cm =0 ; +uint16_t i; +int ret =1 ;struct rte_config *cfg =rte_eal_get_configuration (); -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (cfg->lcore_role[i] ==ROLE_RTE ) - cm |= (1ULL << i); +for (i =0 ; i <RTE_MAX_LCORE && ret; i++) { +if ((cfg->lcore_role[i] ==ROLE_RTE ) != app_used_core_mask[i]) + ret =0 ; } - cm |= (1ULL << cfg->master_lcore); - -return cm; +return ret; }
@@ -292,14 +293,9 @@ app_parse_flow_conf(const char *conf_str) app_used_tx_port_mask |= mask; app_used_port_mask |= mask; - mask =1lu << pconf->rx_core; - app_used_core_mask |= mask; - - mask =1lu << pconf->wt_core; - app_used_core_mask |= mask; - - mask =1lu << pconf->tx_core; - app_used_core_mask |= mask; + app_used_core_mask[pconf->rx_core] =1 ; + app_used_core_mask[pconf->wt_core] =1 ; + app_used_core_mask[pconf->tx_core] =1 ; nb_pfc++;
@@ -335,7 +331,7 @@ app_parse_args(int argc, char **argv)int option_index;const char *optname;char *prgname = argv[0 ]; -uint32_t i, nb_lcores; +uint16_t i, j, k, nb_lcores;static struct option lgopts[] = { {"pfc" ,1 ,0 ,0 },
@@ -349,6 +345,9 @@ app_parse_args(int argc, char **argv) { NULL, 0, 0, 0 } }; +for (i =0 ; i <RTE_MAX_LCORE ; i++) + app_used_core_mask[i] =0 ; +/* initialize EAL first */ ret =rte_eal_init (argc, argv);if (ret <0 )
@@ -436,19 +435,40 @@ app_parse_args(int argc, char **argv) }/* check master core index validity */ -for (i =0 ; i <= app_master_core; i++) { -if (app_used_core_mask & (1u << app_master_core)) { -RTE_LOG (ERR ,APP ,"Master core index is not configured properly\n" ); -app_usage (prgname); -return -1 ; - } +if (app_used_core_mask[app_master_core] ==1 ) { +RTE_LOG (ERR ,APP , +"Master core index is not configured properly\n" ); +app_usage (prgname); +return -1 ; } - app_used_core_mask |=1u << app_master_core; + app_used_core_mask[app_master_core] =1 ; + +if ((app_eal_core_check () ==0 ) || + (app_master_core !=rte_get_master_lcore ())) { + +char used_hexstr[RTE_MAX_LCORE /4 +1 ]; +char conf_hexstr[RTE_MAX_LCORE /4 +1 ]; +int used_byte, conf_byte; +struct rte_config *cfg =rte_eal_get_configuration (); + +for (i =0 ; i <RTE_MAX_LCORE /4 ; i++) { + used_byte =0 ; + conf_byte =0 ; +for (j =0 ; j <3 ; j++) { + k =4 * (RTE_MAX_LCORE /4 - i -1 ) + j; + used_byte += app_used_core_mask[k] << j; + conf_byte += + ((cfg->lcore_role[k] == +ROLE_RTE )?1 :0 ) << j; + } +sprintf (&used_hexstr[i],"%1x" , used_byte); +sprintf (&conf_hexstr[i],"%1x" , used_byte); + } + +RTE_LOG (ERR ,APP ,"EAL core mask not configured properly\n" ); +RTE_LOG (ERR ,APP ," must be : %s\n" , used_hexstr); +RTE_LOG (ERR ,APP ," instead of: %s\n" , conf_hexstr); -if ((app_used_core_mask !=app_eal_core_mask ()) || - (app_master_core !=rte_get_master_lcore ())) { -RTE_LOG (ERR ,APP ,"EAL core mask not configured properly, must be %" PRIx64 -" instead of %" PRIx64"\n" , app_used_core_mask,app_eal_core_mask ());return -1 ; }
Signature · 1 line
1.9.1
Re: [PATCH v3] examples/qos_sched: fix bad bit shift operation
Quoted 170 lines
-----Original Message-----
From: Jastrzebski, MichalX K
Sent: Thursday, April 21, 2016 2:08 PM
To: Dumitrescu, Cristian <[email protected]>; Zhang, Roy Fan <[email protected]>; Singh, Jasvinder <[email protected]>
Cc: [email protected]; Mrozowicz, SlawomirX <[email protected]>
Subject: [PATCH v3] examples/qos_sched: fix bad bit shift operationFrom: Slawomir Mrozowicz <[email protected]>
Fix issue reported by Coverity.
Coverity ID 30690: Bad bit shift operation
large_shift: In expression 1ULL << i, left shifting by more than 63 bits has undefined behavior. The shift amount, i, is as much as 127.Fixes de3cfa2c9823 ("sched: initial import")Signed-off-by Slawomir Mrozowicz <[email protected]>--- examples/qos_sched/args.c | 84 +++++++++++++++++++++++++++++------ ------------ 1 file changed, 52 insertions(+), 32 deletions(-)examples/qos_sched/args.c +52
-31@@ -53,7 +53,7 @@static uint32_t app_master_core =1 ;static uint32_t app_numa_mask; -static uint64_t app_used_core_mask =0 ; +static int app_used_core_mask[RTE_MAX_LCORE ];static uint64_t app_used_port_mask =0 ;static uint64_t app_used_rx_port_mask =0 ;static uint64_t app_used_tx_port_mask =0 ;@@ -115,22 +115,23 @@ static inline int str_is(const char *str, const char *is)return strcmp (str, is) ==0 ; } -/* returns core mask used by DPDK */ -static uint64_t -app_eal_core_mask (void ) +/* compare used core with eal configuration, +returns: +1 if equal +0 if differ */ +static int +app_eal_core_check (void ) { -uint32_t i; -uint64_t cm =0 ; +uint16_t i; +int ret =1 ;struct rte_config *cfg =rte_eal_get_configuration (); -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (cfg->lcore_role[i] ==ROLE_RTE ) - cm |= (1ULL << i); +for (i =0 ; i <RTE_MAX_LCORE && ret; i++) { +if ((cfg->lcore_role[i] ==ROLE_RTE ) != app_used_core_mask[i]) + ret =0 ; } - cm |= (1ULL << cfg->master_lcore); - -return cm; +return ret; }@@ -292,14 +293,9 @@ app_parse_flow_conf(const char *conf_str) app_used_tx_port_mask |= mask; app_used_port_mask |= mask; - mask =1lu << pconf->rx_core; - app_used_core_mask |= mask; - - mask =1lu << pconf->wt_core; - app_used_core_mask |= mask; - - mask =1lu << pconf->tx_core; - app_used_core_mask |= mask; + app_used_core_mask[pconf->rx_core] =1 ; + app_used_core_mask[pconf->wt_core] =1 ; + app_used_core_mask[pconf->tx_core] =1 ; nb_pfc++;@@ -335,7 +331,7 @@ app_parse_args(int argc, char **argv)int option_index;const char *optname;char *prgname = argv[0 ]; -uint32_t i, nb_lcores; +uint16_t i, j, k, nb_lcores;static struct option lgopts[] = { {"pfc" ,1 ,0 ,0 },@@ -349,6 +345,9 @@ app_parse_args(int argc, char **argv) { NULL, 0, 0, 0 } }; +for (i =0 ; i <RTE_MAX_LCORE ; i++) + app_used_core_mask[i] =0 ; +/* initialize EAL first */ ret =rte_eal_init (argc, argv);if (ret <0 )@@ -436,19 +435,40 @@ app_parse_args(int argc, char **argv) }/* check master core index validity */ -for (i =0 ; i <= app_master_core; i++) { -if (app_used_core_mask & (1u << app_master_core)) { - RTE_LOG(ERR, APP, "Master core index is not configured properly\n"); - app_usage(prgname); -return -1 ; - } +if (app_used_core_mask[app_master_core] ==1 ) { +RTE_LOG (ERR ,APP , +"Master core index is not configured properly\n" ); +app_usage (prgname); +return -1 ; } - app_used_core_mask |=1u << app_master_core; + app_used_core_mask[app_master_core] =1 ; + +if ((app_eal_core_check () ==0 ) || + (app_master_core !=rte_get_master_lcore ())) { + +char used_hexstr[RTE_MAX_LCORE /4 +1 ]; +char conf_hexstr[RTE_MAX_LCORE /4 +1 ]; +int used_byte, conf_byte; +struct rte_config *cfg =rte_eal_get_configuration (); + +for (i =0 ; i <RTE_MAX_LCORE /4 ; i++) { + used_byte =0 ; + conf_byte =0 ; +for (j =0 ; j <3 ; j++) { + k =4 * (RTE_MAX_LCORE /4 - i -1 ) + j; + used_byte += app_used_core_mask[k] << j; + conf_byte += + ((cfg->lcore_role[k] == +ROLE_RTE )?1 :0 ) << j; + } +sprintf (&used_hexstr[i],"%1x" , used_byte); +sprintf (&conf_hexstr[i],"%1x" , used_byte); + } + +RTE_LOG (ERR ,APP ,"EAL core mask not configured properly\n"); +RTE_LOG (ERR ,APP ," must be : %s\n" , used_hexstr); +RTE_LOG (ERR ,APP ," instead of: %s\n" , conf_hexstr); - if ((app_used_core_mask !=app_eal_core_mask ()) || - (app_master_core != rte_get_master_lcore())) { - RTE_LOG(ERR, APP, "EAL core mask not configured properly,must be %" PRIx64
examples/qos_sched/args.c +0
-1- " instead of %" PRIx64 "\n" ,
app_used_core_mask,app_eal_core_mask());examples/qos_sched/args.c +0
-1return -1 ; } --
Quoted 1 line
1.9.1
Can you please explain the root issue?
This patch contains way too much code for fixing a shift overflow issue, it is basically a rework without explaining the issue or reason/benefit for the rework.
This approach does not look right to me, I am sure there is a better and quicker way to fix the potential issue once we all understand it.
Re: [PATCH v3] examples/qos_sched: fix bad bit shift operation
Quoted 44 lines
-----Original Message-----
From: Dumitrescu, Cristian
Sent: Thursday, April 28, 2016 1:16 PM
To: Jastrzebski, MichalX K <[email protected]>; Zhang, Roy Fan <[email protected]>; Singh, Jasvinder <[email protected]>
Cc: [email protected]; Mrozowicz, SlawomirX <[email protected]>
Subject: RE: [PATCH v3] examples/qos_sched: fix bad bit shift operationQuoted 7 lines
-----Original Message-----
From: Jastrzebski, MichalX K
Sent: Thursday, April 21, 2016 2:08 PM
To: Dumitrescu, Cristian <[email protected]>; Zhang, Roy Fan <[email protected]>; Singh, Jasvinder <[email protected]>
Cc: [email protected]; Mrozowicz, SlawomirXQuoted 10 lines
Subject: [PATCH v3] examples/qos_sched: fix bad bit shift operation
From: Slawomir Mrozowicz <[email protected]>
Fix issue reported by Coverity.
Coverity ID 30690: Bad bit shift operation
large_shift: In expression 1ULL << i, left shifting by more than 63 bits has undefined behavior. The shift amount, i, is as much as 127.Quoted 5 lines
Fixes de3cfa2c9823 ("sched: initial import")Signed-off-by Slawomir Mrozowicz <[email protected]>--- examples/qos_sched/args.c | 84 +++++++++++++++++++++++++++++------
Quoted 9 lines
------------
1 file changed, 52 insertions(+), 32 deletions(-)examples/qos_sched/args.c +0
-0@@ -53,7 +53,7 @@
Quoted 4 lines
examples/qos_sched/args.c line 56
Quoted 4 lines
examples/qos_sched/args.c +1
-1static uint32_t app_master_core =1 ;static uint32_t app_numa_mask; -static uint64_t app_used_core_mask =0 ; +static int app_used_core_mask[RTE_MAX_LCORE ];
Changed type of the app_used_core_mask variable to store up to RTE_MAX_LCORE cores information.
Quoted 32 lines
examples/qos_sched/args.c static inline int str_is(const char *str, const char
Quoted 3 lines
examples/qos_sched/args.c +0
-0static uint64_t app_used_port_mask =0 ;static uint64_t app_used_rx_port_mask =0 ;static uint64_t app_used_tx_port_mask =0 ;@@ -115,22 +115,23 @@ static inline int str_is(const char *str, const char*is)
Quoted 28 lines
examples/qos_sched/args.c +11
-8return strcmp (str, is) ==0 ; } -/* returns core mask used by DPDK */ -static uint64_t -app_eal_core_mask (void ) +/* compare used core with eal configuration, +returns: +1 if equal +0 if differ */ +static int +app_eal_core_check (void ) { -uint32_t i; -uint64_t cm =0 ; +uint16_t i; +int ret =1 ;struct rte_config *cfg =rte_eal_get_configuration (); -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (cfg->lcore_role[i] ==ROLE_RTE ) - cm |= (1ULL << i); +for (i =0 ; i <RTE_MAX_LCORE && ret; i++) { +if ((cfg->lcore_role[i] ==ROLE_RTE ) != app_used_core_mask[i]) + ret =0 ; }
Quoted 6 lines
examples/qos_sched/args.c static inline int str_is(const char *str, const char *is) · line 136
Quoted 6 lines
examples/qos_sched/args.c +1
-3- cm |= (1ULL << cfg->master_lcore); - -return cm; +return ret; }
Added tool function app_eal_core_check() to check compatibility used cores with information stored in configuration file. The function is used below. Removed not used function app_eal_core_mask()
Quoted 5 lines
Quoted 5 lines
examples/qos_sched/args.c +0
-0@@ -292,14 +293,9 @@ app_parse_flow_conf(const char *conf_str) app_used_tx_port_mask |= mask; app_used_port_mask |= mask;
Quoted 12 lines
examples/qos_sched/args.c app_parse_flow_conf(const char *conf_str) · line 299
Quoted 12 lines
examples/qos_sched/args.c +3
-8- mask =1lu << pconf->rx_core; - app_used_core_mask |= mask; - - mask =1lu << pconf->wt_core; - app_used_core_mask |= mask; - - mask =1lu << pconf->tx_core; - app_used_core_mask |= mask; + app_used_core_mask[pconf->rx_core] =1 ; + app_used_core_mask[pconf->wt_core] =1 ; + app_used_core_mask[pconf->tx_core] =1 ;
Change method of set the mask on each used core according to change mask type.
Quoted 15 lines
Quoted 15 lines
examples/qos_sched/args.c +1
-1nb_pfc++;@@ -335,7 +331,7 @@ app_parse_args(int argc, char **argv)int option_index;const char *optname;char *prgname = argv[0 ]; -uint32_t i, nb_lcores; +uint16_t i, j, k, nb_lcores;static struct option lgopts[] = { {"pfc" ,1 ,0 ,0 },@@ -349,6 +345,9 @@ app_parse_args(int argc, char **argv) { NULL, 0, 0, 0 } };
Quoted 3 lines
examples/qos_sched/args.c app_parse_args(int argc, char **argv) · line 350
Quoted 3 lines
examples/qos_sched/args.c +3
-0+for (i =0 ; i <RTE_MAX_LCORE ; i++) + app_used_core_mask[i] =0 ; +
Set initial value of the mask.
Quoted 6 lines
Quoted 6 lines
examples/qos_sched/args.c +0
-0/* initialize EAL first */ ret =rte_eal_init (argc, argv);if (ret <0 )@@ -436,19 +435,40 @@ app_parse_args(int argc, char **argv) }
Quoted 14 lines
Quoted 4 lines
examples/qos_sched/args.c +0
-3/* check master core index validity */ -for (i =0 ; i <= app_master_core; i++) { -if (app_used_core_mask & (1u << app_master_core)) { - RTE_LOG(ERR, APP, "Master core index is notexamples/qos_sched/args.c app_parse_args(int argc, char **argv) · line 443
Quoted 10 lines
examples/qos_sched/args.c +5
-3configured properly\n"); -app_usage (prgname); -return -1 ; - } +if (app_used_core_mask[app_master_core] ==1 ) { +RTE_LOG (ERR ,APP , +"Master core index is not configured properly\n" ); +app_usage (prgname); +return -1 ; }
Changed method of checking if mask is present on master core.
Quoted 3 lines
examples/qos_sched/args.c app_parse_args(int argc, char **argv) · line 445
Quoted 3 lines
examples/qos_sched/args.c +2
-1- app_used_core_mask |=1u << app_master_core; + app_used_core_mask[app_master_core] =1 ; +
Changed method of set master core in mask.
Quoted 27 lines
Quoted 27 lines
examples/qos_sched/args.c +25
-0+if ((app_eal_core_check () ==0 ) || + (app_master_core !=rte_get_master_lcore ())) { + +char used_hexstr[RTE_MAX_LCORE /4 +1 ]; +char conf_hexstr[RTE_MAX_LCORE /4 +1 ]; +int used_byte, conf_byte; +struct rte_config *cfg =rte_eal_get_configuration (); + +for (i =0 ; i <RTE_MAX_LCORE /4 ; i++) { + used_byte =0 ; + conf_byte =0 ; +for (j =0 ; j <3 ; j++) { + k =4 * (RTE_MAX_LCORE /4 - i -1 ) + j; + used_byte += app_used_core_mask[k] << j; + conf_byte += + ((cfg->lcore_role[k] == +ROLE_RTE )?1 :0 ) << j; + } +sprintf (&used_hexstr[i],"%1x" , used_byte); +sprintf (&conf_hexstr[i],"%1x" , used_byte); + } + +RTE_LOG (ERR ,APP ,"EAL core mask not configured properly\n"); +RTE_LOG (ERR ,APP ," must be : %s\n" , used_hexstr); +RTE_LOG (ERR ,APP ," instead of: %s\n" , conf_hexstr);
Quoted 9 lines
examples/qos_sched/args.c app_parse_args(int argc, char **argv) · line 473
Quoted 9 lines
examples/qos_sched/args.c +0
-3-if ((app_used_core_mask !=app_eal_core_mask ()) || - (app_master_core !=rte_get_master_lcore ())) { - RTE_LOG(ERR, APP, "EAL core mask not configured properly,must be %" PRIx64
examples/qos_sched/args.c +0
-1- " instead of %" PRIx64 "\n" ,
app_used_core_mask,app_eal_core_mask());examples/qos_sched/args.c +0
-0return -1 ; }
Changed method of checking compatibility used cores with information stored in configuration file (the if statement). Extended information about wrong eal configuration to be more readable for the user (body of the true branch).
Quoted 4 lines
Quoted 2 lines
--
1.9.1
Quoted 9 lines
Can you please explain the root issue?
This patch contains way too much code for fixing a shift overflow issue, it is basically a rework without explaining the issue or reason/benefit for the rework.
This approach does not look right to me, I am sure there is a better and quicker way to fix the potential issue once we all understand it.
Hi Cristian
The original problem reported in the Coverity happened in reality if there are used more then 64 lcores. I think we should fix it.
Maximum possible value of lcores is 128 according to RTE_MAX_LCORE definition in configuration file. The problem happened because mask of the used lcores is stored in 64 bits.
Exactly the variable app_used_core_mask has uint64_t type.
To solve this problem I extended type of the variable app_used_core_mask to array size RTE_MAX_LCORE. In this case I should change all places where the variable was used. It is reason why I changed so much code. Detail description you can find inside the code above.
Best Regards,
Sławomir
Re: [PATCH v3] examples/qos_sched: fix bad bit shift operation
Quoted 247 lines
-----Original Message-----
From: Mrozowicz, SlawomirX
Sent: Tuesday, May 10, 2016 10:40 AM
To: Dumitrescu, Cristian <[email protected]>; Jastrzebski, MichalX K <[email protected]>; Zhang, Roy Fan <[email protected]>; Singh, Jasvinder <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v3] examples/qos_sched: fix bad bit shift operationQuoted 4 lines
-----Original Message-----
From: Dumitrescu, Cristian
Sent: Thursday, April 28, 2016 1:16 PM
To: Jastrzebski, MichalX K <[email protected]>; Zhang, RoyFan
Quoted 2 lines
<[email protected]>; Singh, Jasvinder <[email protected]>
Cc: [email protected]; Mrozowicz, SlawomirXQuoted 4 lines
Subject: RE: [PATCH v3] examples/qos_sched: fix bad bit shift operation
Quoted 23 lines
Quoted 7 lines
-----Original Message-----
From: Jastrzebski, MichalX K
Sent: Thursday, April 21, 2016 2:08 PM
To: Dumitrescu, Cristian <[email protected]>; Zhang, Roy Fan <[email protected]>; Singh, Jasvinder <[email protected]>
Cc: [email protected]; Mrozowicz, SlawomirXQuoted 15 lines
Subject: [PATCH v3] examples/qos_sched: fix bad bit shift operation
From: Slawomir Mrozowicz <[email protected]>
Fix issue reported by Coverity.
Coverity ID 30690: Bad bit shift operation
large_shift: In expression 1ULL << i, left shifting by more than 63 bits has undefined behavior. The shift amount, i, is as much as 127.Fixes de3cfa2c9823 ("sched: initial import")Signed-off-by Slawomir Mrozowicz <[email protected]>--- examples/qos_sched/args.c | 84 +++++++++++++++++++++++++++++-----
Quoted 10 lines
-
Quoted 9 lines
------------
1 file changed, 52 insertions(+), 32 deletions(-)examples/qos_sched/args.c +0
-0@@ -53,7 +53,7 @@Quoted 4 lines
examples/qos_sched/args.c line 56
Quoted 4 lines
examples/qos_sched/args.c +1
-1static uint32_t app_master_core =1 ;static uint32_t app_numa_mask; -static uint64_t app_used_core_mask =0 ; +static int app_used_core_mask[RTE_MAX_LCORE ];Changed type of the
app_used_core_maskvariable to store up toRTE_MAX_LCOREcores information.Quoted 2 lines
Quoted 2 lines
examples/qos_sched/args.c +0
-0static uint64_t app_used_port_mask = 0; static uint64_t
app_used_rx_port_mask= 0; staticuint64_tapp_used_tx_port_mask=0;
Quoted 30 lines
examples/qos_sched/args.c static inline int str_is(const char *str, const char
Quoted 1 line
examples/qos_sched/args.c +0
-0@@ -115,22 +115,23 @@ static inline int str_is(const char *str, const char*is)
Quoted 28 lines
examples/qos_sched/args.c +11
-8return strcmp (str, is) ==0 ; } -/* returns core mask used by DPDK */ -static uint64_t -app_eal_core_mask (void ) +/* compare used core with eal configuration, +returns: +1 if equal +0 if differ */ +static int +app_eal_core_check (void ) { -uint32_t i; -uint64_t cm =0 ; +uint16_t i; +int ret =1 ;struct rte_config *cfg =rte_eal_get_configuration (); -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (cfg->lcore_role[i] ==ROLE_RTE ) - cm |= (1ULL << i); +for (i =0 ; i <RTE_MAX_LCORE && ret; i++) { +if ((cfg->lcore_role[i] ==ROLE_RTE ) != app_used_core_mask[i]) + ret =0 ; }Quoted 6 lines
examples/qos_sched/args.c static inline int str_is(const char *str, const char *is) · line 136
Quoted 6 lines
examples/qos_sched/args.c +1
-3- cm |= (1ULL << cfg->master_lcore); - -return cm; +return ret; }Added tool function
app_eal_core_check()to check compatibility used cores with information stored in configuration file. The function is used below. Removed not used functionapp_eal_core_mask()Quoted 5 lines
Quoted 5 lines
examples/qos_sched/args.c +0
-0@@ -292,14 +293,9 @@ app_parse_flow_conf(const char *conf_str) app_used_tx_port_mask |= mask; app_used_port_mask |= mask;Quoted 12 lines
examples/qos_sched/args.c app_parse_flow_conf(const char *conf_str) · line 299
Quoted 12 lines
examples/qos_sched/args.c +3
-8- mask =1lu << pconf->rx_core; - app_used_core_mask |= mask; - - mask =1lu << pconf->wt_core; - app_used_core_mask |= mask; - - mask =1lu << pconf->tx_core; - app_used_core_mask |= mask; + app_used_core_mask[pconf->rx_core] =1 ; + app_used_core_mask[pconf->wt_core] =1 ; + app_used_core_mask[pconf->tx_core] =1 ;Change method of set the mask on each used core according to change mask type.
Quoted 15 lines
Quoted 15 lines
examples/qos_sched/args.c +1
-1nb_pfc++;@@ -335,7 +331,7 @@ app_parse_args(int argc, char **argv)int option_index;const char *optname;char *prgname = argv[0 ]; -uint32_t i, nb_lcores; +uint16_t i, j, k, nb_lcores;static struct option lgopts[] = { {"pfc" ,1 ,0 ,0 },@@ -349,6 +345,9 @@ app_parse_args(int argc, char **argv) { NULL, 0, 0, 0 } };Quoted 3 lines
examples/qos_sched/args.c app_parse_args(int argc, char **argv) · line 350
Quoted 3 lines
examples/qos_sched/args.c +3
-0+for (i =0 ; i <RTE_MAX_LCORE ; i++) + app_used_core_mask[i] =0 ; +Set initial value of the mask.
Quoted 6 lines
Quoted 6 lines
examples/qos_sched/args.c +0
-0/* initialize EAL first */ ret =rte_eal_init (argc, argv);if (ret <0 )@@ -436,19 +435,40 @@ app_parse_args(int argc, char **argv) }Quoted 14 lines
Quoted 4 lines
examples/qos_sched/args.c +0
-3/* check master core index validity */ -for (i =0 ; i <= app_master_core; i++) { -if (app_used_core_mask & (1u << app_master_core)) { - RTE_LOG(ERR, APP, "Master core index is notexamples/qos_sched/args.c app_parse_args(int argc, char **argv) · line 443
Quoted 10 lines
examples/qos_sched/args.c +5
-3configured properly\n"); -app_usage (prgname); -return -1 ; - } +if (app_used_core_mask[app_master_core] ==1 ) { +RTE_LOG (ERR ,APP , +"Master core index is not configured properly\n" ); +app_usage (prgname); +return -1 ; }Changed method of checking if mask is present on master core.
Quoted 3 lines
examples/qos_sched/args.c app_parse_args(int argc, char **argv) · line 445
Quoted 3 lines
examples/qos_sched/args.c +2
-1- app_used_core_mask |=1u << app_master_core; + app_used_core_mask[app_master_core] =1 ; +Changed method of set master core in mask.
Quoted 27 lines
Quoted 27 lines
examples/qos_sched/args.c +25
-0+if ((app_eal_core_check () ==0 ) || + (app_master_core !=rte_get_master_lcore ())) { + +char used_hexstr[RTE_MAX_LCORE /4 +1 ]; +char conf_hexstr[RTE_MAX_LCORE /4 +1 ]; +int used_byte, conf_byte; +struct rte_config *cfg =rte_eal_get_configuration (); + +for (i =0 ; i <RTE_MAX_LCORE /4 ; i++) { + used_byte =0 ; + conf_byte =0 ; +for (j =0 ; j <3 ; j++) { + k =4 * (RTE_MAX_LCORE /4 - i -1 ) + j; + used_byte += app_used_core_mask[k] << j; + conf_byte += + ((cfg->lcore_role[k] == +ROLE_RTE )?1 :0 ) << j; + } +sprintf (&used_hexstr[i],"%1x" , used_byte); +sprintf (&conf_hexstr[i],"%1x" , used_byte); + } + +RTE_LOG (ERR ,APP ,"EAL core mask not configured properly\n"); +RTE_LOG (ERR ,APP ," must be : %s\n" , used_hexstr); +RTE_LOG (ERR ,APP ," instead of: %s\n" , conf_hexstr);Quoted 9 lines
examples/qos_sched/args.c app_parse_args(int argc, char **argv) · line 473
Quoted 9 lines
examples/qos_sched/args.c +0
-3-if ((app_used_core_mask !=app_eal_core_mask ()) || - (app_master_core !=rte_get_master_lcore ())) { - RTE_LOG(ERR, APP, "EAL core mask not configured properly,must be %" PRIx64
examples/qos_sched/args.c +0
-1- " instead of %" PRIx64 "\n" ,
app_used_core_mask,app_eal_core_mask());examples/qos_sched/args.c +0
-0return -1 ; }Changed method of checking compatibility used cores with information stored in configuration file (the if statement).
Extended information about wrong eal configuration to be more readable for the user (body of the true branch).Quoted 4 lines
Quoted 2 lines
--
1.9.1Quoted 9 lines
Can you please explain the root issue?
This patch contains way too much code for fixing a shift overflow issue, it is basically a rework without explaining the issue or reason/benefit for the rework.
This approach does not look right to me, I am sure there is a better and quicker way to fix the potential issue once we all understand it.
Hi Cristian
The original problem reported in the Coverity happened in reality if there are used more then 64 lcores. I think we should fix it.
Maximum possible value of lcores is 128 according to
RTE_MAX_LCOREdefinition in configuration file.
The problem happened because mask of the used lcores is stored in 64 bits. Exactly the variableapp_used_core_maskhasuint64_ttype.
Quoted 11 lines
To solve this problem I extended type of the variable
app_used_core_maskto array sizeRTE_MAX_LCORE.
In this case I should change all places where the variable was used. It is reason why I changed so much code.
Detail description you can find inside the code above.Best Regards,
Sławomir
This is a false problem, as we will never use more than 64 lcores with this application. The typical number of lcores used with this app is 3 or 6, with 12 as the absolute maximum when 4 x 3 lcores are used to handle 4 x 10GbE ports.
The fix you are looking for is a quick and straightforward way to limit the max number of lcores use d by this app to 64. Can you look for this type of solution, please?
Thanks,
Cristian
Quoted 38 lines
-----Original Message-----
From: Jastrzebski, MichalX K
Sent: Thursday, April 21, 2016 2:08 PM
To: Dumitrescu, Cristian <[email protected]>; Zhang, Roy Fan <[email protected]>; Singh, Jasvinder <[email protected]>
Cc: [email protected]; Mrozowicz, SlawomirX <[email protected]>
Subject: [PATCH v3] examples/qos_sched: fix negative loop boundFrom: Slawomir Mrozowicz <[email protected]>
Fix issue reported by Coverity.
Coverity ID 30704: Negative loop bound
negative_returns: Using unsigned variablen_tokensin a loop exit condition.Fixes de3cfa2c9823 ("sched: initial import")Signed-off-by Slawomir Mrozowicz <[email protected]>--- examples/qos_sched/args.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)examples/qos_sched/args.c +1
-1@@ -162,7 +162,7 @@ static int app_parse_opt_vals(const char *conf_str, char separator, uint32_t n_vals, uint32_t *opt_vals) { char *string; -uint32_t i, n_tokens; +int i, n_tokens;char *tokens[MAX_OPT_VALUES ];
Quoted 4 lines
if (
conf_str== NULL ||opt_vals== NULL ||n_vals== 0 ||n_vals>MAX_OPT_VALUES)
--
1.9.1
Quoted 10 lines
Quoted 8 lines
Fix issue reported by Coverity.
Coverity ID 30704: Negative loop bound
negative_returns: Using unsigned variablen_tokensin a loop exit condition.Fixes de3cfa2c9823 ("sched: initial import")Signed-off-by Slawomir Mrozowicz <[email protected]>
There is no explanation but as it is acked and not so important, Applied