migrate: Introduce a 'dc->vmsd' check to avoid segfault for --only-migratable
PATCH v2 1/1 migrate: Introduce a 'dc->vmsd' check to avoid segfault for --only-migratable
Commit a3a3d8c7 introduced a segfault bug while checking for 'dc->vmsd->unmigratable' which caused QEMU to crash when trying to add devices which do no set their 'dc->vmsd' yet while initialization. Place a 'dc->vmsd' check prior to it so that we do not segfault for such devices.
NOTE: This doesn't compromise the functioning of --only-migratable option as all the unmigratable devices do set their 'dc->vmsd'.
---
Changes in v2:
- place dc->vmsd check in hw/usb/bus.c as well
--- hw/usb/bus.c | 2 +- qdev-monitor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/usb/bus.c +1 -1
@@ -731,7 +731,7 @@ USBDevice *usbdevice_create(const char *cmdline) dc =DEVICE_CLASS (klass); -if (only_migratable) { +if (only_migratable && dc->vmsd) {if (dc->vmsd->unmigratable) {error_report ("Device %s is not migratable, but --only-migratable " "was specified" , f->name);
qdev-monitor.c +1 -1
@@ -579,7 +579,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)return NULL ; } -if (only_migratable) { +if (only_migratable && dc->vmsd) {if (dc->vmsd->unmigratable) {error_setg (errp,"Device %s is not migratable, but " "--only-migratable was specified" , driver);
Signature · 1 line
2.6.2
Quoted 38 lines · Ashijeet Acharya
Commit
a3a3d8c7introduced a segfault bug while checking for 'dc->vmsd->unmigratable' which caused QEMU to crash when trying to add devices which do no set their 'dc->vmsd' yet while initialization. Place a 'dc->vmsd' check prior to it so that we do not segfault for such devices.NOTE: This doesn't compromise the functioning of --only-migratable option as all the unmigratable devices do set their '
dc->vmsd'.Signed-off-by Ashijeet Acharya <[email protected]>Reviewed-by Juan Quintela <[email protected]>---
Changes in v2:
- placedc->vmsdcheck inhw/usb/bus.cas well--- hw/usb/bus.c | 2 +- qdev-monitor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/usb/bus.c +1
-1@@ -731,7 +731,7 @@ USBDevice *usbdevice_create(const char *cmdline) dc =DEVICE_CLASS (klass); -if (only_migratable) { +if (only_migratable && dc->vmsd) {if (dc->vmsd->unmigratable) {error_report ("Device %s is not migratable, but --only-migratable " "was specified" , f->name);qdev-monitor.c +0
-0
qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) · line 585
Quoted 8 lines
qdev-monitor.c +1
-1@@ -579,7 +579,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)return NULL ; } -if (only_migratable) { +if (only_migratable && dc->vmsd) {if (dc->vmsd->unmigratable) {error_setg (errp,"Device %s is not migratable, but " "--only-migratable was specified" , driver);
Could you handle only_migratable in device_set_realized (inside "if (value && !dev->realized)"), to avoid the code duplication? Separate patch from this one, of course.
Thanks,
Paolo