[PATCH vfio 1/2] vfio/mlx5: Change reset_lock to mutex_lock

From: Brett Creeley
Date: Wed Nov 22 2023 - 14:32:51 EST


Based on comments from other vfio vendors and the
maintainer the vfio/pds driver changed the reset_lock
to a mutex_lock. As part of that change it was requested
that the other vendor drivers be changed as well. So,
make the change.

The comment that requested the change for reference:
https://lore.kernel.org/kvm/BN9PR11MB52769E037CB356AB15A0D9B88CA0A@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

Also, make checkpatch happy by moving the lock comment.

Signed-off-by: Brett Creeley <brett.creeley@xxxxxxx>
---
drivers/vfio/pci/mlx5/cmd.c | 3 ++-
drivers/vfio/pci/mlx5/cmd.h | 3 +--
drivers/vfio/pci/mlx5/main.c | 12 ++++++------
3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/vfio/pci/mlx5/cmd.c b/drivers/vfio/pci/mlx5/cmd.c
index efd1d252cdc9..5cf68ab2bbd7 100644
--- a/drivers/vfio/pci/mlx5/cmd.c
+++ b/drivers/vfio/pci/mlx5/cmd.c
@@ -202,6 +202,7 @@ void mlx5vf_cmd_remove_migratable(struct mlx5vf_pci_core_device *mvdev)
mlx5_sriov_blocking_notifier_unregister(mvdev->mdev, mvdev->vf_id,
&mvdev->nb);
destroy_workqueue(mvdev->cb_wq);
+ mutex_destroy(&mvdev->reset_mutex);
}

void mlx5vf_cmd_set_migratable(struct mlx5vf_pci_core_device *mvdev,
@@ -238,7 +239,7 @@ void mlx5vf_cmd_set_migratable(struct mlx5vf_pci_core_device *mvdev,
goto end;

mutex_init(&mvdev->state_mutex);
- spin_lock_init(&mvdev->reset_lock);
+ mutex_init(&mvdev->reset_mutex);
mvdev->nb.notifier_call = mlx5fv_vf_event;
ret = mlx5_sriov_blocking_notifier_register(mvdev->mdev, mvdev->vf_id,
&mvdev->nb);
diff --git a/drivers/vfio/pci/mlx5/cmd.h b/drivers/vfio/pci/mlx5/cmd.h
index f2c7227fa683..1cfd126724a2 100644
--- a/drivers/vfio/pci/mlx5/cmd.h
+++ b/drivers/vfio/pci/mlx5/cmd.h
@@ -183,8 +183,7 @@ struct mlx5vf_pci_core_device {
/* protect migration state */
struct mutex state_mutex;
enum vfio_device_mig_state mig_state;
- /* protect the reset_done flow */
- spinlock_t reset_lock;
+ struct mutex reset_mutex; /* protect the reset_done flow */
struct mlx5_vf_migration_file *resuming_migf;
struct mlx5_vf_migration_file *saving_migf;
struct mlx5_vhca_page_tracker tracker;
diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c
index b6ac66c5008d..689edfd750e1 100644
--- a/drivers/vfio/pci/mlx5/main.c
+++ b/drivers/vfio/pci/mlx5/main.c
@@ -1284,16 +1284,16 @@ mlx5vf_pci_step_device_state_locked(struct mlx5vf_pci_core_device *mvdev,
void mlx5vf_state_mutex_unlock(struct mlx5vf_pci_core_device *mvdev)
{
again:
- spin_lock(&mvdev->reset_lock);
+ mutex_lock(&mvdev->reset_mutex);
if (mvdev->deferred_reset) {
mvdev->deferred_reset = false;
- spin_unlock(&mvdev->reset_lock);
+ mutex_unlock(&mvdev->reset_mutex);
mvdev->mig_state = VFIO_DEVICE_STATE_RUNNING;
mlx5vf_disable_fds(mvdev);
goto again;
}
mutex_unlock(&mvdev->state_mutex);
- spin_unlock(&mvdev->reset_lock);
+ mutex_unlock(&mvdev->reset_mutex);
}

static struct file *
@@ -1372,13 +1372,13 @@ static void mlx5vf_pci_aer_reset_done(struct pci_dev *pdev)
* In case the state_mutex was taken already we defer the cleanup work
* to the unlock flow of the other running context.
*/
- spin_lock(&mvdev->reset_lock);
+ mutex_lock(&mvdev->reset_mutex);
mvdev->deferred_reset = true;
if (!mutex_trylock(&mvdev->state_mutex)) {
- spin_unlock(&mvdev->reset_lock);
+ mutex_unlock(&mvdev->reset_mutex);
return;
}
- spin_unlock(&mvdev->reset_lock);
+ mutex_unlock(&mvdev->reset_mutex);
mlx5vf_state_mutex_unlock(mvdev);
}

--
2.17.1