Re: [PATCH V4 32/43] vfio/iommufd: invariant device name

2025-06-09 Thread Cédric Le Goater

On 5/29/25 21:24, Steve Sistare wrote:

cpr-transfer will use the device name as a key to find the value
of the device descriptor in new QEMU.  However, if the descriptor
number is specified by a command-line fd parameter, then
vfio_device_get_name creates a name that includes the fd number.
This causes a chicken-and-egg problem: new QEMU must know the fd
number to construct a name to find the fd number.

To fix, create an invariant name based on the id command-line parameter,
if id is defined.  The user will need to provide such an id to use CPR.

Signed-off-by: Steve Sistare 



Reviewed-by: Cédric Le Goater 

Thanks,

C.



---
  hw/vfio/device.c | 15 ++-
  1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 9fba2c7..71fa9f4 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -300,12 +300,17 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error 
**errp)
  error_setg(errp, "Use FD passing only with iommufd backend");
  return false;
  }
-/*
- * Give a name with fd so any function printing out vbasedev->name
- * will not break.
- */
  if (!vbasedev->name) {
-vbasedev->name = g_strdup_printf("VFIO_FD%d", vbasedev->fd);
+
+if (vbasedev->dev->id) {
+vbasedev->name = g_strdup(vbasedev->dev->id);
+return true;
+} else {
+/*
+ * Assign a name so any function printing it will not break.
+ */
+vbasedev->name = g_strdup_printf("VFIO_FD%d", vbasedev->fd);
+}
  }
  }
  





[PATCH V4 32/43] vfio/iommufd: invariant device name

2025-05-29 Thread Steve Sistare
cpr-transfer will use the device name as a key to find the value
of the device descriptor in new QEMU.  However, if the descriptor
number is specified by a command-line fd parameter, then
vfio_device_get_name creates a name that includes the fd number.
This causes a chicken-and-egg problem: new QEMU must know the fd
number to construct a name to find the fd number.

To fix, create an invariant name based on the id command-line parameter,
if id is defined.  The user will need to provide such an id to use CPR.

Signed-off-by: Steve Sistare 
---
 hw/vfio/device.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 9fba2c7..71fa9f4 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -300,12 +300,17 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error 
**errp)
 error_setg(errp, "Use FD passing only with iommufd backend");
 return false;
 }
-/*
- * Give a name with fd so any function printing out vbasedev->name
- * will not break.
- */
 if (!vbasedev->name) {
-vbasedev->name = g_strdup_printf("VFIO_FD%d", vbasedev->fd);
+
+if (vbasedev->dev->id) {
+vbasedev->name = g_strdup(vbasedev->dev->id);
+return true;
+} else {
+/*
+ * Assign a name so any function printing it will not break.
+ */
+vbasedev->name = g_strdup_printf("VFIO_FD%d", vbasedev->fd);
+}
 }
 }
 
-- 
1.8.3.1