Skip to contentSkip to conversation

i386, acpi: check acpi_memory_hotplug capacity in pre_plug

PATCH Superseded Wei Yang 3 participants 5 messages Feb 14, 2019 – Feb 16, 2019

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 i386, acpi: check acpi_memory_hotplug capacity in pre_plug

Currently we do device realization like below:

hotplug_handler_pre_plug()
dc->realize()
hotplug_handler_plug()

Before we do device realization and plug, we would allocate necessary resources and check the capacity.

While we leave acpi_memory_hotplug capacity check in the last step. This looks not comply with current architecture and does some unnecessary work.

This patch abstract the check on acpi_memory_hotplug capacity in pre_plug stage.

---
 hw/acpi/piix4.c | 14 ++++++++++++--
 hw/i386/pc.c    |  8 ++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)
hw/acpi/piix4.c +12 -2
index e330f24c71..c97b747496 100644
@@ -370,13 +370,22 @@ static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
     acpi_pm1_evt_power_down(&s->ar);
 }
 
+static void piix4_device_pre_plug_cb(HotplugHandler *hotplug_dev,
+                                 DeviceState *dev, Error **errp)
+{
+    PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) &&
+        !s->acpi_memory_hotplug.is_enabled)
+        error_setg(errp,
+            "memory hotplug is not enabled: PIIX4 memory hotplug disabled");
+}
 static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
                                  DeviceState *dev, Error **errp)
 {
     PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-    if (s->acpi_memory_hotplug.is_enabled &&
-        object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
             nvdimm_acpi_plug_cb(hotplug_dev, dev);
         } else {
@@ -702,6 +711,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
      */
     dc->user_creatable = false;
     dc->hotpluggable = false;
+    hc->pre_plug = piix4_device_pre_plug_cb;
     hc->plug = piix4_device_plug_cb;
     hc->unplug_request = piix4_device_unplug_request_cb;
     hc->unplug = piix4_device_unplug_cb;
hw/i386/pc.c +8 -0
index 734d3268fa..3c6eed0cd3 100644
@@ -1662,6 +1662,7 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     const PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     const bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
     const uint64_t legacy_align = TARGET_PAGE_SIZE;
+    HotplugHandlerClass *hhc;
 
     /*
      * When -no-acpi is used with Q35 machine type, no ACPI is built,
@@ -1674,6 +1675,13 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         return;
     }
 
+    /*
+     * Check acpi_dev memory hotplug capacity
+     */
+    hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev);
+    if (hcc->pre_plug)
+        hhc->pre_plug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, errp);
+
     if (is_nvdimm && !pcms->acpi_nvdimm_state.is_enabled) {
         error_setg(errp, "nvdimm is not enabled: missing 'nvdimm' in '-M'");
         return;
Signature · 1 line
2.19.1
#1 lore raw
Quoted 8 lines · On Thu, 14 Feb 2019 08:52:25 +0800 Wei Yang <[email protected]>…

Currently we do device realization like below:

   hotplug_handler_pre_plug()
   dc->realize()
   hotplug_handler_plug()

Before we do device realization and plug, we would allocate necessary resources and check the capacity.

'capacity' probably is not right word to use here
maybe s/the capacity/if 'memory-hotplug-support' property is enabled/

Quoted 2 lines

While we leave acpi_memory_hotplug capacity check in the last step. This

wouldn't use 'leave' and 'capacity' here either, pls rephrase.

Quoted 1 line

looks not comply with current architecture and does some unnecessary

s/looks not/doesn't/

Quoted 1 line

work.

add more explanation about 'unnecessary work'. problem as I see it, is that after successful pc_dimm_plug() we get into piix4_device_plug_cb() and since
s->acpi_memory_hotplug.is_enabled == false
and all other 'if' conditions also false we would endup at g_assert_not_reached() causing QEMU crash in piix4 case and with error_abort up the call chain in case of ich9.

Quoted 7 lines

This patch abstract the check on acpi_memory_hotplug capacity in pre_plug stage.

---
 hw/acpi/piix4.c | 14 ++++++++++++--
 hw/i386/pc.c    |  8 ++++++++

doesn't look complete, why did you skip on similar code in ich9 (Q35 machine)?

Quoted 52 lines
 2 files changed, 20 insertions(+), 2 deletions(-)
hw/acpi/piix4.c +12 -2
index e330f24c71..c97b747496 100644
@@ -370,13 +370,22 @@ static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
     acpi_pm1_evt_power_down(&s->ar);
 }
 
