qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfio: Register/unregister container for CPR only once for each container
@ 2025-04-24  6:33 Zhenzhong Duan
  2025-04-24 12:14 ` Cédric Le Goater
  2025-04-25  7:59 ` Cédric Le Goater
  0 siblings, 2 replies; 5+ messages in thread
From: Zhenzhong Duan @ 2025-04-24  6:33 UTC (permalink / raw)
  To: qemu-devel
  Cc: alex.williamson, clg, eric.auger, nicolinc, joao.m.martins,
	steven.sistare, yi.l.liu, chao.p.peng, Zhenzhong Duan

vfio_cpr_register_container and vfio_cpr_unregister_container are container
scoped function. Calling them for each device attaching/detaching would
corrupt CPR reboot notifier list, i.e., when two VFIO devices are attached
to same container and have same notifier registered twice.

Fixes: d9fa4223b30a ("vfio: register container for cpr")
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
btw: untested as I have no env with two migration capable devices,
     appreciate if someone have env to help test, thanks

 hw/vfio/iommufd.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index f24054a6a5..b2f72dc8c3 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -416,6 +416,7 @@ static void iommufd_cdev_container_destroy(VFIOIOMMUFDContainer *container)
     if (!QLIST_EMPTY(&bcontainer->device_list)) {
         return;
     }
+    vfio_cpr_unregister_container(bcontainer);
     vfio_listener_unregister(bcontainer);
     iommufd_backend_free_id(container->be, container->ioas_id);
     object_unref(container);
@@ -561,6 +562,10 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
         goto err_listener_register;
     }
 
+    if (!vfio_cpr_register_container(bcontainer, errp)) {
+        goto err_listener_register;
+    }
+
     bcontainer->initialized = true;
 
 found_container:
@@ -570,13 +575,9 @@ found_container:
         goto err_listener_register;
     }
 
