vfio: Fix unregister SaveVMHandler in vfio_migration_finalize
PATCH 1/1 vfio: Fix unregister SaveVMHandler in vfio_migration_finalize
In the vfio_migration_init(), the SaveVMHandler is registered for VFIO device. But it lacks the operation of 'unregister'. It will lead to 'Segmentation fault (core dumped)' in qemu_savevm_state_setup(), if performing live migration after a VFIO device is hot deleted.
--- hw/vfio/migration.c | 1 + 1 file changed, 1 insertion(+)
hw/vfio/migration.c +1 -0
@@ -892,6 +892,7 @@ void vfio_migration_finalize(VFIODevice *vbasedev)remove_migration_state_change_notifier (&migration->migration_state);qemu_del_vm_change_state_handler (migration->vm_state); +unregister_savevm (VMSTATE_IF (vbasedev->dev),"vfio" , vbasedev);vfio_migration_exit (vbasedev); }
Signature · 1 line
2.23.0
Quoted 9 lines · Kunkun Jiang
In the
vfio_migration_init(), the SaveVMHandler is registered for VFIO device. But it lacks the operation of 'unregister'. It will lead to 'Segmentation fault (core dumped)' inqemu_savevm_state_setup(), if performing live migration after a VFIO device is hot deleted.Fixes 7c2f5f75f94 (vfio: Register SaveVMHandlers for VFIO device)Reported-by Qixin Gan <[email protected]>Signed-off-by Kunkun Jiang <[email protected]>
hw/vfio/migration.c void vfio_migration_finalize(VFIODevice *vbasedev) · line 895
Quoted 13 lines
--- hw/vfio/migration.c | 1 + 1 file changed, 1 insertion(+)hw/vfio/migration.c +1
-0@@ -892,6 +892,7 @@ void vfio_migration_finalize(VFIODevice *vbasedev)remove_migration_state_change_notifier (&migration->migration_state);qemu_del_vm_change_state_handler (migration->vm_state); +unregister_savevm (VMSTATE_IF (vbasedev->dev),"vfio" , vbasedev);
Hmm what about devices using "%s/vfio" id?
Quoted 4 lines
hw/vfio/migration.c +0
-0vfio_migration_exit (vbasedev); }
Hi Philippe,
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Kunkun Jiang
In the
vfio_migration_init(), the SaveVMHandler is registered for VFIO device. But it lacks the operation of 'unregister'. It will lead to 'Segmentation fault (core dumped)' inqemu_savevm_state_setup(), if performing live migration after a VFIO device is hot deleted.Fixes 7c2f5f75f94 (vfio: Register SaveVMHandlers for VFIO device)Reported-by Qixin Gan <[email protected]>Signed-off-by Kunkun Jiang <[email protected]>Quoted 10 lines
--- hw/vfio/migration.c | 1 + 1 file changed, 1 insertion(+)hw/vfio/migration.c +0
-0@@ -892,6 +892,7 @@ void vfio_migration_finalize(VFIODevice *vbasedev)
Quoted 4 lines
hw/vfio/migration.c void vfio_migration_finalize(VFIODevice *vbasedev) · line 895
Quoted 3 lines
hw/vfio/migration.c +1
-0remove_migration_state_change_notifier (&migration->migration_state);qemu_del_vm_change_state_handler (migration->vm_state); +unregister_savevm (VMSTATE_IF (vbasedev->dev),"vfio" , vbasedev);Hmm what about devices using "%s/vfio" id?
The unregister_savevm() needs 'VMSTATEIf *obj'. If we pass a non-null 'obj' to unregister_svevm(), it will handle the devices using "%s/vfio" id with the following code:
Quoted 9 lines
if (obj) {
char *oid =vmstate_if_get_id(obj);
if (oid) {
pstrcpy(id, sizeof(id), oid);
pstrcat(id, sizeof(id), "/");
g_free(oid);
}
}
pstrcat(id, sizeof(id), idstr);
By the way, I'm puzzled that register_savevm_live() and unregister_savevm() handle devices using "%s/vfio" id differently. So I learned the commit history of register_savevm_live() and unregister_savevm().
In the beginning, both them need 'DeviceState *dev', which are replaced with VMStateIf in 3cad405babb. Later in ce62df5378b, the 'dev' was removed, because no caller of register_savevm_live() need to pass a non-null 'dev' at that time.
So now the vfio devices need to handle the 'id' first and then call register_savevm_live(). I am wondering whether we need to add 'VMSTATEIf *obj' in register_savevm_live(). What do you think of this?
Thanks,
Kunkun Jiang
Quoted 6 lines
hw/vfio/migration.c void vfio_migration_finalize(VFIODevice *vbasedev) · line 898
Quoted 5 lines
hw/vfio/migration.c +0
-0vfio_migration_exit (vbasedev); }.
Quoted 25 lines · Kunkun Jiang
Hi Philippe,
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Kunkun Jiang
In the
vfio_migration_init(), the SaveVMHandler is registered for VFIO device. But it lacks the operation of 'unregister'. It will lead to 'Segmentation fault (core dumped)' inqemu_savevm_state_setup(), if performing live migration after a VFIO device is hot deleted.Fixes 7c2f5f75f94 (vfio: Register SaveVMHandlers for VFIO device)Reported-by Qixin Gan <[email protected]>Signed-off-by Kunkun Jiang <[email protected]>Quoted 10 lines
---
hw/vfio/migration.c| 1 +1 file changed, 1 insertion(+)hw/vfio/migration.c +0
-0@@ -892,6 +892,7 @@ void vfio_migration_finalize(VFIODevice *vbasedev)
Quoted 16 lines
Quoted 4 lines
hw/vfio/migration.c void vfio_migration_finalize(VFIODevice *vbasedev) · line 895
Quoted 3 lines
hw/vfio/migration.c +1
-0remove_migration_state_change_notifier (&migration->migration_state); qemu_del_vm_change_state_handler(migration->vm_state); + unregister_savevm(VMSTATE_IF(vbasedev->dev), "vfio", vbasedev);Hmm what about devices using "%s/vfio" id?
The
unregister_savevm()needs 'VMSTATEIf *obj'. If we pass a non-null 'obj' tounregister_svevm(), it will handle the devices using "%s/vfio" id with the following code:Quoted 9 lines
if (obj) {
char *oid =vmstate_if_get_id(obj);
if (oid) {
pstrcpy(id, sizeof(id), oid);
pstrcat(id, sizeof(id), "/");
g_free(oid);
}
}
pstrcat(id, sizeof(id), idstr);
This fix seems fine to me.
Quoted 5 lines
By the way, I'm puzzled that
register_savevm_live()andunregister_savevm()handle devices using "%s/vfio" id differently. So I learned the commit history ofregister_savevm_live()andunregister_savevm().
Quoted 9 lines
In the beginning, both them need 'DeviceState *dev', which are replaced with VMStateIf in
3cad405babb. Later ince62df5378b, the 'dev' was removed, because no caller ofregister_savevm_live()need to pass a non-null 'dev' at that time.So now the vfio devices need to handle the 'id' first and then call
register_savevm_live(). I am wondering whether we need to add 'VMSTATEIf *obj' inregister_savevm_live(). What do you think of this?
I think proposed change above is independent of this fix. I'll defer to other experts.
Reviewed by: Kirti Wankhede <[email protected]>
Kindly ping,
Hi everyone,
Will this patch be picked up soon, or is there any other work for me to do?
Best Regards,
Kunkun Jiang
Quoted 25 lines · Kunkun Jiang
In the
vfio_migration_init(), the SaveVMHandler is registered for VFIO device. But it lacks the operation of 'unregister'. It will lead to 'Segmentation fault (core dumped)' inqemu_savevm_state_setup(), if performing live migration after a VFIO device is hot deleted.Fixes 7c2f5f75f94 (vfio: Register SaveVMHandlers for VFIO device)Reported-by Qixin Gan <[email protected]>Signed-off-by Kunkun Jiang <[email protected]>--- hw/vfio/migration.c | 1 + 1 file changed, 1 insertion(+)hw/vfio/migration.c +1
-0@@ -892,6 +892,7 @@ void vfio_migration_finalize(VFIODevice *vbasedev)remove_migration_state_change_notifier (&migration->migration_state);qemu_del_vm_change_state_handler (migration->vm_state); +unregister_savevm (VMSTATE_IF (vbasedev->dev),"vfio" , vbasedev);vfio_migration_exit (vbasedev); }