+static void piix4_device_pre_plug_cb(HotplugHandler *hotplug_dev,
+                                 DeviceState *dev, Error **errp)
+{
+    PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) &&
+        !s->acpi_memory_hotplug.is_enabled)
+        error_setg(errp,
+            "memory hotplug is not enabled: PIIX4 memory hotplug disabled");
+}
 static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
                                  DeviceState *dev, Error **errp)
 {
     PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-    if (s->acpi_memory_hotplug.is_enabled &&
-        object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
             nvdimm_acpi_plug_cb(hotplug_dev, dev);
         } else {
@@ -702,6 +711,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
      */
     dc->user_creatable = false;
     dc->hotpluggable = false;
+    hc->pre_plug = piix4_device_pre_plug_cb;
     hc->plug = piix4_device_plug_cb;
     hc->unplug_request = piix4_device_unplug_request_cb;
     hc->unplug = piix4_device_unplug_cb;
hw/i386/pc.c +1 -0
index 734d3268fa..3c6eed0cd3 100644
@@ -1662,6 +1662,7 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     const PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     const bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
     const uint64_t legacy_align = TARGET_PAGE_SIZE;
+    HotplugHandlerClass *hhc;
 
     /*
      * When -no-acpi is used with Q35 machine type, no ACPI is built,

hw/i386/pc.c static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 1683

Quoted 9 lines
hw/i386/pc.c +6 -0
@@ -1674,6 +1675,13 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         return;
     }
 
+    /*
+     * Check acpi_dev memory hotplug capacity
+     */
+    hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev);
+    if (hcc->pre_plug)
+        hhc->pre_plug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, errp);

use hotplug_handler_pre_plug() instead of open-coding check

Quoted 3 lines
hw/i386/pc.c +0 -0
     if (is_nvdimm && !pcms->acpi_nvdimm_state.is_enabled) {
         error_setg(errp, "nvdimm is not enabled: missing 'nvdimm' in '-M'");
         return;
#2 lore raw
Quoted 20 lines · Igor Mammedov
Quoted 8 lines · On Thu, 14 Feb 2019 08:52:25 +0800 Wei Yang <[email protected]>…

Currently we do device realization like below:

   hotplug_handler_pre_plug()
   dc->realize()
   hotplug_handler_plug()

Before we do device realization and plug, we would allocate necessary resources and check the capacity.

'capacity' probably is not right word to use here
maybe s/the capacity/if 'memory-hotplug-support' property is enabled/

Quoted 2 lines

While we leave acpi_memory_hotplug capacity check in the last step. This

wouldn't use 'leave' and 'capacity' here either, pls rephrase.

Quoted 1 line

looks not comply with current architecture and does some unnecessary

s/looks not/doesn't/

Quoted 9 lines
Quoted 1 line

work.

add more explanation about 'unnecessary work'. problem as I see it, is that after successful pc_dimm_plug() we get into piix4_device_plug_cb() and since s->acpi_memory_hotplug.is_enabled == false
and all other 'if' conditions also false we would endup at g_assert_not_reached() causing QEMU crash in piix4 case and with error_abort up the call chain in case of ich9.

Thanks Igor, I rephrase above change log like this. Does this look better to you now?

Before we do device realization and plug, we would allocate necessary resources and check if memory-hotplug-support property is enabled.

In piix4 and ich9, the acpi_memory_hotplug property is checked in plug stage, this doesn't comply with current architecture. This means we have prepared everything and even do pc_dimm_plug() successfuly, but failed at last because acpi_memory_hotplug.is_enabled == false. Which is worse is in piix4, this endup at g_assert_not_reached() and cause QEMU crash.

Quoted 10 lines
Quoted 7 lines

This patch abstract the check on acpi_memory_hotplug capacity in pre_plug stage.

---
 hw/acpi/piix4.c | 14 ++++++++++++--
 hw/i386/pc.c    |  8 ++++++++

doesn't look complete, why did you skip on similar code in ich9 (Q35 machine)?

You are right, I missed this part.

Quoted 55 lines
Quoted 55 lines
 2 files changed, 20 insertions(+), 2 deletions(-)
hw/acpi/piix4.c +12 -2
index e330f24c71..c97b747496 100644
@@ -370,13 +370,22 @@ static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
     acpi_pm1_evt_power_down(&s->ar);
 }
 
