[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/18] spapr: Make spapr_cpu_core_unrealize() idempotent
From: |
David Gibson |
Subject: |
[PULL 08/18] spapr: Make spapr_cpu_core_unrealize() idempotent |
Date: |
Wed, 28 Oct 2020 01:17:25 +1100 |
From: Greg Kurz <groug@kaod.org>
spapr_cpu_core_realize() has a rollback path which partially duplicates
the code of spapr_cpu_core_unrealize().
Let's make spapr_cpu_core_unrealize() idempotent and call it instead. This
requires to:
- move the registration and unregistration of the reset handler around
but it is harmless,
- allocate the array of vCPUs with g_new0() to be able to filter out
unused slots,
- make sure to only unrealize vCPUs that have been already realized.
Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <160279672626.1808373.14142129300586424514.stgit@bahia.lan>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
hw/ppc/spapr_cpu_core.c | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 45eb212187..317fb9934f 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -227,15 +227,26 @@ static void spapr_cpu_core_unrealize(DeviceState *dev)
CPUCore *cc = CPU_CORE(dev);
int i;
- qemu_unregister_reset(spapr_cpu_core_reset_handler, sc);
-
for (i = 0; i < cc->nr_threads; i++) {
- spapr_unrealize_vcpu(sc->threads[i], sc);
+ if (sc->threads[i]) {
+ /*
+ * Since this we can get here from the error path of
+ * spapr_cpu_core_realize(), make sure we only unrealize
+ * vCPUs that have already been realized.
+ */
+ if (object_property_get_bool(OBJECT(sc->threads[i]), "realized",
+ &error_abort)) {
+ spapr_unrealize_vcpu(sc->threads[i], sc);
+ }
+ }
}
for (i = 0; i < cc->nr_threads; i++) {
- spapr_delete_vcpu(sc->threads[i]);
+ if (sc->threads[i]) {
+ spapr_delete_vcpu(sc->threads[i]);
+ }
}
g_free(sc->threads);
+ qemu_unregister_reset(spapr_cpu_core_reset_handler, sc);
}
static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
@@ -322,32 +333,22 @@ static void spapr_cpu_core_realize(DeviceState *dev,
Error **errp)
return;
}
- sc->threads = g_new(PowerPCCPU *, cc->nr_threads);
+ qemu_register_reset(spapr_cpu_core_reset_handler, sc);
+ sc->threads = g_new0(PowerPCCPU *, cc->nr_threads);
for (i = 0; i < cc->nr_threads; i++) {
sc->threads[i] = spapr_create_vcpu(sc, i, errp);
if (!sc->threads[i]) {
- goto err;
+ spapr_cpu_core_unrealize(dev);
+ return;
}
}
for (j = 0; j < cc->nr_threads; j++) {
if (!spapr_realize_vcpu(sc->threads[j], spapr, sc, errp)) {
- goto err_unrealize;
+ spapr_cpu_core_unrealize(dev);
+ return;
}
}
-
- qemu_register_reset(spapr_cpu_core_reset_handler, sc);
- return;
-
-err_unrealize:
- while (--j >= 0) {
- spapr_unrealize_vcpu(sc->threads[j], sc);
- }
-err:
- while (--i >= 0) {
- spapr_delete_vcpu(sc->threads[i]);
- }
- g_free(sc->threads);
}
static Property spapr_cpu_core_properties[] = {
--
2.26.2
- [PULL 00/18] ppc-for-5.2 queue 20201028, David Gibson, 2020/10/27
- [PULL 01/18] spapr: Clarify why DR connectors aren't user creatable, David Gibson, 2020/10/27
- [PULL 02/18] ppc/spapr: re-assert IRQs during event-scan if there are pending, David Gibson, 2020/10/27
- [PULL 03/18] hw/net: move allocation to the heap due to very large stack frame, David Gibson, 2020/10/27
- [PULL 04/18] spapr: Move spapr_create_nvdimm_dr_connectors() to core machine code, David Gibson, 2020/10/27
- [PULL 07/18] spapr: Drop spapr_delete_vcpu() unused argument, David Gibson, 2020/10/27
- [PULL 06/18] spapr: Unrealize vCPUs with qdev_unrealize(), David Gibson, 2020/10/27
- [PULL 08/18] spapr: Make spapr_cpu_core_unrealize() idempotent,
David Gibson <=
- [PULL 13/18] spapr: Pass &error_abort when getting some PC DIMM properties, David Gibson, 2020/10/27
- [PULL 09/18] spapr: Simplify spapr_cpu_core_realize() and spapr_cpu_core_unrealize(), David Gibson, 2020/10/27
- [PULL 11/18] spapr: Use appropriate getter for PC_DIMM_ADDR_PROP, David Gibson, 2020/10/27
- [PULL 14/18] spapr: Simplify error handling in spapr_memory_plug(), David Gibson, 2020/10/27
- [PULL 05/18] spapr: Fix leak of CPU machine specific data, David Gibson, 2020/10/27
- [PULL 12/18] spapr: Use appropriate getter for PC_DIMM_SLOT_PROP, David Gibson, 2020/10/27
- [PULL 10/18] pc-dimm: Drop @errp argument of pc_dimm_plug(), David Gibson, 2020/10/27
- [PULL 15/18] spapr: Use error_append_hint() in spapr_reallocate_hpt(), David Gibson, 2020/10/27
- [PULL 16/18] target/ppc: Fix kvmppc_load_htab_chunk() error reporting, David Gibson, 2020/10/27
- [PULL 17/18] spapr: Improve spapr_reallocate_hpt() error reporting, David Gibson, 2020/10/27