All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Yishai Hadas <yishaih@nvidia.com>
Cc: alex.williamson@redhat.com, kvm@vger.kernel.org,
	kevin.tian@intel.com, joao.m.martins@oracle.com,
	leonro@nvidia.com, shayd@nvidia.com, maorg@nvidia.com,
	avihaih@nvidia.com, cohuck@redhat.com
Subject: Re: [PATCH vfio 05/13] vfio/mlx5: Enforce a single SAVE command at a time
Date: Wed, 9 Nov 2022 14:04:41 -0400	[thread overview]
Message-ID: <Y2vrucy8NNG2856a@nvidia.com> (raw)
In-Reply-To: <20221106174630.25909-6-yishaih@nvidia.com>

On Sun, Nov 06, 2022 at 07:46:22PM +0200, Yishai Hadas wrote:
> Enforce a single SAVE command at a time.
> 
> As the SAVE command is an asynchronous one, we must enforce running only
> a single command at a time.
> 
> This will preserve ordering between multiple calls and protect from
> races on the migration file data structure.
> 
> This is a must for the next patches from the series where as part of
> PRE_COPY we may have multiple images to be saved and multiple SAVE
> commands may be issued from different flows.
> 
> Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
> ---
>  drivers/vfio/pci/mlx5/cmd.c  | 5 +++++
>  drivers/vfio/pci/mlx5/cmd.h  | 2 ++
>  drivers/vfio/pci/mlx5/main.c | 1 +
>  3 files changed, 8 insertions(+)

This should just use a 'counting completion' instead of open coding
one.


> diff --git a/drivers/vfio/pci/mlx5/cmd.c b/drivers/vfio/pci/mlx5/cmd.c
> index 0848bc905d3e..b9ed2f1c8689 100644
> --- a/drivers/vfio/pci/mlx5/cmd.c
> +++ b/drivers/vfio/pci/mlx5/cmd.c
> @@ -281,6 +281,8 @@ void mlx5vf_mig_file_cleanup_cb(struct work_struct *_work)
>  	dma_unmap_sgtable(mdev->device, &migf->table.sgt, DMA_FROM_DEVICE, 0);
>  	mlx5_core_dealloc_pd(mdev, async_data->pdn);
>  	kvfree(async_data->out);
> +	migf->save_cb_active = false;
> +	wake_up(&migf->save_wait);

complete()

>  	fput(migf->filp);
>  }
>  
> @@ -321,6 +323,7 @@ int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev,
>  		return -ENOTCONN;
>  
>  	mdev = mvdev->mdev;
> +	wait_event(migf->save_wait, !migf->save_cb_active);

wait_for_completion_interruptible()

