Skip to contentSkip to conversation

QEmu memory hot unplug support.

PATCH Superseded Tang Chen 1 participant 9 messages Aug 18, 2014

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Tang Chen

author
#0 lore raw

v3 cover QEmu memory hot unplug support.

This patch-set implements memory hot-remove for QEmu.

Approach: QEmu sets GPE status bit, then triggers SCI to notify guest os. Guest os checks device status, and free memory resource if possible, then generate OST. Finally, qemu handles OST events to free dimm device.

Change log v2 -> v3:
1. Divide the large patch into 7 small patches. (patch 1, 3~8)
2. Add new patch 2/8, implementing memory hot-remove for ich9.

Hu Tao (7):
acpi, piix4: Add memory hot unplug support for piix4.
pc: Add memory hot unplug support for pc machine.
qdev: Add memory hot unplug support for bus-less devices.
pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
acpi: Add hardware implementation for memory hot unplug. pc, acpi bios: Add memory hot unplug interface.
monitor: Add memory hot unplug support for device_del command.

Tang Chen (1):
acpi, ich9: Add memory hot unplug support for ich9.

 hw/acpi/ich9.c                   | 12 +++++++
 hw/acpi/memory_hotplug.c         | 77 ++++++++++++++++++++++++++++++++++++++--
 hw/acpi/piix4.c                  |  3 ++
 hw/core/qdev.c                   |  8 +++++
 hw/i386/pc.c                     | 32 +++++++++++++++++
 hw/i386/ssdt-mem.dsl             |  5 +++
 hw/i386/ssdt-misc.dsl            | 15 +++++++-
 hw/isa/lpc_ich9.c                |  5 +--
 hw/mem/pc-dimm.c                 | 10 ++++++
 include/hw/acpi/acpi.h           | 14 ++++++++
 include/hw/acpi/ich9.h           |  2 ++
 include/hw/acpi/memory_hotplug.h |  3 ++
 include/hw/acpi/pc-hotplug.h     |  2 ++
 include/qom/object.h             |  1 +
 qdev-monitor.c                   | 26 +++++++++++++-
 qom/object.c                     |  2 +-
 16 files changed, 210 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.4.2
author
#1 lore raw

PATCH v3 1/8 acpi, piix4: Add memory hot unplug support for piix4.

From: Hu Tao <[email protected]>

Implement acpi_memory_unplug_cb(), sending an sci to guest to trigger memory hot-remove, and call it in piix4_device_unplug_cb().

---
 hw/acpi/memory_hotplug.c         | 25 +++++++++++++++++++++++++
 hw/acpi/piix4.c                  |  3 +++
 include/hw/acpi/memory_hotplug.h |  2 ++
 3 files changed, 30 insertions(+)
hw/acpi/memory_hotplug.c +25 -0
index ed39241..c310b44 100644
@@ -195,6 +195,31 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
     return;
 }
 
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+                           DeviceState *dev, Error **errp)
+{
+    Error *local_err = NULL;
+    int slot = object_property_get_int(OBJECT(dev), "slot", &local_err);
+
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    if (slot >= mem_st->dev_count) {
+        char *dev_path = object_get_canonical_path(OBJECT(dev));
+        error_setg(errp, "acpi_memory_plug_cb: "
+                   "device [%s] returned invalid memory slot[%d]",
+                   dev_path, slot);
+        g_free(dev_path);
+        return;
+    }
+
+    /* do ACPI magic */
+    ar->gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
+    acpi_update_sci(ar, irq);
+}
+
 static const VMStateDescription vmstate_memhp_sts = {
     .name = "memory hotplug device state",
     .version_id = 1,
hw/acpi/piix4.c +3 -0
index b72b34e..c1d5187 100644
@@ -362,6 +362,9 @@ static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
     if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
         acpi_pcihp_device_unplug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev,
                                     errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+        acpi_memory_unplug_cb(&s->ar, s->irq, &s->acpi_memory_hotplug, dev,
+                              errp);
     } else {
         error_setg(errp, "acpi: device unplug request for not supported device"
                    " type: %s", object_get_typename(OBJECT(dev)));
include/hw/acpi/memory_hotplug.h +2 -0
index 7bbf8a0..fc6b868 100644
@@ -28,6 +28,8 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner,
 
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
                          DeviceState *dev, Error **errp);
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+                           DeviceState *dev, Error **errp);
 
 extern const VMStateDescription vmstate_memory_hotplug;
 #define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
