Skip to contentSkip to conversation

mlx5: avoid integer overflow warning for large page size

PATCH In review Arnd Bergmann 3 participants 3 messages Jun 22, 2023

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

PATCH 1/1 mlx5: avoid integer overflow warning for large page size

From: Arnd Bergmann <[email protected]>

Build testing with 'make LLVM=1 W=1' shows a warning about a condition that is always true on configurations with 64KB pages:

drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c:32:22: error: result of comparison of constant 65536 with expression of type 'u16' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

Change the condition in a way that lets clang know this is intentional.

---
 drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c +2 -1
index 36826b5824847..b9f62e531bd4c 100644
@@ -29,7 +29,8 @@ bool mlx5e_validate_xsk_param(struct mlx5e_params *params,
 			      struct mlx5_core_dev *mdev)
 {
 	/* AF_XDP doesn't support frames larger than PAGE_SIZE. */
-	if (xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
+	if ((PAGE_SIZE < U16_MAX && xsk->chunk_size > PAGE_SIZE)
+	    || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
 		mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size,
 			      MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE);
 		return false;
Signature · 1 line
2.39.2
#1 lore raw
Quoted 21 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Build testing with 'make LLVM=1 W=1' shows a warning about a condition that is always true on configurations with 64KB pages:

drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c:32:22: error: result of comparison of constant 65536 with expression of type 'u16' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

Change the condition in a way that lets clang know this is intentional.

---
 drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c +0 -0
index 36826b5824847..b9f62e531bd4c 100644

drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c bool mlx5e_validate_xsk_param(struct mlx5e_params *params, · line 33

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c +2 -1
@@ -29,7 +29,8 @@ bool mlx5e_validate_xsk_param(struct mlx5e_params *params,
 			      struct mlx5_core_dev *mdev)
 {
 	/* AF_XDP doesn't support frames larger than PAGE_SIZE. */
-	if (xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
+	if ((PAGE_SIZE < U16_MAX && xsk->chunk_size > PAGE_SIZE)
+	    || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {

I recall you already sent a fix to silence this warning before:

https://lore.kernel.org/netdev/[email protected]/

I prefer that old one, as it's more future-proof to cast to size_t here in place (chunk_size won't be bigger than size_t for sure). With your new patch, if chunk_size is ever changed from u16 to u32, it's likely that this place will be unnoticed, and a bug will be introduced.

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c +0 -0
 		mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size,
 			      MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE);
 		return false;
Signature · 1 line
2.39.2
#2 lore raw
Quoted 13 lines · Maxim Mikityanskiy

On Thu, 22 Jun 2023 at 12:15:02 +0200, Arnd Bergmann wrote:

I recall you already sent a fix to silence this warning before:

https://lore.kernel.org/netdev/[email protected]/

I prefer that old one, as it's more future-proof to cast to size_t here in place (chunk_size won't be bigger than size_t for sure). With your new patch, if chunk_size is ever changed from u16 to u32, it's likely that this place will be unnoticed, and a bug will be introduced.

Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c +0 -0
 		mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size,
 			      MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE);

Indeed, I don't know why I no longer had the old patch in my randconfig tree, I completely forgot about that. The old patch is also ok.

Arnd