From patchwork Sat Feb 4 08:59:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9555529 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 B3EED602B5 for ; Sat, 4 Feb 2017 09:00:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 628632018E for ; Sat, 4 Feb 2017 09:00:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 571402819A; Sat, 4 Feb 2017 09:00:12 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 465442018E for ; Sat, 4 Feb 2017 09:00:09 +0000 (UTC) Received: from localhost ([::1]:38429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZwCW-0002Ro-EX for patchwork-qemu-devel@patchwork.kernel.org; Sat, 04 Feb 2017 04:00:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZwCF-0002Rj-1D for qemu-devel@nongnu.org; Sat, 04 Feb 2017 03:59:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZwCB-0006EK-UE for qemu-devel@nongnu.org; Sat, 04 Feb 2017 03:59:51 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:36780) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cZwCB-0006DV-On for qemu-devel@nongnu.org; Sat, 04 Feb 2017 03:59:47 -0500 Received: by mail-pg0-x244.google.com with SMTP id 75so4096696pgf.3 for ; Sat, 04 Feb 2017 00:59:47 -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=4pl7TijBp8ARr1tSzOCIXQ1ZpQaSQRiO2DcNpzIPuec=; b=g3j7QYoRQvJu6NMrhdaydzcZmPfwuvJ0ZsCnJF3dNPbo8hC2xEmHTv7eaw/RmI6bnA ZLJk253tJYBd/ZZ6wIL5MyiHv+j7JlNOGGHK8kVOYZkwLzbIrk6Qlu4JH5JSPmD4tASn mCZvo+h/QUmprTl/WE602po0EXeBCjOjB90KQN7f6po92kqVJga0uKmKkvSDTSu/+q+i 2RtkAhU60f9vSr3GnLy7eRhNRngMaAqu3veAUVm9WM1qd8p5ukwZ0m2I2zoxO1JhKpyd aFxGiHUzJ8tayDNC8YRSSD0oM3T9yl8Q/Ip46VNcCVAsMLF6y3TlO/EzvikMXGRPzGF3 1ufw== 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=4pl7TijBp8ARr1tSzOCIXQ1ZpQaSQRiO2DcNpzIPuec=; b=dPbjjX1UELTo0s7ROCM2q/AYC4D97Ea7ZydddH6RLb51YJGNUZGiaJr5SOexKyPGrz s4NesOYGg8CV+Nvmjnp7cnLQ0jT++E9CFM37vpYBPIQtcfA3RhhZWT/cpWcBZFHgeCrA U7ZlgM4JB1pBSFinPc1JBujO+FLiSmiQcVK8lp4PRTGEBuvrZ1cCFh2y2liQksdZQwzG Y35z4SwqiRRLHgmTzzGAHNZm8xhv1pQAZMrwaWTfaMOBjySmWF50SRwNeo3/GCixNC2v Frk9+LSF2dBEma4ycgyK731eg3mBEhHPZ4wP9BNz4/rX/YfNSP6h531WL7hVAFv4Log7 DRWw== X-Gm-Message-State: AIkVDXIHqxRt63dOy2+loY8fYgbnB2R49btFfakkpd/ujh6rLN06q0yt0X2mtLPEVNVEpw== X-Received: by 10.99.144.68 with SMTP id a65mr1498746pge.54.1486198786633; Sat, 04 Feb 2017 00:59:46 -0800 (PST) Received: from linux.local ([157.50.82.48]) by smtp.gmail.com with ESMTPSA id t185sm73484905pgb.32.2017.02.04.00.59.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 04 Feb 2017 00:59:45 -0800 (PST) From: Ashijeet Acharya To: dgilbert@redhat.com Date: Sat, 4 Feb 2017 14:29:44 +0530 Message-Id: <1486198784-31523-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::244 Subject: [Qemu-devel] [PATCH v2] 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, 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'. 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);