-    if (!vfio_cpr_register_container(bcontainer, errp)) {
-        goto err_listener_register;
-    }
-
     if (!vfio_device_hiod_create_and_realize(vbasedev,
                      TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO, errp)) {
-        goto err_hiod_realize;
+        goto err_listener_register;
     }
 
     /*
@@ -600,8 +601,6 @@ found_container:
                                    vbasedev->num_regions, vbasedev->flags);
     return true;
 
-err_hiod_realize:
-    vfio_cpr_unregister_container(bcontainer);
 err_listener_register:
     iommufd_cdev_ram_block_discard_disable(false);
 err_discard_disable:
@@ -632,7 +631,6 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev)
     }
 
     object_unref(vbasedev->hiod);
-    vfio_cpr_unregister_container(bcontainer);
     iommufd_cdev_detach_container(vbasedev, container);
     iommufd_cdev_container_destroy(container);
     vfio_address_space_put(space);
-- 
2.34.1



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

* Re: [PATCH] vfio: Register/unregister container for CPR only once for each container
  2025-04-24  6:33 [PATCH] vfio: Register/unregister container for CPR only once for each container Zhenzhong Duan
@ 2025-04-24 12:14 ` Cédric Le Goater
  2025-04-25  2:24   ` Duan, Zhenzhong
  2025-04-25  7:59 ` Cédric Le Goater
  1 sibling, 1 reply; 5+ messages in thread
From: Cédric Le Goater @ 2025-04-24 12:14 UTC (permalink / raw)
  To: Zhenzhong Duan, qemu-devel
  Cc: alex.williamson, eric.auger, nicolinc, joao.m.martins,
	steven.sistare, yi.l.liu, chao.p.peng

On 4/24/25 08:33, Zhenzhong Duan wrote:
> vfio_cpr_register_container and vfio_cpr_unregister_container are container
> scoped function. Calling them for each device attaching/detaching would
> corrupt CPR reboot notifier list, i.e., when two VFIO devices are attached
> to same container and have same notifier registered twice.
> 
> Fixes: d9fa4223b30a ("vfio: register container for cpr")
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>

Looks OK to me, so

Reviewed-by: Cédric Le Goater <clg@redhat.com>

Some feedback from Steve would be good to have.

> ---
> btw: untested as I have no env with two migration capable devices,
>       appreciate if someone have env to help test, thanks

I did.

Thanks,

C.




> 
>   hw/vfio/iommufd.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index f24054a6a5..b2f72dc8c3 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -416,6 +416,7 @@ static void iommufd_cdev_container_destroy(VFIOIOMMUFDContainer *container)
>       if (!QLIST_EMPTY(&bcontainer->device_list)) {
>           return;
>       }
> +    vfio_cpr_unregister_container(bcontainer);
>       vfio_listener_unregister(bcontainer);
>       iommufd_backend_free_id(container->be, container->ioas_id);
>       object_unref(container);
> @@ -561,6 +562,10 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
>           goto err_listener_register;
>       }
>   
> +    if (!vfio_cpr_register_container(bcontainer, errp)) {
> +        goto err_listener_register;
> +    }
> +
>       bcontainer->initialized = true;
>   
>   found_container:
> @@ -570,13 +575,9 @@ found_container:
>           goto err_listener_register;
>       }
>   
> -    if (!vfio_cpr_register_container(bcontainer, errp)) {
> -        goto err_listener_register;
> -    }
> -
>       if (!vfio_device_hiod_create_and_realize(vbasedev,
>                        TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO, errp)) {
> -        goto err_hiod_realize;
> +        goto err_listener_register;
>       }
>   
>       /*
> @@ -600,8 +601,6 @@ found_container:
>                                      vbasedev->num_regions, vbasedev->flags);
>       return true;
>   
> -err_hiod_realize:
> -    vfio_cpr_unregister_container(bcontainer);
>   err_listener_register:
>       iommufd_cdev_ram_block_discard_disable(false);
>   err_discard_disable:
> @@ -632,7 +631,6 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev)
>       }
>   
>       object_unref(vbasedev->hiod);
> -    vfio_cpr_unregister_container(bcontainer);
>       iommufd_cdev_detach_container(vbasedev, container);
>       iommufd_cdev_container_destroy(container);
>       vfio_address_space_put(space);



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

* RE: [PATCH] vfio: Register/unregister container for CPR only once for each container
  2025-04-24 12:14 ` Cédric Le Goater
@ 2025-04-25  2:24   ` Duan, Zhenzhong
  0 siblings, 0 replies; 5+ messages in thread
From: Duan, Zhenzhong @ 2025-04-25  2:24 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org
  Cc: alex.williamson@redhat.com, eric.auger@redhat.com,
	nicolinc@nvidia.com, joao.m.martins@oracle.com,
	steven.sistare@oracle.com, Liu, Yi L, Peng, Chao P



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: Re: [PATCH] vfio: Register/unregister container for CPR only once for
>each container
>
>On 4/24/25 08:33, Zhenzhong Duan wrote:
>> vfio_cpr_register_container and vfio_cpr_unregister_container are container
>> scoped function. Calling them for each device attaching/detaching would
>> corrupt CPR reboot notifier list, i.e., when two VFIO devices are attached
>> to same container and have same notifier registered twice.
>>
>> Fixes: d9fa4223b30a ("vfio: register container for cpr")
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>
>Looks OK to me, so
>
>Reviewed-by: Cédric Le Goater <clg@redhat.com>
>
>Some feedback from Steve would be good to have.
>
>> ---
>> btw: untested as I have no env with two migration capable devices,
>>       appreciate if someone have env to help test, thanks
>
>I did.

Thanks Cédric!

BRs,
Zhenzhong

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

* Re: [PATCH] vfio: Register/unregister container for CPR only once for each container
  2025-04-24  6:33 [PATCH] vfio: Register/unregister container for CPR only once for each container Zhenzhong Duan
  2025-04-24 12:14 ` Cédric Le Goater
@ 2025-04-25  7:59 ` Cédric Le Goater
  2025-04-25 19:14   ` Steven Sistare
  1 sibling, 1 reply; 5+ messages in thread
From: Cédric Le Goater @ 2025-04-25  7:59 UTC (permalink / raw)
  To: Zhenzhong Duan, qemu-devel
  Cc: alex.williamson, eric.auger, nicolinc, joao.m.martins,
	steven.sistare, yi.l.liu, chao.p.peng

On 4/24/25 08:33, Zhenzhong Duan wrote:
> vfio_cpr_register_container and vfio_cpr_unregister_container are container
> scoped function. Calling them for each device attaching/detaching would
> corrupt CPR reboot notifier list, i.e., when two VFIO devices are attached
> to same container and have same notifier registered twice.
> 
> Fixes: d9fa4223b30a ("vfio: register container for cpr")
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
> btw: untested as I have no env with two migration capable devices,
>       appreciate if someone have env to help test, thanks
> 
>   hw/vfio/iommufd.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)



Applied to vfio-next.

Thanks,

C.




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

* Re: [PATCH] vfio: Register/unregister container for CPR only once for each container
  2025-04-25  7:59 ` Cédric Le Goater
@ 2025-04-25 19:14   ` Steven Sistare
  0 siblings, 0 replies; 5+ messages in thread
From: Steven Sistare @ 2025-04-25 19:14 UTC (permalink / raw)
  To: Cédric Le Goater, Zhenzhong Duan, qemu-devel
  Cc: alex.williamson, eric.auger, nicolinc, joao.m.martins, yi.l.liu,
	chao.p.peng

On 4/25/2025 3:59 AM, Cédric Le Goater wrote:
> On 4/24/25 08:33, Zhenzhong Duan wrote:
>> vfio_cpr_register_container and vfio_cpr_unregister_container are container
>> scoped function. Calling them for each device attaching/detaching would
>> corrupt CPR reboot notifier list, i.e., when two VFIO devices are attached
>> to same container and have same notifier registered twice.
>>
>> Fixes: d9fa4223b30a ("vfio: register container for cpr")
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>> ---
>> btw: untested as I have no env with two migration capable devices,
>>       appreciate if someone have env to help test, thanks
>>
>>   hw/vfio/iommufd.c | 14 ++++++--------
>>   1 file changed, 6 insertions(+), 8 deletions(-)
> 
> Applied to vfio-next.

Looks good - steve




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

end of thread, other threads:[~2025-04-25 19:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-24  6:33 [PATCH] vfio: Register/unregister container for CPR only once for each container Zhenzhong Duan
2025-04-24 12:14 ` Cédric Le Goater
2025-04-25  2:24   ` Duan, Zhenzhong
2025-04-25  7:59 ` Cédric Le Goater
2025-04-25 19:14   ` Steven Sistare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).