qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [BUG] USB assertion triggers in usb_packet_complete()
@ 2011-10-10 13:03 Thomas Huth
  2011-10-11  7:35 ` Thomas Huth
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2011-10-10 13:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


 Hi!

I am currently facing a problem when running QEMU (up-to-date git
version) with OHCI and a lot of virtual USB devices.
The emulator dies with the following assertion:

qemu-system-arm: hw/usb.c:337: usb_packet_complete:
Assertion `p->owner != ((void *)0)' failed.

To reproduce this problem, you can run the configure script with
"--target-list=arm-softmmu" for example, then download the files
vmlinuz-2.6.26-2-versatile and initrd.img-2.6.26-2-versatile
from http://people.debian.org/~aurel32/qemu/arm/ and then run
qemu like this:

qemu-system-arm -kernel vmlinuz-2.6.26-2-versatile \
  -initrd initrd.img-2.6.26-2-versatile -M versatilepb -usb \
  -drive if=none,file=/tmp/linux-0.2.img,cache=none,id=disk0 \
  -device usb-storage,drive=disk0 -usbdevice mouse \
  -usbdevice keyboard -usbdevice tablet

It boots the Linux kernel for a while, then dies with the above
assertion.

Observations:
- It could be related to the fact that QEMU puts a hub into the
  USB tree in that case ... when I specify less USB devices, I was
  not able to reproduce this problem, but in that case there are
  also no hubs in the tree. According to the comment in
  usb_packet_complete(), there might be problems with the assert() in
  case there is a hub ... ?
- So far I was only able to reproduce this problem when the emulated
  platform uses an OHCI controller. I haven't seen the problem to
  occur with UHCI yet (but I have to admit that I also haven't done a
  lot of tests with UHCI).

Do you have any ideas what could be wrong here?

 Regards,
  Thomas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [BUG] USB assertion triggers in usb_packet_complete()
  2011-10-10 13:03 [Qemu-devel] [BUG] USB assertion triggers in usb_packet_complete() Thomas Huth
@ 2011-10-11  7:35 ` Thomas Huth
  2011-10-12 10:02   ` Stefan Hajnoczi
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2011-10-11  7:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Am Mon, 10 Oct 2011 15:03:41 +0200
schrieb Thomas Huth <thuth@linux.vnet.ibm.com>:
> 
> I am currently facing a problem when running QEMU (up-to-date git
> version) with OHCI and a lot of virtual USB devices.
> The emulator dies with the following assertion:
> 
> qemu-system-arm: hw/usb.c:337: usb_packet_complete:
> Assertion `p->owner != ((void *)0)' failed.

Not sure whether this is the right solution, but this patch fixes the
problem for me:

diff --git a/hw/usb.c b/hw/usb.c
index fa90204..7cef9e2 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -25,6 +25,7 @@
  */
 #include "qemu-common.h"
 #include "usb.h"
+#include "usb-desc.h"
 #include "iov.h"
 
 void usb_attach(USBPort *port)
@@ -334,7 +335,9 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
 void usb_packet_complete(USBDevice *dev, USBPacket *p)
 {
     /* Note: p->owner != dev is possible in case dev is a hub */
-    assert(p->owner != NULL);
+    if (dev->device->bDeviceClass != USB_CLASS_HUB) {
+        assert(p->owner != NULL);
+    }
     p->owner = NULL;
     dev->port->ops->complete(dev->port, p);
 }


 Thomas

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [BUG] USB assertion triggers in usb_packet_complete()
  2011-10-11  7:35 ` Thomas Huth
@ 2011-10-12 10:02   ` Stefan Hajnoczi
  2011-10-12 11:17     ` Thomas Huth
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2011-10-12 10:02 UTC (permalink / raw)
  To: Thomas Huth; +Cc: qemu-devel, Gerd Hoffmann

On Tue, Oct 11, 2011 at 8:35 AM, Thomas Huth <thuth@linux.vnet.ibm.com> wrote:
> Am Mon, 10 Oct 2011 15:03:41 +0200
> schrieb Thomas Huth <thuth@linux.vnet.ibm.com>:
>>
>> I am currently facing a problem when running QEMU (up-to-date git
>> version) with OHCI and a lot of virtual USB devices.
>> The emulator dies with the following assertion:
>>
>> qemu-system-arm: hw/usb.c:337: usb_packet_complete:
>> Assertion `p->owner != ((void *)0)' failed.

Hi Thomas,
I hit the same bug recently and Gerd has posted a patch which you can test:
http://patchwork.ozlabs.org/patch/118726/

Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [BUG] USB assertion triggers in usb_packet_complete()
  2011-10-12 10:02   ` Stefan Hajnoczi
@ 2011-10-12 11:17     ` Thomas Huth
  2011-10-13 10:51       ` Gerd Hoffmann
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2011-10-12 11:17 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel, Gerd Hoffmann

Am Wed, 12 Oct 2011 11:02:42 +0100
schrieb Stefan Hajnoczi <stefanha@gmail.com>:

> On Tue, Oct 11, 2011 at 8:35 AM, Thomas Huth <thuth@linux.vnet.ibm.com> wrote:
> > Am Mon, 10 Oct 2011 15:03:41 +0200
> > schrieb Thomas Huth <thuth@linux.vnet.ibm.com>:
> >>
> >> I am currently facing a problem when running QEMU (up-to-date git
> >> version) with OHCI and a lot of virtual USB devices.
> >> The emulator dies with the following assertion:
> >>
> >> qemu-system-arm: hw/usb.c:337: usb_packet_complete:
> >> Assertion `p->owner != ((void *)0)' failed.
> 
> Hi Thomas,
> I hit the same bug recently and Gerd has posted a patch which you can test:
> http://patchwork.ozlabs.org/patch/118726/

Thanks for the hint, Stefan, you're right, that seems to be the same
bug. Your patch is working fine in my scenario, too.

However, Gerd's patch is not working for me, the assertion still
triggers. It seems like usb_packet_complete() is called for the leaf
node before it is called for the hub node, so the leaf node already set
p->owner = NULL.

 Thomas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [BUG] USB assertion triggers in usb_packet_complete()
  2011-10-12 11:17     ` Thomas Huth
@ 2011-10-13 10:51       ` Gerd Hoffmann
  0 siblings, 0 replies; 5+ messages in thread
From: Gerd Hoffmann @ 2011-10-13 10:51 UTC (permalink / raw)
  To: Thomas Huth; +Cc: Stefan Hajnoczi, qemu-devel

   Hi,

>> Hi Thomas,
>> I hit the same bug recently and Gerd has posted a patch which you can test:
>> http://patchwork.ozlabs.org/patch/118726/
>
> Thanks for the hint, Stefan, you're right, that seems to be the same
> bug. Your patch is working fine in my scenario, too.
>
> However, Gerd's patch is not working for me, the assertion still
> triggers. It seems like usb_packet_complete() is called for the leaf
> node before it is called for the hub node, so the leaf node already set
> p->owner = NULL.

Ah, right, on completion the call chain goes the other way around, so 
the usb_handle_packet() style approach doesn't fly.

I think going with Stefans approach + a big fat comment is the best 
solution then.  I'll go queue up a patch.

cheers,
   Gerd

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-10-13 10:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-10 13:03 [Qemu-devel] [BUG] USB assertion triggers in usb_packet_complete() Thomas Huth
2011-10-11  7:35 ` Thomas Huth
2011-10-12 10:02   ` Stefan Hajnoczi
2011-10-12 11:17     ` Thomas Huth
2011-10-13 10:51       ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).