+static void piix4_device_pre_plug_cb(HotplugHandler *hotplug_dev,
+                                 DeviceState *dev, Error **errp)
+{
+    PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) &&
+        !s->acpi_memory_hotplug.is_enabled)
+        error_setg(errp,
+            "memory hotplug is not enabled: PIIX4 memory hotplug disabled");
+}
 static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
                                  DeviceState *dev, Error **errp)
 {
     PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-    if (s->acpi_memory_hotplug.is_enabled &&
-        object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
             nvdimm_acpi_plug_cb(hotplug_dev, dev);
         } else {
@@ -702,6 +711,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
      */
     dc->user_creatable = false;
     dc->hotpluggable = false;
+    hc->pre_plug = piix4_device_pre_plug_cb;
     hc->plug = piix4_device_plug_cb;
     hc->unplug_request = piix4_device_unplug_request_cb;
     hc->unplug = piix4_device_unplug_cb;
hw/i386/pc.c +1 -0
index 734d3268fa..3c6eed0cd3 100644
@@ -1662,6 +1662,7 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     const PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     const bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
     const uint64_t legacy_align = TARGET_PAGE_SIZE;
+    HotplugHandlerClass *hhc;
 
     /*
      * When -no-acpi is used with Q35 machine type, no ACPI is built,
@@ -1674,6 +1675,13 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         return;
     }
 
Quoted 8 lines

hw/i386/pc.c static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 1683

Quoted 6 lines
hw/i386/pc.c +6 -0
+    /*
+     * Check acpi_dev memory hotplug capacity
+     */
+    hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev);
+    if (hcc->pre_plug)
+        hhc->pre_plug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, errp);

use hotplug_handler_pre_plug() instead of open-coding check

Thanks, will fix this.

Quoted 4 lines
Quoted 3 lines
hw/i386/pc.c +0 -0
     if (is_nvdimm && !pcms->acpi_nvdimm_state.is_enabled) {
         error_setg(errp, "nvdimm is not enabled: missing 'nvdimm' in '-M'");
         return;
Signature · 2 lines
Wei Yang
Help you, Help me
#3 lore raw
Quoted 31 lines · On Thu, 14 Feb 2019 20:53:31 +0000 Wei Yang <[email protected]> wrote:
Quoted 20 lines · Igor Mammedov
Quoted 8 lines · On Thu, 14 Feb 2019 08:52:25 +0800 Wei Yang <[email protected]>…

Currently we do device realization like below:

   hotplug_handler_pre_plug()
   dc->realize()
   hotplug_handler_plug()

Before we do device realization and plug, we would allocate necessary resources and check the capacity.

'capacity' probably is not right word to use here
maybe s/the capacity/if 'memory-hotplug-support' property is enabled/

Quoted 2 lines

While we leave acpi_memory_hotplug capacity check in the last step. This

wouldn't use 'leave' and 'capacity' here either, pls rephrase.

Quoted 1 line

looks not comply with current architecture and does some unnecessary

s/looks not/doesn't/

Quoted 9 lines
Quoted 1 line

work.

add more explanation about 'unnecessary work'. problem as I see it, is that after successful pc_dimm_plug() we get into piix4_device_plug_cb() and since s->acpi_memory_hotplug.is_enabled == false
and all other 'if' conditions also false we would endup at g_assert_not_reached() causing QEMU crash in piix4 case and with error_abort up the call chain in case of ich9.

Quoted 4 lines

Thanks Igor, I rephrase above change log like this. Does this look better to you now?

Before we do device realization and plug, we would allocate

s/would/should/

Quoted 4 lines

necessary resources and check if memory-hotplug-support property is enabled.

In piix4 and ich9, the acpi_memory_hotplug property is checked in

s/in/at the/

Quoted 1 line

plug stage, this doesn't comply with current architecture. This

drop ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Quoted 1 line

means we have prepared everything and even do pc_dimm_plug()

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

that device has been realized and mapped into guest address space 'pc_dimm_plug()' by the time acpi plug handler is called, where it might fail and crash QEMU due to reaching g_assert_not_reached() (piix4) or error_abort (ich9).

or something like this, I'm not native speaker either so CC Eric Blake on next respin so he could check commit message.

Quoted 89 lines

successfuly, but failed at last because acpi_memory_hotplug.is_enabled == false. Which is worse is in piix4, this endup at g_assert_not_reached() and cause QEMU crash.

Quoted 10 lines
Quoted 7 lines

This patch abstract the check on acpi_memory_hotplug capacity in pre_plug stage.

---
 hw/acpi/piix4.c | 14 ++++++++++++--
 hw/i386/pc.c    |  8 ++++++++

doesn't look complete, why did you skip on similar code in ich9 (Q35 machine)?

You are right, I missed this part.

Quoted 55 lines
Quoted 55 lines
 2 files changed, 20 insertions(+), 2 deletions(-)
hw/acpi/piix4.c +12 -2
index e330f24c71..c97b747496 100644
@@ -370,13 +370,22 @@ static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
     acpi_pm1_evt_power_down(&s->ar);
 }
 
