Skip to content

Commit ad6dc1d

Browse files
elic307imstsirkin
authored andcommitted
vdpa/mlx5: Avoid processing works if workqueue was destroyed
If mlx5_vdpa gets unloaded while a VM is running, the workqueue will be destroyed. However, vhost might still have reference to the kick function and might attempt to push new works. This could lead to null pointer dereference. To fix this, set mvdev->wq to NULL just before destroying and verify that the workqueue is not NULL in mlx5_vdpa_kick_vq before attempting to push a new work. Fixes: 5262912 ("vdpa/mlx5: Add support for control VQ and MAC setting") Signed-off-by: Eli Cohen <elic@nvidia.com> Link: https://lore.kernel.org/r/20220321141303.9586-1-elic@nvidia.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 03a91c9 commit ad6dc1d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ static void mlx5_vdpa_kick_vq(struct vdpa_device *vdev, u16 idx)
17121712
return;
17131713

17141714
if (unlikely(is_ctrl_vq_idx(mvdev, idx))) {
1715-
if (!mvdev->cvq.ready)
1715+
if (!mvdev->wq || !mvdev->cvq.ready)
17161716
return;
17171717

17181718
wqent = kzalloc(sizeof(*wqent), GFP_ATOMIC);
@@ -2779,9 +2779,12 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
27792779
struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
27802780
struct mlx5_vdpa_dev *mvdev = to_mvdev(dev);
27812781
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
2782+
struct workqueue_struct *wq;
27822783

27832784
mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
2784-
destroy_workqueue(mvdev->wq);
2785+
wq = mvdev->wq;
2786+
mvdev->wq = NULL;
2787+
destroy_workqueue(wq);
27852788
_vdpa_unregister_device(dev);
27862789
mgtdev->ndev = NULL;
27872790
}

0 commit comments

Comments
 (0)