Skip to contentSkip to conversation

spapr: Don't request to unplug the same core twice

PATCH In review Greg Kurz 2 participants 4 messages Oct 23, 2019 – Oct 29, 2019

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

PATCH 1/1 spapr: Don't request to unplug the same core twice

We must not call spapr_drc_detach() on a detached DRC otherwise bad things can happen, ie. QEMU hangs or crashes. This is easily demonstrated with a CPU hotplug/unplug loop using QMP.

---
 hw/ppc/spapr.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ppc/spapr.c +4 -3
index f9410d390a07..94f9d27096af 100644
@@ -3741,9 +3741,10 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
                           spapr_vcpu_id(spapr, cc->core_id));
     g_assert(drc);
 
-    spapr_drc_detach(drc);
-
-    spapr_hotplug_req_remove_by_index(drc);
+    if (!spapr_drc_unplug_requested(drc)) {
+        spapr_drc_detach(drc);
+        spapr_hotplug_req_remove_by_index(drc);
+    }
 }
 
 int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
#1 lore raw
Quoted 5 lines · Greg Kurz

We must not call spapr_drc_detach() on a detached DRC otherwise bad things can happen, ie. QEMU hangs or crashes. This is easily demonstrated with a CPU hotplug/unplug loop using QMP.

Ouch, good catch. Applied.

I wonder if we have the same problem with other DRC types.

Quoted 23 lines
---
 hw/ppc/spapr.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ppc/spapr.c +4 -3
index f9410d390a07..94f9d27096af 100644
@@ -3741,9 +3741,10 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
                           spapr_vcpu_id(spapr, cc->core_id));
     g_assert(drc);
 
-    spapr_drc_detach(drc);
-
-    spapr_hotplug_req_remove_by_index(drc);
+    if (!spapr_drc_unplug_requested(drc)) {
+        spapr_drc_detach(drc);
+        spapr_hotplug_req_remove_by_index(drc);
+    }
 }
 
 int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#2 lore raw
Quoted 11 lines · On Thu, 24 Oct 2019 09:38:17 +1100 David Gibson <[email protected]>…
Quoted 5 lines · Greg Kurz

We must not call spapr_drc_detach() on a detached DRC otherwise bad things can happen, ie. QEMU hangs or crashes. This is easily demonstrated with a CPU hotplug/unplug loop using QMP.

Ouch, good catch. Applied.

I wonder if we have the same problem with other DRC types.

We don't have it with PHB and PCI types, through the same use of spapr_drc_unplug_requested().

LMBs see to avoid it by failing device_del early if an unplug request is already in progress:

    /*
     * An existing pending dimm state for this DIMM means that there is an
     * unplug operation in progress, waiting for the spapr_lmb_release
     * callback to complete the job (BQL can't cover that far). In this case,
     * bail out to avoid detaching DRCs that were already released.
     */
    if (spapr_pending_dimm_unplugs_find(spapr, dimm)) {
        error_setg(&local_err,
                   "Memory unplug already in progress for device %s",
                   dev->id);
        goto out;
    }

Not sure why we error out in this case instead of ignoring the unplug request.

Quoted 24 lines
Quoted 23 lines
---
 hw/ppc/spapr.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ppc/spapr.c +4 -3
index f9410d390a07..94f9d27096af 100644
@@ -3741,9 +3741,10 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
                           spapr_vcpu_id(spapr, cc->core_id));
     g_assert(drc);
 
-    spapr_drc_detach(drc);
-
-    spapr_hotplug_req_remove_by_index(drc);
+    if (!spapr_drc_unplug_requested(drc)) {
+        spapr_drc_detach(drc);
+        spapr_hotplug_req_remove_by_index(drc);
+    }
 }
 
 int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
#3 lore raw
Quoted 34 lines · Greg Kurz
Quoted 11 lines · On Thu, 24 Oct 2019 09:38:17 +1100 David Gibson <[email protected]>…
Quoted 5 lines · Greg Kurz

We must not call spapr_drc_detach() on a detached DRC otherwise bad things can happen, ie. QEMU hangs or crashes. This is easily demonstrated with a CPU hotplug/unplug loop using QMP.

Ouch, good catch. Applied.

I wonder if we have the same problem with other DRC types.

We don't have it with PHB and PCI types, through the same use of spapr_drc_unplug_requested().

LMBs see to avoid it by failing device_del early if an unplug request is already in progress:

    /*
     * An existing pending dimm state for this DIMM means that there is an
     * unplug operation in progress, waiting for the spapr_lmb_release
     * callback to complete the job (BQL can't cover that far). In this case,
     * bail out to avoid detaching DRCs that were already released.
     */
    if (spapr_pending_dimm_unplugs_find(spapr, dimm)) {
        error_setg(&local_err,
                   "Memory unplug already in progress for device %s",
                   dev->id);
        goto out;
    }
Quoted 2 lines

Not sure why we error out in this case instead of ignoring the unplug request.

I suspect no particularly good reason, just history. Everything's a bit different with LMBs because a single device_del will usually remove a whole bunch of LMB DRCs. In general the interfacing between the qemu user side DIMM handling and the PAPR side LMB/DRC handling is... pretty clunky.

Quoted 26 lines
Quoted 25 lines
Quoted 24 lines
---
 hw/ppc/spapr.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ppc/spapr.c +4 -3
index f9410d390a07..94f9d27096af 100644
@@ -3741,9 +3741,10 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
                           spapr_vcpu_id(spapr, cc->core_id));
     g_assert(drc);
 
-    spapr_drc_detach(drc);
-
-    spapr_hotplug_req_remove_by_index(drc);
+    if (!spapr_drc_unplug_requested(drc)) {
+        spapr_drc_detach(drc);
+        spapr_hotplug_req_remove_by_index(drc);
+    }
 }
 
 int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson