Consider an inflight SAVE operation during the PRE_COPY phase, so the caller will wait when no data is currently available but is expected to arrive. This enables a follow-up patch to avoid returning -ENOMSG while a new *initial_bytes* chunk is still pending from an asynchronous SAVE command issued by the VFIO_MIG_GET_PRECOPY_INFO ioctl. Signed-off-by: Yishai Hadas --- drivers/vfio/pci/mlx5/cmd.c | 5 +++++ drivers/vfio/pci/mlx5/cmd.h | 1 + drivers/vfio/pci/mlx5/main.c | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/mlx5/cmd.c b/drivers/vfio/pci/mlx5/cmd.c index ca6d95f293cd..18b8d8594070 100644 --- a/drivers/vfio/pci/mlx5/cmd.c +++ b/drivers/vfio/pci/mlx5/cmd.c @@ -606,6 +606,8 @@ static void mlx5vf_save_callback_complete(struct mlx5_vf_migration_file *migf, struct mlx5vf_async_data *async_data) { + migf->inflight_save = 0; + wake_up_interruptible(&migf->poll_wait); kvfree(async_data->out); complete(&migf->save_comp); fput(migf->filp); @@ -809,6 +811,7 @@ int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev, async_data->header_buf = header_buf; get_file(migf->filp); + migf->inflight_save = 1; err = mlx5_cmd_exec_cb(&migf->async_ctx, in, sizeof(in), async_data->out, out_size, mlx5vf_save_callback, @@ -819,6 +822,8 @@ int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev, return 0; err_exec: + migf->inflight_save = 0; + wake_up_interruptible(&migf->poll_wait); if (header_buf) mlx5vf_put_data_buffer(header_buf); fput(migf->filp); diff --git a/drivers/vfio/pci/mlx5/cmd.h b/drivers/vfio/pci/mlx5/cmd.h index d7821b5ca772..7d2c10be2e60 100644 --- a/drivers/vfio/pci/mlx5/cmd.h +++ b/drivers/vfio/pci/mlx5/cmd.h @@ -111,6 +111,7 @@ struct mlx5_vf_migration_file { struct completion save_comp; struct mlx5_async_ctx async_ctx; struct mlx5vf_async_data async_data; + u8 inflight_save:1; }; struct mlx5_vhca_cq_buf { diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c index fb541c17c712..68e051c48d40 100644 --- a/drivers/vfio/pci/mlx5/main.c +++ b/drivers/vfio/pci/mlx5/main.c @@ -179,7 +179,8 @@ static ssize_t mlx5vf_save_read(struct file *filp, char __user *buf, size_t len, !list_empty(&migf->buf_list) || migf->state == MLX5_MIGF_STATE_ERROR || migf->state == MLX5_MIGF_STATE_PRE_COPY_ERROR || - migf->state == MLX5_MIGF_STATE_PRE_COPY || + (migf->state == MLX5_MIGF_STATE_PRE_COPY && + !migf->inflight_save) || migf->state == MLX5_MIGF_STATE_COMPLETE)) return -ERESTARTSYS; } -- 2.18.1