Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/mlx5: Add MLX5_ARRAY_SET64 to fix BUILD_BUG_ON

I am hitting this in mlx5:

drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c: In function
reclaim_pages_cmd.clone.0:
drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c:346: error: call
to __compiletime_assert_346 declared with attribute error:
BUILD_BUG_ON failed: __mlx5_bit_off(manage_pages_out, pas[i]) % 64
drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c: In function give_pages:
drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c:291: error: call
to __compiletime_assert_291 declared with attribute error:
BUILD_BUG_ON failed: __mlx5_bit_off(manage_pages_in, pas[i]) % 64

Problem is that this is doing a BUILD_BUG_ON on a non-constant
expression because of trying to take offset of pas[i] in the
structure.

Fix is to create MLX5_ARRAY_SET64 that takes an additional argument
that is the field index to separate between BUILD_BUG_ON on the array
constant field and the indexed field to assign the value to.
There are two callers of MLX5_SET64 that are trying to get a variable
offset, change those to call MLX5_ARRAY_SET64 passing 'pas' and 'i'
as the arguments to use in the offset check and the indexed value
assignment.

Fixes: a533ed5e179cd ("net/mlx5: Pages management commands via mlx5 ifc")
Signed-off-by: Tom Herbert <tom@herbertland.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Tom Herbert and committed by
David S. Miller
b8a4ddb2 9a765881

+13 -4
+2 -2
drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
··· 287 287 288 288 goto retry; 289 289 } 290 - MLX5_SET64(manage_pages_in, in, pas[i], addr); 290 + MLX5_ARRAY_SET64(manage_pages_in, in, pas, i, addr); 291 291 } 292 292 293 293 MLX5_SET(manage_pages_in, in, opcode, MLX5_CMD_OP_MANAGE_PAGES); ··· 344 344 if (fwp->func_id != func_id) 345 345 continue; 346 346 347 - MLX5_SET64(manage_pages_out, out, pas[i], fwp->addr); 347 + MLX5_ARRAY_SET64(manage_pages_out, out, pas, i, fwp->addr); 348 348 i++; 349 349 } 350 350
+11 -2
include/linux/mlx5/device.h
··· 92 92 ___t; \ 93 93 }) 94 94 95 - #define MLX5_SET64(typ, p, fld, v) do { \ 95 + #define __MLX5_SET64(typ, p, fld, v) do { \ 96 96 BUILD_BUG_ON(__mlx5_bit_sz(typ, fld) != 64); \ 97 - BUILD_BUG_ON(__mlx5_bit_off(typ, fld) % 64); \ 98 97 *((__be64 *)(p) + __mlx5_64_off(typ, fld)) = cpu_to_be64(v); \ 98 + } while (0) 99 + 100 + #define MLX5_SET64(typ, p, fld, v) do { \ 101 + BUILD_BUG_ON(__mlx5_bit_off(typ, fld) % 64); \ 102 + __MLX5_SET64(typ, p, fld, v); \ 103 + } while (0) 104 + 105 + #define MLX5_ARRAY_SET64(typ, p, fld, idx, v) do { \ 106 + BUILD_BUG_ON(__mlx5_bit_off(typ, fld) % 64); \ 107 + __MLX5_SET64(typ, p, fld[idx], v); \ 99 108 } while (0) 100 109 101 110 #define MLX5_GET64(typ, p, fld) be64_to_cpu(*((__be64 *)(p) + __mlx5_64_off(typ, fld)))