All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for 11.2 v2] backends/iommufd: Delete FD during backend cleanup
@ 2026-11-30 21:14 Eric Farman
  2026-12-01  7:29 ` Duan, Zhenzhong
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Farman @ 2026-11-30 21:14 UTC (permalink / raw)
  To: qemu-devel, Yi Liu, Eric Auger, Zhenzhong Duan
  Cc: qemu-s390x, Matthew Rosato, Omar Elghoul, Eric Farman

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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH for 11.2 v2] backends/iommufd: Delete FD during backend cleanup
  2026-11-30 21:14 [PATCH for 11.2 v2] backends/iommufd: Delete FD during backend cleanup Eric Farman
@ 2026-12-01  7:29 ` Duan, Zhenzhong
  2026-12-01 13:29   ` Eric Farman
  0 siblings, 1 reply; 3+ messages in thread
From: Duan, Zhenzhong @ 2026-12-01  7:29 UTC (permalink / raw)
  To: Eric Farman, qemu-devel@nongnu.org, Liu, Yi L, Eric Auger
  Cc: qemu-s390x@nongnu.org, Matthew Rosato, Omar Elghoul



>-----Original Message-----
>From: Eric Farman <farman@linux.ibm.com>
>Subject: [PATCH for 11.2 v2] backends/iommufd: Delete FD during backend
>cleanup
>
>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;
> }

Sorry, I wasn't clear. I'd prefer to close the FD in the finalize
callback, if complete() fails, prepare_delete() is never called,
so the FD would still leak. Something like below would cover
both paths:

@@ -41,7 +41,7 @@ static void iommufd_backend_finalize(Object *obj)
 {
     IOMMUFDBackend *be = IOMMUFD_BACKEND(obj);

-    if (be->owned) {
+    if (be->fd >= 0) {
         close(be->fd);
         be->fd = -1;
     }

Thanks
Zhenzhong


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH for 11.2 v2] backends/iommufd: Delete FD during backend cleanup
  2026-12-01  7:29 ` Duan, Zhenzhong
@ 2026-12-01 13:29   ` Eric Farman
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Farman @ 2026-12-01 13:29 UTC (permalink / raw)
  To: Duan, Zhenzhong, qemu-devel@nongnu.org, Liu, Yi L, Eric Auger
  Cc: qemu-s390x@nongnu.org, Matthew Rosato, Omar Elghoul



On 12/1/26 2:29 AM, Duan, Zhenzhong wrote:
> 
> 
>> -----Original Message-----
>> From: Eric Farman <farman@linux.ibm.com>
>> Subject: [PATCH for 11.2 v2] backends/iommufd: Delete FD during backend
>> cleanup
>>
>> 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;
>> }
> 
> Sorry, I wasn't clear. I'd prefer to close the FD in the finalize
> callback, if complete() fails, prepare_delete() is never called,
> so the FD would still leak. Something like below would cover
> both paths:

Ah, apologies, I obviously didn't understand the lifecycle here... I'll 
update.

> 
> @@ -41,7 +41,7 @@ static void iommufd_backend_finalize(Object *obj)
>   {
>       IOMMUFDBackend *be = IOMMUFD_BACKEND(obj);
> 
> -    if (be->owned) {
> +    if (be->fd >= 0) {
>           close(be->fd);
>           be->fd = -1;
>       }
> 
> Thanks
> Zhenzhong



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-01 13:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 21:14 [PATCH for 11.2 v2] backends/iommufd: Delete FD during backend cleanup Eric Farman
2026-12-01  7:29 ` Duan, Zhenzhong
2026-12-01 13:29   ` Eric Farman

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.