Skip to content

Commit 2b1c190

Browse files
yishaihawilliam
authored andcommitted
vfio/mlx5: Protect mlx5vf_disable_fds() upon close device
Protect mlx5vf_disable_fds() upon close device to be called under the state mutex as done in all other places. This will prevent a race with any other flow which calls mlx5vf_disable_fds() as of health/recovery upon MLX5_PF_NOTIFY_DISABLE_VF event. Encapsulate this functionality in a separate function named mlx5vf_cmd_close_migratable() to consider migration caps and for further usage upon close device. Fixes: 6fadb02 ("vfio/mlx5: Implement vfio_pci driver for mlx5 devices") Reviewed-by: Kevin Tian <[email protected]> Signed-off-by: Yishai Hadas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent d1877e6 commit 2b1c190

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

drivers/vfio/pci/mlx5/cmd.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ static int mlx5fv_vf_event(struct notifier_block *nb,
8888
return 0;
8989
}
9090

91+
void mlx5vf_cmd_close_migratable(struct mlx5vf_pci_core_device *mvdev)
92+
{
93+
if (!mvdev->migrate_cap)
94+
return;
95+
96+
mutex_lock(&mvdev->state_mutex);
97+
mlx5vf_disable_fds(mvdev);
98+
mlx5vf_state_mutex_unlock(mvdev);
99+
}
100+
91101
void mlx5vf_cmd_remove_migratable(struct mlx5vf_pci_core_device *mvdev)
92102
{
93103
if (!mvdev->migrate_cap)

drivers/vfio/pci/mlx5/cmd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ int mlx5vf_cmd_query_vhca_migration_state(struct mlx5vf_pci_core_device *mvdev,
6464
size_t *state_size);
6565
void mlx5vf_cmd_set_migratable(struct mlx5vf_pci_core_device *mvdev);
6666
void mlx5vf_cmd_remove_migratable(struct mlx5vf_pci_core_device *mvdev);
67+
void mlx5vf_cmd_close_migratable(struct mlx5vf_pci_core_device *mvdev);
6768
int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev,
6869
struct mlx5_vf_migration_file *migf);
6970
int mlx5vf_cmd_load_vhca_state(struct mlx5vf_pci_core_device *mvdev,

drivers/vfio/pci/mlx5/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ static void mlx5vf_pci_close_device(struct vfio_device *core_vdev)
570570
struct mlx5vf_pci_core_device *mvdev = container_of(
571571
core_vdev, struct mlx5vf_pci_core_device, core_device.vdev);
572572

573-
mlx5vf_disable_fds(mvdev);
573+
mlx5vf_cmd_close_migratable(mvdev);
574574
vfio_pci_core_close_device(core_vdev);
575575
}
576576

0 commit comments

Comments
 (0)