+static void piix4_device_pre_plug_cb(HotplugHandler *hotplug_dev,
+                                 DeviceState *dev, Error **errp)
+{
+    PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) &&
+        !s->acpi_memory_hotplug.is_enabled)
+        error_setg(errp,
+            "memory hotplug is not enabled: PIIX4 memory hotplug disabled");
+}
 static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
                                  DeviceState *dev, Error **errp)
 {
     PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-    if (s->acpi_memory_hotplug.is_enabled &&
-        object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
             nvdimm_acpi_plug_cb(hotplug_dev, dev);
         } else {
@@ -702,6 +711,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
      */
     dc->user_creatable = false;
     dc->hotpluggable = false;
+    hc->pre_plug = piix4_device_pre_plug_cb;
     hc->plug = piix4_device_plug_cb;
     hc->unplug_request = piix4_device_unplug_request_cb;
     hc->unplug = piix4_device_unplug_cb;
hw/i386/pc.c +1 -0
index 734d3268fa..3c6eed0cd3 100644
@@ -1662,6 +1662,7 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     const PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     const bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
     const uint64_t legacy_align = TARGET_PAGE_SIZE;
+    HotplugHandlerClass *hhc;
 
     /*
      * When -no-acpi is used with Q35 machine type, no ACPI is built,
@@ -1674,6 +1675,13 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         return;
     }
 
Quoted 8 lines

hw/i386/pc.c static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 1683

Quoted 6 lines
hw/i386/pc.c +6 -0
+    /*
+     * Check acpi_dev memory hotplug capacity
+     */
+    hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev);
+    if (hcc->pre_plug)
+        hhc->pre_plug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, errp);

use hotplug_handler_pre_plug() instead of open-coding check

Thanks, will fix this.

Quoted 4 lines
Quoted 3 lines
hw/i386/pc.c +0 -0
     if (is_nvdimm && !pcms->acpi_nvdimm_state.is_enabled) {
         error_setg(errp, "nvdimm is not enabled: missing 'nvdimm' in '-M'");
         return;
#4 lore raw
Quoted 48 lines · Igor Mammedov
Quoted 31 lines · On Thu, 14 Feb 2019 20:53:31 +0000 Wei Yang <[email protected]> wrote:
Quoted 20 lines · Igor Mammedov
Quoted 8 lines · On Thu, 14 Feb 2019 08:52:25 +0800 Wei Yang <[email protected]>…

Currently we do device realization like below:

   hotplug_handler_pre_plug()
   dc->realize()
   hotplug_handler_plug()

Before we do device realization and plug, we would allocate necessary resources and check the capacity.

'capacity' probably is not right word to use here
maybe s/the capacity/if 'memory-hotplug-support' property is enabled/

Quoted 2 lines

While we leave acpi_memory_hotplug capacity check in the last step. This

wouldn't use 'leave' and 'capacity' here either, pls rephrase.

Quoted 1 line

looks not comply with current architecture and does some unnecessary

s/looks not/doesn't/

Quoted 9 lines
Quoted 1 line

work.

add more explanation about 'unnecessary work'. problem as I see it, is that after successful pc_dimm_plug() we get into piix4_device_plug_cb() and since s->acpi_memory_hotplug.is_enabled == false
and all other 'if' conditions also false we would endup at g_assert_not_reached() causing QEMU crash in piix4 case and with error_abort up the call chain in case of ich9.

Quoted 4 lines

Thanks Igor, I rephrase above change log like this. Does this look better to you now?

Before we do device realization and plug, we would allocate

s/would/should/

Quoted 4 lines

necessary resources and check if memory-hotplug-support property is enabled.

In piix4 and ich9, the acpi_memory_hotplug property is checked in

s/in/at the/

Quoted 1 line

plug stage, this doesn't comply with current architecture. This

drop ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Quoted 1 line

means we have prepared everything and even do pc_dimm_plug()

Quoted 9 lines
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

that device has been realized and mapped into guest address space 'pc_dimm_plug()' by the time acpi plug handler is called, where it might fail and crash QEMU due to reaching g_assert_not_reached() (piix4) or error_abort (ich9).

or something like this, I'm not native speaker either so CC Eric Blake on next respin so he could check commit message.

Thanks for your patience and detailed suggestion :-)