Signature · 1 line
1.8.4.2
author
#2 lore raw

PATCH v3 2/8 acpi, ich9: Add memory hot unplug support for ich9.

In reply to Tang Chen

Implement ich9_pm_device_unplug_cb() to support memory hot-remove, calling acpi_memory_unplug_cb(). And itself will be called in ich9_device_unplug_cb().

---
 hw/acpi/ich9.c         | 12 ++++++++++++
 hw/isa/lpc_ich9.c      |  5 +++--
 include/hw/acpi/ich9.h |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)
hw/acpi/ich9.c +12 -0
index 7b14bbb..d369151 100644
@@ -310,6 +310,18 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp)
     }
 }
 
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp)
+{
+    if (pm->acpi_memory_hotplug.is_enabled &&
+        object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+        acpi_memory_unplug_cb(&pm->acpi_regs, pm->irq, &pm->acpi_memory_hotplug,
+                              dev, errp);
+    } else {
+        error_setg(errp, "acpi: device unplug request for not supported device"
+                   " type: %s", object_get_typename(OBJECT(dev)));
+    }
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
     ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
hw/isa/lpc_ich9.c +3 -2
index b846d81..257e07a 100644
@@ -610,8 +610,9 @@ static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
 static void ich9_device_unplug_cb(HotplugHandler *hotplug_dev,
                                   DeviceState *dev, Error **errp)
 {
-    error_setg(errp, "acpi: device unplug request for not supported device"
-               " type: %s", object_get_typename(OBJECT(dev)));
+    ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+    ich9_pm_device_unplug_cb(&lpc->pm, dev, errp);
 }
 
 static bool ich9_rst_cnt_needed(void *opaque)
include/hw/acpi/ich9.h +2 -0
index 7e42448..029576f 100644
@@ -60,6 +60,8 @@ extern const VMStateDescription vmstate_ich9_pm;
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 
 void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp);
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+                              Error **errp);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
Signature · 1 line
1.8.4.2
author
#3 lore raw

PATCH v3 3/8 pc: Add memory hot unplug support for pc machine.

In reply to Tang Chen

From: Hu Tao <[email protected]>

Implement device unplug callback for PCMachine. And it now only support pc-dimm hot-remove. The callback will call piix4 or ich9 callbacks introduced in previous patches.

---
 hw/i386/pc.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
hw/i386/pc.c +32 -0
index 8fa8d2f..8bafe7c 100644
@@ -61,6 +61,8 @@
 #include "hw/mem/pc-dimm.h"
 #include "trace.h"
 #include "qapi/visitor.h"
+#include "hw/acpi/piix4.h"
+#include "hw/i386/ich9.h"
 
 /* debug PC/ISA interrupts */
 //#define DEBUG_IRQ
@@ -1607,6 +1609,27 @@ out:
     error_propagate(errp, local_err);
 }
 
+static void pc_dimm_unplug(HotplugHandler *hotplug_dev,
+                           DeviceState *dev, Error **errp)
+{
+    Object *acpi_dev;
+    HotplugHandlerClass *hhc;
+    Error *local_err = NULL;
+
+    acpi_dev = (acpi_dev = piix4_pm_find()) ? acpi_dev : ich9_lpc_find();
+    if (!acpi_dev) {
+        error_setg(&local_err,
+                   "memory hotplug is not enabled: missing acpi device");
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    hhc = HOTPLUG_HANDLER_GET_CLASS(acpi_dev);
+    hhc->unplug(HOTPLUG_HANDLER(acpi_dev), dev, &local_err);
+
+    error_propagate(errp, local_err);
+}
+
 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
                                       DeviceState *dev, Error **errp)
 {
@@ -1615,6 +1638,14 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
     }
 }
 
