QEmu memory hot unplug support.
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.
3. Sanitize ACPI hardware implement code in patch 6/8.
Hu Tao (6):
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. pc, acpi bios: Add memory hot unplug interface.
monitor: Add memory hot unplug support for device_del command.
Tang Chen (2):
acpi, ich9: Add memory hot unplug support for ich9.
acpi: Add hardware implementation for memory hot unplug.
hw/acpi/ich9.c | 12 ++++++ hw/acpi/memory_hotplug.c | 87 ++++++++++++++++++++++++++++++++++++++-- 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 | 23 +++++++++++ qom/object.c | 2 +- 16 files changed, 217 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.4.2
PATCH RESEND 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
@@ -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
@@ -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
@@ -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
Re: [Qemu-devel] [RESEND PATCH v3 1/8] acpi, piix4: Add memory hot unplug support for piix4.
Quoted 18 lines · On Wed, 27 Aug 2014 16:08:32 +0800 Tang Chen <[email protected]> wrote:
From: Hu Tao <[email protected]>
Implement
acpi_memory_unplug_cb(), sending an sci to guest to trigger memory hot-remove, and call it inpiix4_device_unplug_cb().Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- 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 +0
-0
hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, · line 202
Quoted 8 lines
hw/acpi/memory_hotplug.c +5
-0@@ -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);
might be worth to use PC_DIMM_SLOT_PROP here, and while at it do the same to acpi_memory_plug_cb() as well in separate patch.
Quoted 4 lines
hw/acpi/memory_hotplug.c +4
-0+ +if (local_err) { +error_propagate (errp, local_err); +return ;
hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, · line 216
Quoted 10 lines
hw/acpi/memory_hotplug.c +10
-0+ } + +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 ; + }
move 3 above blocks into separate function to reduce code duplication with acpi_memory_plug_cb(), perhaps something like following:
MemStatus * acpi_memory_get_slot_status_descriptor(MemHotplugState *mem_st,
DeviceState *dev, Error **errp);
hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, · line 217
Quoted 1 line
hw/acpi/memory_hotplug.c +1
-0+
place here also missing removal signaling for selected mdev, perhaps it's due to wrong patch ordering
hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, · line 220
Quoted 3 lines
hw/acpi/memory_hotplug.c +3
-0+/* do ACPI magic */ + ar->gpe.sts[0 ] |=ACPI_MEMORY_HOTPLUG_STATUS ; +acpi_update_sci (ar, irq);
worth to make this block a separate function and reuse in acpi_memory_plug_cb()
Quoted 32 lines
hw/acpi/memory_hotplug.c +2
-0+} +static const VMStateDescription vmstate_memhp_sts = { .name ="memory hotplug device state" , .version_id =1 ,hw/acpi/piix4.c +3
-0@@ -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@@ -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) \
Re: [Qemu-devel] [RESEND PATCH v3 1/8] acpi, piix4: Add memory hot unplug support for piix4.
Hi Igor,
Quoted 24 lines · Igor Mammedov
Quoted 21 lines · On Wed, 27 Aug 2014 16:08:32 +0800 Tang Chen <[email protected]> wrote:
From: Hu Tao <[email protected]>
Implement
acpi_memory_unplug_cb(), sending an sci to guest to trigger memory hot-remove, and call it inpiix4_device_unplug_cb().Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- 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 +0
-0@@ -195,6 +195,31 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,return ; }
Quoted 8 lines
hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, · line 202
Quoted 5 lines
hw/acpi/memory_hotplug.c +5
-0+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);might be worth to use
PC_DIMM_SLOT_PROPhere, and while at it do the same toacpi_memory_plug_cb()as well in separate patch.
Followed.
Quoted 17 lines
Quoted 4 lines
hw/acpi/memory_hotplug.c +4
-0+ +if (local_err) { +error_propagate (errp, local_err); +return ;hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, · line 216
Quoted 10 lines
hw/acpi/memory_hotplug.c +10
-0+ } + +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 ; + }move 3 above blocks into separate function to reduce code duplication with
acpi_memory_plug_cb(), perhaps something like following:
Quoted 3 lines
MemStatus * acpi_memory_get_slot_status_descriptor(MemHotplugState
*mem_st,DeviceState *dev, Error **errp);
Followed.
Quoted 3 lines
hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, · line 217
Quoted 1 line
hw/acpi/memory_hotplug.c +1
-0+place here also missing removal signaling for selected mdev, perhaps it's due to wrong patch ordering
It is not a wrong ordering of patches. I meant to define mdev->is_removing in patch 6/8. But it is OK to define it here. So followed.
Quoted 5 lines
hw/acpi/memory_hotplug.c void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, · line 220
Quoted 3 lines
hw/acpi/memory_hotplug.c +3
-0+/* do ACPI magic */ + ar->gpe.sts[0 ] |=ACPI_MEMORY_HOTPLUG_STATUS ; +acpi_update_sci (ar, irq);worth to make this block a separate function and reuse in
acpi_memory_plug_cb()
Followed.
Thanks.
Quoted 34 lines
Quoted 24 lines
hw/acpi/memory_hotplug.c +2
-0+} +static const VMStateDescription vmstate_memhp_sts = { .name ="memory hotplug device state" , .version_id =1 ,hw/acpi/piix4.c +3
-0@@ -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 +0
-0include/hw/acpi/memory_hotplug.h void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner, · line 35
Quoted 8 lines
include/hw/acpi/memory_hotplug.h +2
-0@@ -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) \.
PATCH RESEND v3 2/8 acpi, ich9: Add memory hot unplug support for ich9.
In reply to Tang ChenImplement 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
@@ -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
@@ -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
@@ -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
Re: [Qemu-devel] [RESEND PATCH v3 2/8] acpi, ich9: Add memory hot unplug support for ich9.
Quoted 16 lines · On Wed, 27 Aug 2014 16:08:33 +0800 Tang Chen <[email protected]> wrote:
Implement
ich9_pm_device_unplug_cb()to support memory hot-remove, callingacpi_memory_unplug_cb(). And itself will be called inich9_device_unplug_cb().Signed-off-by Tang Chen <[email protected]>--- 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 +0
-0
hw/acpi/ich9.c void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp) · line 315
Quoted 6 lines
hw/acpi/ich9.c +3
-0@@ -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 &&
why checking ^^^^^^^^^^^ here but not doing so in piix4 too?
Quoted 41 lines
hw/acpi/ich9.c +9
-0+ 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@@ -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@@ -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 */
Re: [Qemu-devel] [RESEND PATCH v3 2/8] acpi, ich9: Add memory hot unplug support for ich9.
Hi Igor,
Quoted 22 lines · Igor Mammedov
Quoted 19 lines · On Wed, 27 Aug 2014 16:08:33 +0800 Tang Chen <[email protected]> wrote:
Implement
ich9_pm_device_unplug_cb()to support memory hot-remove, callingacpi_memory_unplug_cb(). And itself will be called inich9_device_unplug_cb().Signed-off-by Tang Chen <[email protected]>--- 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 +0
-0@@ -310,6 +310,18 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp) } }
Quoted 4 lines
hw/acpi/ich9.c void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp) · line 315
Quoted 3 lines
hw/acpi/ich9.c +3
-0+void ich9_pm_device_unplug_cb (ICH9LPCPMRegs *pm,DeviceState *dev,Error **errp) +{ + if (pm->acpi_memory_hotplug.is_enabled &&why checking ^^^^^^^^^^^ here but not doing so in piix4 too?
Yes, we should also check it in piix4. Fixed.
Thanks.
Quoted 44 lines
Quoted 34 lines
hw/acpi/ich9.c +9
-0+ 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@@ -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 +0
-0include/hw/acpi/ich9.h extern const VMStateDescription vmstate_ich9_pm; · line 67
Quoted 8 lines
include/hw/acpi/ich9.h +2
-0@@ -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 */ .
PATCH RESEND v3 3/8 pc: Add memory hot unplug support for pc machine.
In reply to Tang ChenFrom: 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
@@ -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
Re: [Qemu-devel] [RESEND PATCH v3 3/8] pc: Add memory hot unplug support for pc machine.
Quoted 33 lines · On Wed, 27 Aug 2014 16:08:34 +0800 Tang Chen <[email protected]> wrote:
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.
Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- hw/i386/pc.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)hw/i386/pc.c +6
-0@@ -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;
hw/i386/pc.c out: · line 1625
Quoted 10 lines
hw/i386/pc.c +10
-0+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 ; + }
drop/replace above block, see: "if (!pcms->acpi_dev) {" for reference
hw/i386/pc.c out: · line 1628
Quoted 3 lines
hw/i386/pc.c +3
-0+ + hhc =HOTPLUG_HANDLER_GET_CLASS (acpi_dev); + hhc->unplug (HOTPLUG_HANDLER (acpi_dev), dev, &local_err);
you should take care about dev's vmstate here, that was registered in pc_dimm_plug()
Quoted 30 lines
hw/i386/pc.c +13
-0+ +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 = {
Re: [Qemu-devel] [RESEND PATCH v3 3/8] pc: Add memory hot unplug support for pc machine.
Quoted 48 lines · On Thu, 4 Sep 2014 14:44:41 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 33 lines · On Wed, 27 Aug 2014 16:08:34 +0800 Tang Chen <[email protected]> wrote:
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.
Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- hw/i386/pc.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)hw/i386/pc.c +6
-0@@ -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;hw/i386/pc.c out: · line 1625
Quoted 10 lines
hw/i386/pc.c +10
-0+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 ; + }drop/replace above block, see: "if (!pcms->acpi_dev) {" for reference
Quoted 5 lines
hw/i386/pc.c out: · line 1628
Quoted 3 lines
hw/i386/pc.c +3
-0+ + hhc =HOTPLUG_HANDLER_GET_CLASS (acpi_dev); + hhc->unplug (HOTPLUG_HANDLER (acpi_dev), dev, &local_err);you should take care about dev's vmstate here, that was registered in
pc_dimm_plug()
I'm wrong here, vmstate_unregister should take place at pc_dimm unrealize time,
hhc->unplug handler is more like unplug_request handler,
perhaps we need to give some thought to renaming it to unplug_request to avoid confusion and have an optional unplug callback that could do tear-down with HotplugHandler if needed before device is unrealized.
PATCH RESEND v3 4/8 qdev: Add memory hot unplug support for bus-less devices.
In reply to Tang ChenFrom: 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
@@ -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
Re: [Qemu-devel] [RESEND PATCH v3 4/8] qdev: Add memory hot unplug support for bus-less devices.
Quoted 5 lines · On Wed, 27 Aug 2014 16:08:35 +0800 Tang Chen <[email protected]> wrote:
From: Hu Tao <[email protected]>
Implement bus-less device hot-remove in
qdev_unplug(). It will call PCMachine callback introduced in previous patch.
subject/commit message doesn't need to mention memory hotplug/PCMachine, it's generic handling that applies to other devices even though pc-dimm is the only bus-less device handled here.
Quoted 11 lines
Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- hw/core/qdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)hw/core/qdev.c +0
-0
hw/core/qdev.c void qdev_unplug(DeviceState *dev, Error **errp) · line 231
Quoted 4 lines
hw/core/qdev.c +1
-0@@ -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 ) {
what's the reason for ^^^ condition here?
Quoted 10 lines
hw/core/qdev.c +7
-0+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 */
Re: [Qemu-devel] [RESEND PATCH v3 4/8] qdev: Add memory hot unplug support for bus-less devices.
Hi Igor,
Quoted 11 lines · Igor Mammedov
Quoted 5 lines · On Wed, 27 Aug 2014 16:08:35 +0800 Tang Chen <[email protected]> wrote:
From: Hu Tao <[email protected]>
Implement bus-less device hot-remove in
qdev_unplug(). It will call PCMachine callback introduced in previous patch.subject/commit message doesn't need to mention memory hotplug/PCMachine, it's generic handling that applies to other devices even though pc-dimm is the only bus-less device handled here.
Followed.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- hw/core/qdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)hw/core/qdev.c +0
-0@@ -228,6 +228,14 @@ void qdev_unplug(DeviceState *dev, Error **errp)
Quoted 4 lines
hw/core/qdev.c void qdev_unplug(DeviceState *dev, Error **errp) · line 231
Quoted 3 lines
hw/core/qdev.c +1
-0if (dev->parent_bus && dev->parent_bus->hotplug_handler) {hotplug_handler_unplug (dev->parent_bus->hotplug_handler, dev, errp); + }else if (*errp ==NULL ) {what's the reason for ^^^ condition here?
It should be "else if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) "
Just like we do in device_set_realized().
Thanks.
Quoted 13 lines
hw/core/qdev.c void qdev_unplug(DeviceState *dev, Error **errp) · line 241
Quoted 10 lines
hw/core/qdev.c +7
-0+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 */ .
PATCH RESEND v3 5/8 pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
In reply to Tang ChenFrom: 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
@@ -270,12 +270,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
Re: [Qemu-devel] [RESEND PATCH v3 5/8] pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
Quoted 3 lines · On Wed, 27 Aug 2014 16:08:36 +0800 Tang Chen <[email protected]> wrote:
From: Hu Tao <[email protected]>
Implement unrealize function for pc-dimm device. It delete subregion from
s/delete/removes/
Quoted 13 lines
hotplug region, and delete ram address range from guest ram list.
Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- hw/mem/pc-dimm.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/mem/pc-dimm.c +0
-0
hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm) · line 278
Quoted 9 lines
hw/mem/pc-dimm.c +6
-0@@ -270,12 +270,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);
usually MemoryRegion is treated as opaque and it's fields accessed via memory_region_foo() helpers.
hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm) · line 279
Quoted 1 line
hw/mem/pc-dimm.c +1
-0+vmstate_unregister_ram (mr, dev);
these 2 lines look like a job for PCMachine which did original mapping/vmstate registration
Quoted 12 lines
hw/mem/pc-dimm.c +3
-0+} +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;
Re: [Qemu-devel] [RESEND PATCH v3 5/8] pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
Quoted 33 lines · Igor Mammedov
Quoted 3 lines · On Wed, 27 Aug 2014 16:08:36 +0800 Tang Chen<[email protected]> wrote:
From: Hu Tao<[email protected]>
Implement unrealize function for pc-dimm device. It delete subregion from
s/delete/removes/
Quoted 13 lines
hotplug region, and delete ram address range from guest ram list.
Signed-off-by Hu Tao<[email protected]>Signed-off-by Tang Chen<[email protected]>--- hw/mem/pc-dimm.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/mem/pc-dimm.c +0
-0hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm) · line 278
Quoted 9 lines
hw/mem/pc-dimm.c +6
-0@@ -270,12 +270,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);usually MemoryRegion is treated as opaque and it's fields accessed via
memory_region_foo()helpers.
Quoted 3 lines
hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm) · line 279
Quoted 1 line
hw/mem/pc-dimm.c +1
-0+vmstate_unregister_ram (mr, dev);these 2 lines look like a job for PCMachine which did original mapping/vmstate registration
Actually, this patch also fix the bug *when hotplug memory failing in the place where after pc_dimm_plug but before the end of device_set_realized, it does not clear the work done by pc_dimm_plug*.
For there is no callback like pc_dimm_plug_fail_cb for us to call when fail, Maybe pc_dimm_unrealize is the only place where we can do the clear work...
Thanks,
zhanghailiang
Quoted 16 lines
Quoted 12 lines
hw/mem/pc-dimm.c +3
-0+} +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;
Re: [Qemu-devel] [RESEND PATCH v3 5/8] pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
Quoted 38 lines · On Fri, 12 Sep 2014 13:30:36 +0800 zhanghailiang…
Quoted 33 lines · Igor Mammedov
Quoted 3 lines · On Wed, 27 Aug 2014 16:08:36 +0800 Tang Chen<[email protected]> wrote:
From: Hu Tao<[email protected]>
Implement unrealize function for pc-dimm device. It delete subregion from
s/delete/removes/
Quoted 13 lines
hotplug region, and delete ram address range from guest ram list.
Signed-off-by Hu Tao<[email protected]>Signed-off-by Tang Chen<[email protected]>--- hw/mem/pc-dimm.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/mem/pc-dimm.c +0
-0hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm) · line 278
Quoted 9 lines
hw/mem/pc-dimm.c +6
-0@@ -270,12 +270,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);usually MemoryRegion is treated as opaque and it's fields accessed via
memory_region_foo()helpers.Quoted 3 lines
hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm) · line 279
Quoted 1 line
hw/mem/pc-dimm.c +1
-0+vmstate_unregister_ram (mr, dev);these 2 lines look like a job for PCMachine which did original mapping/vmstate registration
Quoted 6 lines
Actually, this patch also fix the bug *when hotplug memory failing in the place where after
pc_dimm_plugbut before the end ofdevice_set_realized, it does not clear the work done by pc_dimm_plug*.For there is no callback like
pc_dimm_plug_fail_cbfor us to call when fail, Maybepc_dimm_unrealizeis the only place where we can do the clear work...
Looking at device_set_realized() and pc-dimm case in patrticular there is no point where it could fail after hotplug_handler_plug() is called.
But even if there where, one should use pc_dimm_unplug() first to reverse actions performed by successful pc_dimm_plug().
The problem here is that currently unplug callback is actually doing only unplug request part asking guest to eject memory, but we also have destroy device when guest tells via ACPI to ejct memory. You are doing it implicitly by unparenting pc-dimm from ACPI code and pulling in pc-dimm.unrealize() unrelated stuff that should be done by PCMachine.
I'm suggesting that we extend hotplug-handler API to handle this async/split unplug workflow. By converting current hotplug_handler_unplug() and related code to hotplug_handler_unplug_request() that would do the first part of unplug sequence (see/review http://patchwork.ozlabs.org/patch/387018/)
And then on top of it add hotplug_handler_unplug() that would handle actual device removal when ACPI asks for it.
I'm working now on doing above for PCIDevices since they have the same workflow (expect to submit patches next week) and it looks like we would need to use the same approach for CPU unplug as well.
Quoted 22 lines
Thanks,
zhanghailiangQuoted 16 lines
Quoted 12 lines
hw/mem/pc-dimm.c +3
-0+} +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;
Re: [Qemu-devel] [RESEND PATCH v3 5/8] pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
Hi Igor, Zhang,
Quoted 20 lines · Igor Mammedov
......
Actually, this patch also fix the bug *when hotplug memory failing in the place where afterpc_dimm_plugbut before the end ofdevice_set_realized, it does not clear the work done by pc_dimm_plug*.For there is no callback like
pc_dimm_plug_fail_cbfor us to call when fail, Maybepc_dimm_unrealizeis the only place where we can do the clear work... Looking atdevice_set_realized()and pc-dimm case in patrticular there is no point where it could fail afterhotplug_handler_plug()is called.But even if there where, one should use
pc_dimm_unplug()first to reverse actions performed by successfulpc_dimm_plug().The problem here is that currently unplug callback is actually doing only unplug request part asking guest to eject memory, but we also have destroy device when guest tells via ACPI to ejct memory. You are doing it implicitly by unparenting pc-dimm from ACPI code and pulling in pc-dimm.unrealize() unrelated stuff that should be done by PCMachine.
Quoted 5 lines
I'm suggesting that we extend hotplug-handler API to handle this async/split unplug workflow. By converting current
hotplug_handler_unplug()and related code tohotplug_handler_unplug_request()that would do the first part of unplug sequence (see/review http://patchwork.ozlabs.org/patch/387018/)
I've read the above patch.
1. I think you proposal would help to resolve the following problem:
If guest OS failed to handle hoplug sci, QEmu does not know it, and
could
release resources incorrectly.
Would you please have a look at the following patch.
https://www.mail-archive.com/qemu-devel%40nongnu.org/msg253025.html
I added a pthread wait condition to synchronize :
sci request -> guest OS handling -> _OST -> QEmu handling (Of course, according to the previous discussing, _OST is optional.)
And IIUC, your proposal may be :
hotplug request -> guest OS handling -> real hotplug handling
right ?
I think it is the same. How do you think synchronize it with a wait
condition ?
Or you have any better idea ?
Since no one has replied the patch, I'm not sure if it is OK.
2. Let's finish memory and cpu hotplug job based on the current framework, shall we ? In the above patch, it renames a lot of functions that are being
used in memory and
cpu hotplug patches. I think we can push memory and cpu hotplug
jobs, and in the
next phase, let's improve the framework.
And of course, the problem I mentioned above should also be put in
the next phase.
So I want to submit the next version memory hotplug patches based
on the original
framework, and help to improve it in the next phase.
How do you think ?
Quoted 11 lines
And then on top of it add
hotplug_handler_unplug()that would handle actual device removal when ACPI asks for it.I'm working now on doing above for PCIDevices since they have the same workflow (expect to submit patches next week) and it looks like we would need to use the same approach for CPU unplug as well.
PATCH RESEND v3 6/8 acpi: Add hardware implementation for memory hot unplug.
In reply to Tang ChenThis 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 | 62 ++++++++++++++++++++++++++++++++++++++-- include/hw/acpi/acpi.h | 14 +++++++++ include/hw/acpi/memory_hotplug.h | 1 + 3 files changed, 74 insertions(+), 3 deletions(-)
hw/acpi/memory_hotplug.c +59 -3
@@ -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 :
@@ -84,6 +85,51 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr addr,return val; } +static void acpi_handle_eject (MemStatus *mdev) +{ +switch (mdev->ost_status) { +case ACPI_SUCCESS : +object_unparent (OBJECT (mdev->dimm)); + mdev->is_removing = false; + mdev->dimm =NULL ; +break ; +case ACPI_EJECT_IN_PROGRESS : +/* For ejection triggered by hardware (device_del command), +* mdev->is_removing is set to true by acpi_memory_unplug_cb() +* before sending SCI. So we only handle ejection triggered by +* guest OS. +*/ +if (mdev->ost_event ==ACPI_OSPM_EJECT ) { + mdev->is_enabled = false; + mdev->is_removing = true; + } +break ; +case ACPI_FAILURE : +case ACPI_UNRECOGNIZED_NOTIFY : +case ACPI_EJECT_NOT_SUPPORTED : +case ACPI_EJECT_DEVICE_IN_USE : +case ACPI_EJECT_DEVICE_BUSY : +case ACPI_EJECT_DEPENDENCY_BUSY : + mdev->is_removing = false; + mdev->is_enabled = true; +break ; +default : +break ; + } +} + +static void acpi_handle_ost_event (MemStatus *mdev) +{ +switch (mdev->ost_event) { +case ACPI_NOTIFY_EJECT_REQUEST :/* Ejection triggered by hardware. */ +case ACPI_OSPM_EJECT :/* Ejection triggered by guest OS. */ +acpi_handle_eject (mdev); +break ; +default : +break ; + } +} +static void acpi_memory_hotplug_write (void *opaque,hwaddr addr,uint64_t data,unsigned int size) {
@@ -121,21 +167,27 @@ 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); + +acpi_handle_ost_event (mdev);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 ) {/* request removal of device */ + mdev->is_enabled = false; } + +break ; +default :break ; } - }static const MemoryRegionOps acpi_memory_hotplug_ops = { .read = acpi_memory_hotplug_read,
@@ -198,6 +250,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 +268,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
@@ -91,6 +91,20 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 +/* OST_EVENT */ +#define ACPI_NOTIFY_EJECT_REQUEST 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_EJECT_DEVICE_IN_USE 0x81 +#define ACPI_EJECT_DEVICE_BUSY 0x82 +#define ACPI_EJECT_DEPENDENCY_BUSY 0x83 +#define ACPI_EJECT_IN_PROGRESS 0x84 +/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ;typedef struct ACPIPM1EVT ACPIPM1EVT ;
include/hw/acpi/memory_hotplug.h +1 -0
@@ -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
Re: [Qemu-devel] [RESEND PATCH v3 6/8] acpi: Add hardware implementation for memory hot unplug.
Quoted 19 lines · On Wed, 27 Aug 2014 16:08:37 +0800 Tang Chen <[email protected]> wrote:
This patch adds a bool member named "
is_removing" to MemStatus indicating if the memory device is being removed. It is set to true inacpi_memory_unplug_cb()when doing memory hot-remove withdevice_delcommand, or write anACPI_EJECTION_IN_PROGRESSstatus to ACPI register when triggering memory hot-remove in guest.Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- hw/acpi/memory_hotplug.c | 62 ++++++++++++++++++++++++++++++++++++++-- include/hw/acpi/acpi.h | 14 +++++++++ include/hw/acpi/memory_hotplug.h | 1 + 3 files changed, 74 insertions(+), 3 deletions(-)hw/acpi/memory_hotplug.c +0
-0
hw/acpi/memory_hotplug.c static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr addr, · line 78
Quoted 4 lines
hw/acpi/memory_hotplug.c +1
-0@@ -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 ;
update docs/specs/acpi_mem_hotplug.txt with new bit field
Quoted 56 lines
hw/acpi/memory_hotplug.c +45
-0trace_mhp_acpi_read_flags (mem_st->selector, val);break ;default :@@ -84,6 +85,51 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr addr,return val; } +static void acpi_handle_eject (MemStatus *mdev) +{ +switch (mdev->ost_status) { +case ACPI_SUCCESS : +object_unparent (OBJECT (mdev->dimm)); + mdev->is_removing = false; + mdev->dimm =NULL ; +break ; +case ACPI_EJECT_IN_PROGRESS : +/* For ejection triggered by hardware (device_del command), +* mdev->is_removing is set to true by acpi_memory_unplug_cb() +* before sending SCI. So we only handle ejection triggered by +* guest OS. +*/ +if (mdev->ost_event ==ACPI_OSPM_EJECT ) { + mdev->is_enabled = false; + mdev->is_removing = true; + } +break ; +case ACPI_FAILURE : +case ACPI_UNRECOGNIZED_NOTIFY : +case ACPI_EJECT_NOT_SUPPORTED : +case ACPI_EJECT_DEVICE_IN_USE : +case ACPI_EJECT_DEVICE_BUSY : +case ACPI_EJECT_DEPENDENCY_BUSY : + mdev->is_removing = false; + mdev->is_enabled = true; +break ; +default : +break ; + } +} + +static void acpi_handle_ost_event (MemStatus *mdev) +{ +switch (mdev->ost_event) { +case ACPI_NOTIFY_EJECT_REQUEST :/* Ejection triggered by hardware. */ +case ACPI_OSPM_EJECT :/* Ejection triggered by guest OS. */ +acpi_handle_eject (mdev); +break ; +default : +break ; + } +} +static void acpi_memory_hotplug_write (void *opaque,hwaddr addr,uint64_t data,unsigned int size) {
hw/acpi/memory_hotplug.c static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data, · line 175
Quoted 10 lines
hw/acpi/memory_hotplug.c +2
-1@@ -121,21 +167,27 @@ 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); + +acpi_handle_ost_event (mdev);
_OST is optional and OSPM doesn't have to call it at all,
it was already discussed on list and using _OST for device removal was evaluated as not usable.
We use _OST here as supplementary status information for management tools and no more /i.e. as LEDs on real hardware/.
See "Figure 6-37 Device Ejection Flow Example Using _OST." in ACPI 5.1 spec and note below it.
hw/acpi/memory_hotplug.c static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data, · line 184
Quoted 10 lines
hw/acpi/memory_hotplug.c +4
-1break ; -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 ) {/* request removal of device */ + mdev->is_enabled = false;
device tear-down should be initiated here, when OSPM calls _EJ0 method and when we return from this function it should be destroyed.
Quoted 65 lines
hw/acpi/memory_hotplug.c +7
-1} + +break ; +default :break ; } - }static const MemoryRegionOps acpi_memory_hotplug_ops = { .read = acpi_memory_hotplug_read,@@ -198,6 +250,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 +268,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@@ -91,6 +91,20 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 +/* OST_EVENT */ +#define ACPI_NOTIFY_EJECT_REQUEST 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_EJECT_DEVICE_IN_USE 0x81 +#define ACPI_EJECT_DEVICE_BUSY 0x82 +#define ACPI_EJECT_DEPENDENCY_BUSY 0x83 +#define ACPI_EJECT_IN_PROGRESS 0x84 +/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ;typedef struct ACPIPM1EVT ACPIPM1EVT ;include/hw/acpi/memory_hotplug.h +1
-0@@ -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;
Re: [Qemu-devel] [RESEND PATCH v3 6/8] acpi: Add hardware implementation for memory hot unplug.
Hi Igor,
Quoted 11 lines · Igor Mammedov
......
hw/acpi/memory_hotplug.c +2
-0+ +acpi_handle_ost_event (mdev);
_OSTis optional and OSPM doesn't have to call it at all,
it was already discussed on list and using_OSTfor device removal was evaluated as not usable.
We use_OSThere as supplementary status information for management tools and no more /i.e. as LEDs on real hardware/.See "Figure 6-37 Device Ejection Flow Example Using
_OST." in ACPI 5.1 spec and note below it.
OK, I agree we should not make memory hotplug process depend on _OST.
But we do need to handle one problem: When guest OS failed to remove device,
we should not clear QEmu data of that device.
As you and ACPI spec said, Platform (which is QEmu here) should reply _OST rised by guest OS except things such as LEDs on real hardware. But _OST is the only way I can find to get status from guest OS.
So, let's do it in the following way:
1. Make device hotplug process independent from _OST for the compatibility reason.
2. For OSPMs that support _OST, QEmu use _OST to catch error from guest OS. May be report an error message only, and stop QEmu from remove
related data.
(Please see/review patch-set:
https://www.mail-archive.com/qemu-devel%40nongnu.org/msg253025.html)
3. For OSPMs that do not support _OST, do not handle guest OS error for now.
How do you think ?
Thanks.
Quoted 82 lines
hw/acpi/memory_hotplug.c static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data, · line 184
Quoted 12 lines
break;hw/acpi/memory_hotplug.c +4
-1-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 ) {/* request removal of device */ + mdev->is_enabled = false;device tear-down should be initiated here, when OSPM calls
_EJ0method and when we return from this function it should be destroyed.Quoted 58 lines
}hw/acpi/memory_hotplug.c +7
-1+ +break ; +default :break ; } - }static const MemoryRegionOps acpi_memory_hotplug_ops = { .read = acpi_memory_hotplug_read,@@ -198,6 +250,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 +268,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@@ -91,6 +91,20 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 +/* OST_EVENT */ +#define ACPI_NOTIFY_EJECT_REQUEST 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_EJECT_DEVICE_IN_USE 0x81 +#define ACPI_EJECT_DEVICE_BUSY 0x82 +#define ACPI_EJECT_DEPENDENCY_BUSY 0x83 +#define ACPI_EJECT_IN_PROGRESS 0x84 +/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ;typedef struct ACPIPM1EVT ACPIPM1EVT ;include/hw/acpi/memory_hotplug.h +0
-0include/hw/acpi/memory_hotplug.h typedef struct MemStatus { · line 17
Quoted 7 lines
include/hw/acpi/memory_hotplug.h +1
-0@@ -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;.
Re: [Qemu-devel] [RESEND PATCH v3 6/8] acpi: Add hardware implementation for memory hot unplug.
Quoted 36 lines · On Tue, 16 Sep 2014 18:12:02 +0800 Tang Chen <[email protected]> wrote:
Hi Igor,
Quoted 11 lines · Igor Mammedov
......
hw/acpi/memory_hotplug.c +2
-0+ +acpi_handle_ost_event (mdev);
_OSTis optional and OSPM doesn't have to call it at all,
it was already discussed on list and using_OSTfor device removal was evaluated as not usable.
We use_OSThere as supplementary status information for management tools and no more /i.e. as LEDs on real hardware/.See "Figure 6-37 Device Ejection Flow Example Using
_OST." in ACPI 5.1 spec and note below it.OK, I agree we should not make memory hotplug process depend on
_OST.But we do need to handle one problem: When guest OS failed to remove
device,
we should not clear QEmu data of that device.As you and ACPI spec said, Platform (which is QEmu here) should reply
_OSTrised by guest OS except things such as LEDs on real hardware. But_OSTis the only way I can find to get status from guest OS.So, let's do it in the following way:
1. Make device hotplug process independent from_OSTfor the compatibility reason.2. For OSPMs that support
_OST, QEmu use_OSTto catch error from guest OS. May be report an error message only, and stop QEmu from remove
related data.
(Please see/review patch-set:
https://www.mail-archive.com/qemu-devel%40nongnu.org/msg253025.html)
Quoted 3 lines
3. For OSPMs that do not support
_OST, do not handle guest OS error for now.How do you think ?
I'd keep _OST handling in ACPI write handler only for notification purposes only. This way management tools/end user will see guest OS error if supported , otherwise we do not care.
Make '_OST unplug handler' reset removing bit in case of error, so that guest won't see DIMM stuck in continuous removing state when following hotplug events happen.
Quoted 86 lines
Thanks.
Quoted 82 lines
hw/acpi/memory_hotplug.c static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data, · line 184
Quoted 12 lines
break;hw/acpi/memory_hotplug.c +4
-1-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 ) {/* request removal of device */ + mdev->is_enabled = false;device tear-down should be initiated here, when OSPM calls
_EJ0method and when we return from this function it should be destroyed.Quoted 58 lines
}hw/acpi/memory_hotplug.c +7
-1+ +break ; +default :break ; } - }static const MemoryRegionOps acpi_memory_hotplug_ops = { .read = acpi_memory_hotplug_read,@@ -198,6 +250,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 +268,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@@ -91,6 +91,20 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 +/* OST_EVENT */ +#define ACPI_NOTIFY_EJECT_REQUEST 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_EJECT_DEVICE_IN_USE 0x81 +#define ACPI_EJECT_DEVICE_BUSY 0x82 +#define ACPI_EJECT_DEPENDENCY_BUSY 0x83 +#define ACPI_EJECT_IN_PROGRESS 0x84 +/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ;typedef struct ACPIPM1EVT ACPIPM1EVT ;include/hw/acpi/memory_hotplug.h +0
-0include/hw/acpi/memory_hotplug.h typedef struct MemStatus { · line 17
Quoted 7 lines
include/hw/acpi/memory_hotplug.h +1
-0@@ -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;.
PATCH RESEND v3 7/8 pc, acpi bios: Add memory hot unplug interface.
In reply to Tang ChenFrom: 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
@@ -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_HOTPLUG_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_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD(_UID, Arg0) + } } } }
hw/i386/ssdt-misc.dsl +14 -1
@@ -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
@@ -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
Re: [Qemu-devel] [RESEND PATCH v3 7/8] pc, acpi bios: Add memory hot unplug interface.
Quoted 49 lines · On Wed, 27 Aug 2014 16:08:38 +0800 Tang Chen <[email protected]> wrote:
From: Hu Tao <[email protected]>
This patch implements
MEMORY_SLOT_EJECT_METHODaccording to ACPI spec.Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- 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@@ -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_HOTPLUG_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_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD(_UID, Arg0) + } } } }hw/i386/ssdt-misc.dsl +1
-0@@ -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)
hw/i386/ssdt-misc.dsl DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1) · line 184
Quoted 10 lines
hw/i386/ssdt-misc.dsl +3
-1while (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
please use ELSE IF here, otherwise OSPM could try to do insert/remove simultaneously
hw/i386/ssdt-misc.dsl DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1) · line 185
Quoted 1 line
hw/i386/ssdt-misc.dsl +1
-0+ MTFY(Local0, 3)
use MEMORY_SLOT_NOTIFY_METHOD here
Quoted 6 lines
hw/i386/ssdt-misc.dsl +2
-0+ } + Add(Local0, One, Local0) // goto next DIMM } Release(MEMORY_SLOT_LOCK)
hw/i386/ssdt-misc.dsl DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1) · line 292
Quoted 9 lines
hw/i386/ssdt-misc.dsl +6
-0@@ -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)
use macros here too, see Method(MEMORY_SLOT_OST_METHOD, 4) for example
Quoted 17 lines
hw/i386/ssdt-misc.dsl +1
-0+ } } // Device() } // Scope() }include/hw/acpi/pc-hotplug.h +1
-0@@ -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
include/hw/acpi/pc-hotplug.h line 54
Quoted 4 lines
include/hw/acpi/pc-hotplug.h +1
-0@@ -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
maybe s/MDEJ/MEJ0/ to be clearer what eject method is implied
Quoted 3 lines
include/hw/acpi/pc-hotplug.h +0
-0#define MEMORY_SLOT_NOTIFY_METHOD MTFY#define MEMORY_SLOT_SCAN_METHOD MSCN
PATCH RESEND v3 8/8 monitor: Add memory hot unplug support for device_del command.
In reply to Tang ChenFrom: 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 | 23 +++++++++++++++++++++++ qom/object.c | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-)
include/qom/object.h +1 -0
@@ -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 +23 -0
@@ -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,34 @@ 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 (!dev) { + dev =find_peripheral_device (id); + } + +if (!dev) {error_set (errp,QERR_DEVICE_NOT_FOUND , id);return ; }
qom/object.c +1 -1
@@ -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
Re: [Qemu-devel] [RESEND PATCH v3 8/8] monitor: Add memory hot unplug support for device_del command.
Quoted 5 lines · On Wed, 27 Aug 2014 16:08:39 +0800 Tang Chen <[email protected]> wrote:
From: Hu Tao <[email protected]>
Implement
find_peripheral_device()to find bus-less device, and call it inqmp_device_del()so thatdevice_delcommand will be able to remove memory device.
probably patch should go before 4/8
Quoted 40 lines
Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- include/qom/object.h | 1 + qdev-monitor.c | 23 +++++++++++++++++++++++ qom/object.c | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-)include/qom/object.h +1
-0@@ -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 +5
-0@@ -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,34 @@ 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 ;
qdev-monitor.c int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) · line 700
Quoted 10 lines
qdev-monitor.c +10
-0+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; + } + } + }
It's not permitted to access internal fields of Object outside of object.c
checkout usage of object_resolve_path()/object_resolve_path_type(), that's what you need to use.
Quoted 30 lines
qdev-monitor.c +8
-0+ +return NULL ; +} +void qmp_device_del (const char *id,Error **errp) {DeviceState *dev; dev =qdev_find_recursive (sysbus_get_default (), id);if (!dev) { + dev =find_peripheral_device (id); + } + +if (!dev) {error_set (errp,QERR_DEVICE_NOT_FOUND , id);return ; }qom/object.c +1
-1@@ -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 ); }