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 3/3] vdpa/mlx5: Don't flush the workqueue under reslock
Date: Mon, 23 Nov 2026 15:56:46 +0200 [thread overview]
Message-ID: <20261123135646.3962652-5-dtatulea@nvidia.com> (raw)
In-Reply-To: <20261123135646.3962652-2-dtatulea@nvidia.com>
The control VQ work (mlx5_cvq_kick_handler()) runs on mvdev->wq and
takes reslock. Device reset and the error path of .set_status take
reslock and then call unregister_link_notifier() which flushes the same
workqueue. A deadlock occurs if a CVQ kick arrives just before the reset
for the CVQ work.
Lockdep caught this when QEMU quits (pkill qemu) and closes the
vhost-vdpa device:
======================================================
WARNING: possible circular locking dependency detected
------------------------------------------------------
qemu-system-x86/5785 is trying to acquire lock:
ff110001cd292940 ((wq_completion)mlx5_vdpa_wq){+.+.}-{0:0}, at: touch_wq_lockdep_map+0x7a/0x180
but task is already holding lock:
ff11000136eb4928 (&ndev->reslock){+.+.}-{4:4}, at: mlx5_vdpa_compat_reset+0xed/0x760 [mlx5_vdpa]
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&ndev->reslock){+.+.}-{4:4}:
lock_acquire+0x126/0x330
down_write+0x87/0x1d0
mlx5_cvq_kick_handler+0xb1/0x1180 [mlx5_vdpa]
process_one_work+0x8df/0x1660
worker_thread+0x62c/0x1030
kthread+0x377/0x490
ret_from_fork+0x4d7/0x720
ret_from_fork_asm+0x11/0x20
-> #1 ((work_completion)(&ndev->cvq_ent.work)){+.+.}-{0:0}:
lock_acquire+0x126/0x330
process_one_work+0x874/0x1660
worker_thread+0x62c/0x1030
kthread+0x377/0x490
ret_from_fork+0x4d7/0x720
ret_from_fork_asm+0x11/0x20
-> #0 ((wq_completion)mlx5_vdpa_wq){+.+.}-{0:0}:
check_prev_add+0xe8/0xdb0
__lock_acquire+0x1801/0x23e0
lock_acquire+0x126/0x330
touch_wq_lockdep_map+0x93/0x180
__flush_workqueue+0xed/0x1090
unregister_link_notifier+0x10c/0x170 [mlx5_vdpa]
mlx5_vdpa_compat_reset+0xfe/0x760 [mlx5_vdpa]
mlx5_vdpa_reset+0x15/0x30 [mlx5_vdpa]
_compat_vdpa_reset+0x29b/0x3b0 [vhost_vdpa]
vhost_vdpa_release+0x16f/0x380 [vhost_vdpa]
__fput+0x36a/0xaa0
task_work_run+0x111/0x1f0
do_exit+0x7ba/0x2590
do_group_exit+0xb8/0x250
get_signal+0x1f46/0x2020
arch_do_signal_or_restart+0x79/0x4a0
exit_to_user_mode_loop+0xbe/0x450
do_syscall_64+0x257/0x4f0
entry_SYSCALL_64_after_hwframe+0x4b/0x53
other info that might help us debug this:
Chain exists of:
(wq_completion)mlx5_vdpa_wq --> (work_completion)(&ndev->cvq_ent.work) --> &ndev->reslock
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&ndev->reslock);
lock((work_completion)(&ndev->cvq_ent.work));
lock(&ndev->reslock);
lock((wq_completion)mlx5_vdpa_wq);
*** DEADLOCK ***
locks held by qemu-system-x86/5785: 3, last CPU#9:
#0: ff1100021d7c2068 (&dev->mutex#3){+.+.}-{4:4}, at: vhost_vdpa_release+0x4b/0x380 [vhost_vdpa]
#1: ff11000136eb44c8 (&vdev->cf_lock){++++}-{4:4}, at: _compat_vdpa_reset+0x16b/0x3b0 [vhost_vdpa]
#2: ff11000136eb4928 (&ndev->reslock){+.+.}-{4:4}, at: mlx5_vdpa_compat_reset+0xed/0x760 [mlx5_vdpa]
vhost_vdpa_release() resets the device before stopping the kick
handlers, so CVQ kicks can still be queued while the reset runs.
The fix is to move unregister_link_notifier() calls outside of
reslock. The function doesn't need the reslock.
Fixes: c384c2401eed ("vdpa/mlx5: Avoid losing link state updates")
Cc: stable@vger.kernel.org
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
---
drivers/vdpa/mlx5/net/mlx5_vnet.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index f1c5f72032a3..a175f734517d 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -2908,6 +2908,8 @@ static void unregister_link_notifier(struct mlx5_vdpa_net *ndev)
ndev->nb_registered = false;
mlx5_notifier_unregister(ndev->mvdev.mdev, &ndev->nb);
+ /* mlx5_cvq_kick_handler() work needs the reslock. */
+ lockdep_assert_not_held(&ndev->reslock);
if (ndev->mvdev.wq)
flush_workqueue(ndev->mvdev.wq);
}
@@ -3215,6 +3217,7 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status)
{
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
+ bool unregister_nb = false;
int err;
print_status(mvdev, status, true);
@@ -3257,12 +3260,14 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status)
return;
err_driver:
- unregister_link_notifier(ndev);
+ unregister_nb = true;
err_setup:
mlx5_vdpa_clean_mrs(&ndev->mvdev);
ndev->mvdev.status |= VIRTIO_CONFIG_S_FAILED;
err_clear:
up_write(&ndev->reslock);
+ if (unregister_nb)
+ unregister_link_notifier(ndev);
}
static void init_group_to_asid_map(struct mlx5_vdpa_dev *mvdev)
@@ -3301,9 +3306,9 @@ static int mlx5_vdpa_compat_reset(struct vdpa_device *vdev, u32 flags)
print_status(mvdev, 0, true);
mlx5_vdpa_info(mvdev, "performing device reset\n");
+ unregister_link_notifier(ndev);
down_write(&ndev->reslock);
- unregister_link_notifier(ndev);
vq_reset = needs_vqs_reset(mvdev);
if (vq_reset) {
teardown_vq_resources(ndev);
--
2.54.0
next prev parent reply other threads:[~2026-11-23 13:59 UTC|newest]
Thread overview: 10+ 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 ` [PATCH 1/3] vdpa/mlx5: Fix error cleanup when VQ setup fails in .dev_add Dragos Tatulea
2026-11-23 16:08 ` Eugenio Perez Martin
2026-11-24 19:15 ` Dragos Tatulea
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-24 19:08 ` Dragos Tatulea
2026-11-23 13:56 ` Dragos Tatulea [this message]
2026-11-23 15:47 ` [PATCH 3/3] vdpa/mlx5: Don't flush the workqueue under reslock Eugenio Perez Martin
2026-11-23 14:06 ` [PATCH 0/3] vdpa/mlx5: Misc fixes sashiko-bot
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-5-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.