+static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
+                                        DeviceState *dev, Error **errp)
+{
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+        pc_dimm_unplug(hotplug_dev, dev, errp);
+    }
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
                                              DeviceState *dev)
 {
@@ -1701,6 +1732,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     pcmc->get_hotplug_handler = mc->get_hotplug_handler;
     mc->get_hotplug_handler = pc_get_hotpug_handler;
     hc->plug = pc_machine_device_plug_cb;
+    hc->unplug = pc_machine_device_unplug_cb;
 }
 
 static const TypeInfo pc_machine_info = {
Signature · 1 line
1.8.4.2
author
#4 lore raw

PATCH v3 4/8 qdev: Add memory hot unplug support for bus-less devices.

In reply to Tang Chen

From: Hu Tao <[email protected]>

Implement bus-less device hot-remove in qdev_unplug(). It will call PCMachine callback introduced in previous patch.

---
 hw/core/qdev.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/core/qdev.c +8 -0
index da1ba48..e365a74 100644
@@ -228,6 +228,14 @@ void qdev_unplug(DeviceState *dev, Error **errp)
 
     if (dev->parent_bus && dev->parent_bus->hotplug_handler) {
         hotplug_handler_unplug(dev->parent_bus->hotplug_handler, dev, errp);
+    } else if (*errp == NULL) {
+        HotplugHandler *hotplug_ctrl;
+        MachineState *machine = MACHINE(qdev_get_machine());
+        MachineClass *mc = MACHINE_GET_CLASS(machine);
+
+        hotplug_ctrl = mc->get_hotplug_handler(machine, dev);
+        if (hotplug_ctrl)
+            hotplug_handler_unplug(hotplug_ctrl, dev, errp);
     } else {
         assert(dc->unplug != NULL);
         if (dc->unplug(dev) < 0) { /* legacy handler */
Signature · 1 line
1.8.4.2
author
#5 lore raw

PATCH v3 5/8 pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.

In reply to Tang Chen

From: Hu Tao <[email protected]>

Implement unrealize function for pc-dimm device. It delete subregion from hotplug region, and delete ram address range from guest ram list.

---
 hw/mem/pc-dimm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
hw/mem/pc-dimm.c +10 -0
index 5bfc5b7..ec8b1a3 100644
@@ -265,12 +265,22 @@ static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm)
     return host_memory_backend_get_memory(dimm->hostmem, &error_abort);
 }
 
+static void pc_dimm_unrealize(DeviceState *dev, Error **errp)
+{
+    PCDIMMDevice *dimm = PC_DIMM(dev);
+    MemoryRegion *mr = pc_dimm_get_memory_region(dimm);
+
+    memory_region_del_subregion(mr->container, mr);
+    vmstate_unregister_ram(mr, dev);
+}
+
 static void pc_dimm_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
     PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);
 
     dc->realize = pc_dimm_realize;
+    dc->unrealize = pc_dimm_unrealize;
     dc->props = pc_dimm_properties;
 
     ddc->get_memory_region = pc_dimm_get_memory_region;
Signature · 1 line
1.8.4.2
author
#6 lore raw

PATCH v3 6/8 acpi: Add hardware implementation for memory hot unplug.

In reply to Tang Chen

From: Hu Tao <[email protected]>

This patch adds a bool member named "is_removing" to MemStatus indicating if the memory device is being removed. It is set to true in acpi_memory_unplug_cb() when doing memory hot-remove with device_del command, or write an ACPI_EJECTION_IN_PROGRESS status to ACPI register when triggering memory hot-remove in guest.

---
 hw/acpi/memory_hotplug.c         | 52 ++++++++++++++++++++++++++++++++++++++--
 include/hw/acpi/acpi.h           | 14 +++++++++++
 include/hw/acpi/memory_hotplug.h |  1 +
 3 files changed, 65 insertions(+), 2 deletions(-)
