From nobody Tue Apr 30 16:32:20 2024 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 1486210918614268.78412036282737; Sat, 4 Feb 2017 04:21:58 -0800 (PST) Received: from localhost ([::1]:38976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZzLp-0002JN-5t for importer@patchew.org; Sat, 04 Feb 2017 07:21:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54870) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZzKu-0001zk-BM for qemu-devel@nongnu.org; Sat, 04 Feb 2017 07:21:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZzKq-0005fl-Bh for qemu-devel@nongnu.org; Sat, 04 Feb 2017 07:21:00 -0500 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:33072) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cZzKq-0005fN-5h for qemu-devel@nongnu.org; Sat, 04 Feb 2017 07:20:56 -0500 Received: by mail-pg0-x241.google.com with SMTP id 194so4413166pgd.0 for ; Sat, 04 Feb 2017 04:20:55 -0800 (PST) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id 89sm74855680pfo.40.2017.02.04.04.20.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 04 Feb 2017 04:20:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Nk2eFEqf0Jg06hdx/xqBo39dBPcuckhXZ+lQafLs61E=; b=SA3eb+QVZ39hv0eza1dmou/ruYqNpgQNNDGv7YRSBmWG2fXbEJa6GiElT2rQRXIluE l1vWekydmoAENUyS8j74ieCgzZkGqtpVeVSqE835QhO+cO8Rh9GWZDIEN5qB9BdkGufv yXesHGFbLSzcoEU/afiEwItSfn5+LE8Hp64KWbpIgKC5Z/nggHnV5UZf88x3Ctl1vpWN QVdlmqwM9DvRlDD1ssoRhypYE83u/vvsykPC9mTrTSGcQyIxMGsqjWDgBfA9K/K5kvtJ YKlVERTrOodfZwHDAwDAtrSBdrOClUgoVnXOl74x2WKHCIIeEidSCNUf/5JSP75Ex95j +bTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Nk2eFEqf0Jg06hdx/xqBo39dBPcuckhXZ+lQafLs61E=; b=ILqwr+PqfUduMEfFTF3hzgFuQkdG0AINxB5fu8YjSPxjJPrTY4110d46I0ugkRhmT8 O77xTkWTSKR0aviz54prBVSrn/nJzGCCf2mr5ZjAwdZewNp4TJxzYNKZnetAGaRSQaC3 UZgvVsyjG9EZ5uJwzi26ExehZmebCGLZqkqdjXhQP7KSnd0t3qfquS4zH/6kxxo1aHQJ rghVI16Gjn6JHZ65t2yacvBBtHyHBic3v0LX/cF+PiUgNlpSsaEWpGEgKjSuDofv2bhW hsDAZXq+su6ehWUppSANO1jvMoy5cOaMHSec8aVxdVrAtfeCkK5LFPikPSs4c3niud9r epFg== X-Gm-Message-State: AIkVDXIg6UwNGbOVJ8E9kxlDkOWIc/AjV4Kt/3C6eyPHdafT3W+UAaOyJo1xJQf8usVAYw== X-Received: by 10.98.36.134 with SMTP id k6mr2228441pfk.41.1486210854982; Sat, 04 Feb 2017 04:20:54 -0800 (PST) From: Ashijeet Acharya To: dgilbert@redhat.com Date: Sat, 4 Feb 2017 17:51:03 +0530 Message-Id: <1486210863-14924-1-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH v3] 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: peter.maydell@linaro.org, pbonzini@redhat.com, qemu-devel@nongnu.org, Ashijeet Acharya , quintela@redhat.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" 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'. Also, move the only_migratable check inside device_set_realized() to avoid code duplication and fix the bug to display only_migratable error message only if the device constructuon is right. Signed-off-by: Ashijeet Acharya --- Changes is v3: - move only_migratable check inside device_set_realized() to avoid code=20 - duplication - I have dropped Juan's R-b tag for this one Changes in v2: - place dc->vmsd check in hw/usb/bus.c as well --- hw/core/qdev.c | 10 ++++++++++ hw/usb/bus.c | 19 ------------------- qdev-monitor.c | 9 --------- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 5783442..4438cbf 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; @@ -896,6 +897,15 @@ static void device_set_realized(Object *obj, bool valu= e, Error **errp) } =20 if (value && !dev->realized) { + if (only_migratable && dc->vmsd) { + if (dc->vmsd->unmigratable) { + error_setg(&local_err, "Device %s is not migratable, but " + "--only-migratable was specified", + object_get_typename(obj)); + 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 1dcc35c..25913ad 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 @@ -687,8 +686,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) { @@ -723,22 +720,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/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) { --=20 2.6.2