Skip to content

Commit 543640a

Browse files
Yishai Hadasawilliam
authored andcommitted
vfio/mlx5: Enable querying state size which is > 4GB
Once the device supports 'chunk mode' the driver can support state size which is larger than 4GB. In that case the device has the capability to split a single image to multiple chunks as long as the software provides a buffer in the minimum size reported by the device. The driver should query for the minimum buffer size required using QUERY_VHCA_MIGRATION_STATE command with the 'chunk' bit set in its input, in that case, the output will include both the minimum buffer size (i.e. required_umem_size) and also the remaining total size to be reported/used where that it will be applicable. At that point in the series the 'chunk' bit is off, the last patch will activate the feature once all pieces will be ready. Note: Before this change we were limited to 4GB state size as of 4 bytes max value based on the device specification for the query/save/load commands. Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20230911093856.81910-5-yishaih@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 34a64c8 commit 543640a

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

drivers/vfio/pci/mlx5/cmd.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ int mlx5vf_cmd_resume_vhca(struct mlx5vf_pci_core_device *mvdev, u16 op_mod)
8686
}
8787

8888
int mlx5vf_cmd_query_vhca_migration_state(struct mlx5vf_pci_core_device *mvdev,
89-
size_t *state_size, u8 query_flags)
89+
size_t *state_size, u64 *total_size,
90+
u8 query_flags)
9091
{
9192
u32 out[MLX5_ST_SZ_DW(query_vhca_migration_state_out)] = {};
9293
u32 in[MLX5_ST_SZ_DW(query_vhca_migration_state_in)] = {};
@@ -128,6 +129,7 @@ int mlx5vf_cmd_query_vhca_migration_state(struct mlx5vf_pci_core_device *mvdev,
128129
MLX5_SET(query_vhca_migration_state_in, in, op_mod, 0);
129130
MLX5_SET(query_vhca_migration_state_in, in, incremental,
130131
query_flags & MLX5VF_QUERY_INC);
132+
MLX5_SET(query_vhca_migration_state_in, in, chunk, mvdev->chunk_mode);
131133

132134
ret = mlx5_cmd_exec_inout(mvdev->mdev, query_vhca_migration_state, in,
133135
out);
@@ -139,6 +141,11 @@ int mlx5vf_cmd_query_vhca_migration_state(struct mlx5vf_pci_core_device *mvdev,
139141

140142
*state_size = MLX5_GET(query_vhca_migration_state_out, out,
141143
required_umem_size);
144+
if (total_size)
145+
*total_size = mvdev->chunk_mode ?
146+
MLX5_GET64(query_vhca_migration_state_out, out,
147+
remaining_total_size) : *state_size;
148+
142149
return 0;
143150
}
144151

drivers/vfio/pci/mlx5/cmd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ struct mlx5vf_pci_core_device {
164164
u8 deferred_reset:1;
165165
u8 mdev_detach:1;
166166
u8 log_active:1;
167+
u8 chunk_mode:1;
167168
struct completion tracker_comp;
168169
/* protect migration state */
169170
struct mutex state_mutex;
@@ -186,7 +187,8 @@ enum {
186187
int mlx5vf_cmd_suspend_vhca(struct mlx5vf_pci_core_device *mvdev, u16 op_mod);
187188
int mlx5vf_cmd_resume_vhca(struct mlx5vf_pci_core_device *mvdev, u16 op_mod);
188189
int mlx5vf_cmd_query_vhca_migration_state(struct mlx5vf_pci_core_device *mvdev,
189-
size_t *state_size, u8 query_flags);
190+
size_t *state_size, u64 *total_size,
191+
u8 query_flags);
190192
void mlx5vf_cmd_set_migratable(struct mlx5vf_pci_core_device *mvdev,
191193
const struct vfio_migration_ops *mig_ops,
192194
const struct vfio_log_ops *log_ops);

drivers/vfio/pci/mlx5/main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static long mlx5vf_precopy_ioctl(struct file *filp, unsigned int cmd,
428428
* As so, the other code below is safe with the proper locks.
429429
*/
430430
ret = mlx5vf_cmd_query_vhca_migration_state(mvdev, &inc_length,
431-
MLX5VF_QUERY_INC);
431+
NULL, MLX5VF_QUERY_INC);
432432
if (ret)
433433
goto err_state_unlock;
434434
}
@@ -505,7 +505,7 @@ static int mlx5vf_pci_save_device_inc_data(struct mlx5vf_pci_core_device *mvdev)
505505
if (migf->state == MLX5_MIGF_STATE_ERROR)
506506
return -ENODEV;
507507

508-
ret = mlx5vf_cmd_query_vhca_migration_state(mvdev, &length,
508+
ret = mlx5vf_cmd_query_vhca_migration_state(mvdev, &length, NULL,
509509
MLX5VF_QUERY_INC | MLX5VF_QUERY_FINAL);
510510
if (ret)
511511
goto err;
@@ -574,7 +574,7 @@ mlx5vf_pci_save_device_data(struct mlx5vf_pci_core_device *mvdev, bool track)
574574
INIT_LIST_HEAD(&migf->buf_list);
575575
INIT_LIST_HEAD(&migf->avail_list);
576576
spin_lock_init(&migf->list_lock);
577-
ret = mlx5vf_cmd_query_vhca_migration_state(mvdev, &length, 0);
577+
ret = mlx5vf_cmd_query_vhca_migration_state(mvdev, &length, NULL, 0);
578578
if (ret)
579579
goto out_pd;
580580

@@ -1195,13 +1195,14 @@ static int mlx5vf_pci_get_data_size(struct vfio_device *vdev,
11951195
struct mlx5vf_pci_core_device *mvdev = container_of(
11961196
vdev, struct mlx5vf_pci_core_device, core_device.vdev);
11971197
size_t state_size;
1198+
u64 total_size;
11981199
int ret;
11991200

12001201
mutex_lock(&mvdev->state_mutex);
1201-
ret = mlx5vf_cmd_query_vhca_migration_state(mvdev,
1202-
&state_size, 0);
1202+
ret = mlx5vf_cmd_query_vhca_migration_state(mvdev, &state_size,
1203+
&total_size, 0);
12031204
if (!ret)
1204-
*stop_copy_length = state_size;
1205+
*stop_copy_length = total_size;
12051206
mlx5vf_state_mutex_unlock(mvdev);
12061207
return ret;
12071208
}

0 commit comments

Comments
 (0)