hw/acpi/memory_hotplug.c +50 -2
index c310b44..c85a619 100644
@@ -75,6 +75,7 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr addr,
     case 0x14: /* pack and return is_* fields */
         val |= mdev->is_enabled   ? 1 : 0;
         val |= mdev->is_inserting ? 2 : 0;
+        val |= mdev->is_removing  ? 4 : 0;
         trace_mhp_acpi_read_flags(mem_st->selector, val);
         break;
     default:
@@ -121,18 +122,61 @@ static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data,
         mdev = &mem_st->devs[mem_st->selector];
         mdev->ost_status = data;
         trace_mhp_acpi_write_ost_status(mem_st->selector, mdev->ost_status);
-        /* TODO: implement memory removal on guest signal */
 
         info = acpi_memory_device_status(mem_st->selector, mdev);
         qapi_event_send_acpi_device_ost(info, &error_abort);
         qapi_free_ACPIOSTInfo(info);
+
+        switch (mdev->ost_event) {
+        case ACPI_EJECT:
+            switch (mdev->ost_status) {
+            case ACPI_SUCCESS:
+                object_unparent(OBJECT(mdev->dimm));
+                mdev->is_removing = false;
+                mdev->dimm = NULL;
+                break;
+            case ACPI_FAILURE:
+            case ACPI_UNRECOGNIZED_NOTIFY:
+            case ACPI_EJECT_NOT_SUPPORTED:
+            case ACPI_DEVICE_IN_USE:
+            case ACPI_DEVICE_BUSY:
+            case ACPI_EJECT_DEPENDENCY_BUSY:
+                mdev->is_removing = false;
+                mdev->is_enabled = true;
+                break;
+            case ACPI_EJECTION_IN_PROGRESS:
+                break;
+            default:
+                break;
+            }
+            break;
+        case ACPI_OSPM_EJECT:
+            switch (mdev->ost_status) {
+            case ACPI_SUCCESS:
+                object_unparent(OBJECT(mdev->dimm));
+                mdev->is_removing = false;
+                mdev->dimm = NULL;
+                break;
+            case ACPI_EJECTION_IN_PROGRESS:
+                mdev->is_enabled = false;
+                mdev->is_removing = true;
+                break;
+            default:
+                break;
+            }
+        }
+
         break;
-    case 0x14:
+    case 0x14: /* set is_* fields */
         mdev = &mem_st->devs[mem_st->selector];
+
         if (data & 2) { /* clear insert event */
             mdev->is_inserting  = false;
             trace_mhp_acpi_clear_insert_evt(mem_st->selector);
+        } else if (data & 4) { /* MRMV */
+            mdev->is_enabled = false;
         }
+
         break;
     }
 
@@ -198,6 +242,7 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
 void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
                            DeviceState *dev, Error **errp)
 {
+    MemStatus *mdev;
     Error *local_err = NULL;
     int slot = object_property_get_int(OBJECT(dev), "slot", &local_err);
 
@@ -215,6 +260,9 @@ void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
         return;
     }
 
+    mdev = &mem_st->devs[slot];
+    mdev->is_removing = true;
+
     /* do ACPI magic */
     ar->gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
     acpi_update_sci(ar, irq);
include/hw/acpi/acpi.h +14 -0
index 1f678b4..8654ae6 100644
@@ -91,6 +91,20 @@
 /* PM2_CNT */
 #define ACPI_BITMASK_ARB_DISABLE                0x0001
 
+/* OST_EVENT */
+#define ACPI_EJECT                              0x03
+#define ACPI_OSPM_EJECT                         0x103
+
+/* OST_STATUS */
+#define ACPI_SUCCESS                            0x0
+#define ACPI_FAILURE                            0x1
+#define ACPI_UNRECOGNIZED_NOTIFY                0x2
+#define ACPI_EJECT_NOT_SUPPORTED                0x80
+#define ACPI_DEVICE_IN_USE                      0x81
+#define ACPI_DEVICE_BUSY                        0x82
+#define ACPI_EJECT_DEPENDENCY_BUSY              0x83
+#define ACPI_EJECTION_IN_PROGRESS               0x84
+
 /* structs */
 typedef struct ACPIPMTimer ACPIPMTimer;
 typedef struct ACPIPM1EVT ACPIPM1EVT;
