All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Farman <farman@linux.ibm.com>
To: qemu-devel@nongnu.org, Yi Liu <yi.l.liu@intel.com>,
	Eric Auger <eric.auger@redhat.com>,
	Zhenzhong Duan <zhenzhong.duan@intel.com>
Cc: qemu-s390x@nongnu.org, Matthew Rosato <mjrosato@linux.ibm.com>,
	Omar Elghoul <oelghoul@linux.ibm.com>,
	Eric Farman <farman@linux.ibm.com>
Subject: [PATCH for 11.2 v2] backends/iommufd: Delete FD during backend cleanup
Date: Mon, 30 Nov 2026 22:14:50 +0100	[thread overview]
Message-ID: <20261130211450.3871691-1-farman@linux.ibm.com> (raw)

Commit de8002534892 ("migration/cpr: forbid saving duplicate CprFds into
hash table") added enforcement that the hash of file descriptors be
stored under a unique key, and will reject duplicates in the table.
When using a device with an iommufd backend, performing an unplug
and replug presents the following messages and subsequent hang as
reported by the host kernel:

  virtqemud[1172]: internal error: unable to execute QEMU command
    'object- add': cpr fd 'iommufd0' id 0 is already registered
  virtqemud[1172]: internal error: unable to execute QEMU command
    'closefd': File descriptor named 'iommufd' not found
  kernel: mlx5_vfio_pci 0004:00:00.0: No device request channel
    registered, blocked until released by user

What is missing is the cleanup of the iommufd fd upon the unplug,
such that a re-plug is able to create a new connection with a new fd.
Add this to the iommufd_backend_prepare_delete() routine once the
user count drops to zero, to allow subsequent (re)plugs to succeed.

Fixes: 2a3f0a59bd64 ("vfio/iommufd: preserve descriptors")
Link: https://lore.kernel.org/qemu-devel/133cca35-7ff1-4010-9ad9-4b3e32ed3e17@linux.ibm.com/
Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Signed-off-by: Eric Farman <farman@linux.ibm.com>
---

Notes:
    v1->v2:
     - [ZD] Add explicit close(fd) in the cleanup path
    v1: https://lore.kernel.org/qemu-devel/20261113134335.2451039-1-farman@linux.ibm.com/

 backends/iommufd.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/backends/iommufd.c b/backends/iommufd.c
index ecf4caee1a8..ef3b41e7788 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -72,6 +72,11 @@ static bool iommufd_backend_prepare_delete(UserCreatable *uc, Error **errp)
                    object_get_canonical_path_component(OBJECT(uc)), be->users);
         return false;
     }
+    if (!be->owned) {
+        cpr_delete_fd(iommufd_fd_name(be), 0);
+        close(be->fd);
+        be->fd = -1;
+    }
     return true;
 }
 
-- 
2.53.0



             reply	other threads:[~2026-11-30 21:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 21:14 Eric Farman [this message]
2026-12-01  7:29 ` [PATCH for 11.2 v2] backends/iommufd: Delete FD during backend cleanup Duan, Zhenzhong
2026-12-01 13:29   ` Eric Farman

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=20261130211450.3871691-1-farman@linux.ibm.com \
    --to=farman@linux.ibm.com \
    --cc=eric.auger@redhat.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=oelghoul@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=yi.l.liu@intel.com \
    --cc=zhenzhong.duan@intel.com \
    /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.