From nobody Mon Feb 9 08:56:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148828579747365.10709291572834; Tue, 28 Feb 2017 04:43:17 -0800 (PST) Received: from localhost ([::1]:60714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cih7c-00017S-5I for importer@patchew.org; Tue, 28 Feb 2017 07:43:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cih5h-00087f-MX for qemu-devel@nongnu.org; Tue, 28 Feb 2017 07:41:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cih5g-0000GF-EH for qemu-devel@nongnu.org; Tue, 28 Feb 2017 07:41:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cih5g-0000G6-5H for qemu-devel@nongnu.org; Tue, 28 Feb 2017 07:41:16 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4872E4E4CB; Tue, 28 Feb 2017 12:41:16 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-149.ams2.redhat.com [10.36.117.149]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SCewt8019858; Tue, 28 Feb 2017 07:41:14 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Tue, 28 Feb 2017 12:40:37 +0000 Message-Id: <20170228124056.5074-9-dgilbert@redhat.com> In-Reply-To: <20170228124056.5074-1-dgilbert@redhat.com> References: <20170228124056.5074-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 28 Feb 2017 12:41:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/27] migrate: Introduce a 'dc->vmsd' check to avoid segfault for --only-migratable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, pasic@linux.vnet.ibm.com, vsementsov@virtuozzo.com, quintela@redhat.com, ashijeetacharya@gmail.com, marcandre.lureau@redhat.com, danielhb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ashijeet Acharya 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'. Introduce a new function check_migratable() and move the only_migratable check inside it, also use stubs to avoid user-mode qemu build failures. Signed-off-by: Ashijeet Acharya Message-Id: <1487009088-23891-1-git-send-email-ashijeetacharya@gmail.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- hw/core/qdev.c | 7 +++++++ hw/usb/bus.c | 19 ------------------- include/migration/migration.h | 3 +++ migration/migration.c | 15 +++++++++++++++ qdev-monitor.c | 9 --------- stubs/vmstate.c | 6 ++++++ 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 06ba02e..dd1ca1c 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -37,6 +37,7 @@ #include "hw/boards.h" #include "hw/sysbus.h" #include "qapi-event.h" +#include "migration/migration.h" =20 int qdev_hotplug =3D 0; static bool qdev_hot_added =3D false; @@ -889,6 +890,7 @@ static void device_set_realized(Object *obj, bool value= , Error **errp) Error *local_err =3D NULL; bool unattached_parent =3D false; static int unattached_count; + int ret; =20 if (dev->hotplugged && !dc->hotpluggable) { error_setg(errp, QERR_DEVICE_NO_HOTPLUG, object_get_typename(obj)); @@ -896,6 +898,11 @@ static void device_set_realized(Object *obj, bool valu= e, Error **errp) } =20 if (value && !dev->realized) { + ret =3D check_migratable(obj, &local_err); + if (ret < 0) { + goto fail; + } + if (!obj->parent) { gchar *name =3D g_strdup_printf("device[%d]", unattached_count= ++); =20 diff --git a/hw/usb/bus.c b/hw/usb/bus.c index efe4b8e..24f1608 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -8,7 +8,6 @@ #include "monitor/monitor.h" #include "trace.h" #include "qemu/cutils.h" -#include "migration/migration.h" =20 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); =20 @@ -688,8 +687,6 @@ USBDevice *usbdevice_create(const char *cmdline) const char *params; int len; USBDevice *dev; - ObjectClass *klass; - DeviceClass *dc; =20 params =3D strchr(cmdline,':'); if (params) { @@ -724,22 +721,6 @@ USBDevice *usbdevice_create(const char *cmdline) return NULL; } =20 - klass =3D object_class_by_name(f->name); - if (klass =3D=3D NULL) { - error_report("Device '%s' not found", f->name); - return NULL; - } - - dc =3D DEVICE_CLASS(klass); - - if (only_migratable) { - if (dc->vmsd->unmigratable) { - error_report("Device %s is not migratable, but --only-migratab= le " - "was specified", f->name); - return NULL; - } - } - if (f->usbdevice_init) { dev =3D f->usbdevice_init(bus, params); } else { diff --git a/include/migration/migration.h b/include/migration/migration.h index 1735d66..34a383e 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -22,6 +22,7 @@ #include "qapi-types.h" #include "exec/cpu-common.h" #include "qemu/coroutine_int.h" +#include "qom/object.h" =20 #define QEMU_VM_FILE_MAGIC 0x5145564d #define QEMU_VM_FILE_VERSION_COMPAT 0x00000002 @@ -313,6 +314,8 @@ int migrate_add_blocker(Error *reason, Error **errp); */ void migrate_del_blocker(Error *reason); =20 +int check_migratable(Object *obj, Error **err); + bool migrate_release_ram(void); bool migrate_postcopy_ram(void); bool migrate_zero_blocks(void); diff --git a/migration/migration.c b/migration/migration.c index 4fab538..481c540 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1150,6 +1150,21 @@ void migrate_del_blocker(Error *reason) migration_blockers =3D g_slist_remove(migration_blockers, reason); } =20 +int check_migratable(Object *obj, Error **err) +{ + DeviceClass *dc =3D DEVICE_GET_CLASS(obj); + if (only_migratable && dc->vmsd) { + if (dc->vmsd->unmigratable) { + error_setg(err, "Device %s is not migratable, but " + "--only-migratable was specified", + object_get_typename(obj)); + return -1; + } + } + + return 0; +} + void qmp_migrate_incoming(const char *uri, Error **errp) { Error *local_err =3D NULL; diff --git a/qdev-monitor.c b/qdev-monitor.c index 549f45f..5f2fcdf 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -29,7 +29,6 @@ #include "qemu/error-report.h" #include "qemu/help_option.h" #include "sysemu/block-backend.h" -#include "migration/migration.h" =20 /* * Aliases were a bad idea from the start. Let's keep them @@ -579,14 +578,6 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **e= rrp) return NULL; } =20 - if (only_migratable) { - if (dc->vmsd->unmigratable) { - error_setg(errp, "Device %s is not migratable, but " - "--only-migratable was specified", driver); - return NULL; - } - } - /* find bus */ path =3D qemu_opt_get(opts, "bus"); if (path !=3D NULL) { diff --git a/stubs/vmstate.c b/stubs/vmstate.c index bbe158f..6d52f29 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -1,6 +1,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "migration/vmstate.h" +#include "migration/migration.h" =20 const VMStateDescription vmstate_dummy =3D {}; =20 @@ -19,3 +20,8 @@ void vmstate_unregister(DeviceState *dev, void *opaque) { } + +int check_migratable(Object *obj, Error **err) +{ + return 0; +} --=20 2.9.3