include/hw/acpi/memory_hotplug.h +1 -0
index fc6b868..fe41268 100644
@@ -11,6 +11,7 @@ typedef struct MemStatus {
     DeviceState *dimm;
     bool is_enabled;
     bool is_inserting;
+    bool is_removing;
     uint32_t ost_event;
     uint32_t ost_status;
 } MemStatus;
Signature · 1 line
1.8.4.2
author
#7 lore raw

PATCH v3 7/8 pc, acpi bios: Add memory hot unplug interface.

In reply to Tang Chen

From: Hu Tao <[email protected]>

This patch implements MEMORY_SLOT_EJECT_METHOD according to ACPI spec.

---
 hw/i386/ssdt-mem.dsl         |  5 +++++
 hw/i386/ssdt-misc.dsl        | 15 ++++++++++++++-
 include/hw/acpi/pc-hotplug.h |  2 ++
 3 files changed, 21 insertions(+), 1 deletion(-)
hw/i386/ssdt-mem.dsl +5 -0
index 22ff5dd..232c507 100644
@@ -43,6 +43,7 @@ DefinitionBlock ("ssdt-mem.aml", "SSDT", 0x02, "BXPC", "CSSDT", 0x1)
     External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD, MethodObj)
     External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD, MethodObj)
     External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD, MethodObj)
+    External(\_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD, MethodObj)
 
     Scope(\_SB) {
 /*  v------------------ DO NOT EDIT ------------------v */
@@ -72,6 +73,10 @@ DefinitionBlock ("ssdt-mem.aml", "SSDT", 0x02, "BXPC", "CSSDT", 0x1)
             Method(_OST, 3) {
                 \_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD(_UID, Arg0, Arg1, Arg2)
             }
+
+            Method(_EJ0, 1) {
+                \_SB.PCI0.MEMORY_HOPTLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD(_UID, Arg0)
+            }
         }
     }
 }
hw/i386/ssdt-misc.dsl +14 -1
index 0fd4480..79228ac 100644
@@ -156,6 +156,7 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
                 Offset(20),
                 MEMORY_SLOT_ENABLED,  1, // 1 if enabled, read only
                 MEMORY_SLOT_INSERT_EVENT, 1, // (read) 1 if has a insert event. (write) 1 to clear event
+                MEMORY_SLOT_REMOVE_EVENT, 1, // 1 if DIMM has a remove request, read only
             }
 
             Mutex (MEMORY_SLOT_LOCK, 0)
@@ -174,11 +175,16 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
                 Acquire(MEMORY_SLOT_LOCK, 0xFFFF)
                 while (LLess(Local0, MEMORY_SLOTS_NUMBER)) {
                     Store(Local0, MEMORY_SLOT_SLECTOR) // select Local0 DIMM
+
                     If (LEqual(MEMORY_SLOT_INSERT_EVENT, One)) { // Memory device needs check
                         MEMORY_SLOT_NOTIFY_METHOD(Local0, 1)
                         Store(1, MEMORY_SLOT_INSERT_EVENT)
                     }
-                    // TODO: handle memory eject request
+
+                    If (LEqual(MEMORY_SLOT_REMOVE_EVENT, One)) { // Ejection request
+                        MTFY(Local0, 3)
+                    }
+
                     Add(Local0, One, Local0) // goto next DIMM
                 }
                 Release(MEMORY_SLOT_LOCK)
@@ -278,6 +284,13 @@ DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
                 Store(Arg2, MEMORY_SLOT_OST_STATUS)
                 Release(MEMORY_SLOT_LOCK)
             }
