Skip to contentSkip to conversation

-device xen-platform crashes

Qemu-devel Markus Armbruster 2 participants 8 messages Jan 29, 2015 – Feb 4, 2015

lore
Share & tools
lore
#0 lore raw

Reproducer: qemu -nodefaults -S -display none -device xen-platform

Yes, xen-platform makes no sense without Xen, but it shouldn't crash.

Backtrace:

#0 0x00007fffef5a677c in hypercall_buffer_cache_lock ()
from /lib64/libxenctrl.so.4.3
#1 0x00007fffef5a68f1 in xc.hypercall_buffer_alloc_pages ()
from /lib64/libxenctrl.so.4.3
#2 0x00007fffef5a6a61 in xc.hypercall_buffer_alloc ()
from /lib64/libxenctrl.so.4.3
#3 0x00007fffef59da54 in xc_hvm_set_mem_type () from /lib64/libxenctrl.so.4.3 #4 0x00005555556d5bcd in platform_fixed_ioport_writeb (opaque=0x5555564713b0,

    addr=0, val=0) at /work/armbru/qemu/hw/i386/xen/xen_platform.c:184
#5  0x00005555556d5ca4 in platform_fixed_ioport_reset (opaque=0x5555564713b0)
    at /work/armbru/qemu/hw/i386/xen/xen_platform.c:238
#6  0x00005555556d608c in platform_reset (dev=0x5555564713b0)
    at /work/armbru/qemu/hw/i386/xen/xen_platform.c:417
#7  0x00005555557e915b in device_reset (dev=0x5555564713b0)
    at /work/armbru/qemu/hw/core/qdev.c:1269
#8  0x00005555557e6a7b in qdev_reset_one (dev=0x5555564713b0, opaque=0x0)
    at /work/armbru/qemu/hw/core/qdev.c:329
#9  0x00005555557e7608 in qdev_walk_children (dev=0x5555564713b0, 
    pre_devfn=0x0, pre_busfn=0x0, post_devfn=0x5555557e6a5f <qdev_reset_one>, 
    post_busfn=0x5555557e6a82 <qbus_reset_one>, opaque=0x0)
    at /work/armbru/qemu/hw/core/qdev.c:643
#10 0x00005555557e74fb in qbus_walk_children (bus=0x5555563b1f00, 
    pre_devfn=0x0, pre_busfn=0x0, post_devfn=0x5555557e6a5f <qdev_reset_one>, 
    post_busfn=0x5555557e6a82 <qbus_reset_one>, opaque=0x0)
    at /work/armbru/qemu/hw/core/qdev.c:601
#11 0x00005555557e75cc in qdev_walk_children (dev=0x5555563d67d0, 
    pre_devfn=0x0, pre_busfn=0x0, post_devfn=0x5555557e6a5f <qdev_reset_one>, 
    post_busfn=0x5555557e6a82 <qbus_reset_one>, opaque=0x0)
    at /work/armbru/qemu/hw/core/qdev.c:635
#12 0x00005555557e74fb in qbus_walk_children (bus=0x5555563bd3c0, 
    pre_devfn=0x0, pre_busfn=0x0, post_devfn=0x5555557e6a5f <qdev_reset_one>, 
    post_busfn=0x5555557e6a82 <qbus_reset_one>, opaque=0x0)
    at /work/armbru/qemu/hw/core/qdev.c:601
#13 0x00005555557e6b57 in qbus_reset_all (bus=0x5555563bd3c0)
    at /work/armbru/qemu/hw/core/qdev.c:350
#14 0x00005555557e6b79 in qbus_reset_all_fn (opaque=0x5555563bd3c0)
    at /work/armbru/qemu/hw/core/qdev.c:356
#15 0x00005555557587b9 in qemu_devices_reset () at /work/armbru/qemu/vl.c:1614
#16 0x0000555555758845 in qemu_system_reset (report=false)
    at /work/armbru/qemu/vl.c:1627
#17 0x0000555555760739 in main (argc=7, argv=0x7fffffffe0f8, 
    envp=0x7fffffffe138) at /work/armbru/qemu/vl.c:4315

Sorry, no libxenctrl symbols installed.

#1 lore raw
Quoted 3 lines · Markus Armbruster

Reproducer: qemu -nodefaults -S -display none -device xen-platform

Yes, xen-platform makes no sense without Xen, but it shouldn't crash.

Is it just a matter of doing the following?

