From patchwork Sat Feb 4 12:21:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9555629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D5B4602B7 for ; Sat, 4 Feb 2017 12:21:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6560E2723E for ; Sat, 4 Feb 2017 12:21:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 590A8283F6; Sat, 4 Feb 2017 12:21:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AD94A2723E for ; Sat, 4 Feb 2017 12:21:19 +0000 (UTC) Received: from localhost ([::1]:38973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZzLC-00020G-OH for patchwork-qemu-devel@patchwork.kernel.org; Sat, 04 Feb 2017 07:21:18 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 - 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" int qdev_hotplug = 0; static bool qdev_hot_added = false; @@ -896,6 +897,15 @@ static void device_set_realized(Object *obj, bool value, Error **errp) } 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 = g_strdup_printf("device[%d]", unattached_count++); 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" static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); @@ -687,8 +686,6 @@ USBDevice *usbdevice_create(const char *cmdline) const char *params; int len; USBDevice *dev; - ObjectClass *klass; - DeviceClass *dc; params = strchr(cmdline,':'); if (params) { @@ -723,22 +720,6 @@ USBDevice *usbdevice_create(const char *cmdline) return NULL; } - klass = object_class_by_name(f->name); - if (klass == NULL) { - error_report("Device '%s' not found", f->name); - return NULL; - } - - dc = DEVICE_CLASS(klass); - - if (only_migratable) { - if (dc->vmsd->unmigratable) { - error_report("Device %s is not migratable, but --only-migratable " - "was specified", f->name); - return NULL; - } - } - if (f->usbdevice_init) { dev = 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" /* * Aliases were a bad idea from the start. Let's keep them @@ -579,14 +578,6 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) return NULL; } - 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 = qemu_opt_get(opts, "bus"); if (path != NULL) {