qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] usb: fix segfault when hot-unplugging usb host adapter
@ 2015-03-17 11:28 arei.gonglei
  2015-03-17 11:58 ` Gerd Hoffmann
  0 siblings, 1 reply; 3+ messages in thread
From: arei.gonglei @ 2015-03-17 11:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Gonglei, peter.huangpeng, kraxel

From: Gonglei <arei.gonglei@huawei.com>

When hot-unplugging the usb controllers (ehci/uhci),
we have to clean all resouce of these devices,
involed registered reset handler. Otherwise, it
may cause NULL pointer access and/or segmentation fault
if we reboot the guest os after hot-unplugging.

Cc: qemu-stable <qemu-stable@nongnu.org>
Reported-by: Lidonglin <lidonglin@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/hcd-ehci.c | 1 +
 hw/usb/hcd-ohci.c | 1 +
 hw/usb/hcd-uhci.c | 2 ++
 3 files changed, 4 insertions(+)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index ccf54b6..5be41f8 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -2495,6 +2495,7 @@ void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp)
     memory_region_del_subregion(&s->mem, &s->mem_opreg);
     memory_region_del_subregion(&s->mem, &s->mem_ports);
 
+    qemu_unregister_reset(ehci_reset, s);
     usb_bus_release(&s->bus);
 
     if (s->vmstate) {
diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index a0d478e..840d254 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -1949,6 +1949,7 @@ static void usb_ohci_exit(PCIDevice *dev)
     if (!ohci->masterbus) {
         usb_bus_release(&s->bus);
     }
+    qemu_register_reset(ohci_reset, ohci);
 }
 
 #define TYPE_SYSBUS_OHCI "sysbus-ohci"
diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index f903de7..70ad52a 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -1274,6 +1274,8 @@ static void usb_uhci_exit(PCIDevice *dev)
     if (!s->masterbus) {
         usb_bus_release(&s->bus);
     }
+
+    qemu_unregister_reset(uhci_reset, s);
 }
 
 static Property uhci_properties_companion[] = {
-- 
1.7.12.4

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

* Re: [Qemu-devel] [PATCH] usb: fix segfault when hot-unplugging usb host adapter
  2015-03-17 11:28 [Qemu-devel] [PATCH] usb: fix segfault when hot-unplugging usb host adapter arei.gonglei
@ 2015-03-17 11:58 ` Gerd Hoffmann
  2015-03-17 12:10   ` Gonglei
  0 siblings, 1 reply; 3+ messages in thread
From: Gerd Hoffmann @ 2015-03-17 11:58 UTC (permalink / raw)
  To: arei.gonglei; +Cc: qemu-stable, qemu-devel, peter.huangpeng

> +    qemu_unregister_reset(ehci_reset, s);

We should hook up reset via DeviceClass->reset then (xhci already does
it this way) and drop the qemu_register_reset() calls.

Then qemu will register and unregister the reset handler automatically
for us.

cheers,
  Gerd

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

* Re: [Qemu-devel] [PATCH] usb: fix segfault when hot-unplugging usb host adapter
  2015-03-17 11:58 ` Gerd Hoffmann
@ 2015-03-17 12:10   ` Gonglei
  0 siblings, 0 replies; 3+ messages in thread
From: Gonglei @ 2015-03-17 12:10 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-stable, qemu-devel, peter.huangpeng

On 2015/3/17 19:58, Gerd Hoffmann wrote:
>> +    qemu_unregister_reset(ehci_reset, s);
> 
> We should hook up reset via DeviceClass->reset then (xhci already does
> it this way) and drop the qemu_register_reset() calls.
> 
> Then qemu will register and unregister the reset handler automatically
> for us.
> 
I'll look for this, thanks :)

Regards,
-Gonglei

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

end of thread, other threads:[~2015-03-17 12:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-17 11:28 [Qemu-devel] [PATCH] usb: fix segfault when hot-unplugging usb host adapter arei.gonglei
2015-03-17 11:58 ` Gerd Hoffmann
2015-03-17 12:10   ` Gonglei

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).