hw/i386/xen/xen_platform.c +4 -0
index 28b324a..40ae1f3 100644
@@ -177,6 +177,10 @@ static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v
 {
     PCIXenPlatformState *s = opaque;
 
+    if (!xen_enabled()) {
+        return;
+    }
+
     switch (addr) {
     case 0: /* Platform flags */ {
         hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?
Quoted 47 lines
Backtrace:

#0 0x00007fffef5a677c in hypercall_buffer_cache_lock ()
from /lib64/libxenctrl.so.4.3
#1 0x00007fffef5a68f1 in xc.hypercall_buffer_alloc_pages ()
from /lib64/libxenctrl.so.4.3
#2 0x00007fffef5a6a61 in xc.hypercall_buffer_alloc ()
from /lib64/libxenctrl.so.4.3
#3 0x00007fffef59da54 in xc_hvm_set_mem_type () from /lib64/libxenctrl.so.4.3 #4 0x00005555556d5bcd in platform_fixed_ioport_writeb (opaque=0x5555564713b0,

    addr=0, val=0) at /work/armbru/qemu/hw/i386/xen/xen_platform.c:184
#5  0x00005555556d5ca4 in platform_fixed_ioport_reset (opaque=0x5555564713b0)
    at /work/armbru/qemu/hw/i386/xen/xen_platform.c:238
#6  0x00005555556d608c in platform_reset (dev=0x5555564713b0)
    at /work/armbru/qemu/hw/i386/xen/xen_platform.c:417
#7  0x00005555557e915b in device_reset (dev=0x5555564713b0)
    at /work/armbru/qemu/hw/core/qdev.c:1269
#8  0x00005555557e6a7b in qdev_reset_one (dev=0x5555564713b0, opaque=0x0)
    at /work/armbru/qemu/hw/core/qdev.c:329
#9  0x00005555557e7608 in qdev_walk_children (dev=0x5555564713b0, 
    pre_devfn=0x0, pre_busfn=0x0, post_devfn=0x5555557e6a5f <qdev_reset_one>, 
    post_busfn=0x5555557e6a82 <qbus_reset_one>, opaque=0x0)
    at /work/armbru/qemu/hw/core/qdev.c:643
#10 0x00005555557e74fb in qbus_walk_children (bus=0x5555563b1f00, 
    pre_devfn=0x0, pre_busfn=0x0, post_devfn=0x5555557e6a5f <qdev_reset_one>, 
    post_busfn=0x5555557e6a82 <qbus_reset_one>, opaque=0x0)
    at /work/armbru/qemu/hw/core/qdev.c:601
#11 0x00005555557e75cc in qdev_walk_children (dev=0x5555563d67d0, 
    pre_devfn=0x0, pre_busfn=0x0, post_devfn=0x5555557e6a5f <qdev_reset_one>, 
    post_busfn=0x5555557e6a82 <qbus_reset_one>, opaque=0x0)
    at /work/armbru/qemu/hw/core/qdev.c:635
#12 0x00005555557e74fb in qbus_walk_children (bus=0x5555563bd3c0, 
    pre_devfn=0x0, pre_busfn=0x0, post_devfn=0x5555557e6a5f <qdev_reset_one>, 
    post_busfn=0x5555557e6a82 <qbus_reset_one>, opaque=0x0)
    at /work/armbru/qemu/hw/core/qdev.c:601
#13 0x00005555557e6b57 in qbus_reset_all (bus=0x5555563bd3c0)
    at /work/armbru/qemu/hw/core/qdev.c:350
#14 0x00005555557e6b79 in qbus_reset_all_fn (opaque=0x5555563bd3c0)
    at /work/armbru/qemu/hw/core/qdev.c:356
#15 0x00005555557587b9 in qemu_devices_reset () at /work/armbru/qemu/vl.c:1614
#16 0x0000555555758845 in qemu_system_reset (report=false)
    at /work/armbru/qemu/vl.c:1627
#17 0x0000555555760739 in main (argc=7, argv=0x7fffffffe0f8, 
    envp=0x7fffffffe138) at /work/armbru/qemu/vl.c:4315

Sorry, no libxenctrl symbols installed.

#2 lore raw
Quoted 12 lines · Stefano Stabellini
Quoted 3 lines · Markus Armbruster

Reproducer: qemu -nodefaults -S -display none -device xen-platform

Yes, xen-platform makes no sense without Xen, but it shouldn't crash.

Is it just a matter of doing the following?

hw/i386/xen/xen_platform.c +0 -0
index 28b324a..40ae1f3 100644

hw/i386/xen/xen_platform.c static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v · line 186

