Skip to contentSkip to conversation

vfio/mlx5: Fix range size calculation upon tracker creation

PATCH Applied Yishai Hadas 2 participants 2 messages Feb 8, 2023 – Feb 9, 2023

Subsystems (4)
lore
Share & tools
lore

Yishai Hadas

author maintainer
#0 lore raw

PATCH 1/1 vfio/mlx5: Fix range size calculation upon tracker creation

Fix range size calculation to include the last byte of each range.

In addition, log round up the length of the total ranges to be stricter.

Fixes c1d050b0d169 ("vfio/mlx5: Create and destroy page tracker object")
---
 drivers/vfio/pci/mlx5/cmd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vfio/pci/mlx5/cmd.c +2 -2
index 5161d845c478..deed156e6165 100644
@@ -830,7 +830,7 @@ static int mlx5vf_create_tracker(struct mlx5_core_dev *mdev,
 	node = interval_tree_iter_first(ranges, 0, ULONG_MAX);
 	for (i = 0; i < num_ranges; i++) {
 		void *addr_range_i_base = range_list_ptr + record_size * i;
-		unsigned long length = node->last - node->start;
+		unsigned long length = node->last - node->start + 1;
 
 		MLX5_SET64(page_track_range, addr_range_i_base, start_address,
 			   node->start);
@@ -840,7 +840,7 @@ static int mlx5vf_create_tracker(struct mlx5_core_dev *mdev,
 	}
 
 	WARN_ON(node);
-	log_addr_space_size = ilog2(total_ranges_len);
+	log_addr_space_size = ilog2(roundup_pow_of_two(total_ranges_len));
 	if (log_addr_space_size <
 	    (MLX5_CAP_ADV_VIRTUALIZATION(mdev, pg_track_log_min_addr_space)) ||
 	    log_addr_space_size >
Signature · 1 line
2.18.1
#1 lore raw
Quoted 24 lines · On Wed, 8 Feb 2023 17:22:34 +0200 Yishai Hadas <[email protected]> wrote:

Fix range size calculation to include the last byte of each range.

In addition, log round up the length of the total ranges to be stricter.

Fixes c1d050b0d169 ("vfio/mlx5: Create and destroy page tracker object")
---
 drivers/vfio/pci/mlx5/cmd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vfio/pci/mlx5/cmd.c +1 -1
index 5161d845c478..deed156e6165 100644
@@ -830,7 +830,7 @@ static int mlx5vf_create_tracker(struct mlx5_core_dev *mdev,
 	node = interval_tree_iter_first(ranges, 0, ULONG_MAX);
 	for (i = 0; i < num_ranges; i++) {
 		void *addr_range_i_base = range_list_ptr + record_size * i;
-		unsigned long length = node->last - node->start;
+		unsigned long length = node->last - node->start + 1;
 
 		MLX5_SET64(page_track_range, addr_range_i_base, start_address,
 			   node->start);

drivers/vfio/pci/mlx5/cmd.c static int mlx5vf_create_tracker(struct mlx5_core_dev *mdev, · line 846

Quoted 8 lines
drivers/vfio/pci/mlx5/cmd.c +1 -1
@@ -840,7 +840,7 @@ static int mlx5vf_create_tracker(struct mlx5_core_dev *mdev,
 	}
 
 	WARN_ON(node);
-	log_addr_space_size = ilog2(total_ranges_len);
+	log_addr_space_size = ilog2(roundup_pow_of_two(total_ranges_len));
 	if (log_addr_space_size <
 	    (MLX5_CAP_ADV_VIRTUALIZATION(mdev, pg_track_log_min_addr_space)) ||
 	    log_addr_space_size >

Applied to vfio next branch for v6.3. Thanks,

Alex