Skip to contentSkip to conversation

mlx5: avoid 64-bit division in dr_icm_pool_mr_create()

PATCH In review Michal Kubecek 3 participants 3 messages Oct 2, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlx5: avoid 64-bit division in dr_icm_pool_mr_create()

Recently added code introduces 64-bit division in dr_icm_pool_mr_create() so that build on 32-bit architectures fails with

ERROR: "__umoddi3" [drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko] undefined!

As the divisor is always a power of 2, we can use bitwise operation instead.

Fixes 29cf8febd185 ("net/mlx5: DR, ICM pool memory allocator")
---
 drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c +2 -1
index 913f1e5aaaf2..d7c7467e2d53 100644
@@ -137,7 +137,8 @@ dr_icm_pool_mr_create(struct mlx5dr_icm_pool *pool,
 
 	icm_mr->icm_start_addr = icm_mr->dm.addr;
 
-	align_diff = icm_mr->icm_start_addr % align_base;
+	/* align_base is always a power of 2 */
+	align_diff = icm_mr->icm_start_addr & (align_base - 1);
 	if (align_diff)
 		icm_mr->used_length = align_base - align_diff;
 
Signature · 1 line
2.23.0
#1 lore raw
Quoted 20 lines · Michal Kubecek

Recently added code introduces 64-bit division in dr_icm_pool_mr_create() so that build on 32-bit architectures fails with

ERROR: "__umoddi3" [drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko] undefined!

As the divisor is always a power of 2, we can use bitwise operation instead.

Fixes 29cf8febd185 ("net/mlx5: DR, ICM pool memory allocator")
---
  drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c +0 -0
index 913f1e5aaaf2..d7c7467e2d53 100644

drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c dr_icm_pool_mr_create(struct mlx5dr_icm_pool *pool, · line 144

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c +2 -1
@@ -137,7 +137,8 @@ dr_icm_pool_mr_create(struct mlx5dr_icm_pool *pool,
 
  	icm_mr->icm_start_addr = icm_mr->dm.addr;
 
-	align_diff = icm_mr->icm_start_addr % align_base;
+	/* align_base is always a power of 2 */
+	align_diff = icm_mr->icm_start_addr & (align_base - 1);
  	if (align_diff)
  		icm_mr->used_length = align_base - align_diff;
 

Align diff is power of 2,  looks good to me.
Thanks for fixing it Michal.

maintainer
#2 lore raw

From: Alex Vesker <[email protected]>
Date: Wed, 2 Oct 2019 14:58:44 +0000

Quoted 12 lines · Michal Kubecek
Quoted 11 lines

Recently added code introduces 64-bit division in dr_icm_pool_mr_create() so that build on 32-bit architectures fails with

ERROR: "__umoddi3" [drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko] undefined!

As the divisor is always a power of 2, we can use bitwise operation instead.

Fixes 29cf8febd185 ("net/mlx5: DR, ICM pool memory allocator")

...

Quoted 2 lines

Align diff is power of 2,  looks good to me.
Thanks for fixing it Michal.

I'll just apply this directly, thanks everyone.