Subject: [net-next 16/17] net/mlx5: Ensure SF BAR size is at least PAGE_SIZE

From: Saeed Mahameed <[email-masked]>
Date: Wed, 26 May 2021 21:36:08 -0700

From: Eli Cohen <[email-masked]>

Make sure the allocated SF BAR size is at least PAGE_SIZE so that when
mapping it userspace, the mapped page will not cover other SFs.

Signed-off-by: Eli Cohen <[email-masked]>
Signed-off-by: Saeed Mahameed <[email-masked]>
---
 drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
index 6a0c6f965ad1..9f9728324731 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
@@ -227,7 +227,8 @@ void mlx5_sf_dev_table_create(struct mlx5_core_dev *dev)
 		max_sfs = MLX5_CAP_GEN(dev, max_num_sf);
 	else
 		max_sfs = 1 << MLX5_CAP_GEN(dev, log_max_sf);
-	table->sf_bar_length = 1 << (MLX5_CAP_GEN(dev, log_min_sf_size) + 12);
+	table->sf_bar_length = 1 << (max_t(u8, MLX5_CAP_GEN(dev, log_min_sf_size) + 12,
+					   PAGE_SHIFT));
 	table->base_address = pci_resource_start(dev->pdev, 2);
 	table->max_sfs = max_sfs;
 	xa_init(&table->devices);
-- 
2.31.1