From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8FFA0A00C3 for ; Fri, 15 May 2020 10:14:09 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5A8FF1DA84; Fri, 15 May 2020 10:14:09 +0200 (CEST) Received: from git-send-mailer.rdmz.labs.mlnx (unknown [37.142.13.130]) by dpdk.org (Postfix) with ESMTP id 214951DA7C; Fri, 15 May 2020 10:14:07 +0200 (CEST) From: Bing Zhao To: viacheslavo@mellanox.com, rasland@mellanox.com Cc: orika@mellanox.com, matan@mellanox.com, dev@dpdk.org, stable@dpdk.org, dekelp@mellanox.com Date: Fri, 15 May 2020 16:13:58 +0800 Message-Id: <1589530438-437604-1-git-send-email-bingz@mellanox.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dpdk-stable] [PATCH] net/mlx5: fix left shift extension of doorbell bitmap X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" The doorbell record is organized with page and bitmap. When some new doorbell needs to be associated with a queue, the bit will be set in the bitmap to indicate the corresponding doorbell occupied. A counter is used to record the number of doorbell occupied to speed up the searching. If the number reachs the maximal value of a pre-defined number of a page, a new page will be allocated. If not, then the bitmap will be checked to find a free one. The LSHIFT and OR (AND NOT) operations are used to update the bitmap of a page. But 1 will be treated as a signed integer when compiling. When the shift number is 31, the shifted value will be considered as negative. Then a wrong extension will be done when setting it to a 64-bits variable. All the upper 32-bits will be set to 1 by such extension. Then a wrong offset value will be calculated because of this. The next 64 bits will be also treated as the bitmap and get corrupted through the bit set operation. The immediate value 1 needs to be used as 64 bits width explicitly. Fixes: 21cae8580fd0 ("net/mlx5: allocate door-bells via DevX") Cc: dekelp@mellanox.com Cc: stable@dpdk.org Signed-off-by: Bing Zhao Acked-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 1445809..ab4adec 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -2174,7 +2174,7 @@ struct mlx5_flow_id_pool * /* Find the first clear bit. */ MLX5_ASSERT(i < MLX5_DBR_BITMAP_SIZE); j = rte_bsf64(~page->dbr_bitmap[i]); - page->dbr_bitmap[i] |= (1 << j); + page->dbr_bitmap[i] |= (UINT64_C(1) << j); page->dbr_count++; *dbr_page = page; return (((i * 64) + j) * sizeof(uint64_t)); @@ -2219,7 +2219,7 @@ struct mlx5_flow_id_pool * int i = offset / 64; int j = offset % 64; - page->dbr_bitmap[i] &= ~(1 << j); + page->dbr_bitmap[i] &= ~(UINT64_C(1) << j); } return ret; } -- 1.8.3.1