Release the vCPU objects after CPU hot unplug so that vCPU fd
can be parked and reused.

Signed-off-by: Bharata B Rao <bhar...@linux.vnet.ibm.com>
---
 hw/ppc/spapr.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 7b8784d..3e56d9e 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1886,6 +1886,23 @@ static void spapr_cpu_hotplug_add(DeviceState *dev, 
CPUState *cs, Error **errp)
     }
 }
 
+static void spapr_cpu_release(DeviceState *dev, void *opaque)
+{
+    CPUState *cs;
+    int i;
+    int id = ppc_get_vcpu_dt_id(POWERPC_CPU(CPU(dev)));
+
+    for (i = id; i < id + smp_threads; i++) {
+        CPU_FOREACH(cs) {
+            PowerPCCPU *cpu = POWERPC_CPU(cs);
+
+            if (i == ppc_get_vcpu_dt_id(cpu)) {
+                cpu_remove(cs);
+            }
+        }
+    }
+}
+
 static void spapr_cpu_hotplug_remove(DeviceState *dev, CPUState *cs,
                                      Error **errp)
 {
@@ -1895,7 +1912,7 @@ static void spapr_cpu_hotplug_remove(DeviceState *dev, 
CPUState *cs,
         spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id);
     sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
 
-    drck->detach(drc, dev, NULL, NULL, errp);
+    drck->detach(drc, dev, spapr_cpu_release, NULL, errp);
 }
 
 static void spapr_cpu_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
-- 
2.1.0


Reply via email to