From: Yishai Hadas Date: Tue, 17 Mar 2026 16:17:52 +0000 (+0200) Subject: vfio/mlx5: consider inflight SAVE during PRE_COPY X-Git-Tag: v7.1-rc1~132^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd0da611312b94f34b0e2b7342fdbd0431851347;p=thirdparty%2Fkernel%2Fstable.git vfio/mlx5: consider inflight SAVE during PRE_COPY 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 Link: https://lore.kernel.org/r/20260317161753.18964-6-yishaih@nvidia.com Signed-off-by: Alex Williamson --- diff --git a/drivers/vfio/pci/mlx5/cmd.c b/drivers/vfio/pci/mlx5/cmd.c index ca6d95f293cd8..18b8d85940703 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 d7821b5ca7729..7d2c10be2e60f 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 fb541c17c7128..68e051c48d401 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; }