event/dlb2: fix invalid shift value

Message ID 1646233928-4124603-1-git-send-email-timothy.mcdaniel@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers
Series event/dlb2: fix invalid shift value |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
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/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Timothy McDaniel March 2, 2022, 3:12 p.m. UTC
  Add a check to ensure that all shift counts are valid.
Shifting by more than 63 bits may result in undefined behavior, as
noted during coverity scan.

Fixes: e697f35dbdd1 ("event/dlb2: update rolling mask used for dequeue")
Coverity issue: 376527

Signed-off-by: Timothy McDaniel <timothy.mcdaniel@intel.com>
---
 drivers/event/dlb2/dlb2.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
  

Comments

Jerin Jacob March 3, 2022, 9:25 a.m. UTC | #1
On Wed, Mar 2, 2022 at 8:42 PM Timothy McDaniel
<timothy.mcdaniel@intel.com> wrote:
>
> Add a check to ensure that all shift counts are valid.
> Shifting by more than 63 bits may result in undefined behavior, as
> noted during coverity scan.
>
> Fixes: e697f35dbdd1 ("event/dlb2: update rolling mask used for dequeue")
> Coverity issue: 376527


Applied to dpdk-next-net-eventdev/for-main. Thanks


> Signed-off-by: Timothy McDaniel <timothy.mcdaniel@intel.com>
> ---
>  drivers/event/dlb2/dlb2.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/event/dlb2/dlb2.c b/drivers/event/dlb2/dlb2.c
> index 09abdd1660..7789dd74e0 100644
> --- a/drivers/event/dlb2/dlb2.c
> +++ b/drivers/event/dlb2/dlb2.c
> @@ -3916,15 +3916,17 @@ dlb2_hw_dequeue_sparse(struct dlb2_eventdev *dlb2,
>                                                                 &events[num],
>                                                                 &qes[0],
>                                                                 num_avail);
> -                       num += n_iter;
> -                       /* update rolling_mask for vector code support */
> -                       m_rshift = qm_port->cq_rolling_mask >> n_iter;
> -                       m_lshift = qm_port->cq_rolling_mask << (64 - n_iter);
> -                       m2_rshift = qm_port->cq_rolling_mask_2 >> n_iter;
> -                       m2_lshift = qm_port->cq_rolling_mask_2 <<
> +                       if (n_iter != 0) {
> +                               num += n_iter;
> +                               /* update rolling_mask for vector code support */
> +                               m_rshift = qm_port->cq_rolling_mask >> n_iter;
> +                               m_lshift = qm_port->cq_rolling_mask << (64 - n_iter);
> +                               m2_rshift = qm_port->cq_rolling_mask_2 >> n_iter;
> +                               m2_lshift = qm_port->cq_rolling_mask_2 <<
>                                         (64 - n_iter);
> -                       qm_port->cq_rolling_mask = (m_rshift | m2_lshift);
> -                       qm_port->cq_rolling_mask_2 = (m2_rshift | m_lshift);
> +                               qm_port->cq_rolling_mask = (m_rshift | m2_lshift);
> +                               qm_port->cq_rolling_mask_2 = (m2_rshift | m_lshift);
> +                       }
>                 } else { /* !use_scalar */
>                         num_avail = dlb2_recv_qe_sparse_vec(qm_port,
>                                                             &events[num],
> --
> 2.25.1
>
  

Patch

diff --git a/drivers/event/dlb2/dlb2.c b/drivers/event/dlb2/dlb2.c
index 09abdd1660..7789dd74e0 100644
--- a/drivers/event/dlb2/dlb2.c
+++ b/drivers/event/dlb2/dlb2.c
@@ -3916,15 +3916,17 @@  dlb2_hw_dequeue_sparse(struct dlb2_eventdev *dlb2,
 								&events[num],
 								&qes[0],
 								num_avail);
-			num += n_iter;
-			/* update rolling_mask for vector code support */
-			m_rshift = qm_port->cq_rolling_mask >> n_iter;
-			m_lshift = qm_port->cq_rolling_mask << (64 - n_iter);
-			m2_rshift = qm_port->cq_rolling_mask_2 >> n_iter;
-			m2_lshift = qm_port->cq_rolling_mask_2 <<
+			if (n_iter != 0) {
+				num += n_iter;
+				/* update rolling_mask for vector code support */
+				m_rshift = qm_port->cq_rolling_mask >> n_iter;
+				m_lshift = qm_port->cq_rolling_mask << (64 - n_iter);
+				m2_rshift = qm_port->cq_rolling_mask_2 >> n_iter;
+				m2_lshift = qm_port->cq_rolling_mask_2 <<
 					(64 - n_iter);
-			qm_port->cq_rolling_mask = (m_rshift | m2_lshift);
-			qm_port->cq_rolling_mask_2 = (m2_rshift | m_lshift);
+				qm_port->cq_rolling_mask = (m_rshift | m2_lshift);
+				qm_port->cq_rolling_mask_2 = (m2_rshift | m_lshift);
+			}
 		} else { /* !use_scalar */
 			num_avail = dlb2_recv_qe_sparse_vec(qm_port,
 							    &events[num],