Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp306769pxb; Tue, 29 Mar 2022 04:24:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdmZFWhoLY4uroD9dOOPDRqzTyMMeIxrcKHyCIL79gvpKfQl+S4zyAsPeiuve9E9DPmXfz X-Received: by 2002:a05:6214:21a5:b0:440:f64e:c038 with SMTP id t5-20020a05621421a500b00440f64ec038mr25670952qvc.32.1648553071781; Tue, 29 Mar 2022 04:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648553071; cv=none; d=google.com; s=arc-20160816; b=c42k+MaPrxNLWLabY8VzHSNt+KIkHlefsjPXEWcqxHK6886YszPOfdFaOSNCP+BmwB zM5AQXlOhCne/edtL1N51xizirdJ5zh/r8Pao4/oUkd7Rux+KaDPkqMBJFFZm2y4Pfbd PCShU8dVn7lpEKxseKLRWYdlVy3D5F/Weg+uVxDXTn40yMgyVP0cF1bEHmjWpWA9s1LW 4PKMkERNxNvzIRUDEK8rJTX5Q/7ECTqBciBgpKoDNR/KIy1M3XXdyNqh+5ovbzXjIxu2 eEUiv/KPoMJOReoWhMkhvrM5r9sIxt+V5aUqpATcF8Io0lNRoYpf8TLN6vtKUU+7qGiX NQKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/Fki2qhrqzIn3lkIi3YIPXgrFjahMDx8WQomnumvye4=; b=EyGi7puSiR+M4n18c7KJh3jdI0DMWhrlUOnf7DgnLcNvO7eDn5jbd6SxDQnVpB0qqd thmzFYtqQbS+zbcQ8pPvIgQZuHlBquwzq8oBfQUQ0hA2zbo0vTDlBTCkyIIJy4Vrs0Wr OAvaHjRW+eu5cUqZQM/LMCnYZc+HYSWIuK81DVP1hiReQ95wTSoYTRgyk+DDpEBFu0P6 678Wq2BKJj9zuYSYkMDIvfYGhdFLzTR0Vl+OR1VI28sd0xdKlrGziba3vVz48gFLYn2t B/2u8jSTrjtmGyrIJyecF9p3v1SFqTO2hgyA3JOVvZQOEmpzUTwMNeqbhgJBZfj2W6gx Gb1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b+IXYznI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s72-20020a37a94b000000b0067e4be239b2si8501358qke.503.2022.03.29.04.23.59; Tue, 29 Mar 2022 04:24:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b+IXYznI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231990AbiC2EXT (ORCPT + 99 others); Tue, 29 Mar 2022 00:23:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231980AbiC2EXI (ORCPT ); Tue, 29 Mar 2022 00:23:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7B30423B3D7 for ; Mon, 28 Mar 2022 21:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648527684; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/Fki2qhrqzIn3lkIi3YIPXgrFjahMDx8WQomnumvye4=; b=b+IXYznIvo5PN/UJ4/XtC5rmhEpsYZXQyQECkmQNde4yFw6Ld+758Gsr5evEdOyFRQKAtl VesBCAh6i/hWWvoHIFAggecVkCa92kRac8M8YKFt7uIVgv/vWxN0ETGox5SP0w5qADd0NT J29Xo2voaEa7R2Ux7/hIPqjeGV80VEU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-500-_GFlxY4ZMDycqaqXkHLD-w-1; Tue, 29 Mar 2022 00:21:16 -0400 X-MC-Unique: _GFlxY4ZMDycqaqXkHLD-w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 98654811E80; Tue, 29 Mar 2022 04:21:15 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-210.pek2.redhat.com [10.72.13.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68A94401DEA; Tue, 29 Mar 2022 04:21:12 +0000 (UTC) From: Jason Wang To: jasowang@redhat.com, mst@redhat.com Cc: elic@nvidia.com, hdanton@sina.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND V2 1/3] vdpa: mlx5: prevent cvq work from hogging CPU Date: Tue, 29 Mar 2022 12:21:07 +0800 Message-Id: <20220329042109.4029-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: 5262912ef3cfc ("vdpa/mlx5: Add support for control VQ and MAC setting") Signed-off-by: Jason Wang --- Changes since V1: - Using 1 as the budget --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index d0f91078600e..b2afd2b6fbca 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -163,6 +163,7 @@ struct mlx5_vdpa_net { u32 cur_num_vqs; struct notifier_block nb; struct vdpa_callback config_cb; + struct mlx5_vdpa_wq_ent cvq_ent; }; static void free_resources(struct mlx5_vdpa_net *ndev); @@ -1616,10 +1617,10 @@ static void mlx5_cvq_kick_handler(struct work_struct *work) ndev = to_mlx5_vdpa_ndev(mvdev); cvq = &mvdev->cvq; if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ))) - goto out; + return; if (!cvq->ready) - goto out; + return; while (true) { err = vringh_getdesc_iotlb(&cvq->vring, &cvq->riov, &cvq->wiov, &cvq->head, @@ -1653,9 +1654,10 @@ static void mlx5_cvq_kick_handler(struct work_struct *work) if (vringh_need_notify_iotlb(&cvq->vring)) vringh_notify(&cvq->vring); + + queue_work(mvdev->wq, &wqent->work); + break; } -out: - kfree(wqent); } static void mlx5_vdpa_kick_vq(struct vdpa_device *vdev, u16 idx) @@ -1663,7 +1665,6 @@ static void mlx5_vdpa_kick_vq(struct vdpa_device *vdev, u16 idx) struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); struct mlx5_vdpa_virtqueue *mvq; - struct mlx5_vdpa_wq_ent *wqent; if (!is_index_valid(mvdev, idx)) return; @@ -1672,13 +1673,7 @@ static void mlx5_vdpa_kick_vq(struct vdpa_device *vdev, u16 idx) if (!mvdev->cvq.ready) return; - wqent = kzalloc(sizeof(*wqent), GFP_ATOMIC); - if (!wqent) - return; - - wqent->mvdev = mvdev; - INIT_WORK(&wqent->work, mlx5_cvq_kick_handler); - queue_work(mvdev->wq, &wqent->work); + queue_work(mvdev->wq, &ndev->cvq_ent.work); return; } @@ -2668,6 +2663,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, if (err) goto err_mr; + ndev->cvq_ent.mvdev = mvdev; + INIT_WORK(&ndev->cvq_ent.work, mlx5_cvq_kick_handler); mvdev->wq = create_singlethread_workqueue("mlx5_vdpa_wq"); if (!mvdev->wq) { err = -ENOMEM; -- 2.18.1