netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] mlx5: avoid 64-bit division in dr_icm_pool_mr_create()
@ 2019-10-02 12:12 Michal Kubecek
  2019-10-02 14:58 ` Alex Vesker
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Kubecek @ 2019-10-02 12:12 UTC (permalink / raw)
  To: Saeed Mahameed, Leon Romanovsky
  Cc: Alex Vesker, Borislav Petkov, Stephen Hemminger, netdev,
	linux-rdma, linux-kernel

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")
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c
index 913f1e5aaaf2..d7c7467e2d53 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c
@@ -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;
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] mlx5: avoid 64-bit division in dr_icm_pool_mr_create()
  2019-10-02 12:12 [PATCH net] mlx5: avoid 64-bit division in dr_icm_pool_mr_create() Michal Kubecek
@ 2019-10-02 14:58 ` Alex Vesker
  2019-10-02 15:08   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Vesker @ 2019-10-02 14:58 UTC (permalink / raw)
  To: Michal Kubecek, Saeed Mahameed, Leon Romanovsky
  Cc: Borislav Petkov, Stephen Hemminger, netdev, linux-rdma, linux-kernel

On 10/2/2019 3:12 PM, Michal Kubecek wrote:
> 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")
> Reported-by: Borislav Petkov <bp@alien8.de>
> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c
> index 913f1e5aaaf2..d7c7467e2d53 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c
> @@ -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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] mlx5: avoid 64-bit division in dr_icm_pool_mr_create()
  2019-10-02 14:58 ` Alex Vesker
@ 2019-10-02 15:08   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2019-10-02 15:08 UTC (permalink / raw)
  To: valex
  Cc: mkubecek, saeedm, leon, bp, stephen, netdev, linux-rdma, linux-kernel

From: Alex Vesker <valex@mellanox.com>
Date: Wed, 2 Oct 2019 14:58:44 +0000

> On 10/2/2019 3:12 PM, Michal Kubecek wrote:
>> 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")
>> Reported-by: Borislav Petkov <bp@alien8.de>
>> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
 ...
> Align diff is power of 2,  looks good to me.
> Thanks for fixing it Michal.

I'll just apply this directly, thanks everyone.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-02 15:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-02 12:12 [PATCH net] mlx5: avoid 64-bit division in dr_icm_pool_mr_create() Michal Kubecek
2019-10-02 14:58 ` Alex Vesker
2019-10-02 15:08   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).