iommufd_cdev_attach should not call vfio_cpr_register_container if an existing container is found. Fix that by registering earlier in the code flow, which requires an additional call to unregister during error recovery. Note it is safe to call unregister even if register has not been called.
Signed-off-by: Steve Sistare <steven.sist...@oracle.com> --- hw/vfio/iommufd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 2de2811..87c3bc2c 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -596,6 +596,10 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev, bcontainer->initialized = true; + if (!vfio_cpr_register_container(bcontainer, errp)) { + goto err_listener_register; + } + found_container: ret = ioctl(devfd, VFIO_DEVICE_GET_INFO, &dev_info); if (ret) { @@ -603,10 +607,6 @@ found_container: goto err_listener_register; } - if (!vfio_cpr_register_container(bcontainer, errp)) { - goto err_listener_register; - } - /* * TODO: examine RAM_BLOCK_DISCARD stuff, should we do group level * for discarding incompatibility check as well? @@ -629,6 +629,7 @@ found_container: return true; err_listener_register: + vfio_cpr_unregister_container(bcontainer); iommufd_cdev_ram_block_discard_disable(false); err_discard_disable: iommufd_cdev_detach_container(vbasedev, container); -- 1.8.3.1