All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfio-user: disconnect container when device info query fails
@ 2026-05-22  6:56 zhaoguohan
  2026-05-26  8:51 ` John Levon
  0 siblings, 1 reply; 2+ messages in thread
From: zhaoguohan @ 2026-05-22  6:56 UTC (permalink / raw)
  To: John Levon, Thanos Makatos, Cédric Le Goater; +Cc: qemu-devel

From: GuoHan Zhao <zhaoguohan@kylinos.cn>

vfio_user_device_attach() connects the vfio-user container before querying
VFIO_USER_DEVICE_GET_INFO.  If the device info query fails,
vfio_device_prepare() has not run yet, so vbasedev->bcontainer is still
NULL and the later vfio_device_detach() cleanup path cannot reach the new
container.

Disconnect the container before returning the attach failure so the listener,
RAM discard state, object reference and address space reference are released
on this error path.

Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
---
 hw/vfio-user/container.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c
index 796289a46903..dc23b06eebf1 100644
--- a/hw/vfio-user/container.c
+++ b/hw/vfio-user/container.c
@@ -309,7 +309,12 @@ static bool vfio_user_device_attach(const char *name, VFIODevice *vbasedev,
         return false;
     }
 
-    return vfio_user_device_get(container, vbasedev, errp);
+    if (!vfio_user_device_get(container, vbasedev, errp)) {
+        vfio_user_container_disconnect(container);
+        return false;
+    }
+
+    return true;
 }
 
 static void vfio_user_device_detach(VFIODevice *vbasedev)
-- 
2.43.0



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

end of thread, other threads:[~2026-05-26  8:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-22  6:56 [PATCH] vfio-user: disconnect container when device info query fails zhaoguohan
2026-05-26  8:51 ` John Levon

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.