Received: from eggs.gnu.org ([2001:4830:134:3::10]:38564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgxqa-0002ly-Ix for qemu-devel@nongnu.org; Wed, 22 Oct 2014 11:29:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgxqR-0002SG-8p for qemu-devel@nongnu.org; Wed, 22 Oct 2014 11:29:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgxqR-0002S7-0d for qemu-devel@nongnu.org; Wed, 22 Oct 2014 11:29:03 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9MFT25f031124 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 22 Oct 2014 11:29:02 -0400 Message-ID: <1413991695.2376.29.camel@localhost.localdomain> From: Marcel Apfelbaum Date: Wed, 22 Oct 2014 18:28:15 +0300 In-Reply-To: <20141022083116.GC7797@redhat.com> References: <1413895032-10116-1-git-send-email-marcel.a@redhat.com> <20141022061849.GA20771@redhat.com> <1413963261.2376.8.camel@localhost.localdomain> <20141022075834.GA4566@redhat.com> <1413965765.2376.15.camel@localhost.localdomain> <20141022083116.GC7797@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] hw/pci: fixed crash when using rombar=0 for hotplugged devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org On Wed, 2014-10-22 at 11:31 +0300, Michael S. Tsirkin wrote: > On Wed, Oct 22, 2014 at 11:16:05AM +0300, Marcel Apfelbaum wrote: > > On Wed, 2014-10-22 at 10:58 +0300, Michael S. Tsirkin wrote: > > > On Wed, Oct 22, 2014 at 10:34:21AM +0300, Marcel Apfelbaum wrote: > > > > On Wed, 2014-10-22 at 09:18 +0300, Michael S. Tsirkin wrote: > > > > > On Tue, Oct 21, 2014 at 03:37:12PM +0300, Marcel Apfelbaum wrote: > > > > > > 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; > > > > > > } > > > > > > > > > > Fair enough for this chunk. > > > > > > > > > > > @@ -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; > > > > > > > > > > > > > > > The message is confusing. rombar=0 is ok if you > > > > > don't also try to force romfile. > > > > > Generally why are you adding this logic in pci? > > > > Because rom_add_option will call eventually rom_insert > > > > that will crash QEMU with the call to hw_error. > > > > > > So fix rom_insert to return an error code instead? > > OK, thanks > > > > > > > > > > And what about e.g. vga? > > > > This logic would apply also to rom_add_vga, I was not > > > > aware we can hotplug vga devices. Can we? > > > > I can add it also to vga, of course. > > > > > > > > > I think the right thing to do is to propagate return codes correctly, > > > > > and report the error where it occurs. > > > > I can remove the error_report, but this gives an extra hint to user. > > > > > > Move it to rom_insert, instead of hw_error. > > Sure, I was a little "afraid" to change the "crash" policy of rom_insert. > > > > Thanks, > > Marcel > > You will need to audit all users, and make sure they > check the error and handle it. > So it's a lot of work ... The truth is, while I don't mind getting into it, I was interested in solving the crash issue rather than re-factoring hw_error. I'll prefer to find a solution for the crash and deffer hw_error re-factoring to another series... Checking "hotplugged" at pci_add_option_rom for both rom_ad_option and rom_add_vga can be a PCI specific solution since it connects hotplug -> no rombar=0. Propagating rom_insert error seems indeed difficult since the callers are mostly returning void. Thanks, Marcel > > > > > > > > I didn't see any other way to propagate the error message. > > > > Should I drop it? > > > > > > > > Thanks, > > > > Marcel > > > > > > > > > > > -- > > > > > > 1.8.3.1 > > > > > > > > > > > >