RE: [PATCH V5 28/38] vfio/iommufd: device name blocker

2025-06-23 Thread Duan, Zhenzhong



>-Original Message-
>From: Steve Sistare 
>Subject: [PATCH V5 28/38] vfio/iommufd: device name blocker
>
>If an invariant device name cannot be created, block CPR.
>
>Signed-off-by: Steve Sistare 

Reviewed-by: Zhenzhong Duan 

Thanks
Zhenzhong



[PATCH V5 28/38] vfio/iommufd: device name blocker

2025-06-10 Thread Steve Sistare
If an invariant device name cannot be created, block CPR.

Signed-off-by: Steve Sistare 
---
 include/hw/vfio/vfio-cpr.h |  1 +
 hw/vfio/device.c   | 11 +++
 2 files changed, 12 insertions(+)

diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h
index 25e74ee..170a116 100644
--- a/include/hw/vfio/vfio-cpr.h
+++ b/include/hw/vfio/vfio-cpr.h
@@ -29,6 +29,7 @@ typedef struct VFIOContainerCPR {
 
 typedef struct VFIODeviceCPR {
 Error *mdev_blocker;
+Error *id_blocker;
 } VFIODeviceCPR;
 
 bool vfio_legacy_cpr_register_container(struct VFIOContainer *container,
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index a3603f5..8c3835b 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -28,6 +28,8 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/units.h"
+#include "migration/cpr.h"
+#include "migration/blocker.h"
 #include "monitor/monitor.h"
 #include "vfio-helpers.h"
 
@@ -308,8 +310,16 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error 
**errp)
 } else {
 /*
  * Assign a name so any function printing it will not break.
+ * The fd number changes across processes, so this cannot be
+ * used as an invariant name for CPR.
  */
 vbasedev->name = g_strdup_printf("VFIO_FD%d", vbasedev->fd);
+error_setg(&vbasedev->cpr.id_blocker,
+   "vfio device with fd=%d needs an id property",
+   vbasedev->fd);
+return migrate_add_blocker_modes(&vbasedev->cpr.id_blocker,
+ errp, MIG_MODE_CPR_TRANSFER,
+ -1) == 0;
 }
 }
 }
@@ -320,6 +330,7 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error 
**errp)
 void vfio_device_free_name(VFIODevice *vbasedev)
 {
 g_clear_pointer(&vbasedev->name, g_free);
+migrate_del_blocker(&vbasedev->cpr.id_blocker);
 }
 
 void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp)
-- 
1.8.3.1