Quoted 10 lines
hw/i386/xen/xen_platform.c +4 -0
@@ -177,6 +177,10 @@ static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v
 {
     PCIXenPlatformState *s = opaque;
 
+    if (!xen_enabled()) {
+        return;
+    }
+
     switch (addr) {
     case 0: /* Platform flags */ {
         hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?

Fixes the crash for me.

Should Xen-only devices fail to realize when !xen_enabled()?

#3 lore raw
Quoted 27 lines · Markus Armbruster
Quoted 12 lines · Stefano Stabellini
Quoted 3 lines · Markus Armbruster

Reproducer: qemu -nodefaults -S -display none -device xen-platform

Yes, xen-platform makes no sense without Xen, but it shouldn't crash.

Is it just a matter of doing the following?

hw/i386/xen/xen_platform.c +0 -0
index 28b324a..40ae1f3 100644

hw/i386/xen/xen_platform.c static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v · line 186

Quoted 10 lines
hw/i386/xen/xen_platform.c +4 -0
@@ -177,6 +177,10 @@ static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v
 {
     PCIXenPlatformState *s = opaque;
 
+    if (!xen_enabled()) {
+        return;
+    }
+
     switch (addr) {
     case 0: /* Platform flags */ {
         hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?

Fixes the crash for me.

Quoted 1 line

Should Xen-only devices fail to realize when !xen_enabled()?

Accelerators are configured after device registration unfortunately.

#4 lore raw
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Markus Armbruster
Quoted 12 lines · Stefano Stabellini
Quoted 3 lines · Markus Armbruster

Reproducer: qemu -nodefaults -S -display none -device xen-platform

Yes, xen-platform makes no sense without Xen, but it shouldn't crash.

Is it just a matter of doing the following?

hw/i386/xen/xen_platform.c +0 -0
index 28b324a..40ae1f3 100644

hw/i386/xen/xen_platform.c static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v · line 186

Quoted 10 lines
hw/i386/xen/xen_platform.c +4 -0
@@ -177,6 +177,10 @@ static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v
 {
     PCIXenPlatformState *s = opaque;
 
+    if (!xen_enabled()) {
+        return;
+    }
+
     switch (addr) {
     case 0: /* Platform flags */ {
         hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?

Fixes the crash for me.

Quoted 3 lines
Quoted 1 line

Should Xen-only devices fail to realize when !xen_enabled()?

Accelerators are configured after device registration unfortunately.

Realization happens even later, doesn't it?

With this patch:

    @@ -389,6 +393,11 @@ static int xen_platform_initfn(PCIDevice *dev)
         PCIXenPlatformState *d = XEN_PLATFORM(dev);
         uint8_t *pci_conf;

    +    if (!xen_enabled()) {
    +        error_report("Nope");
    +        return -1;
    +    }
    +
         pci_conf = dev->config;

         pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);

I get:

    $ upstream-qemu -nodefaults -S -display none -device xen-platform
    upstream-qemu: -device xen-platform: Nope
    upstream-qemu: -device xen-platform: Device initialization failed.
    upstream-qemu: -device xen-platform: Device 'xen-platform' could not be initialized
    [Exit 1 ]

Note that error_report() is a bit problematic in init methods. The best solution is to convert the device to realize (requires my "pci: Partial conversion to realize" series) and use error_setg().

#5 lore raw
Quoted 30 lines · Markus Armbruster
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Markus Armbruster
Quoted 12 lines · Stefano Stabellini
Quoted 3 lines · Markus Armbruster

Reproducer: qemu -nodefaults -S -display none -device xen-platform

Yes, xen-platform makes no sense without Xen, but it shouldn't crash.

Is it just a matter of doing the following?

hw/i386/xen/xen_platform.c +0 -0
index 28b324a..40ae1f3 100644

hw/i386/xen/xen_platform.c static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v · line 186

Quoted 10 lines
hw/i386/xen/xen_platform.c +4 -0
@@ -177,6 +177,10 @@ static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v
 {
     PCIXenPlatformState *s = opaque;
 
+    if (!xen_enabled()) {
+        return;
+    }
+
     switch (addr) {
     case 0: /* Platform flags */ {
         hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?

Fixes the crash for me.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Should Xen-only devices fail to realize when !xen_enabled()?

Accelerators are configured after device registration unfortunately.

Realization happens even later, doesn't it?

Yes, you are right.

Quoted 23 lines

With this patch:

    @@ -389,6 +393,11 @@ static int xen_platform_initfn(PCIDevice *dev)
         PCIXenPlatformState *d = XEN_PLATFORM(dev);
         uint8_t *pci_conf;

    +    if (!xen_enabled()) {
    +        error_report("Nope");
    +        return -1;
    +    }
    +
         pci_conf = dev->config;

         pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);

I get:

    $ upstream-qemu -nodefaults -S -display none -device xen-platform
    upstream-qemu: -device xen-platform: Nope
    upstream-qemu: -device xen-platform: Device initialization failed.
    upstream-qemu: -device xen-platform: Device 'xen-platform' could not be initialized
    [Exit 1 ]
Quoted 3 lines

Note that error_report() is a bit problematic in init methods. The best solution is to convert the device to realize (requires my "pci: Partial conversion to realize" series) and use error_setg().

I agree that this is much better than breaking at runtime for no clear reason. Are you going to submit a proper patch?

#6 lore raw
Quoted 63 lines · Stefano Stabellini
Quoted 30 lines · Markus Armbruster
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Markus Armbruster
Quoted 12 lines · Stefano Stabellini
Quoted 3 lines · Markus Armbruster

Reproducer: qemu -nodefaults -S -display none -device xen-platform

Yes, xen-platform makes no sense without Xen, but it shouldn't crash.

Is it just a matter of doing the following?

hw/i386/xen/xen_platform.c +0 -0
index 28b324a..40ae1f3 100644

hw/i386/xen/xen_platform.c static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v · line 186

Quoted 10 lines
hw/i386/xen/xen_platform.c +4 -0
@@ -177,6 +177,10 @@ static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v
 {
     PCIXenPlatformState *s = opaque;
 
+    if (!xen_enabled()) {
+        return;
+    }
+
     switch (addr) {
     case 0: /* Platform flags */ {
         hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?

Fixes the crash for me.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Should Xen-only devices fail to realize when !xen_enabled()?

Accelerators are configured after device registration unfortunately.

Realization happens even later, doesn't it?

Yes, you are right.

Quoted 23 lines

With this patch:

    @@ -389,6 +393,11 @@ static int xen_platform_initfn(PCIDevice *dev)
         PCIXenPlatformState *d = XEN_PLATFORM(dev);
         uint8_t *pci_conf;

    +    if (!xen_enabled()) {
    +        error_report("Nope");
    +        return -1;
    +    }
    +
         pci_conf = dev->config;

         pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);

I get:

    $ upstream-qemu -nodefaults -S -display none -device xen-platform
    upstream-qemu: -device xen-platform: Nope
    upstream-qemu: -device xen-platform: Device initialization failed.
    upstream-qemu: -device xen-platform: Device 'xen-platform' could not be initialized
    [Exit 1 ]
Quoted 6 lines
Quoted 3 lines

Note that error_report() is a bit problematic in init methods. The best solution is to convert the device to realize (requires my "pci: Partial conversion to realize" series) and use error_setg().

I agree that this is much better than breaking at runtime for no clear reason. Are you going to submit a proper patch?

Can do. Best for all the xen-only PCI devices, not just this one.

I'd prefer to do it on top of a conversion to realize. Makes the task depend on [PATCH 00/10] pci: Partial conversion to realize.

#7 lore raw
Quoted 65 lines · Markus Armbruster
Quoted 63 lines · Stefano Stabellini
Quoted 30 lines · Markus Armbruster
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Markus Armbruster
Quoted 12 lines · Stefano Stabellini
Quoted 3 lines · Markus Armbruster

Reproducer: qemu -nodefaults -S -display none -device xen-platform

Yes, xen-platform makes no sense without Xen, but it shouldn't crash.

Is it just a matter of doing the following?

hw/i386/xen/xen_platform.c +0 -0
index 28b324a..40ae1f3 100644

hw/i386/xen/xen_platform.c static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v · line 186

Quoted 10 lines
hw/i386/xen/xen_platform.c +4 -0
@@ -177,6 +177,10 @@ static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v
 {
     PCIXenPlatformState *s = opaque;
 
+    if (!xen_enabled()) {
+        return;
+    }
+
     switch (addr) {
     case 0: /* Platform flags */ {
         hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?

Fixes the crash for me.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Should Xen-only devices fail to realize when !xen_enabled()?

Accelerators are configured after device registration unfortunately.

Realization happens even later, doesn't it?

Yes, you are right.

Quoted 23 lines

With this patch:

    @@ -389,6 +393,11 @@ static int xen_platform_initfn(PCIDevice *dev)
         PCIXenPlatformState *d = XEN_PLATFORM(dev);
         uint8_t *pci_conf;

    +    if (!xen_enabled()) {
    +        error_report("Nope");
    +        return -1;
    +    }
    +
         pci_conf = dev->config;

         pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);

I get:

    $ upstream-qemu -nodefaults -S -display none -device xen-platform
    upstream-qemu: -device xen-platform: Nope
    upstream-qemu: -device xen-platform: Device initialization failed.
    upstream-qemu: -device xen-platform: Device 'xen-platform' could not be initialized
    [Exit 1 ]
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Note that error_report() is a bit problematic in init methods. The best solution is to convert the device to realize (requires my "pci: Partial conversion to realize" series) and use error_setg().

I agree that this is much better than breaking at runtime for no clear reason. Are you going to submit a proper patch?

Can do. Best for all the xen-only PCI devices, not just this one.

Uhm.. what are the other Xen-only PCI devices? All the other Xen "devices" are actually PV backends.

Quoted 3 lines

I'd prefer to do it on top of a conversion to realize. Makes the task depend on [PATCH 00/10] pci: Partial conversion to realize.