Patchwork [2/2] all vga: fail graicefully when vga ports are taken

login
register
mail settings
Submitter Gerd Hoffmann
Date May 11, 2010, 8:43 p.m.
Message ID <1273610601-12805-2-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/52316/
State New
Headers show

Comments

Gerd Hoffmann - May 11, 2010, 8:43 p.m.
Try to pci hotplug a vga card, watch qemu die with hw_error().
This patch fixes it.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/cirrus_vga.c |    3 +++
 hw/vga-pci.c    |    3 +++
 hw/vmware_vga.c |    3 +++
 3 files changed, 9 insertions(+), 0 deletions(-)
Blue Swirl - May 12, 2010, 6:59 p.m.
On 5/11/10, Gerd Hoffmann <kraxel@redhat.com> wrote:
> Try to pci hotplug a vga card, watch qemu die with hw_error().
>  This patch fixes it.
>
>  Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>  ---
>   hw/cirrus_vga.c |    3 +++
>   hw/vga-pci.c    |    3 +++
>   hw/vmware_vga.c |    3 +++
>   3 files changed, 9 insertions(+), 0 deletions(-)
>
>  diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
>  index 9f61a01..2f50e86 100644
>  --- a/hw/cirrus_vga.c
>  +++ b/hw/cirrus_vga.c
>  @@ -3189,6 +3189,9 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
>       uint8_t *pci_conf = d->dev.config;
>       int device_id = CIRRUS_ID_CLGD5446;
>
>  +     if (is_ioport_assigned(0x3c0))
>  +         return -1;
>  +

-ECODING_STYLE.

>       /* setup VGA */
>       vga_common_init(&s->vga, VGA_RAM_SIZE);
>       cirrus_init_common(s, device_id, 1);
>  diff --git a/hw/vga-pci.c b/hw/vga-pci.c
>  index c8d260c..2ef3278 100644
>  --- a/hw/vga-pci.c
>  +++ b/hw/vga-pci.c
>  @@ -79,6 +79,9 @@ static int pci_vga_initfn(PCIDevice *dev)
>       VGACommonState *s = &d->vga;
>       uint8_t *pci_conf = d->dev.config;
>
>  +     if (is_ioport_assigned(0x3c0))
>  +         return -1;
>  +
>       // vga + console init
>       vga_common_init(s, VGA_RAM_SIZE);
>       vga_init(s);
>  diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
>  index 4e7a75d..cd0eb57 100644
>  --- a/hw/vmware_vga.c
>  +++ b/hw/vmware_vga.c
>  @@ -1232,6 +1232,9 @@ static int pci_vmsvga_initfn(PCIDevice *dev)
>      struct pci_vmsvga_state_s *s =
>          DO_UPCAST(struct pci_vmsvga_state_s, card, dev);
>
>  +    if (is_ioport_assigned(0x3c0))
>  +        return -1;
>  +
>      pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE);
>      pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID);
>      s->card.config[PCI_COMMAND]        = PCI_COMMAND_IO |
>
> --
>  1.6.6.1
>
>
>
Markus Armbruster - May 18, 2010, 12:33 p.m.
Gerd Hoffmann <kraxel@redhat.com> writes:

> Try to pci hotplug a vga card, watch qemu die with hw_error().
> This patch fixes it.

Looks good.

Are there any other hot-pluggable devices that acquire single-use
resources such as fixed I/O ports?
Gerd Hoffmann - May 18, 2010, 12:45 p.m.
On 05/18/10 14:33, Markus Armbruster wrote:
> Gerd Hoffmann<kraxel@redhat.com>  writes:
>
>> Try to pci hotplug a vga card, watch qemu die with hw_error().
>> This patch fixes it.
>
> Looks good.
>
> Are there any other hot-pluggable devices that acquire single-use
> resources such as fixed I/O ports?

Any PCI device doing ISA compatibility stuff I'd guess, which makes IDE 
a candidate.  Checking ...

Yes (hw/ide/piix.c):

     ide_init_ioport(&d->bus[0], 0x1f0, 0x3f6);
     ide_init_ioport(&d->bus[1], 0x170, 0x376);

Those are tagged with "no-user" though due to being hard-coded in pc.c, 
so any attempt to hot-plug one of those should fail way before it 
attempts to grab the I/O ports.

cheers,
   Gerd
Markus Armbruster - May 18, 2010, 2:06 p.m.
Gerd Hoffmann <kraxel@redhat.com> writes:

> On 05/18/10 14:33, Markus Armbruster wrote:
>> Gerd Hoffmann<kraxel@redhat.com>  writes:
>>
>>> Try to pci hotplug a vga card, watch qemu die with hw_error().
>>> This patch fixes it.
>>
>> Looks good.
>>
>> Are there any other hot-pluggable devices that acquire single-use
>> resources such as fixed I/O ports?
>
> Any PCI device doing ISA compatibility stuff I'd guess, which makes
> IDE a candidate.  Checking ...
>
> Yes (hw/ide/piix.c):
>
>     ide_init_ioport(&d->bus[0], 0x1f0, 0x3f6);
>     ide_init_ioport(&d->bus[1], 0x170, 0x376);
>
> Those are tagged with "no-user" though due to being hard-coded in
> pc.c, so any attempt to hot-plug one of those should fail way before
> it attempts to grab the I/O ports.

So a more general mechanism than you ad hoc is_ioport_assigned() check
doesn't seem to be justified.

Patch

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 9f61a01..2f50e86 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -3189,6 +3189,9 @@  static int pci_cirrus_vga_initfn(PCIDevice *dev)
      uint8_t *pci_conf = d->dev.config;
      int device_id = CIRRUS_ID_CLGD5446;
 
+     if (is_ioport_assigned(0x3c0))
+         return -1;
+
      /* setup VGA */
      vga_common_init(&s->vga, VGA_RAM_SIZE);
      cirrus_init_common(s, device_id, 1);
diff --git a/hw/vga-pci.c b/hw/vga-pci.c
index c8d260c..2ef3278 100644
--- a/hw/vga-pci.c
+++ b/hw/vga-pci.c
@@ -79,6 +79,9 @@  static int pci_vga_initfn(PCIDevice *dev)
      VGACommonState *s = &d->vga;
      uint8_t *pci_conf = d->dev.config;
 
+     if (is_ioport_assigned(0x3c0))
+         return -1;
+
      // vga + console init
      vga_common_init(s, VGA_RAM_SIZE);
      vga_init(s);
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index 4e7a75d..cd0eb57 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -1232,6 +1232,9 @@  static int pci_vmsvga_initfn(PCIDevice *dev)
     struct pci_vmsvga_state_s *s =
         DO_UPCAST(struct pci_vmsvga_state_s, card, dev);
 
+    if (is_ioport_assigned(0x3c0))
+        return -1;
+
     pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE);
     pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID);
     s->card.config[PCI_COMMAND]	= PCI_COMMAND_IO |