From: "Michael S. Tsirkin" <mst@redhat.com>
To: Marcel Apfelbaum <marcel.a@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] hw/pci: fixed crash when using rombar=0 for hotplugged devices
Date: Wed, 22 Oct 2014 18:49:48 +0300 [thread overview]
Message-ID: <20141022154948.GA30233@redhat.com> (raw)
In-Reply-To: <1413991695.2376.29.camel@localhost.localdomain>
On Wed, Oct 22, 2014 at 06:28:15PM +0300, Marcel Apfelbaum wrote:
> 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 <marcel.a@redhat.com>
> > > > > > > ---
> > > > > > > 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
But it's ugly, I'm not sure the crash as result of user error
is important enough to justify this.
> >
> > > >
> > > > > I didn't see any other way to propagate the error message.
> > > > > Should I drop it?
> > > > >
> > > > > Thanks,
> > > > > Marcel
> > > > > >
> > > > > > > --
> > > > > > > 1.8.3.1
> > > > >
> > > > >
> > >
> > >
>
>
prev parent reply other threads:[~2014-10-22 15:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-21 12:37 [Qemu-devel] [PATCH] hw/pci: fixed crash when using rombar=0 for hotplugged devices Marcel Apfelbaum
2014-10-21 22:06 ` Paolo Bonzini
2014-10-22 6:26 ` Michael S. Tsirkin
2014-10-22 7:41 ` Marcel Apfelbaum
2014-10-22 8:02 ` Michael S. Tsirkin
2014-10-22 16:26 ` Alex Williamson
2014-10-22 18:24 ` Marcel Apfelbaum
2014-10-22 6:18 ` Michael S. Tsirkin
2014-10-22 7:34 ` Marcel Apfelbaum
2014-10-22 7:58 ` Michael S. Tsirkin
2014-10-22 8:16 ` Marcel Apfelbaum
2014-10-22 8:31 ` Michael S. Tsirkin
2014-10-22 15:28 ` Marcel Apfelbaum
2014-10-22 15:49 ` Michael S. Tsirkin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141022154948.GA30233@redhat.com \
--to=mst@redhat.com \
--cc=marcel.a@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.