Skip to content

Commit

Permalink
virtio: new post_load hook
Browse files Browse the repository at this point in the history
Post load hook in virtio vmsd is called early while device is processed,
and when VirtIODevice core isn't fully initialized.  Most device
specific code isn't ready to deal with a device in such state, and
behaves weirdly.

Add a new post_load hook in a device class instead.  Devices should use
this unless they specifically want to verify the migration stream as
it's processed, e.g. for bounds checking.

Cc: qemu-stable@nongnu.org
Suggested-by: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Mikhail Sennikovsky <mikhail.sennikovskii@cloud.ionos.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
  • Loading branch information
mstsirkin authored and AndrewFasano committed Oct 16, 2023
1 parent a1ed8b3 commit 599ef0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions hw/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3089,6 +3089,13 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
}
rcu_read_unlock();

if (vdc->post_load) {
ret = vdc->post_load(vdev);
if (ret) {
return ret;
}
}

return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions include/hw/virtio/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ typedef struct VirtioDeviceClass {
*/
void (*save)(VirtIODevice *vdev, QEMUFile *f);
int (*load)(VirtIODevice *vdev, QEMUFile *f, int version_id);
/* Post load hook in vmsd is called early while device is processed, and
* when VirtIODevice isn't fully initialized. Devices should use this instead,
* unless they specifically want to verify the migration stream as it's
* processed, e.g. for bounds checking.
*/
int (*post_load)(VirtIODevice *vdev);
const VMStateDescription *vmsd;
} VirtioDeviceClass;

Expand Down

0 comments on commit 599ef0a

Please sign in to comment.