Add chunk mode support for mlx5 driver
Subsystems (6)
Yishai Hadas
maintainercover Add chunk mode support for mlx5 driver
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
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 and also the remaining total size to be reported/used where it will be applicable.
Upon chunk mode, there may be multiple images that will be read from the device upon STOP_COPY. The driver will read ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.
The chunk buffer size is picked up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
With that series in place, we could migrate successfully a device state with a larger size than 4GB, while even improving the downtime in some scenarios.
Note:
As the first patch should go to net/mlx5 we may need to send it as a pull request format to VFIO to avoid conflicts before acceptance.
Yishai
Yishai Hadas (9):
net/mlx5: Introduce ifc bits for migration in a chunk mode vfio/mlx5: Wake up the reader post of disabling the SAVING migration
file
vfio/mlx5: Refactor the SAVE callback to activate a work only upon an
error
vfio/mlx5: Enable querying state size which is > 4GB vfio/mlx5: Rename some stuff to match chunk mode vfio/mlx5: Pre-allocate chunks for the STOP_COPY phase vfio/mlx5: Add support for SAVING in chunk mode
vfio/mlx5: Add support for READING in chunk mode vfio/mlx5: Activate the chunk mode functionality
drivers/vfio/pci/mlx5/cmd.c | 103 +++++++++---- drivers/vfio/pci/mlx5/cmd.h | 28 +++- drivers/vfio/pci/mlx5/main.c | 283 +++++++++++++++++++++++++--------- include/linux/mlx5/mlx5_ifc.h | 15 +- 4 files changed, 322 insertions(+), 107 deletions(-)
Signature · 1 line
2.18.1
Yishai Hadas
maintainerPATCH 1/9 net/mlx5: Introduce ifc bits for migration in a chunk mode
Introduce ifc related stuff to enable migration in a chunk mode.
--- include/linux/mlx5/mlx5_ifc.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
include/linux/mlx5/mlx5_ifc.h +11 -4
@@ -1948,7 +1948,9 @@ struct mlx5_ifc_cmd_hca_cap_2_bits {u8 reserved_at_c0[0x8 ];u8 migration_multi_load[0x1 ];u8 migration_tracking_state[0x1 ]; -u8 reserved_at_ca[0x16 ]; +u8 reserved_at_ca[0x6 ]; +u8 migration_in_chunks[0x1 ]; +u8 reserved_at_d1[0xf ];u8 reserved_at_e0[0xc0 ];
@@ -12392,7 +12394,8 @@ struct mlx5_ifc_query_vhca_migration_state_in_bits {u8 op_mod[0x10 ];u8 incremental[0x1 ]; -u8 reserved_at_41[0xf ]; +u8 chunk[0x1 ]; +u8 reserved_at_42[0xe ];u8 vhca_id[0x10 ];u8 reserved_at_60[0x20 ];
@@ -12408,7 +12411,11 @@ struct mlx5_ifc_query_vhca_migration_state_out_bits {u8 required_umem_size[0x20 ]; -u8 reserved_at_a0[0x160 ]; +u8 reserved_at_a0[0x20 ]; + +u8 remaining_total_size[0x40 ]; + +u8 reserved_at_100[0x100 ]; };struct mlx5_ifc_save_vhca_state_in_bits {
@@ -12440,7 +12447,7 @@ struct mlx5_ifc_save_vhca_state_out_bits {u8 actual_image_size[0x20 ]; -u8 reserved_at_60[0x20 ]; +u8 next_required_umem_size[0x20 ]; };struct mlx5_ifc_load_vhca_state_in_bits {
Signature · 1 line
2.18.1
Yishai Hadas
maintainerPATCH 2/9 vfio/mlx5: Wake up the reader post of disabling the SAVING migration file
In reply to Yishai HadasPost of disabling the SAVING migration file, which includes setting the file state to be MLX5_MIGF_STATE_ERROR, call to wake_up_interruptible() on its poll_wait member.
This lets any potential reader which is waiting already for data as part of mlx5vf_save_read() to wake up, recognize the error state and return with an error.
Post of that we don't need to rely on any other condition to wake up the reader as of the returning of the SAVE command that was previously executed, etc.
In addition, this change will simplify error flows (e.g health recovery) once we'll move to chunk mode and multiple SAVE commands may run in the STOP_COPY phase as we won't need to rely any more on a SAVE command to wake-up a potential waiting reader.
--- drivers/vfio/pci/mlx5/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/vfio/pci/mlx5/main.c +1 -0
@@ -1019,6 +1019,7 @@ void mlx5vf_disable_fds(struct mlx5vf_pci_core_device *mvdev)mlx5_cmd_cleanup_async_ctx (&mvdev->saving_migf->async_ctx);cancel_work_sync (&mvdev->saving_migf->async_data.work);mlx5vf_disable_fd (mvdev->saving_migf); +wake_up_interruptible (&mvdev->saving_migf->poll_wait);mlx5fv_cmd_clean_migf_resources (mvdev->saving_migf);fput (mvdev->saving_migf->filp); mvdev->saving_migf =NULL ;
Signature · 1 line
2.18.1
Yishai Hadas
maintainerPATCH 3/9 vfio/mlx5: Refactor the SAVE callback to activate a work only upon an error
In reply to Yishai HadasUpon a successful SAVE callback there is no need to activate a work, all the required stuff can be done directly.
As so, refactor the above flow to activate a work only upon an error.
--- drivers/vfio/pci/mlx5/cmd.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/vfio/pci/mlx5/cmd.c +13 -7
@@ -475,6 +475,15 @@ mlx5vf_get_data_buffer(struct mlx5_vf_migration_file *migf,return buf; } +static void +mlx5vf_save_callback_complete (struct mlx5_vf_migration_file *migf, +struct mlx5vf_async_data *async_data) +{ +kvfree (async_data->out); +complete (&migf->save_comp); +fput (migf->filp); +} +void mlx5vf_mig_file_cleanup_cb (struct work_struct *_work) { struct mlx5vf_async_data *async_data = container_of(_work,
@@ -494,9 +503,7 @@ void mlx5vf_mig_file_cleanup_cb(struct work_struct *_work)wake_up_interruptible (&migf->poll_wait); }mutex_unlock (&migf->lock); -kvfree (async_data->out); -complete (&migf->save_comp); -fput (migf->filp); +mlx5vf_save_callback_complete (migf, async_data); } static int add_buf_header(struct mlx5_vhca_data_buffer *header_buf,
@@ -560,13 +567,12 @@ static void mlx5vf_save_callback(int status, struct mlx5_async_work *context) migf->state = async_data->last_chunk ?MLX5_MIGF_STATE_COMPLETE :MLX5_MIGF_STATE_PRE_COPY ;wake_up_interruptible (&migf->poll_wait); +mlx5vf_save_callback_complete (migf, async_data); +return ; } err: -/* -* The error and the cleanup flows can't run from an -* interrupt context -*/ +/* The error flow can't run from an interrupt context */ if (status == -EREMOTEIO ) status =MLX5_GET (save_vhca_state_out, async_data->out, status); async_data->status = status;
Signature · 1 line
2.18.1
Yishai Hadas
maintainerPATCH 4/9 vfio/mlx5: Enable querying state size which is > 4GB
In reply to Yishai HadasOnce 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.
--- drivers/vfio/pci/mlx5/cmd.c | 9 ++++++++- drivers/vfio/pci/mlx5/cmd.h | 4 +++- drivers/vfio/pci/mlx5/main.c | 13 +++++++------ 3 files changed, 18 insertions(+), 8 deletions(-)
drivers/vfio/pci/mlx5/cmd.c +8 -1
@@ -86,7 +86,8 @@ int mlx5vf_cmd_resume_vhca(struct mlx5vf_pci_core_device *mvdev, u16 op_mod) }int mlx5vf_cmd_query_vhca_migration_state (struct mlx5vf_pci_core_device *mvdev, -size_t *state_size,u8 query_flags) +size_t *state_size,u64 *total_size, +u8 query_flags) {u32 out[MLX5_ST_SZ_DW (query_vhca_migration_state_out)] = {};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,MLX5_SET (query_vhca_migration_state_in, in, op_mod,0 );MLX5_SET (query_vhca_migration_state_in, in, incremental, query_flags &MLX5VF_QUERY_INC ); +MLX5_SET (query_vhca_migration_state_in, in, chunk, mvdev->chunk_mode); ret =mlx5_cmd_exec_inout (mvdev->mdev, query_vhca_migration_state, in, out);
@@ -139,6 +141,11 @@ int mlx5vf_cmd_query_vhca_migration_state(struct mlx5vf_pci_core_device *mvdev, *state_size =MLX5_GET (query_vhca_migration_state_out, out, required_umem_size); +if (total_size) + *total_size = mvdev->chunk_mode ? +MLX5_GET64 (query_vhca_migration_state_out, out, + remaining_total_size) : *state_size; +return 0 ; }
drivers/vfio/pci/mlx5/cmd.h +3 -1
@@ -164,6 +164,7 @@ struct mlx5vf_pci_core_device { u8 deferred_reset:1; u8 mdev_detach:1; u8 log_active:1; + u8 chunk_mode:1;struct completion tracker_comp;/* protect migration state */ struct mutex state_mutex;
@@ -186,7 +187,8 @@ enum {int mlx5vf_cmd_suspend_vhca (struct mlx5vf_pci_core_device *mvdev,u16 op_mod);int mlx5vf_cmd_resume_vhca (struct mlx5vf_pci_core_device *mvdev,u16 op_mod);int mlx5vf_cmd_query_vhca_migration_state (struct mlx5vf_pci_core_device *mvdev, -size_t *state_size,u8 query_flags); +size_t *state_size,u64 *total_size, +u8 query_flags);void mlx5vf_cmd_set_migratable (struct mlx5vf_pci_core_device *mvdev,const struct vfio_migration_ops *mig_ops,const struct vfio_log_ops *log_ops);
drivers/vfio/pci/mlx5/main.c +7 -6
@@ -428,7 +428,7 @@ static long mlx5vf_precopy_ioctl(struct file *filp, unsigned int cmd,* As so, the other code below is safe with the proper locks. */ ret =mlx5vf_cmd_query_vhca_migration_state (mvdev, &inc_length, -MLX5VF_QUERY_INC ); +NULL ,MLX5VF_QUERY_INC );if (ret) goto err_state_unlock; }
@@ -505,7 +505,7 @@ static int mlx5vf_pci_save_device_inc_data(struct mlx5vf_pci_core_device *mvdev)if (migf->state ==MLX5_MIGF_STATE_ERROR )return -ENODEV ; - ret =mlx5vf_cmd_query_vhca_migration_state (mvdev, &length, + ret =mlx5vf_cmd_query_vhca_migration_state (mvdev, &length,NULL ,MLX5VF_QUERY_INC |MLX5VF_QUERY_FINAL );if (ret) goto err;
@@ -574,7 +574,7 @@ mlx5vf_pci_save_device_data(struct mlx5vf_pci_core_device *mvdev, bool track)INIT_LIST_HEAD (&migf->buf_list);INIT_LIST_HEAD (&migf->avail_list);spin_lock_init (&migf->list_lock); - ret =mlx5vf_cmd_query_vhca_migration_state (mvdev, &length,0 ); + ret =mlx5vf_cmd_query_vhca_migration_state (mvdev, &length,NULL ,0 );if (ret) goto out_pd;
@@ -1195,13 +1195,14 @@ static int mlx5vf_pci_get_data_size(struct vfio_device *vdev,struct mlx5vf_pci_core_device *mvdev =container_of ( vdev, struct mlx5vf_pci_core_device, core_device.vdev);size_t state_size; +u64 total_size;int ret;mutex_lock (&mvdev->state_mutex); - ret =mlx5vf_cmd_query_vhca_migration_state (mvdev, - &state_size,0 ); + ret =mlx5vf_cmd_query_vhca_migration_state (mvdev, &state_size, + &total_size,0 );if (!ret) - *stop_copy_length = state_size; + *stop_copy_length = total_size;mlx5vf_state_mutex_unlock (mvdev);return ret; }
Signature · 1 line
2.18.1
Yishai Hadas
maintainerPATCH 5/9 vfio/mlx5: Rename some stuff to match chunk mode
In reply to Yishai HadasUpon chunk mode there may be multiple images that will be read from the device upon STOP_COPY.
This patch is some preparation for that mode by replacing the relevant stuff to a better matching name.
As part of that, be stricter to recognize PRE_COPY error only when it didn't occur on a STOP_COPY chunk.
--- drivers/vfio/pci/mlx5/cmd.c | 15 ++++++++------- drivers/vfio/pci/mlx5/cmd.h | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-)
drivers/vfio/pci/mlx5/cmd.c +8 -7
@@ -503,7 +503,8 @@ void mlx5vf_mig_file_cleanup_cb(struct work_struct *_work)mlx5vf_put_data_buffer (async_data->buf);if (async_data->header_buf)mlx5vf_put_data_buffer (async_data->header_buf); -if (async_data->status ==MLX5_CMD_STAT_BAD_RES_STATE_ERR ) +if (!async_data->stop_copy_chunk && + async_data->status ==MLX5_CMD_STAT_BAD_RES_STATE_ERR ) migf->state =MLX5_MIGF_STATE_PRE_COPY_ERROR ;else migf->state =MLX5_MIGF_STATE_ERROR ;
@@ -553,7 +554,7 @@ static void mlx5vf_save_callback(int status, struct mlx5_async_work *context)size_t image_size;unsigned long flags;bool initial_pre_copy = migf->state !=MLX5_MIGF_STATE_PRE_COPY && - !async_data->last_chunk; + !async_data->stop_copy_chunk; image_size =MLX5_GET (save_vhca_state_out, async_data->out, actual_image_size);
@@ -571,7 +572,7 @@ static void mlx5vf_save_callback(int status, struct mlx5_async_work *context)spin_unlock_irqrestore (&migf->list_lock, flags);if (initial_pre_copy) migf->pre_copy_initial_bytes += image_size; - migf->state = async_data->last_chunk ? + migf->state = async_data->stop_copy_chunk ?MLX5_MIGF_STATE_COMPLETE :MLX5_MIGF_STATE_PRE_COPY ;wake_up_interruptible (&migf->poll_wait);mlx5vf_save_callback_complete (migf, async_data);
@@ -623,7 +624,7 @@ int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev, async_data = &migf->async_data; async_data->buf = buf; - async_data->last_chunk = !track; + async_data->stop_copy_chunk = !track; async_data->out =kvzalloc (out_size,GFP_KERNEL );if (!async_data->out) { err = -ENOMEM ;
@@ -631,7 +632,7 @@ int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev, }if (MLX5VF_PRE_COPY_SUPP (mvdev)) { -if (async_data->last_chunk && migf->buf_header) { +if (async_data->stop_copy_chunk && migf->buf_header) { header_buf = migf->buf_header; migf->buf_header =NULL ; }else {
@@ -644,8 +645,8 @@ int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev, } } -if (async_data->last_chunk) - migf->state =MLX5_MIGF_STATE_SAVE_LAST ; +if (async_data->stop_copy_chunk) + migf->state =MLX5_MIGF_STATE_SAVE_STOP_COPY_CHUNK ; async_data->header_buf = header_buf;get_file (migf->filp);
drivers/vfio/pci/mlx5/cmd.h +2 -2
@@ -20,7 +20,7 @@ enum mlx5_vf_migf_state {MLX5_MIGF_STATE_ERROR =1 ,MLX5_MIGF_STATE_PRE_COPY_ERROR ,MLX5_MIGF_STATE_PRE_COPY , -MLX5_MIGF_STATE_SAVE_LAST , +MLX5_MIGF_STATE_SAVE_STOP_COPY_CHUNK , MLX5_MIGF_STATE_COMPLETE, };
@@ -78,7 +78,7 @@ struct mlx5vf_async_data {struct mlx5_vhca_data_buffer *buf;struct mlx5_vhca_data_buffer *header_buf;int status; - u8 last_chunk:1; + u8 stop_copy_chunk:1;void *out; };
Signature · 1 line
2.18.1
Yishai Hadas
maintainerPATCH 6/9 vfio/mlx5: Pre-allocate chunks for the STOP_COPY phase
In reply to Yishai HadasThis patch is another preparation step towards working in chunk mode.
It pre-allocates chunks for the STOP_COPY phase to let the driver use them immediately and prevent an extra allocation upon that phase.
Before that patch we had a single large buffer that was dedicated for the STOP_COPY phase as there was a single SAVE in the source for the last image.
Once we'll move to chunk mode the idea is to have some small buffers that will be used upon the STOP_COPY phase.
The driver will read-ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.
Each buffer holds its chunk number to let it be recognized down the road in the coming patches.
The chunk buffer size is picked-up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
As the chunk mode is applicable even if we move directly to STOP_COPY the buffers preparation and some other related stuff is done unconditionally with regards to STOP/PRE-COPY.
Note:
In that phase in the series we still didn't activate the chunk mode and the first buffer will be used in all the places.
--- drivers/vfio/pci/mlx5/cmd.c | 23 +++--- drivers/vfio/pci/mlx5/cmd.h | 8 +- drivers/vfio/pci/mlx5/main.c | 150 ++++++++++++++++++++++------------- 3 files changed, 116 insertions(+), 65 deletions(-)
drivers/vfio/pci/mlx5/cmd.c +13 -10
@@ -632,9 +632,9 @@ int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev, }if (MLX5VF_PRE_COPY_SUPP (mvdev)) { -if (async_data->stop_copy_chunk && migf->buf_header) { - header_buf = migf->buf_header; - migf->buf_header =NULL ; +if (async_data->stop_copy_chunk && migf->buf_header[0 ]) { + header_buf = migf->buf_header[0 ]; + migf->buf_header[0 ] =NULL ; }else { header_buf =mlx5vf_get_data_buffer (migf,sizeof (struct mlx5_vf_migration_header ),DMA_NONE );
@@ -721,18 +721,21 @@ void mlx5vf_cmd_dealloc_pd(struct mlx5_vf_migration_file *migf)void mlx5fv_cmd_clean_migf_resources (struct mlx5_vf_migration_file *migf) {struct mlx5_vhca_data_buffer *entry; +int i;lockdep_assert_held (&migf->mvdev->state_mutex);WARN_ON (migf->mvdev->mdev_detach); -if (migf->buf) { -mlx5vf_free_data_buffer (migf->buf); - migf->buf =NULL ; - } +for (i =0 ; i <MAX_NUM_CHUNKS ; i++) { +if (migf->buf[i]) { +mlx5vf_free_data_buffer (migf->buf[i]); + migf->buf[i] =NULL ; + } -if (migf->buf_header) { -mlx5vf_free_data_buffer (migf->buf_header); - migf->buf_header =NULL ; +if (migf->buf_header[i]) { +mlx5vf_free_data_buffer (migf->buf_header[i]); + migf->buf_header[i] =NULL ; + } }list_splice (&migf->avail_list, &migf->buf_list);
drivers/vfio/pci/mlx5/cmd.h +6 -2
@@ -64,6 +64,7 @@ struct mlx5_vhca_data_buffer {u32 mkey;enum dma_data_direction dma_dir; u8 dmaed:1; +u8 stop_copy_chunk_num;struct list_head buf_elm;struct mlx5_vf_migration_file *migf;/* Optimize mlx5vf_get_migration_page() for sequential access */
@@ -82,6 +83,8 @@ struct mlx5vf_async_data {void *out; }; +#define MAX_NUM_CHUNKS 2 +struct mlx5_vf_migration_file {struct file *filp;struct mutex lock;
@@ -94,8 +97,9 @@ struct mlx5_vf_migration_file {u32 record_tag;u64 stop_copy_prep_size;u64 pre_copy_initial_bytes; -struct mlx5_vhca_data_buffer *buf; -struct mlx5_vhca_data_buffer *buf_header; +/* Upon chunk mode preserve another set of buffers for stop_copy phase */ +struct mlx5_vhca_data_buffer *buf[MAX_NUM_CHUNKS ]; +struct mlx5_vhca_data_buffer *buf_header[MAX_NUM_CHUNKS ];spinlock_t list_lock;struct list_head buf_list;struct list_head avail_list;
drivers/vfio/pci/mlx5/main.c +97 -53
266 lines not on this page · raw message
Signature · 1 line
2.18.1
Yishai Hadas
maintainerPATCH 7/9 vfio/mlx5: Add support for SAVING in chunk mode
In reply to Yishai HadasAdd support for SAVING in chunk mode, it includes running a work that will fill the next chunk from the device.
In case the number of available chunks will reach the MAX_NUM_CHUNKS, the next chunk SAVING will be delayed till the reader will consume one chunk.
The next patch from the series will add the reader part of the chunk mode.
--- drivers/vfio/pci/mlx5/cmd.c | 43 +++++++++++++++--- drivers/vfio/pci/mlx5/cmd.h | 12 ++++++ drivers/vfio/pci/mlx5/main.c | 84 +++++++++++++++++++++++++++++++----- 3 files changed, 122 insertions(+), 17 deletions(-)
drivers/vfio/pci/mlx5/cmd.c +36 -7
@@ -435,6 +435,7 @@ mlx5vf_alloc_data_buffer(struct mlx5_vf_migration_file *migf,void mlx5vf_put_data_buffer (struct mlx5_vhca_data_buffer *buf) {spin_lock_irq (&buf->migf->list_lock); + buf->stop_copy_chunk_num =0 ;list_add_tail (&buf->buf_elm, &buf->migf->avail_list);spin_unlock_irq (&buf->migf->list_lock); }
@@ -551,6 +552,8 @@ static void mlx5vf_save_callback(int status, struct mlx5_async_work *context) struct mlx5_vf_migration_file, async_data);if (!status) { +size_t next_required_umem_size =0 ; +bool stop_copy_last_chunk;size_t image_size;unsigned long flags; bool initial_pre_copy = migf->state != MLX5_MIGF_STATE_PRE_COPY &&
@@ -558,6 +561,11 @@ static void mlx5vf_save_callback(int status, struct mlx5_async_work *context) image_size =MLX5_GET (save_vhca_state_out, async_data->out, actual_image_size); +if (async_data->buf->stop_copy_chunk_num) + next_required_umem_size =MLX5_GET (save_vhca_state_out, + async_data->out, next_required_umem_size); + stop_copy_last_chunk = async_data->stop_copy_chunk && + !next_required_umem_size;if (async_data->header_buf) { status =add_buf_header (async_data->header_buf, image_size, initial_pre_copy);
@@ -569,12 +577,28 @@ static void mlx5vf_save_callback(int status, struct mlx5_async_work *context) migf->max_pos += async_data->buf->length;spin_lock_irqsave (&migf->list_lock, flags);list_add_tail (&async_data->buf->buf_elm, &migf->buf_list); +if (async_data->buf->stop_copy_chunk_num) { + migf->num_ready_chunks++; +if (next_required_umem_size && + migf->num_ready_chunks >=MAX_NUM_CHUNKS ) { +/* Delay the next SAVE till one chunk be consumed */ + migf->next_required_umem_size = next_required_umem_size; + next_required_umem_size =0 ; + } + }spin_unlock_irqrestore (&migf->list_lock, flags); -if (initial_pre_copy) +if (initial_pre_copy) { migf->pre_copy_initial_bytes += image_size; - migf->state = async_data->stop_copy_chunk ? -MLX5_MIGF_STATE_COMPLETE :MLX5_MIGF_STATE_PRE_COPY ; + migf->state =MLX5_MIGF_STATE_PRE_COPY ; + } +if (stop_copy_last_chunk) + migf->state =MLX5_MIGF_STATE_COMPLETE ;wake_up_interruptible (&migf->poll_wait); +if (next_required_umem_size) +mlx5vf_mig_file_set_save_work (migf, +/* Picking up the next chunk num */ + (async_data->buf->stop_copy_chunk_num %MAX_NUM_CHUNKS ) +1 , + next_required_umem_size);mlx5vf_save_callback_complete (migf, async_data);return ; }
@@ -632,10 +656,15 @@ int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev, }if (MLX5VF_PRE_COPY_SUPP (mvdev)) { -if (async_data->stop_copy_chunk && migf->buf_header[0 ]) { - header_buf = migf->buf_header[0 ]; - migf->buf_header[0 ] =NULL ; - }else { +if (async_data->stop_copy_chunk) { +u8 header_idx = buf->stop_copy_chunk_num ? + buf->stop_copy_chunk_num -1 :0 ; + + header_buf = migf->buf_header[header_idx]; + migf->buf_header[header_idx] =NULL ; + } + +if (!header_buf) { header_buf =mlx5vf_get_data_buffer (migf,sizeof (struct mlx5_vf_migration_header ),DMA_NONE );if (IS_ERR (header_buf)) {
drivers/vfio/pci/mlx5/cmd.h +12 -0
@@ -83,6 +83,13 @@ struct mlx5vf_async_data {void *out; }; +struct mlx5vf_save_work_data { +struct mlx5_vf_migration_file *migf; +size_t next_required_umem_size; +struct work_struct work; +u8 chunk_num; +}; +#define MAX_NUM_CHUNKS 2struct mlx5_vf_migration_file {
@@ -97,9 +104,12 @@ struct mlx5_vf_migration_file {u32 record_tag;u64 stop_copy_prep_size;u64 pre_copy_initial_bytes; +size_t next_required_umem_size; +u8 num_ready_chunks;/* Upon chunk mode preserve another set of buffers for stop_copy phase */ struct mlx5_vhca_data_buffer *buf[MAX_NUM_CHUNKS ];struct mlx5_vhca_data_buffer *buf_header[MAX_NUM_CHUNKS ]; +struct mlx5vf_save_work_data save_data[MAX_NUM_CHUNKS ];spinlock_t list_lock;struct list_head buf_list;struct list_head avail_list;
@@ -223,6 +233,8 @@ struct page *mlx5vf_get_migration_page(struct mlx5_vhca_data_buffer *buf,void mlx5vf_state_mutex_unlock (struct mlx5vf_pci_core_device *mvdev);void mlx5vf_disable_fds (struct mlx5vf_pci_core_device *mvdev);void mlx5vf_mig_file_cleanup_cb (struct work_struct *_work); +void mlx5vf_mig_file_set_save_work (struct mlx5_vf_migration_file *migf, +u8 chunk_num,size_t next_required_umem_size);int mlx5vf_start_page_tracker (struct vfio_device *vdev,struct rb_root_cached *ranges,u32 nnodes,u64 *page_size);int mlx5vf_stop_page_tracker (struct vfio_device *vdev);
drivers/vfio/pci/mlx5/main.c +74 -10
102 lines not on this page · raw message
Signature · 1 line
2.18.1
Yishai Hadas
maintainerPATCH 8/9 vfio/mlx5: Add support for READING in chunk mode
In reply to Yishai HadasAdd support for READING in chunk mode.
In case the last SAVE command recognized that there was still some image to be read, however, there was no available chunk to use for, this task was delayed for the reader till one chunk will be consumed and becomes available.
In the above case, a work will be executed to read in the background the next image from the device.
--- drivers/vfio/pci/mlx5/main.c | 43 +++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-)
drivers/vfio/pci/mlx5/main.c +37 -6
@@ -160,6 +160,41 @@ mlx5vf_get_data_buff_from_pos(struct mlx5_vf_migration_file *migf, loff_t pos,return found ? buf :NULL ; } +static void mlx5vf_buf_read_done (struct mlx5_vhca_data_buffer *vhca_buf) +{ +struct mlx5_vf_migration_file *migf = vhca_buf->migf; + +if (vhca_buf->stop_copy_chunk_num) { +bool is_header = vhca_buf->dma_dir ==DMA_NONE ; +u8 chunk_num = vhca_buf->stop_copy_chunk_num; +size_t next_required_umem_size =0 ; + +if (is_header) + migf->buf_header[chunk_num -1 ] = vhca_buf; +else + migf->buf[chunk_num -1 ] = vhca_buf; + +spin_lock_irq (&migf->list_lock); +list_del_init (&vhca_buf->buf_elm); +if (!is_header) { + next_required_umem_size = + migf->next_required_umem_size; + migf->next_required_umem_size =0 ; + migf->num_ready_chunks--; + } +spin_unlock_irq (&migf->list_lock); +if (next_required_umem_size) +mlx5vf_mig_file_set_save_work (migf, chunk_num, + next_required_umem_size); +return ; + } + +spin_lock_irq (&migf->list_lock); +list_del_init (&vhca_buf->buf_elm); +list_add_tail (&vhca_buf->buf_elm, &vhca_buf->migf->avail_list); +spin_unlock_irq (&migf->list_lock); +} +static ssize_t mlx5vf_buf_read (struct mlx5_vhca_data_buffer *vhca_buf,char __user **buf,size_t *len,loff_t *pos) {
@@ -195,12 +230,8 @@ static ssize_t mlx5vf_buf_read(struct mlx5_vhca_data_buffer *vhca_buf, copy_len -= page_len; } -if (*pos >= vhca_buf->start_pos + vhca_buf->length) { -spin_lock_irq (&vhca_buf->migf->list_lock); -list_del_init (&vhca_buf->buf_elm); -list_add_tail (&vhca_buf->buf_elm, &vhca_buf->migf->avail_list); -spin_unlock_irq (&vhca_buf->migf->list_lock); - } +if (*pos >= vhca_buf->start_pos + vhca_buf->length) +mlx5vf_buf_read_done (vhca_buf);return done; }
Signature · 1 line
2.18.1
Yishai Hadas
maintainerPATCH 9/9 vfio/mlx5: Activate the chunk mode functionality
In reply to Yishai HadasNow that all pieces are in place, activate the chunk mode functionality based on device capabilities.
--- drivers/vfio/pci/mlx5/cmd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/vfio/pci/mlx5/cmd.c +3 -0
@@ -261,6 +261,9 @@ void mlx5vf_cmd_set_migratable(struct mlx5vf_pci_core_device *mvdev, mvdev->core_device.vdev.migration_flags |=VFIO_MIGRATION_PRE_COPY ; +if (MLX5_CAP_GEN_2 (mvdev->mdev, migration_in_chunks)) + mvdev->chunk_mode =1 ; + end:mlx5_vf_put_core_dev (mvdev->mdev); }
Signature · 1 line
2.18.1
Quoted 40 lines · Yishai Hadas
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
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_STATEcommand with the 'chunk' bit set in its input, in that case, the output will include both the minimum buffer size and also the remaining total size to be reported/used where it will be applicable.Upon chunk mode, there may be multiple images that will be read from the device upon
STOP_COPY. The driver will read ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.The chunk buffer size is picked up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
With that series in place, we could migrate successfully a device state with a larger size than 4GB, while even improving the downtime in some scenarios.
Note:
As the first patch should go to net/mlx5 we may need to send it as a pull request format to VFIO to avoid conflicts before acceptance.Yishai
Quoted 12 lines
Yishai Hadas (9):
net/mlx5: Introduce ifc bits for migration in a chunk mode vfio/mlx5: Wake up the reader post of disabling the SAVING migration
file
vfio/mlx5: Refactor the SAVE callback to activate a work only upon an
error
vfio/mlx5: Enable querying state size which is > 4GB vfio/mlx5: Rename some stuff to match chunk mode vfio/mlx5: Pre-allocate chunks for theSTOP_COPYphase vfio/mlx5: Add support for SAVING in chunk mode
vfio/mlx5: Add support for READING in chunk mode vfio/mlx5: Activate the chunk mode functionality
I didn't check in great depth but this looks OK to me
I think this is a good design to start motivating more qmeu improvements, eg using io_uring as we could go further in the driver to optimize with that kind of support.
Jason
Yishai Hadas
maintainerQuoted 53 lines · Jason Gunthorpe
Quoted 40 lines · Yishai Hadas
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
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_STATEcommand with the 'chunk' bit set in its input, in that case, the output will include both the minimum buffer size and also the remaining total size to be reported/used where it will be applicable.Upon chunk mode, there may be multiple images that will be read from the device upon
STOP_COPY. The driver will read ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.The chunk buffer size is picked up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
With that series in place, we could migrate successfully a device state with a larger size than 4GB, while even improving the downtime in some scenarios.
Note:
As the first patch should go to net/mlx5 we may need to send it as a pull request format to VFIO to avoid conflicts before acceptance.Yishai
Quoted 12 lines
Yishai Hadas (9):
net/mlx5: Introduce ifc bits for migration in a chunk mode vfio/mlx5: Wake up the reader post of disabling the SAVING migration
file
vfio/mlx5: Refactor the SAVE callback to activate a work only upon an
error
vfio/mlx5: Enable querying state size which is > 4GB vfio/mlx5: Rename some stuff to match chunk mode vfio/mlx5: Pre-allocate chunks for theSTOP_COPYphase vfio/mlx5: Add support for SAVING in chunk mode vfio/mlx5: Add support for READING in chunk mode vfio/mlx5: Activate the chunk mode functionality
Quoted 3 lines
I didn't check in great depth but this looks OK to me
Reviewed-by Jason Gunthorpe <[email protected]>
Thanks Jason
Quoted 6 lines
I think this is a good design to start motivating more qmeu improvements, eg using
io_uringas we could go further in the driver to optimize with that kind of support.Jason
Alex,
Can we move forward with the series and send a PR for the first patch that needs to go also to net/mlx5 ?
Thanks,
Yishai
Quoted 65 lines · On Wed, 27 Sep 2023 13:59:06 +0300 Yishai Hadas <[email protected]> wrote:
Quoted 53 lines · Jason Gunthorpe
Quoted 40 lines · Yishai Hadas
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
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_STATEcommand with the 'chunk' bit set in its input, in that case, the output will include both the minimum buffer size and also the remaining total size to be reported/used where it will be applicable.Upon chunk mode, there may be multiple images that will be read from the device upon
STOP_COPY. The driver will read ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.The chunk buffer size is picked up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
With that series in place, we could migrate successfully a device state with a larger size than 4GB, while even improving the downtime in some scenarios.
Note:
As the first patch should go to net/mlx5 we may need to send it as a pull request format to VFIO to avoid conflicts before acceptance.Yishai
Quoted 12 lines
Yishai Hadas (9):
net/mlx5: Introduce ifc bits for migration in a chunk mode vfio/mlx5: Wake up the reader post of disabling the SAVING migration
file
vfio/mlx5: Refactor the SAVE callback to activate a work only upon an
error
vfio/mlx5: Enable querying state size which is > 4GB vfio/mlx5: Rename some stuff to match chunk mode vfio/mlx5: Pre-allocate chunks for theSTOP_COPYphase vfio/mlx5: Add support for SAVING in chunk mode vfio/mlx5: Add support for READING in chunk mode vfio/mlx5: Activate the chunk mode functionalityQuoted 3 lines
I didn't check in great depth but this looks OK to me
Reviewed-by Jason Gunthorpe <[email protected]>Thanks Jason
Quoted 5 lines
I think this is a good design to start motivating more qmeu improvements, eg using
io_uringas we could go further in the driver to optimize with that kind of support.
Quoted 6 lines
Quoted 1 line
Jason
Alex,
Can we move forward with the series and send a PR for the first patch that needs to go also to net/mlx5 ?
Yeah, I don't spot any issues with it either. Thanks,
Alex
Quoted 68 lines · Alex Williamson
Quoted 65 lines · On Wed, 27 Sep 2023 13:59:06 +0300 Yishai Hadas <[email protected]> wrote:
Quoted 53 lines · Jason Gunthorpe
Quoted 40 lines · Yishai Hadas
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
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_STATEcommand with the 'chunk' bit set in its input, in that case, the output will include both the minimum buffer size and also the remaining total size to be reported/used where it will be applicable.Upon chunk mode, there may be multiple images that will be read from the device upon
STOP_COPY. The driver will read ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.The chunk buffer size is picked up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
With that series in place, we could migrate successfully a device state with a larger size than 4GB, while even improving the downtime in some scenarios.
Note:
As the first patch should go to net/mlx5 we may need to send it as a pull request format to VFIO to avoid conflicts before acceptance.Yishai
Quoted 12 lines
Yishai Hadas (9):
net/mlx5: Introduce ifc bits for migration in a chunk mode vfio/mlx5: Wake up the reader post of disabling the SAVING migration
file
vfio/mlx5: Refactor the SAVE callback to activate a work only upon an
error
vfio/mlx5: Enable querying state size which is > 4GB vfio/mlx5: Rename some stuff to match chunk mode vfio/mlx5: Pre-allocate chunks for theSTOP_COPYphase vfio/mlx5: Add support for SAVING in chunk mode vfio/mlx5: Add support for READING in chunk mode vfio/mlx5: Activate the chunk mode functionalityQuoted 3 lines
I didn't check in great depth but this looks OK to me
Reviewed-by Jason Gunthorpe <[email protected]>Thanks Jason
Quoted 5 lines
I think this is a good design to start motivating more qmeu improvements, eg using
io_uringas we could go further in the driver to optimize with that kind of support.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Jason
Alex,
Can we move forward with the series and send a PR for the first patch that needs to go also to net/mlx5 ?
Yeah, I don't spot any issues with it either. Thanks,
Hi Alex,
I uploaded the first patch to shared branch, can you please pull it?
https://git.kernel.org/pub/scm/linux/kernel/git/mellanox/linux.git/log/?h=mlx5-vfio
Thanks
Quoted 4 lines
Alex
Quoted 76 lines · On Thu, 28 Sep 2023 14:08:08 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 75 lines · Alex Williamson
Quoted 71 lines · On Wed, 27 Sep 2023 13:59:06 +0300 Yishai Hadas <[email protected]> wrote:
Quoted 53 lines · Jason Gunthorpe
Quoted 40 lines · Yishai Hadas
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
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_STATEcommand with the 'chunk' bit set in its input, in that case, the output will include both the minimum buffer size and also the remaining total size to be reported/used where it will be applicable.Upon chunk mode, there may be multiple images that will be read from the device upon
STOP_COPY. The driver will read ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.The chunk buffer size is picked up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
With that series in place, we could migrate successfully a device state with a larger size than 4GB, while even improving the downtime in some scenarios.
Note:
As the first patch should go to net/mlx5 we may need to send it as a pull request format to VFIO to avoid conflicts before acceptance.Yishai
Quoted 12 lines
Yishai Hadas (9):
net/mlx5: Introduce ifc bits for migration in a chunk mode vfio/mlx5: Wake up the reader post of disabling the SAVING migration
file
vfio/mlx5: Refactor the SAVE callback to activate a work only upon an
error
vfio/mlx5: Enable querying state size which is > 4GB vfio/mlx5: Rename some stuff to match chunk mode vfio/mlx5: Pre-allocate chunks for theSTOP_COPYphase vfio/mlx5: Add support for SAVING in chunk mode vfio/mlx5: Add support for READING in chunk mode vfio/mlx5: Activate the chunk mode functionalityQuoted 3 lines
I didn't check in great depth but this looks OK to me
Reviewed-by Jason Gunthorpe <[email protected]>Thanks Jason
Quoted 6 lines
I think this is a good design to start motivating more qmeu improvements, eg using
io_uringas we could go further in the driver to optimize with that kind of support.Jason
Alex,
Can we move forward with the series and send a PR for the first patch that needs to go also to net/mlx5 ?
Quoted 6 lines
Quoted 1 line
Yeah, I don't spot any issues with it either. Thanks,
Hi Alex,
I uploaded the first patch to shared branch, can you please pull it?
https://git.kernel.org/pub/scm/linux/kernel/git/mellanox/linux.git/log/?h=mlx5-vfio
Yep, got it. Thanks.
Yishai, were you planning to resend the remainder or do you just want me to pull 2-9 from this series? Thanks,
Alex
Quoted 83 lines · Alex Williamson
Quoted 80 lines · On Thu, 28 Sep 2023 14:08:08 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 68 lines · Alex Williamson
Quoted 65 lines · On Wed, 27 Sep 2023 13:59:06 +0300 Yishai Hadas <[email protected]> wrote:
Quoted 53 lines · Jason Gunthorpe
Quoted 40 lines · Yishai Hadas
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
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_STATEcommand with the 'chunk' bit set in its input, in that case, the output will include both the minimum buffer size and also the remaining total size to be reported/used where it will be applicable.Upon chunk mode, there may be multiple images that will be read from the device upon
STOP_COPY. The driver will read ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.The chunk buffer size is picked up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
With that series in place, we could migrate successfully a device state with a larger size than 4GB, while even improving the downtime in some scenarios.
Note:
As the first patch should go to net/mlx5 we may need to send it as a pull request format to VFIO to avoid conflicts before acceptance.Yishai
Quoted 12 lines
Yishai Hadas (9):
net/mlx5: Introduce ifc bits for migration in a chunk mode vfio/mlx5: Wake up the reader post of disabling the SAVING migration
file
vfio/mlx5: Refactor the SAVE callback to activate a work only upon an
error
vfio/mlx5: Enable querying state size which is > 4GB vfio/mlx5: Rename some stuff to match chunk mode vfio/mlx5: Pre-allocate chunks for theSTOP_COPYphase vfio/mlx5: Add support for SAVING in chunk mode vfio/mlx5: Add support for READING in chunk mode vfio/mlx5: Activate the chunk mode functionalityQuoted 3 lines
I didn't check in great depth but this looks OK to me
Reviewed-by Jason Gunthorpe <[email protected]>Thanks Jason
Quoted 5 lines
I think this is a good design to start motivating more qmeu improvements, eg using
io_uringas we could go further in the driver to optimize with that kind of support.Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Jason
Alex,
Can we move forward with the series and send a PR for the first patch that needs to go also to net/mlx5 ?
Yeah, I don't spot any issues with it either. Thanks,
Hi Alex,
Quoted 7 lines
Quoted 2 lines
I uploaded the first patch to shared branch, can you please pull it?
https://git.kernel.org/pub/scm/linux/kernel/git/mellanox/linux.git/log/?h=mlx5-vfioYep, got it. Thanks.
Yishai, were you planning to resend the remainder or do you just want me to pull 2-9 from this series? Thanks,
Just pull, like I did with b4 :)
~/src/b4/b4.sh shazam -l -s https://lore.kernel.org/kvm/[email protected]/ -P 2-9 -t
Thanks
Quoted 3 lines
Alex
Quoted 87 lines · On Thu, 28 Sep 2023 21:42:22 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 86 lines · Alex Williamson
Quoted 82 lines · On Thu, 28 Sep 2023 14:08:08 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 68 lines · Alex Williamson
Quoted 65 lines · On Wed, 27 Sep 2023 13:59:06 +0300 Yishai Hadas <[email protected]> wrote:
Quoted 53 lines · Jason Gunthorpe
Quoted 40 lines · Yishai Hadas
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
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_STATEcommand with the 'chunk' bit set in its input, in that case, the output will include both the minimum buffer size and also the remaining total size to be reported/used where it will be applicable.Upon chunk mode, there may be multiple images that will be read from the device upon
STOP_COPY. The driver will read ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.The chunk buffer size is picked up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
With that series in place, we could migrate successfully a device state with a larger size than 4GB, while even improving the downtime in some scenarios.
Note:
As the first patch should go to net/mlx5 we may need to send it as a pull request format to VFIO to avoid conflicts before acceptance.Yishai
Quoted 12 lines
Yishai Hadas (9):
net/mlx5: Introduce ifc bits for migration in a chunk mode vfio/mlx5: Wake up the reader post of disabling the SAVING migration
file
vfio/mlx5: Refactor the SAVE callback to activate a work only upon an
error
vfio/mlx5: Enable querying state size which is > 4GB vfio/mlx5: Rename some stuff to match chunk mode vfio/mlx5: Pre-allocate chunks for theSTOP_COPYphase vfio/mlx5: Add support for SAVING in chunk mode vfio/mlx5: Add support for READING in chunk mode vfio/mlx5: Activate the chunk mode functionalityQuoted 3 lines
I didn't check in great depth but this looks OK to me
Reviewed-by Jason Gunthorpe <[email protected]>Thanks Jason
Quoted 5 lines
I think this is a good design to start motivating more qmeu improvements, eg using
io_uringas we could go further in the driver to optimize with that kind of support.Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Jason
Alex,
Can we move forward with the series and send a PR for the first patch that needs to go also to net/mlx5 ?
Yeah, I don't spot any issues with it either. Thanks,
Hi Alex,
I uploaded the first patch to shared branch, can you please pull it?
https://git.kernel.org/pub/scm/linux/kernel/git/mellanox/linux.git/log/?h=mlx5-vfio
Quoted 8 lines
Quoted 4 lines
Yep, got it. Thanks.
Yishai, were you planning to resend the remainder or do you just want me to pull 2-9 from this series? Thanks,
Just pull, like I did with b4 :)
~/src/b4/b4.shshazam -l -s https://lore.kernel.org/kvm/[email protected]/ -P 2-9 -t
Yep, the mechanics were really not the question, I'm just double checking to avoid any conflicts with a re-post. Thanks,
Alex
Quoted 95 lines · Alex Williamson
Quoted 92 lines · On Thu, 28 Sep 2023 21:42:22 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 90 lines · Alex Williamson
Quoted 76 lines · On Thu, 28 Sep 2023 14:08:08 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 75 lines · Alex Williamson
Quoted 71 lines · On Wed, 27 Sep 2023 13:59:06 +0300 Yishai Hadas <[email protected]> wrote:
Quoted 53 lines · Jason Gunthorpe
Quoted 40 lines · Yishai Hadas
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
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_STATEcommand with the 'chunk' bit set in its input, in that case, the output will include both the minimum buffer size and also the remaining total size to be reported/used where it will be applicable.Upon chunk mode, there may be multiple images that will be read from the device upon
STOP_COPY. The driver will read ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.The chunk buffer size is picked up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
With that series in place, we could migrate successfully a device state with a larger size than 4GB, while even improving the downtime in some scenarios.
Note:
As the first patch should go to net/mlx5 we may need to send it as a pull request format to VFIO to avoid conflicts before acceptance.Yishai
Quoted 12 lines
Yishai Hadas (9):
net/mlx5: Introduce ifc bits for migration in a chunk mode vfio/mlx5: Wake up the reader post of disabling the SAVING migration
file
vfio/mlx5: Refactor the SAVE callback to activate a work only upon an
error
vfio/mlx5: Enable querying state size which is > 4GB vfio/mlx5: Rename some stuff to match chunk mode vfio/mlx5: Pre-allocate chunks for theSTOP_COPYphase vfio/mlx5: Add support for SAVING in chunk mode vfio/mlx5: Add support for READING in chunk mode vfio/mlx5: Activate the chunk mode functionalityQuoted 3 lines
I didn't check in great depth but this looks OK to me
Reviewed-by Jason Gunthorpe <[email protected]>Thanks Jason
Quoted 6 lines
I think this is a good design to start motivating more qmeu improvements, eg using
io_uringas we could go further in the driver to optimize with that kind of support.Jason
Alex,
Can we move forward with the series and send a PR for the first patch that needs to go also to net/mlx5 ?
Quoted 6 lines
Quoted 1 line
Yeah, I don't spot any issues with it either. Thanks,
Hi Alex,
I uploaded the first patch to shared branch, can you please pull it?
https://git.kernel.org/pub/scm/linux/kernel/git/mellanox/linux.git/log/?h=mlx5-vfioYep, got it. Thanks.
Yishai, were you planning to resend the remainder or do you just want me to pull 2-9 from this series? Thanks,
Quoted 6 lines
Quoted 3 lines
Just pull, like I did with b4 :)
~/src/b4/b4.shshazam -l -s https://lore.kernel.org/kvm/[email protected]/ -P 2-9 -tYep, the mechanics were really not the question, I'm just double checking to avoid any conflicts with a re-post. Thanks,
It is pretty safe to say that he won't re-post.
He had no plans to resend the series.
Thanks
Quoted 3 lines
Alex
Quoted 98 lines · On Thu, 28 Sep 2023 21:51:02 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 97 lines · Alex Williamson
Quoted 94 lines · On Thu, 28 Sep 2023 21:42:22 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 83 lines · Alex Williamson
Quoted 80 lines · On Thu, 28 Sep 2023 14:08:08 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 68 lines · Alex Williamson
Quoted 65 lines · On Wed, 27 Sep 2023 13:59:06 +0300 Yishai Hadas <[email protected]> wrote:
Quoted 53 lines · Jason Gunthorpe
Quoted 40 lines · Yishai Hadas
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
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_STATEcommand with the 'chunk' bit set in its input, in that case, the output will include both the minimum buffer size and also the remaining total size to be reported/used where it will be applicable.Upon chunk mode, there may be multiple images that will be read from the device upon
STOP_COPY. The driver will read ahead from the firmware the full state in small/optimized chunks while letting QEMU/user space read in parallel the available data.The chunk buffer size is picked up based on the minimum size that firmware requires, the total full size and some max value in the driver code which was set to 8MB to achieve some optimized downtime in the general case.
With that series in place, we could migrate successfully a device state with a larger size than 4GB, while even improving the downtime in some scenarios.
Note:
As the first patch should go to net/mlx5 we may need to send it as a pull request format to VFIO to avoid conflicts before acceptance.Yishai
Quoted 12 lines
Yishai Hadas (9):
net/mlx5: Introduce ifc bits for migration in a chunk mode vfio/mlx5: Wake up the reader post of disabling the SAVING migration
file
vfio/mlx5: Refactor the SAVE callback to activate a work only upon an
error
vfio/mlx5: Enable querying state size which is > 4GB vfio/mlx5: Rename some stuff to match chunk mode vfio/mlx5: Pre-allocate chunks for theSTOP_COPYphase vfio/mlx5: Add support for SAVING in chunk mode vfio/mlx5: Add support for READING in chunk mode vfio/mlx5: Activate the chunk mode functionalityQuoted 3 lines
I didn't check in great depth but this looks OK to me
Reviewed-by Jason Gunthorpe <[email protected]>Thanks Jason
Quoted 5 lines
I think this is a good design to start motivating more qmeu improvements, eg using
io_uringas we could go further in the driver to optimize with that kind of support.Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Jason
Alex,
Can we move forward with the series and send a PR for the first patch that needs to go also to net/mlx5 ?
Yeah, I don't spot any issues with it either. Thanks,
Hi Alex,
Quoted 7 lines
Quoted 2 lines
I uploaded the first patch to shared branch, can you please pull it?
https://git.kernel.org/pub/scm/linux/kernel/git/mellanox/linux.git/log/?h=mlx5-vfioYep, got it. Thanks.
Yishai, were you planning to resend the remainder or do you just want me to pull 2-9 from this series? Thanks,
Just pull, like I did with b4 :)
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
~/src/b4/b4.shshazam -l -s https://lore.kernel.org/kvm/[email protected]/ -P 2-9 -tYep, the mechanics were really not the question, I'm just double checking to avoid any conflicts with a re-post. Thanks,
It is pretty safe to say that he won't re-post.
He had no plans to resend the series.
Ok, applied the remainder of the series to the vfio next branch for v6.7. Thanks,
Alex
Leon Romanovsky
AppliedRe: (subset) [PATCH vfio 0/9] Add chunk mode support for mlx5 driver
In reply to Yishai HadasQuoted 8 lines · Yishai Hadas
This series adds 'chunk mode' support for mlx5 driver upon the migration flow.
Before this series, we were limited to 4GB state size, as of the 4 bytes max value based on the device specification for the query/save/load commands.
[...]
Applied, thanks!
[1/9] net/mlx5: Introduce ifc bits for migration in a chunk mode
https://git.kernel.org/rdma/rdma/c/5aa4c9608d2d5f
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>