Quoted 89 lines
Quoted 89 lines

successfuly, but failed at last because acpi_memory_hotplug.is_enabled == false. Which is worse is in piix4, this endup at g_assert_not_reached() and cause QEMU crash.

Quoted 10 lines
Quoted 7 lines

This patch abstract the check on acpi_memory_hotplug capacity in pre_plug stage.

---
 hw/acpi/piix4.c | 14 ++++++++++++--
 hw/i386/pc.c    |  8 ++++++++

doesn't look complete, why did you skip on similar code in ich9 (Q35 machine)?

You are right, I missed this part.

Quoted 55 lines
Quoted 55 lines
 2 files changed, 20 insertions(+), 2 deletions(-)
hw/acpi/piix4.c +12 -2
index e330f24c71..c97b747496 100644
@@ -370,13 +370,22 @@ static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
     acpi_pm1_evt_power_down(&s->ar);
 }
 
+static void piix4_device_pre_plug_cb(HotplugHandler *hotplug_dev,
+                                 DeviceState *dev, Error **errp)
+{
+    PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) &&
+        !s->acpi_memory_hotplug.is_enabled)
+        error_setg(errp,
+            "memory hotplug is not enabled: PIIX4 memory hotplug disabled");
+}
 static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
                                  DeviceState *dev, Error **errp)
 {
     PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-    if (s->acpi_memory_hotplug.is_enabled &&
-        object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
             nvdimm_acpi_plug_cb(hotplug_dev, dev);
         } else {
@@ -702,6 +711,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
      */
     dc->user_creatable = false;
     dc->hotpluggable = false;
+    hc->pre_plug = piix4_device_pre_plug_cb;
     hc->plug = piix4_device_plug_cb;
     hc->unplug_request = piix4_device_unplug_request_cb;
     hc->unplug = piix4_device_unplug_cb;
hw/i386/pc.c +1 -0
index 734d3268fa..3c6eed0cd3 100644
@@ -1662,6 +1662,7 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     const PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     const bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
     const uint64_t legacy_align = TARGET_PAGE_SIZE;
+    HotplugHandlerClass *hhc;
 
     /*
      * When -no-acpi is used with Q35 machine type, no ACPI is built,
@@ -1674,6 +1675,13 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         return;
     }
 
Quoted 8 lines

hw/i386/pc.c static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 1683

Quoted 6 lines
hw/i386/pc.c +6 -0
+    /*
+     * Check acpi_dev memory hotplug capacity
+     */
+    hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev);
+    if (hcc->pre_plug)
+        hhc->pre_plug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, errp);

use hotplug_handler_pre_plug() instead of open-coding check

Thanks, will fix this.

Quoted 4 lines
Quoted 3 lines
hw/i386/pc.c +0 -0
     if (is_nvdimm && !pcms->acpi_nvdimm_state.is_enabled) {
         error_setg(errp, "nvdimm is not enabled: missing 'nvdimm' in '-M'");
         return;
Signature · 2 lines
Wei Yang
Help you, Help me