From patchwork Tue Oct 21 12:37:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 401459 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1A7CB14003E for ; Tue, 21 Oct 2014 23:38:33 +1100 (AEDT) Received: from localhost ([::1]:50239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgYhr-0007cR-9M for incoming@patchwork.ozlabs.org; Tue, 21 Oct 2014 08:38:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgYhR-0007CB-TC for qemu-devel@nongnu.org; Tue, 21 Oct 2014 08:38:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgYhL-0006oH-66 for qemu-devel@nongnu.org; Tue, 21 Oct 2014 08:38:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31046) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgYhK-0006nq-Vb for qemu-devel@nongnu.org; Tue, 21 Oct 2014 08:37:59 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9LCbvFE017334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 21 Oct 2014 08:37:57 -0400 Received: from localhost.tlv.redhat.com (dhcp-4-171.tlv.redhat.com [10.35.4.171]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9LCbuWm032073; Tue, 21 Oct 2014 08:37:56 -0400 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Tue, 21 Oct 2014 15:37:12 +0300 Message-Id: <1413895032-10116-1-git-send-email-marcel.a@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: mst@redhat.com Subject: [Qemu-devel] [PATCH] hw/pci: fixed crash when using rombar=0 for hotplugged devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org ROM images must be loaded at startup. Usage of rombar=0 after that is not allowed, but should not crash QEMU. Check that the device is not hotplugged before trying to insert the rom file. Signed-off-by: Marcel Apfelbaum --- hw/pci/pci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 6ce75aa..3907c90 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1776,7 +1776,12 @@ static int pci_qdev_init(DeviceState *qdev) pci_dev->romfile = g_strdup(pc->romfile); is_default_rom = true; } - pci_add_option_rom(pci_dev, is_default_rom); + + rc = pci_add_option_rom(pci_dev, is_default_rom); + if (rc != 0) { + pci_unregister_device(DEVICE(pci_dev)); + return rc; + } return 0; } @@ -1940,6 +1945,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) if (class == 0x0300) { rom_add_vga(pdev->romfile); } else { + if (DEVICE(pdev)->hotplugged) { + error_report("PCI: rombar can't be 0 for hotplugged devices!"); + return -1; + } rom_add_option(pdev->romfile, -1); } return 0;