+
+            Method(MEMORY_SLOT_EJECT_METHOD, 2) {
+                Acquire(MLCK, 0xFFFF)
+                Store(ToInteger(Arg0), MSEL) // select DIMM
+                Store(One, MEMORY_SLOT_REMOVE_EVENT)
+                Release(MLCK)
+            }
         } // Device()
     } // Scope()
 }
include/hw/acpi/pc-hotplug.h +2 -0
index b9db295..b3770a1 100644
@@ -42,6 +42,7 @@
 #define MEMORY_SLOT_PROXIMITY        MPX
 #define MEMORY_SLOT_ENABLED          MES
 #define MEMORY_SLOT_INSERT_EVENT     MINS
+#define MEMORY_SLOT_REMOVE_EVENT     MRMV
 #define MEMORY_SLOT_SLECTOR          MSEL
 #define MEMORY_SLOT_OST_EVENT        MOEV
 #define MEMORY_SLOT_OST_STATUS       MOSC
@@ -50,6 +51,7 @@
 #define MEMORY_SLOT_CRS_METHOD       MCRS
 #define MEMORY_SLOT_OST_METHOD       MOST
 #define MEMORY_SLOT_PROXIMITY_METHOD MPXM
+#define MEMORY_SLOT_EJECT_METHOD     MDEJ
 #define MEMORY_SLOT_NOTIFY_METHOD    MTFY
 #define MEMORY_SLOT_SCAN_METHOD      MSCN
 
Signature · 1 line
1.8.4.2
author
#8 lore raw

PATCH v3 8/8 monitor: Add memory hot unplug support for device_del command.

In reply to Tang Chen

From: Hu Tao <[email protected]>

Implement find_peripheral_device() to find bus-less device, and call it in qmp_device_del() so that device_del command will be able to remove memory device.

---
 include/qom/object.h |  1 +
 qdev-monitor.c       | 26 +++++++++++++++++++++++++-
 qom/object.c         |  2 +-
 3 files changed, 27 insertions(+), 2 deletions(-)
include/qom/object.h +1 -0
index 8a05a81..a352beb 100644
@@ -1300,5 +1300,6 @@ int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
  */
 Object *container_get(Object *root, const char *path);
 
+bool object_property_is_child(ObjectProperty *prop);
 
 #endif
qdev-monitor.c +25 -1
index 5fe5e75..f57b379 100644
@@ -24,6 +24,7 @@
 #include "qmp-commands.h"
 #include "sysemu/arch_init.h"
 #include "qemu/config-file.h"
+#include "qom/object.h"
 
 /*
  * Aliases were a bad idea from the start.  Let's keep them
@@ -683,12 +684,35 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
     return 0;
 }
 
+static DeviceState *find_peripheral_device(const char *id)
+{
+    Object *peripheral = qdev_get_peripheral();
+    DeviceState *dev = NULL;
+    ObjectProperty *prop;
+
+    QTAILQ_FOREACH(prop, &peripheral->properties, node) {
+        if (object_property_is_child(prop)) {
+            dev = DEVICE(prop->opaque);
+            if (!strcmp(dev->id, id)) {
+                return dev;
+            }
+        }
+    }
+
+    return NULL;
+}
+
 void qmp_device_del(const char *id, Error **errp)
 {
     DeviceState *dev;
 
     dev = qdev_find_recursive(sysbus_get_default(), id);
-    if (NULL == dev) {
+
+    if (dev == NULL) {
+        dev = find_peripheral_device(id);
+    }
+
+    if (dev == NULL) {
         error_set(errp, QERR_DEVICE_NOT_FOUND, id);
         return;
     }
qom/object.c +1 -1
index 0e8267b..1183e5d 100644
@@ -351,7 +351,7 @@ void object_initialize(void *data, size_t size, const char *typename)
     object_initialize_with_type(data, size, type);
 }
 
-static inline bool object_property_is_child(ObjectProperty *prop)
+bool object_property_is_child(ObjectProperty *prop)
 {
     return strstart(prop->type, "child<", NULL);
 }
Signature · 1 line
1.8.4.2