Skip to contentSkip to conversation

net/mlx5: fix left shift extension of doorbell bitmap

PATCH In review Bing Zhao 3 participants 4 messages May 15, 2020 – May 17, 2020 Network drivers

lore
Share & tools
lore

Bing Zhao

author
#0 lore raw

PATCH 1/1 net/mlx5: fix left shift extension of doorbell bitmap

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")
---
 drivers/net/mlx5/mlx5.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.c +2 -2
index 1445809..ab4adec 100644
@@ -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;
 }
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw

From: Bing Zhao:

Quoted 17 lines

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.

Quoted 6 lines
Fixes 21cae8580fd0 ("net/mlx5: allocate door-bells via DevX")

Suggested title:
net/mlx5: fix doorbell bitmap management offsets

Other than that:

Quoted 27 lines
 drivers/net/mlx5/mlx5.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.c index renamed from drivers/net/mlx5/mlx5.c +0 -0

1445809..ab4adec 100644

drivers/net/mlx5/mlx5.c +1 -1
@@ -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 *

drivers/net/mlx5/mlx5.c +1 -2
 		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

#2 lore raw
In reply to Bing Zhao

Hi,

Quoted 61 lines

-----Original Message-----
From: Bing Zhao <[email protected]>
Sent: Friday, May 15, 2020 11:14 AM
To: Slava Ovsiienko <[email protected]>; Raslan Darawsheh <[email protected]>
Cc: Ori Kam <[email protected]>; Matan Azrad <[email protected]>; [email protected]; [email protected]; Dekel Peled <[email protected]>
Subject: [PATCH] net/mlx5: fix left shift extension of doorbell bitmap

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")
---
 drivers/net/mlx5/mlx5.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.c +2 -3
index 1445809..ab4adec 100644
@@ -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;
 }
--
Quoted 1 line

1.8.3.1

Commit title changed to:
net/mlx5: fix left shift extension of doorbell bitmap

Patch applied to next-net-mlx,

Kindest regards
Raslan Darawsheh

#3 lore raw
Quoted 68 lines

-----Original Message-----
From: Raslan Darawsheh
Sent: Sunday, May 17, 2020 12:19 PM
To: Bing Zhao <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: Ori Kam <[email protected]>; Matan Azrad <[email protected]>; [email protected]; [email protected]; Dekel Peled <[email protected]>
Subject: RE: [PATCH] net/mlx5: fix left shift extension of doorbell bitmap

Hi,

Quoted 6 lines

-----Original Message-----
From: Bing Zhao <[email protected]>
Sent: Friday, May 15, 2020 11:14 AM
To: Slava Ovsiienko <[email protected]>; Raslan Darawsheh <[email protected]>
Cc: Ori Kam <[email protected]>; Matan Azrad

<[email protected]>;

Quoted 49 lines

[email protected]; [email protected]; Dekel Peled <[email protected]>
Subject: [PATCH] net/mlx5: fix left shift extension of doorbell bitmap

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")
---
 drivers/net/mlx5/mlx5.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.c +1 -1
index 1445809..ab4adec 100644
@@ -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;
 
Quoted 10 lines
Quoted 7 lines
drivers/net/mlx5/mlx5.c +1 -2
-		page->dbr_bitmap[i] &= ~(1 << j);
+		page->dbr_bitmap[i] &= ~(UINT64_C(1) << j);
 	}
 	return ret;
 }
--

1.8.3.1

Commit title changed to:
net/mlx5: fix left shift extension of doorbell bitmap

Commit title sent incorrectly, the fix title is:
net/mlx5: fix doorbell bitmap management offsets

Quoted 5 lines

Patch applied to next-net-mlx,

Kindest regards
Raslan Darawsheh

Kindest regards
Raslan Darawsheh