Received: from eggs.gnu.org ([2001:4830:134:3::10]:60923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZwXE-0006hO-6K for qemu-devel@nongnu.org; Sat, 04 Feb 2017 04:21:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZwXA-0006Ui-5j for qemu-devel@nongnu.org; Sat, 04 Feb 2017 04:21:32 -0500 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:33985) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cZwX9-0006UW-VR for qemu-devel@nongnu.org; Sat, 04 Feb 2017 04:21:28 -0500 Received: by mail-pg0-x242.google.com with SMTP id v184so4130437pgv.1 for ; Sat, 04 Feb 2017 01:21:27 -0800 (PST) Sender: Paolo Bonzini References: <1486198784-31523-1-git-send-email-ashijeetacharya@gmail.com> From: Paolo Bonzini Message-ID: Date: Sat, 4 Feb 2017 01:21:23 -0800 MIME-Version: 1.0 In-Reply-To: <1486198784-31523-1-git-send-email-ashijeetacharya@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2] migrate: Introduce a 'dc->vmsd' check to avoid segfault for --only-migratable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ashijeet Acharya , dgilbert@redhat.com Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org, quintela@redhat.com On 04/02/2017 00:59, Ashijeet Acharya wrote: > 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'. > > Signed-off-by: Ashijeet Acharya > Reviewed-by: Juan Quintela > --- > 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(-) > > diff --git a/hw/usb/bus.c b/hw/usb/bus.c > index 1dcc35c..1e39b2c 100644 > --- a/hw/usb/bus.c > +++ b/hw/usb/bus.c > @@ -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); > diff --git a/qdev-monitor.c b/qdev-monitor.c > index 549f45f..b72e5a4 100644 > --- a/qdev-monitor.c > +++ b/qdev-monitor.c > @@ -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