[PATCH for 11.2] backends/iommufd: Delete FD during backend cleanup

Eric Farman posted 1 patch 1 week, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261113134335.2451039-1-farman@linux.ibm.com
Maintainers: Yi Liu <yi.l.liu@intel.com>, Eric Auger <eric.auger@redhat.com>, Zhenzhong Duan <zhenzhong.duan@intel.com>
backends/iommufd.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH for 11.2] backends/iommufd: Delete FD during backend cleanup
Posted by Eric Farman 1 week, 2 days ago
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.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
---
 backends/iommufd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/backends/iommufd.c b/backends/iommufd.c
index ecf4caee1a8..bb3219767f0 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -72,6 +72,9 @@ 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);
+    }
     return true;
 }
 
-- 
2.53.0
Re: [PATCH for 11.2] backends/iommufd: Delete FD during backend cleanup
Posted by Eric Farman 3 days, 15 hours ago
Ping?

Would like this to get fixed for 11.2, as it fixes the regression 
mentioned here:

https://lore.kernel.org/qemu-devel/133cca35-7ff1-4010-9ad9-4b3e32ed3e17@linux.ibm.com/

On 11/13/26 8:43 AM, Eric Farman wrote:
> 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.
> 
> Signed-off-by: Eric Farman <farman@linux.ibm.com>
> ---
>   backends/iommufd.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/backends/iommufd.c b/backends/iommufd.c
> index ecf4caee1a8..bb3219767f0 100644
> --- a/backends/iommufd.c
> +++ b/backends/iommufd.c
> @@ -72,6 +72,9 @@ 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);
> +    }
>       return true;
>   }
>