>  	err = mlx5_core_alloc_pd(mdev, &pdn);
>  	if (err)
>  		return err;
> @@ -353,6 +356,7 @@ int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev,
>  	get_file(migf->filp);
>  	async_data->mkey = mkey;
>  	async_data->pdn = pdn;
> +	migf->save_cb_active = true;
>  	err = mlx5_cmd_exec_cb(&migf->async_ctx, in, sizeof(in),
>  			       async_data->out,
>  			       out_size, mlx5vf_save_callback,
> @@ -371,6 +375,7 @@ int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev,
>  	dma_unmap_sgtable(mdev->device, &migf->table.sgt, DMA_FROM_DEVICE, 0);
>  err_dma_map:
>  	mlx5_core_dealloc_pd(mdev, pdn);
> +	migf->save_cb_active = false;

complete()

>  	return err;
>  }
>  
> diff --git a/drivers/vfio/pci/mlx5/cmd.h b/drivers/vfio/pci/mlx5/cmd.h
> index 921d5720a1e5..b1c5dd2ff144 100644
> --- a/drivers/vfio/pci/mlx5/cmd.h
> +++ b/drivers/vfio/pci/mlx5/cmd.h
> @@ -26,6 +26,7 @@ struct mlx5_vf_migration_file {
>  	struct mutex lock;
>  	u8 disabled:1;
>  	u8 is_err:1;
> +	u8 save_cb_active:1;
>  
>  	struct sg_append_table table;
>  	size_t total_length;
> @@ -37,6 +38,7 @@ struct mlx5_vf_migration_file {
>  	unsigned long last_offset;
>  	struct mlx5vf_pci_core_device *mvdev;
>  	wait_queue_head_t poll_wait;
> +	wait_queue_head_t save_wait;
>  	struct mlx5_async_ctx async_ctx;
>  	struct mlx5vf_async_data async_data;
>  };
> diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c
> index 4c7a39ffd247..5da278f3c31c 100644
> --- a/drivers/vfio/pci/mlx5/main.c
> +++ b/drivers/vfio/pci/mlx5/main.c
> @@ -245,6 +245,7 @@ mlx5vf_pci_save_device_data(struct mlx5vf_pci_core_device *mvdev)
>  	stream_open(migf->filp->f_inode, migf->filp);
>  	mutex_init(&migf->lock);
>  	init_waitqueue_head(&migf->poll_wait);
> +	init_waitqueue_head(&migf->save_wait);

init_completion()
complete()

Jason

  reply	other threads:[~2022-11-09 18:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-06 17:46 [PATCH vfio 00/13] Add migration PRE_COPY support for mlx5 driver Yishai Hadas
2022-11-06 17:46 ` [PATCH vfio 01/13] vfio: Add an option to get migration data size Yishai Hadas
2022-11-09  7:42   ` liulongfang
2022-11-09 17:06   ` Jason Gunthorpe
2022-11-13 16:58     ` Yishai Hadas
2022-11-14 19:04       ` Alex Williamson
2022-11-06 17:46 ` [PATCH vfio 02/13] vfio/mlx5: Fix a typo in mlx5vf_cmd_load_vhca_state() Yishai Hadas
2022-11-09 17:06   ` Jason Gunthorpe
2022-11-06 17:46 ` [PATCH vfio 03/13] net/mlx5: Introduce ifc bits for pre_copy Yishai Hadas
2022-11-06 17:46 ` [PATCH vfio 04/13] vfio: Extend the device migration protocol with PRE_COPY Yishai Hadas
2022-11-06 17:46 ` [PATCH vfio 05/13] vfio/mlx5: Enforce a single SAVE command at a time Yishai Hadas
2022-11-09 18:04   ` Jason Gunthorpe [this message]
2022-11-10 10:38     ` Yishai Hadas
2022-11-06 17:46 ` [PATCH vfio 06/13] vfio/mlx5: Refactor total_length name and usage Yishai Hadas
2022-11-09 18:11   ` Jason Gunthorpe
2022-11-10 11:38     ` Yishai Hadas
2022-11-06 17:46 ` [PATCH vfio 07/13] vfio/mlx5: Introduce device transitions of PRE_COPY Yishai Hadas
2022-11-06 17:46 ` [PATCH vfio 08/13] vfio/mlx5: Introduce vfio precopy ioctl implementation Yishai Hadas
2022-11-06 17:46 ` [PATCH vfio 09/13] vfio/mlx5: Manage read() of multiple state saves Yishai Hadas
2022-11-06 17:46 ` [PATCH vfio 10/13] vfio/mlx5: Introduce SW headers for migration states Yishai Hadas
2022-11-09 18:38   ` Jason Gunthorpe
2022-11-06 17:46 ` [PATCH vfio 11/13] vfio/mlx5: Introduce multiple loads Yishai Hadas
2022-11-09 18:45   ` Jason Gunthorpe
2022-11-06 17:46 ` [PATCH vfio 12/13] vfio/mlx5: Fallback to STOP_COPY upon specific PRE_COPY error Yishai Hadas
2022-11-06 17:46 ` [PATCH vfio 13/13] vfio/mlx5: Enable MIGRATION_PRE_COPY flag Yishai Hadas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y2vrucy8NNG2856a@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=alex.williamson@redhat.com \
    --cc=avihaih@nvidia.com \
    --cc=cohuck@redhat.com \
    --cc=joao.m.martins@oracle.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=leonro@nvidia.com \
    --cc=maorg@nvidia.com \
    --cc=shayd@nvidia.com \
    --cc=yishaih@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.