]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
vfio/mlx5: consider inflight SAVE during PRE_COPY
authorYishai Hadas <yishaih@nvidia.com>
Tue, 17 Mar 2026 16:17:52 +0000 (18:17 +0200)
committerAlex Williamson <alex@shazbot.org>
Thu, 19 Mar 2026 18:32:09 +0000 (12:32 -0600)
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 <yishaih@nvidia.com>
Link: https://lore.kernel.org/r/20260317161753.18964-6-yishaih@nvidia.com
Signed-off-by: Alex Williamson <alex@shazbot.org>
drivers/vfio/pci/mlx5/cmd.c
drivers/vfio/pci/mlx5/cmd.h
drivers/vfio/pci/mlx5/main.c

index ca6d95f293cd85efdd2f569c83a1cfe8872e8c7f..18b8d85940703205d7599a3ec157d4bc1cbea70a 100644 (file)
@@ -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);
index d7821b5ca77293259bc19d689cedf0c203138bff..7d2c10be2e60f0113cca724769623b86d413e3a7 100644 (file)
@@ -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 {
index fb541c17c71284e9dcee1bd6a55c4c31e3878df5..68e051c48d4012888158f6f071415640f99c6fc5 100644 (file)
@@ -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;
        }