Skip to content

Commit 69ec350

Browse files
jasowanggregkh
authored andcommitted
vdpa: mlx5: prevent cvq work from hogging CPU
[ Upstream commit 55ebf0d ] A userspace triggerable infinite loop could happen in mlx5_cvq_kick_handler() if userspace keeps sending a huge amount of cvq requests. Fixing this by introducing a quota and re-queue the work if we're out of the budget (currently the implicit budget is one) . While at it, using a per device work struct to avoid on demand memory allocation for cvq. Fixes: 5262912 ("vdpa/mlx5: Add support for control VQ and MAC setting") Signed-off-by: Jason Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Eli Cohen <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 893c70f commit 69ec350

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ struct mlx5_vdpa_net {
163163
u32 cur_num_vqs;
164164
struct notifier_block nb;
165165
struct vdpa_callback config_cb;
166+
struct mlx5_vdpa_wq_ent cvq_ent;
166167
};
167168

168169
static void free_resources(struct mlx5_vdpa_net *ndev);
@@ -1587,10 +1588,10 @@ static void mlx5_cvq_kick_handler(struct work_struct *work)
15871588
ndev = to_mlx5_vdpa_ndev(mvdev);
15881589
cvq = &mvdev->cvq;
15891590
if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ)))
1590-
goto out;
1591+
return;
15911592

15921593
if (!cvq->ready)
1593-
goto out;
1594+
return;
15941595

15951596
while (true) {
15961597
err = vringh_getdesc_iotlb(&cvq->vring, &cvq->riov, &cvq->wiov, &cvq->head,
@@ -1624,17 +1625,17 @@ static void mlx5_cvq_kick_handler(struct work_struct *work)
16241625

16251626
if (vringh_need_notify_iotlb(&cvq->vring))
16261627
vringh_notify(&cvq->vring);
1628+
1629+
queue_work(mvdev->wq, &wqent->work);
1630+
break;
16271631
}
1628-
out:
1629-
kfree(wqent);
16301632
}
16311633

16321634
static void mlx5_vdpa_kick_vq(struct vdpa_device *vdev, u16 idx)
16331635
{
16341636
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
16351637
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
16361638
struct mlx5_vdpa_virtqueue *mvq;
1637-
struct mlx5_vdpa_wq_ent *wqent;
16381639

16391640
if (!is_index_valid(mvdev, idx))
16401641
return;
@@ -1643,13 +1644,7 @@ static void mlx5_vdpa_kick_vq(struct vdpa_device *vdev, u16 idx)
16431644
if (!mvdev->cvq.ready)
16441645
return;
16451646

1646-
wqent = kzalloc(sizeof(*wqent), GFP_ATOMIC);
1647-
if (!wqent)
1648-
return;
1649-
1650-
wqent->mvdev = mvdev;
1651-
INIT_WORK(&wqent->work, mlx5_cvq_kick_handler);
1652-
queue_work(mvdev->wq, &wqent->work);
1647+
queue_work(mvdev->wq, &ndev->cvq_ent.work);
16531648
return;
16541649
}
16551650

@@ -2588,6 +2583,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
25882583
if (err)
25892584
goto err_mr;
25902585

2586+
ndev->cvq_ent.mvdev = mvdev;
2587+
INIT_WORK(&ndev->cvq_ent.work, mlx5_cvq_kick_handler);
25912588
mvdev->wq = create_singlethread_workqueue("mlx5_vdpa_wq");
25922589
if (!mvdev->wq) {
25932590
err = -ENOMEM;

0 commit comments

Comments
 (0)