qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gonglei <arei.gonglei@huawei.com>,
	qemu-stable <qemu-stable@nongnu.org>,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PULL 11/13] uhci: fix segfault when hot-unplugging uhci controller
Date: Wed, 18 Mar 2015 14:07:53 +0100	[thread overview]
Message-ID: <1426684075-27224-12-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1426684075-27224-1-git-send-email-kraxel@redhat.com>

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

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

Let's hook up reset via DeviceClass->reset() and drop
the qemu_register_reset() call. Then Qemu will register
and unregister the reset handler automatically.

Cc: qemu-stable <qemu-stable@nongnu.org>
Reported-by: Lidonglin <lidonglin@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/hcd-uhci.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index e791377..327f26d 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -348,9 +348,10 @@ static void uhci_update_irq(UHCIState *s)
     pci_set_irq(&s->dev, level);
 }
 
-static void uhci_reset(void *opaque)
+static void uhci_reset(DeviceState *dev)
 {
-    UHCIState *s = opaque;
+    PCIDevice *d = PCI_DEVICE(dev);
+    UHCIState *s = DO_UPCAST(UHCIState, dev, d);
     uint8_t *pci_conf;
     int i;
     UHCIPort *port;
@@ -454,11 +455,11 @@ static void uhci_port_write(void *opaque, hwaddr addr,
                 port = &s->ports[i];
                 usb_device_reset(port->port.dev);
             }
-            uhci_reset(s);
+            uhci_reset(DEVICE(s));
             return;
         }
         if (val & UHCI_CMD_HCRESET) {
-            uhci_reset(s);
+            uhci_reset(DEVICE(s));
             return;
         }
         s->cmd = val;
@@ -1230,8 +1231,6 @@ static void usb_uhci_common_realize(PCIDevice *dev, Error **errp)
     s->num_ports_vmstate = NB_PORTS;
     QTAILQ_INIT(&s->queues);
 
-    qemu_register_reset(uhci_reset, s);
-
     memory_region_init_io(&s->io_bar, OBJECT(s), &uhci_ioport_ops, s,
                           "uhci", 0x20);
 
@@ -1305,6 +1304,7 @@ static void uhci_class_init(ObjectClass *klass, void *data)
     k->revision  = info->revision;
     k->class_id  = PCI_CLASS_SERIAL_USB;
     dc->vmsd = &vmstate_uhci;
+    dc->reset = uhci_reset;
     if (!info->unplug) {
         /* uhci controllers in companion setups can't be hotplugged */
         dc->hotpluggable = false;
-- 
1.8.3.1

  parent reply	other threads:[~2015-03-18 13:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-18 13:07 [Qemu-devel] [PULL for-2.3 00/13] usb patch queue Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 01/13] usb: Propagate errors through usb_register_companion() Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 02/13] usb: Improve companion configuration error messages Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 03/13] ohci: Complete conversion to realize Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 04/13] uhci: Convert " Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 05/13] monitor: Drop dead QMP check from monitor_read_password() Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 06/13] monitor: Plug memory leak in monitor_read_bdrv_key_start() Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 07/13] monitor usb: Inline monitor_read_bdrv_key_start()'s first part Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 08/13] usb/dev-storage: Fix QMP device_add missing encryption key failure Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 09/13] usb/dev-storage: Avoid qerror_report_err() outside QMP handlers Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 10/13] hw/usb: Include USB files only if necessary Gerd Hoffmann
2015-03-18 13:07 ` Gerd Hoffmann [this message]
2015-03-18 13:07 ` [Qemu-devel] [PULL 12/13] ohci: fix resource cleanup leak Gerd Hoffmann
2015-03-18 13:07 ` [Qemu-devel] [PULL 13/13] ehci: fix segfault when hot-unplugging ehci controller Gerd Hoffmann
2015-03-19 12:11 ` [Qemu-devel] [PULL for-2.3 00/13] usb patch queue Peter Maydell
2015-03-19 14:50   ` Gerd Hoffmann
2015-03-19 19:00     ` Peter Maydell
2015-03-19 19:33       ` Peter Maydell

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=1426684075-27224-12-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=arei.gonglei@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@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 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).