All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: pbonzini@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] pci: unplug all devs of same slot once
Date: Fri, 11 May 2012 22:57:25 +0800	[thread overview]
Message-ID: <20120511145725.16518.77110.stgit@t> (raw)
In-Reply-To: <4FACB4E4.2070708@redhat.com>

The whole PCI slot should be removed once. Currently only one func
is cleaned in pci_unplug_device(), if you try to remove a single
func by monitor cmd.

Start VM with 8 multiple-function block devs, hot-removing
those block devs by 'device_del ...' would cause qemu abort.

| (qemu) device_del virti0-0-0
| (qemu) **
|ERROR:qom/object.c:389:object_delete: assertion failed: (obj->ref == 0)

Execute 'device_del $blkid' in monitor
 \_handle_user_command()
    \_qmp_device_del()
       \_qdev_unplug()
          \_pci_unplug_device()
               | //only one obj(func) is unpluged
               v //need process funcs here
   object_unparent()
    \_object_finalize_child_property()

Guest sets pci dev by ioport write (eject from acpi)
 \_kvm_handle_io()
    \_pciej_write()
      \_acpi_piix_eject_slot()
           |
           v  //all qdevs(funcs) will be free
 QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
     PCIDevice *dev = PCI_DEVICE(qdev);
     if (PCI_SLOT(dev->devfn) == slot) {
         qdev_free()

Signed-off-by: Amos Kong <akong@redhat.com>
---
 hw/pci.c |   34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index b706e69..960cf53 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1520,16 +1520,34 @@ static int pci_qdev_init(DeviceState *qdev)
 
 static int pci_unplug_device(DeviceState *qdev)
 {
-    PCIDevice *dev = PCI_DEVICE(qdev);
-    PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
+    DeviceState *dev, *next;
+    PCIDevice *cur;
+    int ret, slot = PCI_SLOT(PCI_DEVICE(qdev)->devfn);
+    BusState *bus = qdev->parent_bus;
+
+    ret = 0;
+    QTAILQ_FOREACH_SAFE(dev, &bus->children, sibling, next) {
+        cur = PCI_DEVICE(dev);
+
+        if (PCI_SLOT(cur->devfn) == slot) {
+            PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(cur);
+            if (pc->no_hotplug) {
+                qerror_report(QERR_DEVICE_NO_HOTPLUG,
+                              object_get_typename(OBJECT(dev)));
+                return -1;
+            }
 
-    if (pc->no_hotplug) {
-        qerror_report(QERR_DEVICE_NO_HOTPLUG, object_get_typename(OBJECT(dev)));
-        return -1;
+            object_unparent(OBJECT(cur));
+            ret = cur->bus->hotplug(cur->bus->hotplug_qdev, cur,
+                                    PCI_HOTPLUG_DISABLED);
+            if (ret < 0) {
+                qerror_report(QERR_UNDEFINED_ERROR,
+                              object_get_typename(OBJECT(dev)));
+                break;
+            }
+        }
     }
-    object_unparent(OBJECT(dev));
-    return dev->bus->hotplug(dev->bus->hotplug_qdev, dev,
-                             PCI_HOTPLUG_DISABLED);
+    return ret;
 }
 
 PCIDevice *pci_create_multifunction(PCIBus *bus, int devfn, bool multifunction,

  parent reply	other threads:[~2012-05-11 14:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-11  2:15 [Qemu-devel] [PATCH] qom: fix refcounting in object_property_del_child() Amos Kong
2012-05-11  6:42 ` Paolo Bonzini
2012-05-11 14:52   ` Amos Kong
2012-05-11 14:57   ` Amos Kong [this message]
2012-05-13  0:40     ` [Qemu-devel] [PATCH] pci: unplug all devs of same slot once Amos Kong
2012-05-13 10:54     ` Michael S. Tsirkin
2012-05-14  7:55       ` Paolo Bonzini
2012-05-20  9:57     ` [Qemu-devel] [PATCH v3] pci: call object_unparent() before free_qdev() Amos Kong
2012-05-20 10:22       ` Michael S. Tsirkin
2012-06-04 20:15       ` Jason Baron
2012-06-04 21:52         ` Michael S. Tsirkin
2012-06-07 14:06           ` Jason Baron

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=20120511145725.16518.77110.stgit@t \
    --to=akong@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.