mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dragos Tatulea <dtatulea@nvidia.com>
To: "Michael S . Tsirkin" <mst@redhat.com>,
	Eugenio Perez Martin <eperezma@redhat.com>,
	<virtualization@lists.linux.dev>
Cc: Dragos Tatulea <dtatulea@nvidia.com>, <kvm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, Gal Pressman <gal@nvidia.com>,
	<stable@vger.kernel.org>
Subject: [PATCH 1/3] vdpa/mlx5: Fix error cleanup when VQ setup fails in .dev_add
Date: Mon, 23 Nov 2026 15:56:44 +0200	[thread overview]
Message-ID: <20261123135646.3962652-3-dtatulea@nvidia.com> (raw)
In-Reply-To: <20261123135646.3962652-2-dtatulea@nvidia.com>

When setup_vq_resources() fails in mlx5_vdpa_dev_add(), e.g. because the
firmware rejects the provisioned features (HOST_TSO4/6 without CSUM),
the error path unregisters the vdpa device first and then keeps using
it:

- _vdpa_unregister_device() drops the last reference to the device, so
  mlx5_vdpa_free() runs and ndev is freed.
- destroy_workqueue(mvdev->wq) then reads the freed ndev.
- put_device() on the freed device underflows the refcount:

  refcount_t: underflow; use-after-free.
  WARNING: lib/refcount.c:28 at refcount_warn_saturate+0x59/0x90
  Call Trace:
   mlx5_vdpa_dev_add+0x3e0/0x760 [mlx5_vdpa]
   vdpa_nl_cmd_dev_add_set_doit+0x362/0x440 [vdpa]
   ...

- mgtdev->ndev is left pointing to the freed ndev, so every following
  "vdpa dev add" on this management device fails with -ENOSPC.

mlx5_vdpa_dev_del() already does the cleanup properly so use that. Just
make sure that an extra reference is taken during the call to avoid
_vdpa_unregister_device() from freeing the device under us.

Fixes: ffb1aae43ed5 ("vdpa/mlx5: Pre-create hardware VQs at vdpa .dev_add time")
Cc: stable@vger.kernel.org
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 6830a80e8543..7a39b0bbbee3 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -161,6 +161,8 @@ static void mvqs_set_defaults(struct mlx5_vdpa_net *ndev);
 static int setup_vq_resources(struct mlx5_vdpa_net *ndev, bool filled);
 static void teardown_vq_resources(struct mlx5_vdpa_net *ndev);
 static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq);
+static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev,
+			      struct vdpa_device *dev);
 
 static bool mlx5_vdpa_debug;
 
@@ -4043,7 +4045,10 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	return 0;
 
 err_setup_vq_res:
-	_vdpa_unregister_device(&mvdev->vdev);
+	get_device(&mvdev->vdev.dev);
+	mlx5_vdpa_dev_del(&mgtdev->mgtdev, &mvdev->vdev);
+	put_device(&mvdev->vdev.dev);
+	return err;
 err_reg:
 	destroy_workqueue(mvdev->wq);
 err_alloc:
-- 
2.54.0


  reply	other threads:[~2026-11-23 13:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 13:56 [PATCH 0/3] vdpa/mlx5: Misc fixes Dragos Tatulea
2026-11-23 13:56 ` Dragos Tatulea [this message]
2026-11-23 16:08   ` [PATCH 1/3] vdpa/mlx5: Fix error cleanup when VQ setup fails in .dev_add Eugenio Perez Martin
2026-11-23 13:56 ` [PATCH 2/3] vdpa/mlx5: Increase the maximum virtqueue size Dragos Tatulea
2026-11-23 15:38   ` Eugenio Perez Martin
2026-11-23 13:56 ` [PATCH 3/3] vdpa/mlx5: Don't flush the workqueue under reslock Dragos Tatulea
2026-11-23 15:47   ` Eugenio Perez Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123135646.3962652-3-dtatulea@nvidia.com \
    --to=dtatulea@nvidia.com \
    --cc=eperezma@redhat.com \
    --cc=gal@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®