diff options
author | Zhenzhong Duan <zhenzhong.duan@intel.com> | 2025-04-23 15:28:22 +0800 |
---|---|---|
committer | Cédric Le Goater <clg@redhat.com> | 2025-04-25 09:01:38 +0200 |
commit | 0327ffc8530e9733526fab6c790ad5f0661b008d (patch) | |
tree | d042b5ae47a0a054bd60e6b5b4865ab2bc7da9ba | |
parent | c45d88b8a2f25600c69748bfcf37911412c396ab (diff) | |
download | qemu-0327ffc8530e9733526fab6c790ad5f0661b008d.zip qemu-0327ffc8530e9733526fab6c790ad5f0661b008d.tar.gz qemu-0327ffc8530e9733526fab6c790ad5f0661b008d.tar.bz2 |
vfio/container: Move realize() after attachment
To match the change for IOMMUFD backend, move realize() after attachment
for legacy backend too.
Suggested-by: Cédric Le Goater <clg@redhat.com>
Suggested-by: Donald Dutile <ddutile@redhat.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20250423072824.3647952-4-zhenzhong.duan@intel.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
-rw-r--r-- | hw/vfio/container.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 7177747..652a6197 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -883,10 +883,6 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev, trace_vfio_device_attach(vbasedev->name, groupid); - if (!vfio_device_hiod_realize(vbasedev, errp)) { - return false; - } - group = vfio_group_get(groupid, as, errp); if (!group) { return false; @@ -895,13 +891,15 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev, QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { if (strcmp(vbasedev_iter->name, vbasedev->name) == 0) { error_setg(errp, "device is already attached"); - vfio_group_put(group); - return false; + goto group_put_exit; } } if (!vfio_device_get(group, name, vbasedev, errp)) { - vfio_group_put(group); - return false; + goto group_put_exit; + } + + if (!vfio_device_hiod_realize(vbasedev, errp)) { + goto device_put_exit; } bcontainer = &group->container->bcontainer; @@ -910,6 +908,12 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev, QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); return true; + +device_put_exit: + vfio_device_put(vbasedev); +group_put_exit: + vfio_group_put(group); + return false; } static void vfio_legacy_detach_device(VFIODevice *vbasedev) |