Skip to contentSkip to conversation

backends/iommufd: Delete FD during backend cleanup

PATCH In review Eric Farman 2 participants 4 messages Nov 13 – Nov 23

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 backends/iommufd.c | 3 +++
 1 file changed, 3 insertions(+)
backends/iommufd.c +3 -0
index ecf4caee1a8..bb3219767f0 100644
@@ -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;
 }
 
Signature · 1 line
2.53.0
#1 lore raw

Ping?

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

https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 38 lines · 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.

---
  backends/iommufd.c | 3 +++
  1 file changed, 3 insertions(+)
backends/iommufd.c +3 -0
index ecf4caee1a8..bb3219767f0 100644
@@ -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;
  }
 
Reviewed-by
#2 lore raw
Quoted 7 lines

-----Original Message-----
From: Eric Farman <[email protected]>
Subject: Re: [PATCH for 11.2] backends/iommufd: Delete FD during backend cleanup

Quoted 7 lines

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-
[email protected]/

The code change looks good.

Fixes 2a3f0a59bd64 ("vfio/iommufd: preserve descriptors")

Thanks
Zhenzhong

Quoted 42 lines · Eric Farman

backends/iommufd.c static bool

Quoted 29 lines

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.

---
  backends/iommufd.c | 3 +++
  1 file changed, 3 insertions(+)
backends/iommufd.c +0 -0
index ecf4caee1a8..bb3219767f0 100644
@@ -72,6 +72,9 @@ static bool

iommufd_backend_prepare_delete(UserCreatable *uc, Error **errp)

Quoted 10 lines
backends/iommufd.c +3 -0
                     object_get_canonical_path_component(OBJECT(uc)), be-
 users);
          return false;
      }
+    if (!be->owned) {
+        cpr_delete_fd(iommufd_fd_name(be), 0);
+    }
      return true;
  }
#3 lore raw
Quoted 59 lines

-----Original Message-----
From: Duan, Zhenzhong
Subject: RE: [PATCH for 11.2] backends/iommufd: Delete FD during backend cleanup

Quoted 5 lines

-----Original Message-----
From: Eric Farman <[email protected]>
Subject: Re: [PATCH for 11.2] backends/iommufd: Delete FD during backend cleanup

Quoted 7 lines

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-
[email protected]/

The code change looks good.

Fixes 2a3f0a59bd64 ("vfio/iommufd: preserve descriptors")

[email protected]/

Thanks
Zhenzhong

Quoted 26 lines · Eric Farman
Quoted 24 lines

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.

---
  backends/iommufd.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 13 lines
Quoted 7 lines

backends/iommufd.c static bool

Quoted 5 lines
backends/iommufd.c +0 -0
index ecf4caee1a8..bb3219767f0 100644
@@ -72,6 +72,9 @@ static bool

iommufd_backend_prepare_delete(UserCreatable *uc, Error **errp)

Quoted 1 line
backends/iommufd.c +0 -0
                     object_get_canonical_path_component(OBJECT(uc)),

be-

Quoted 5 lines
Quoted 5 lines
backends/iommufd.c +2 -0
 users);
          return false;
      }
+    if (!be->owned) {
+        cpr_delete_fd(iommufd_fd_name(be), 0);

Oh, I find I missed one thing, if we should delete cpr entry when not owned, should we also take responsibility to close iommufd fd when destroy this iommufd instance?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
backends/iommufd.c +1 -0
+    }
      return true;
  }