Skip to content

Commit b9b389b

Browse files
Steve Sistarelegoater
authored andcommitted
vfio/iommufd: invariant device name
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 <steven.sistare@oracle.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Link: https://lore.kernel.org/qemu-devel/1751493538-202042-10-git-send-email-steven.sistare@oracle.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
1 parent fb32965 commit b9b389b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

hw/vfio/device.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,17 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp)
316316
error_setg(errp, "Use FD passing only with iommufd backend");
317317
return false;
318318
}
319-
/*
320-
* Give a name with fd so any function printing out vbasedev->name
321-
* will not break.
322-
*/
323319
if (!vbasedev->name) {
324-
vbasedev->name = g_strdup_printf("VFIO_FD%d", vbasedev->fd);
320+
321+
if (vbasedev->dev->id) {
322+
vbasedev->name = g_strdup(vbasedev->dev->id);
323+
return true;
324+
} else {
325+
/*
326+
* Assign a name so any function printing it will not break.
327+
*/
328+
vbasedev->name = g_strdup_printf("VFIO_FD%d", vbasedev->fd);
329+
}
325330
}
326331
}
327332

0 commit comments

Comments
 (0)