From nobody Sat May 4 00:05:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529013171497721.4234122486414; Thu, 14 Jun 2018 14:52:51 -0700 (PDT) Received: from localhost ([::1]:43168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTaAf-0008Tu-Hc for importer@patchew.org; Thu, 14 Jun 2018 17:52:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTa8T-0007IS-4T for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:50:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTa8O-00020U-9E for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:50:29 -0400 Received: from 10.mo69.mail-out.ovh.net ([46.105.73.241]:47829) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fTa8N-0001z6-Qu for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:50:24 -0400 Received: from player157.ha.ovh.net (unknown [10.109.122.108]) by mo69.mail-out.ovh.net (Postfix) with ESMTP id 4DF6B185FB for ; Thu, 14 Jun 2018 23:50:22 +0200 (CEST) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player157.ha.ovh.net (Postfix) with ESMTPA id 24B2B5000A3; Thu, 14 Jun 2018 23:50:17 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 14 Jun 2018 23:50:11 +0200 Message-ID: <152901301117.252222.1572533397608306446.stgit@bahia.lan> In-Reply-To: <152901299450.252222.14219708016930421485.stgit@bahia.lan> References: <152901299450.252222.14219708016930421485.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 16365518099405445515 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrleeggddtgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.73.241 Subject: [Qemu-devel] [PATCH 1/5] spapr_cpu_core: convert last snprintf() to g_strdup_printf() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric?= Le Goater , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Because this is the preferred practice in QEMU. Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 7e3a9e78d090..27602245fd55 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -190,7 +190,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Er= ror **errp) =20 sc->threads =3D g_new(PowerPCCPU *, cc->nr_threads); for (i =3D 0; i < cc->nr_threads; i++) { - char id[32]; + char *id; CPUState *cs; PowerPCCPU *cpu; =20 @@ -208,8 +208,9 @@ static void spapr_cpu_core_realize(DeviceState *dev, Er= ror **errp) /* Set NUMA node for the threads belonged to core */ cpu->node_id =3D sc->node_id; =20 - snprintf(id, sizeof(id), "thread[%d]", i); + id =3D g_strdup_printf("thread[%d]", i); object_property_add_child(OBJECT(sc), id, obj, &local_err); + g_free(id); if (local_err) { goto err; } From nobody Sat May 4 00:05:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529013182407967.5494245775959; Thu, 14 Jun 2018 14:53:02 -0700 (PDT) Received: from localhost ([::1]:43170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTaAr-0000Ew-LH for importer@patchew.org; Thu, 14 Jun 2018 17:52:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTa8i-0007Pj-1e for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTa8d-0002EU-9e for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:50:44 -0400 Received: from 12.mo6.mail-out.ovh.net ([178.32.125.228]:44585) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fTa8d-0002DK-2t for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:50:39 -0400 Received: from player718.ha.ovh.net (unknown [10.109.108.77]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id 785EE164232 for ; Thu, 14 Jun 2018 23:50:37 +0200 (CEST) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player718.ha.ovh.net (Postfix) with ESMTPA id 1FBAB4E0082; Thu, 14 Jun 2018 23:50:33 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 14 Jun 2018 23:50:27 +0200 Message-ID: <152901302718.252222.18367624313137740494.stgit@bahia.lan> In-Reply-To: <152901299450.252222.14219708016930421485.stgit@bahia.lan> References: <152901299450.252222.14219708016930421485.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 16369740223616620939 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrleeggddtgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.32.125.228 Subject: [Qemu-devel] [PATCH 2/5] spapr_cpu_core: fix potential leak in spapr_cpu_core_realize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric?= Le Goater , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Commit 94ad93bd97684 (QEMU 2.12) switched to instantiate CPUs separately but it missed to adapt the error path accordingly. If something fails in the CPU creation loop, then the CPU object that was just created is leaked. The error paths in this function are a bit obfuscated, and adding yet another label to free this CPU object makes it worse. We should move the block of the loop to a separate function, with a proper rollback path, but this is a bigger cleanup. For now, let's just fix the bug by adding the missing calls to object_unref(). This will allow easier backport to older QEMU versions. Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 27602245fd55..003c4c5a79d2 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -201,6 +201,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Er= ror **errp) cs->cpu_index =3D cc->core_id + i; spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err); if (local_err) { + object_unref(obj); goto err; } =20 @@ -212,6 +213,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Er= ror **errp) object_property_add_child(OBJECT(sc), id, obj, &local_err); g_free(id); if (local_err) { + object_unref(obj); goto err; } object_unref(obj); From nobody Sat May 4 00:05:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529013296412897.0893434128742; Thu, 14 Jun 2018 14:54:56 -0700 (PDT) Received: from localhost ([::1]:43185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTaCl-00021o-MM for importer@patchew.org; Thu, 14 Jun 2018 17:54:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTa8x-0007dj-3V for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:51:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTa8s-0002TB-7R for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:50:59 -0400 Received: from 4.mo69.mail-out.ovh.net ([46.105.42.102]:54222) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fTa8r-0002Rd-VD for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:50:54 -0400 Received: from player730.ha.ovh.net (unknown [10.109.105.36]) by mo69.mail-out.ovh.net (Postfix) with ESMTP id 744E817FA6 for ; Thu, 14 Jun 2018 23:50:52 +0200 (CEST) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player730.ha.ovh.net (Postfix) with ESMTPA id 2A50B440086; Thu, 14 Jun 2018 23:50:48 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 14 Jun 2018 23:50:42 +0200 Message-ID: <152901304242.252222.9947658955703347553.stgit@bahia.lan> In-Reply-To: <152901299450.252222.14219708016930421485.stgit@bahia.lan> References: <152901299450.252222.14219708016930421485.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 16373962345317898635 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrleeggddtgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.42.102 Subject: [Qemu-devel] [PATCH 3/5] spapr_cpu_core: add missing rollback on realization path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric?= Le Goater , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 The spapr_realize_vcpu() function doesn't rollback in case of error. This isn't a problem with coldplugged CPUs because the machine won't start and QEMU will exit. Hotplug is a different story though: the CPU thread is started under object_property_set_bool() and it assumes it can access the CPU object. If icp_create() fails, we return an error without unregistering the reset handler for this CPU, and we let the underlying QEMU thread for this CPU alive. Since spapr_cpu_core_realize() doesn't care to unrealize already realized CPUs either, but happily frees all of them anyway, the CPU thread crashes instantly: (qemu) device_add host-spapr-cpu-core,core-id=3D1,id=3Dgku GKU: failing icp_create (cpu 0x11497fd0) ^^^^^^^^^^ Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffee3feaa0 (LWP 24725)] 0x00000000104c8374 in object_dynamic_cast_assert (obj=3D0x11497fd0, ^^^^^^^^^^^^^^ pointer to the CPU object 623 trace_object_dynamic_cast_assert(obj ? obj->class->type->name (gdb) p obj->class->type $1 =3D (Type) 0x0 (gdb) p * obj $2 =3D {class =3D 0x10ea9c10, free =3D 0x11244620, ^^^^^^^^^^ should be g_free (gdb) p g_free $3 =3D {} 0x7ffff282bef0 obj is a dangling pointer to the CPU that was just destroyed in spapr_cpu_core_realize(). This patch adds proper rollback to both spapr_realize_vcpu() and spapr_cpu_core_realize(). Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 003c4c5a79d2..04c818a6ecac 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -159,12 +159,16 @@ static void spapr_realize_vcpu(PowerPCCPU *cpu, sPAPR= MachineState *spapr, spapr_cpu->icp =3D icp_create(OBJECT(cpu), spapr->icp_type, XICS_FABRIC(spapr), &local_err); if (local_err) { - goto error; + goto error_unregister; } =20 return; =20 +error_unregister: + qemu_unregister_reset(spapr_cpu_reset, cpu); + cpu_remove_sync(CPU(cpu)); error: + g_free(spapr_cpu); error_propagate(errp, local_err); } =20 @@ -222,11 +226,15 @@ static void spapr_cpu_core_realize(DeviceState *dev, = Error **errp) for (j =3D 0; j < cc->nr_threads; j++) { spapr_realize_vcpu(sc->threads[j], spapr, &local_err); if (local_err) { - goto err; + goto err_unrealize; } } return; =20 +err_unrealize: + while (--j >=3D 0) { + spapr_unrealize_vcpu(sc->threads[i]); + } err: while (--i >=3D 0) { obj =3D OBJECT(sc->threads[i]); From nobody Sat May 4 00:05:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529013210203945.6549120929959; Thu, 14 Jun 2018 14:53:30 -0700 (PDT) Received: from localhost ([::1]:43171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTaBN-0000g3-FI for importer@patchew.org; Thu, 14 Jun 2018 17:53:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48032) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTa9B-0007qZ-Dq for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:51:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTa96-0002mq-Lu for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:51:13 -0400 Received: from 1.mo178.mail-out.ovh.net ([178.33.251.53]:54540) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fTa96-0002k6-Do for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:51:08 -0400 Received: from player714.ha.ovh.net (unknown [10.109.122.43]) by mo178.mail-out.ovh.net (Postfix) with ESMTP id E77671A262 for ; Thu, 14 Jun 2018 23:51:06 +0200 (CEST) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player714.ha.ovh.net (Postfix) with ESMTPA id 20DC43C0093; Thu, 14 Jun 2018 23:51:03 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 14 Jun 2018 23:50:57 +0200 Message-ID: <152901305726.252222.7317082325256499414.stgit@bahia.lan> In-Reply-To: <152901299450.252222.14219708016930421485.stgit@bahia.lan> References: <152901299450.252222.14219708016930421485.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 16377902996543019403 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrleeggddtgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.33.251.53 Subject: [Qemu-devel] [PATCH 4/5] spapr_cpu_core: introduce spapr_create_vcpu() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric?= Le Goater , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This moves some code out from spapr_cpu_core_realize() for clarity. No functional change. Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 73 +++++++++++++++++++++++++++++--------------= ---- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 04c818a6ecac..0ebaf804a9bc 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -172,6 +172,49 @@ error: error_propagate(errp, local_err); } =20 +static PowerPCCPU *spapr_create_vcpu(sPAPRCPUCore *sc, int i, Error **errp) +{ + sPAPRCPUCoreClass *scc =3D SPAPR_CPU_CORE_GET_CLASS(sc); + CPUCore *cc =3D CPU_CORE(sc); + Object *obj; + char *id; + CPUState *cs; + PowerPCCPU *cpu; + Error *local_err =3D NULL; + + obj =3D object_new(scc->cpu_type); + + cs =3D CPU(obj); + cpu =3D POWERPC_CPU(obj); + cs->cpu_index =3D cc->core_id + i; + spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err); + if (local_err) { + goto err; + } + + cpu->node_id =3D sc->node_id; + + id =3D g_strdup_printf("thread[%d]", i); + object_property_add_child(OBJECT(sc), id, obj, &local_err); + g_free(id); + if (local_err) { + goto err; + } + + object_unref(obj); + return cpu; + +err: + object_unref(obj); + error_propagate(errp, local_err); + return NULL; +} + +static void spapr_delete_vcpu(PowerPCCPU *cpu) +{ + object_unparent(OBJECT(cpu)); +} + static void spapr_cpu_core_realize(DeviceState *dev, Error **errp) { /* We don't use SPAPR_MACHINE() in order to exit gracefully if the user @@ -181,10 +224,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, E= rror **errp) (sPAPRMachineState *) object_dynamic_cast(qdev_get_machine(), TYPE_SPAPR_MACHINE); sPAPRCPUCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); - sPAPRCPUCoreClass *scc =3D SPAPR_CPU_CORE_GET_CLASS(OBJECT(dev)); CPUCore *cc =3D CPU_CORE(OBJECT(dev)); Error *local_err =3D NULL; - Object *obj; int i, j; =20 if (!spapr) { @@ -194,33 +235,10 @@ static void spapr_cpu_core_realize(DeviceState *dev, = Error **errp) =20 sc->threads =3D g_new(PowerPCCPU *, cc->nr_threads); for (i =3D 0; i < cc->nr_threads; i++) { - char *id; - CPUState *cs; - PowerPCCPU *cpu; - - obj =3D object_new(scc->cpu_type); - - cs =3D CPU(obj); - cpu =3D sc->threads[i] =3D POWERPC_CPU(obj); - cs->cpu_index =3D cc->core_id + i; - spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err); - if (local_err) { - object_unref(obj); - goto err; - } - - - /* Set NUMA node for the threads belonged to core */ - cpu->node_id =3D sc->node_id; - - id =3D g_strdup_printf("thread[%d]", i); - object_property_add_child(OBJECT(sc), id, obj, &local_err); - g_free(id); + sc->threads[i] =3D spapr_create_vcpu(sc, i, &local_err); if (local_err) { - object_unref(obj); goto err; } - object_unref(obj); } =20 for (j =3D 0; j < cc->nr_threads; j++) { @@ -237,8 +255,7 @@ err_unrealize: } err: while (--i >=3D 0) { - obj =3D OBJECT(sc->threads[i]); - object_unparent(obj); + spapr_delete_vcpu(sc->threads[i]); } g_free(sc->threads); error_propagate(errp, local_err); From nobody Sat May 4 00:05:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529013371583429.6334898626619; Thu, 14 Jun 2018 14:56:11 -0700 (PDT) Received: from localhost ([::1]:43195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTaDy-0002pB-VC for importer@patchew.org; Thu, 14 Jun 2018 17:56:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTa9P-00080Z-J4 for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:51:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTa9K-00032q-Sf for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:51:27 -0400 Received: from 5.mo179.mail-out.ovh.net ([46.105.43.140]:46080) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fTa9K-00031k-K4 for qemu-devel@nongnu.org; Thu, 14 Jun 2018 17:51:22 -0400 Received: from player738.ha.ovh.net (unknown [10.109.105.58]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id E00F2CDA36 for ; Thu, 14 Jun 2018 23:51:20 +0200 (CEST) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player738.ha.ovh.net (Postfix) with ESMTPA id 1F062ED5; Thu, 14 Jun 2018 23:51:17 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 14 Jun 2018 23:51:11 +0200 Message-ID: <152901307192.252222.7502403316148525219.stgit@bahia.lan> In-Reply-To: <152901299450.252222.14219708016930421485.stgit@bahia.lan> References: <152901299450.252222.14219708016930421485.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 16381843648404887947 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrleeggddtgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.43.140 Subject: [Qemu-devel] [PATCH 5/5] spapr_cpu_core: simplify spapr_cpu_core_realize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric?= Le Goater , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 There's no real reason to create all CPUs in a first pass and to realize them in a second pass. Merging these two loops makes the code simpler. Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 0ebaf804a9bc..f52af20e0096 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -172,7 +172,8 @@ error: error_propagate(errp, local_err); } =20 -static PowerPCCPU *spapr_create_vcpu(sPAPRCPUCore *sc, int i, Error **errp) +static PowerPCCPU *spapr_create_vcpu(sPAPRCPUCore *sc, int i, + sPAPRMachineState *spapr, Error **err= p) { sPAPRCPUCoreClass *scc =3D SPAPR_CPU_CORE_GET_CLASS(sc); CPUCore *cc =3D CPU_CORE(sc); @@ -201,9 +202,16 @@ static PowerPCCPU *spapr_create_vcpu(sPAPRCPUCore *sc,= int i, Error **errp) goto err; } =20 + spapr_realize_vcpu(cpu, spapr, &local_err); + if (local_err) { + goto err_unparent; + } + object_unref(obj); return cpu; =20 +err_unparent: + object_unparent(obj); err: object_unref(obj); error_propagate(errp, local_err); @@ -212,6 +220,7 @@ err: =20 static void spapr_delete_vcpu(PowerPCCPU *cpu) { + spapr_unrealize_vcpu(cpu); object_unparent(OBJECT(cpu)); } =20 @@ -226,7 +235,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Er= ror **errp) sPAPRCPUCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); CPUCore *cc =3D CPU_CORE(OBJECT(dev)); Error *local_err =3D NULL; - int i, j; + int i; =20 if (!spapr) { error_setg(errp, TYPE_SPAPR_CPU_CORE " needs a pseries machine"); @@ -235,24 +244,14 @@ static void spapr_cpu_core_realize(DeviceState *dev, = Error **errp) =20 sc->threads =3D g_new(PowerPCCPU *, cc->nr_threads); for (i =3D 0; i < cc->nr_threads; i++) { - sc->threads[i] =3D spapr_create_vcpu(sc, i, &local_err); + sc->threads[i] =3D spapr_create_vcpu(sc, i, spapr, &local_err); if (local_err) { goto err; } } =20 - for (j =3D 0; j < cc->nr_threads; j++) { - spapr_realize_vcpu(sc->threads[j], spapr, &local_err); - if (local_err) { - goto err_unrealize; - } - } return; =20 -err_unrealize: - while (--j >=3D 0) { - spapr_unrealize_vcpu(sc->threads[i]); - } err: while (--i >=3D 0) { spapr_delete_vcpu(sc->threads[i]);