Skip to content

Commit a434fd8

Browse files
Steve Sistarelegoater
authored andcommitted
vfio/iommufd: device name blocker
If an invariant device name cannot be created, block CPR. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Link: https://lore.kernel.org/qemu-devel/1751493538-202042-12-git-send-email-steven.sistare@oracle.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
1 parent 184053f commit a434fd8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

hw/vfio/device.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "qapi/error.h"
2929
#include "qemu/error-report.h"
3030
#include "qemu/units.h"
31+
#include "migration/cpr.h"
32+
#include "migration/blocker.h"
3133
#include "monitor/monitor.h"
3234
#include "vfio-helpers.h"
3335

@@ -324,8 +326,16 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp)
324326
} else {
325327
/*
326328
* Assign a name so any function printing it will not break.
329+
* The fd number changes across processes, so this cannot be
330+
* used as an invariant name for CPR.
327331
*/
328332
vbasedev->name = g_strdup_printf("VFIO_FD%d", vbasedev->fd);
333+
error_setg(&vbasedev->cpr.id_blocker,
334+
"vfio device with fd=%d needs an id property",
335+
vbasedev->fd);
336+
return migrate_add_blocker_modes(&vbasedev->cpr.id_blocker,
337+
errp, MIG_MODE_CPR_TRANSFER,
338+
-1) == 0;
329339
}
330340
}
331341
}
@@ -336,6 +346,7 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp)
336346
void vfio_device_free_name(VFIODevice *vbasedev)
337347
{
338348
g_clear_pointer(&vbasedev->name, g_free);
349+
migrate_del_blocker(&vbasedev->cpr.id_blocker);
339350
}
340351

341352
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp)

include/hw/vfio/vfio-cpr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef struct VFIOContainerCPR {
3030

3131
typedef struct VFIODeviceCPR {
3232
Error *mdev_blocker;
33+
Error *id_blocker;
3334
} VFIODeviceCPR;
3435

3536
bool vfio_legacy_cpr_register_container(struct VFIOContainer *container,

0 commit comments

Comments
 (0)