From nobody Thu Apr 25 23:54:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1602797354; cv=none; d=zohomail.com; s=zohoarc; b=cxKzsFT4Zjij70jDJHODQiQpjuXEw7fidbACXik3TfmqdA9CkTZX/3Lq8mCNEWOV1uv9Ee4s/bLaPXl9xLDoGUMQ2RAjMpU7PFFfPMt3DwISR4403Q2zZjQ+JAWLuijtlPYXCe144NQpFhtodeHNoCCwSFOJB3q61G7x84ptbh4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602797354; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ac0suURcJKo63wouGonNv8P9xtbyUzXcBbzMz2oF+8k=; b=Y/S6zJtqrZZpTNAZhEiSn4PTROgAjFQACgbSoMDaRWbIkIo3dsLEPLpQBJR4TMzEtFd6qv9GDjqYUvdigYZTzV8C0pDaGdpjr1uZJk2uB+rb8oRjSAFyyFy5wNAYK8VvsfJseZXk3cWIfZQhoUg4ZlbPv9wgIxZrQqw60NUQAp8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602797354586969.3153240736802; Thu, 15 Oct 2020 14:29:14 -0700 (PDT) Received: from localhost ([::1]:48086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTAoD-0005RE-5U for importer@patchew.org; Thu, 15 Oct 2020 17:29:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTAha-0007r5-Eu for qemu-devel@nongnu.org; Thu, 15 Oct 2020 17:22:24 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:53063) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kTAhY-0001ZZ-0h for qemu-devel@nongnu.org; Thu, 15 Oct 2020 17:22:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-473-j1UHeKcCMxSkP1SEha9QxQ-1; Thu, 15 Oct 2020 17:18:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CB428030DC; Thu, 15 Oct 2020 21:18:27 +0000 (UTC) Received: from bahia.lan (ovpn-112-78.ams2.redhat.com [10.36.112.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 616C976673; Thu, 15 Oct 2020 21:18:26 +0000 (UTC) X-MC-Unique: j1UHeKcCMxSkP1SEha9QxQ-1 Subject: [PATCH v2 1/5] spapr: Fix leak of CPU machine specific data From: Greg Kurz To: David Gibson Date: Thu, 15 Oct 2020 23:18:25 +0200 Message-ID: <160279670540.1808373.17319746576919615623.stgit@bahia.lan> In-Reply-To: <160279669833.1808373.9524145092720289601.stgit@bahia.lan> References: <160279669833.1808373.9524145092720289601.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 17:18:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When a CPU core is being removed, the machine specific data of each CPU thread object is leaked. Fix this by calling the dedicated helper we have for that instead of simply unparenting the CPU object. Call it from a separate loop in spapr_cpu_core_unrealize() for symmetry with spapr_cpu_core_realize(). Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index b03620823adb..c55211214524 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -188,7 +188,6 @@ static void spapr_unrealize_vcpu(PowerPCCPU *cpu, Spapr= CpuCore *sc) } spapr_irq_cpu_intc_destroy(SPAPR_MACHINE(qdev_get_machine()), cpu); cpu_remove_sync(CPU(cpu)); - object_unparent(OBJECT(cpu)); } =20 /* @@ -213,6 +212,15 @@ static void spapr_cpu_core_reset_handler(void *opaque) spapr_cpu_core_reset(opaque); } =20 +static void spapr_delete_vcpu(PowerPCCPU *cpu, SpaprCpuCore *sc) +{ + SpaprCpuState *spapr_cpu =3D spapr_cpu_state(cpu); + + cpu->machine_data =3D NULL; + g_free(spapr_cpu); + object_unparent(OBJECT(cpu)); +} + static void spapr_cpu_core_unrealize(DeviceState *dev) { SpaprCpuCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); @@ -224,6 +232,9 @@ static void spapr_cpu_core_unrealize(DeviceState *dev) for (i =3D 0; i < cc->nr_threads; i++) { spapr_unrealize_vcpu(sc->threads[i], sc); } + for (i =3D 0; i < cc->nr_threads; i++) { + spapr_delete_vcpu(sc->threads[i], sc); + } g_free(sc->threads); } =20 @@ -294,15 +305,6 @@ err: return NULL; } =20 -static void spapr_delete_vcpu(PowerPCCPU *cpu, SpaprCpuCore *sc) -{ - SpaprCpuState *spapr_cpu =3D spapr_cpu_state(cpu); - - cpu->machine_data =3D NULL; - g_free(spapr_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 From nobody Thu Apr 25 23:54:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1602796986; cv=none; d=zohomail.com; s=zohoarc; b=kDavI/BCjGP6uCurLwQbwFGkk4ROF6FTWmU7VlGFq/Xt7flL4mFsqRtOrwd6S+8+MHaNV6zj4foz6GRTCsBaXoECDKCWMXJjw9qHKW2/zXkOH0Q+N07FQPdZDw+wnyQSVRwXSqF0npuM1qHLf/FZ6LOc12jMRaAL1r4yiZJ77S8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602796986; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GqZF4if23WTPNT5zyI6GflZHwZk07FOs2KbTomqn2Y8=; b=KzIOqZ6NfdMfJNAJkLh5fXZBfKGA6gOawY6dPgnUdYtxO0c6Azu1obcUvAAAGJrdbN78+k9O+CkM5qrOPzdrpXmSUvcTerDA234pX3bdHYjSP5PT2FlI3W8roAa/jRouqLfV5R0HPjXLXWQpMKR/6rcfxMPTiBOo1vPciKj6n00= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602796986276195.63837012205533; Thu, 15 Oct 2020 14:23:06 -0700 (PDT) Received: from localhost ([::1]:33882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTAiH-0007of-48 for importer@patchew.org; Thu, 15 Oct 2020 17:23:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTAgO-0006Yv-DC for qemu-devel@nongnu.org; Thu, 15 Oct 2020 17:21:08 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:28323) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kTAgM-0001V3-QE for qemu-devel@nongnu.org; Thu, 15 Oct 2020 17:21:08 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-63-8AiGXCELNCqNDW6G6a9MSw-1; Thu, 15 Oct 2020 17:18:35 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B10F18A822B; Thu, 15 Oct 2020 21:18:34 +0000 (UTC) Received: from bahia.lan (ovpn-112-78.ams2.redhat.com [10.36.112.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 538CF76663; Thu, 15 Oct 2020 21:18:33 +0000 (UTC) X-MC-Unique: 8AiGXCELNCqNDW6G6a9MSw-1 Subject: [PATCH v2 2/5] spapr: Unrealize vCPUs with qdev_unrealize() From: Greg Kurz To: David Gibson Date: Thu, 15 Oct 2020 23:18:32 +0200 Message-ID: <160279671236.1808373.14732005038172874990.stgit@bahia.lan> In-Reply-To: <160279669833.1808373.9524145092720289601.stgit@bahia.lan> References: <160279669833.1808373.9524145092720289601.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 17:18:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Since we introduced CPU hot-unplug in sPAPR, we don't unrealize the vCPU objects explicitly. Instead, we let QOM handle that for us under object_property_del_all() when the CPU core object is finalized. The only thing we do is calling cpu_remove_sync() to tear the vCPU thread down. This happens to work but it is ugly because: - we call qdev_realize() but the corresponding qdev_unrealize() is buried deep in the QOM code - we call cpu_remove_sync() to undo qemu_init_vcpu() called by ppc_cpu_realize() in target/ppc/translate_init.c.inc - the CPU init and teardown paths aren't really symmetrical The latter didn't bite us so far but a future patch that greatly simplifies the CPU core realize path needs it to avoid a crash in QOM. For all these reasons, have ppc_cpu_unrealize() to undo the changes of ppc_cpu_realize() by calling cpu_remove_sync() at the right place, and have the sPAPR CPU core code to call qdev_unrealize(). This requires to add a missing stub because translate_init.c.inc is also compiled for user mode. Signed-off-by: Greg Kurz --- accel/tcg/user-exec-stub.c | 4 ++++ hw/ppc/spapr_cpu_core.c | 4 ++-- target/ppc/translate_init.c.inc | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/accel/tcg/user-exec-stub.c b/accel/tcg/user-exec-stub.c index f6d8c8fb6f2d..b876f5c1e45d 100644 --- a/accel/tcg/user-exec-stub.c +++ b/accel/tcg/user-exec-stub.c @@ -9,6 +9,10 @@ void cpu_resume(CPUState *cpu) { } =20 +void cpu_remove_sync(CPUState *cpu) +{ +} + void qemu_init_vcpu(CPUState *cpu) { } diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index c55211214524..e4aeb93c0299 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -187,7 +187,7 @@ static void spapr_unrealize_vcpu(PowerPCCPU *cpu, Spapr= CpuCore *sc) vmstate_unregister(NULL, &vmstate_spapr_cpu_state, cpu->machine_da= ta); } spapr_irq_cpu_intc_destroy(SPAPR_MACHINE(qdev_get_machine()), cpu); - cpu_remove_sync(CPU(cpu)); + qdev_unrealize(DEVICE(cpu)); } =20 /* @@ -255,7 +255,7 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMa= chineState *spapr, kvmppc_set_papr(cpu); =20 if (spapr_irq_cpu_intc_create(spapr, cpu, errp) < 0) { - cpu_remove_sync(CPU(cpu)); + qdev_unrealize(DEVICE(cpu)); return false; } =20 diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.= inc index bb66526280ef..d2a8204d6011 100644 --- a/target/ppc/translate_init.c.inc +++ b/target/ppc/translate_init.c.inc @@ -10328,6 +10328,8 @@ static void ppc_cpu_unrealize(DeviceState *dev) =20 pcc->parent_unrealize(dev); =20 + cpu_remove_sync(CPU(cpu)); + for (i =3D 0; i < PPC_CPU_OPCODES_LEN; i++) { if (cpu->opcodes[i] =3D=3D &invalid_handler) { continue; From nobody Thu Apr 25 23:54:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1602796820; cv=none; d=zohomail.com; s=zohoarc; b=BMhe4HcpTE7uEPyb9IE4D70mqUaCXSXWyNdygg6LeAHdFeCfL/2Eq7H9q4Q3jhgXEFq6qU+KQNvbWfXcJeXu5+EoHHS8RIe3OgtIc2YRKZzlsxbdUXZFa+CVKsu3F7q3OlVqHIWyfWOt3wm1OIY3ze5qPme1f7ezXTSsx7CUP4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602796820; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RUjDravabxB40C0AGeaziuS+YehywD2uqS/GgvkOfzw=; b=Tkzy5HTpPciLfeckZgT6ADiNt27T533PYPTNLHhsC0Pcs2uxImUMYVqOhsxDXn0Tlcp4bcvDwV1heoNLGpzIVK47Z4VmBJp2Qv1a7/TEjlLoUmUdoBH8ao4f+Ac8kYMmj/z+LXhVaxd6nabUaaqrBOgDnpEfQ6BReWTltZuNCU8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602796820751303.7811987975648; Thu, 15 Oct 2020 14:20:20 -0700 (PDT) Received: from localhost ([::1]:56220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTAfb-0005I2-Bv for importer@patchew.org; Thu, 15 Oct 2020 17:20:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTAe8-0004Jt-9r for qemu-devel@nongnu.org; Thu, 15 Oct 2020 17:18:48 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:27988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kTAe6-0001Cz-Nz for qemu-devel@nongnu.org; Thu, 15 Oct 2020 17:18:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-512-IfEXydzVMKe9jT1HNtmcYQ-1; Thu, 15 Oct 2020 17:18:42 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0172F1019625; Thu, 15 Oct 2020 21:18:41 +0000 (UTC) Received: from bahia.lan (ovpn-112-78.ams2.redhat.com [10.36.112.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43914610F3; Thu, 15 Oct 2020 21:18:40 +0000 (UTC) X-MC-Unique: IfEXydzVMKe9jT1HNtmcYQ-1 Subject: [PATCH v2 3/5] spapr: Drop spapr_delete_vcpu() unused argument From: Greg Kurz To: David Gibson Date: Thu, 15 Oct 2020 23:18:39 +0200 Message-ID: <160279671929.1808373.10333672533575251075.stgit@bahia.lan> In-Reply-To: <160279669833.1808373.9524145092720289601.stgit@bahia.lan> References: <160279669833.1808373.9524145092720289601.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 17:18:44 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The 'sc' argument is unused. Drop it. Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index e4aeb93c0299..45eb2121876e 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -212,7 +212,7 @@ static void spapr_cpu_core_reset_handler(void *opaque) spapr_cpu_core_reset(opaque); } =20 -static void spapr_delete_vcpu(PowerPCCPU *cpu, SpaprCpuCore *sc) +static void spapr_delete_vcpu(PowerPCCPU *cpu) { SpaprCpuState *spapr_cpu =3D spapr_cpu_state(cpu); =20 @@ -233,7 +233,7 @@ static void spapr_cpu_core_unrealize(DeviceState *dev) spapr_unrealize_vcpu(sc->threads[i], sc); } for (i =3D 0; i < cc->nr_threads; i++) { - spapr_delete_vcpu(sc->threads[i], sc); + spapr_delete_vcpu(sc->threads[i]); } g_free(sc->threads); } @@ -345,7 +345,7 @@ err_unrealize: } err: while (--i >=3D 0) { - spapr_delete_vcpu(sc->threads[i], sc); + spapr_delete_vcpu(sc->threads[i]); } g_free(sc->threads); } From nobody Thu Apr 25 23:54:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1602796847; cv=none; d=zohomail.com; s=zohoarc; b=G3KmcQ/cqJigA2pCWpZ26bFzbOTRPIpX4ot1Ol9cx3FB7TqbhuF+W0Z+SBcGKMgjWuHNTUPnpn8rrxXrMUEfPD2l6FLX29d5O68MmTl9bWAQ3kfm9ilrfPnpCkCNTX2VIwpBHYe9bDwZCuKgCWHJxfN38Qk/bIa7HRIIyBrZaQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602796847; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8+qeh/usq3WaBjkRVtW2073aouRubxmOzVEI27C3cPg=; b=JMv1zpHVTids6DM0aHth4aZ6xBmvXWPgkkiRFhBySxVM4Zmp/0cpCtYpzN4RttVdSglXrehP8QbF9zTg/ltPRIRaqyHU0Bz3r97Q99tlAYuX4xErFHyMlKwewR695KEfFkh2qzI7TaXa1hcT/ZVFjrdG9XzLmSQ3fDDXU6K4wV8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602796847943583.5451534377805; Thu, 15 Oct 2020 14:20:47 -0700 (PDT) Received: from localhost ([::1]:56522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTAg2-0005PY-D2 for importer@patchew.org; Thu, 15 Oct 2020 17:20:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTAeD-0004Ov-EU for qemu-devel@nongnu.org; Thu, 15 Oct 2020 17:18:53 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:43090) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kTAeB-0001DU-T2 for qemu-devel@nongnu.org; Thu, 15 Oct 2020 17:18:53 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-176-yuWT6LbRNjSTn2sZ8uS0VQ-1; Thu, 15 Oct 2020 17:18:49 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4E678030B3; Thu, 15 Oct 2020 21:18:47 +0000 (UTC) Received: from bahia.lan (ovpn-112-78.ams2.redhat.com [10.36.112.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35767610F3; Thu, 15 Oct 2020 21:18:47 +0000 (UTC) X-MC-Unique: yuWT6LbRNjSTn2sZ8uS0VQ-1 Subject: [PATCH v2 4/5] spapr: Make spapr_cpu_core_unrealize() idempotent From: Greg Kurz To: David Gibson Date: Thu, 15 Oct 2020 23:18:46 +0200 Message-ID: <160279672626.1808373.14142129300586424514.stgit@bahia.lan> In-Reply-To: <160279669833.1808373.9524145092720289601.stgit@bahia.lan> References: <160279669833.1808373.9524145092720289601.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 17:18:44 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 --- 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 45eb2121876e..317fb9934f58 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 =3D CPU_CORE(dev); int i; =20 - qemu_unregister_reset(spapr_cpu_core_reset_handler, sc); - for (i =3D 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 =3D 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); } =20 static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr, @@ -322,32 +333,22 @@ static void spapr_cpu_core_realize(DeviceState *dev, = Error **errp) return; } =20 - sc->threads =3D g_new(PowerPCCPU *, cc->nr_threads); + qemu_register_reset(spapr_cpu_core_reset_handler, sc); + sc->threads =3D g_new0(PowerPCCPU *, cc->nr_threads); for (i =3D 0; i < cc->nr_threads; i++) { sc->threads[i] =3D spapr_create_vcpu(sc, i, errp); if (!sc->threads[i]) { - goto err; + spapr_cpu_core_unrealize(dev); + return; } } =20 for (j =3D 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 >=3D 0) { - spapr_unrealize_vcpu(sc->threads[j], sc); - } -err: - while (--i >=3D 0) { - spapr_delete_vcpu(sc->threads[i]); - } - g_free(sc->threads); } =20 static Property spapr_cpu_core_properties[] =3D { From nobody Thu Apr 25 23:54:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1602796985; cv=none; d=zohomail.com; s=zohoarc; b=Kuth8MwMleqbQ0Orb/xFSmMxGCJBxOTAkoqdkK1hewmyDZQv5lC4sS6PCmlzt3S1otNN2Ear6BPhe+u+0JSlFSQISlbPJlnpSDydQEoeAqeoXNIjV2mAF+X2AYyRrdpwrzYbla9sfLQMeUBE0TAemVlbctLi/wqpZ6PXd7WA57s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602796985; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4Odn1ao7xV7zshy/qTmLlaVFa8vt5vWVlWppck8uF+0=; b=EyCMZODHSWwVSsKpjULwFX5vFXbd3aBUJA1Q/rlMbdLgUb/aewitwYhKPnJDH9jn4Zs+KDHH0PRO0xDqahtXdKdQY+PFBSD7NN7ElJ1nFiLKFmlmU63ljp/Qrt31cX5+WD/aPnyYm1YWlB49fwQFTmHwMMEjURPncy61feRis5o= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602796985735949.6009987207754; Thu, 15 Oct 2020 14:23:05 -0700 (PDT) Received: from localhost ([::1]:33826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTAiC-0007nR-BR for importer@patchew.org; Thu, 15 Oct 2020 17:23:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTAeL-0004c7-Ir for qemu-devel@nongnu.org; Thu, 15 Oct 2020 17:19:01 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:49307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kTAeJ-0001Do-4c for qemu-devel@nongnu.org; Thu, 15 Oct 2020 17:19:01 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-519-edjElHy5NOSg5FY3J8C8Xg-1; Thu, 15 Oct 2020 17:18:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1B3518A8221; Thu, 15 Oct 2020 21:18:54 +0000 (UTC) Received: from bahia.lan (ovpn-112-78.ams2.redhat.com [10.36.112.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26D2A75128; Thu, 15 Oct 2020 21:18:53 +0000 (UTC) X-MC-Unique: edjElHy5NOSg5FY3J8C8Xg-1 Subject: [PATCH v2 5/5] spapr: Simplify spapr_cpu_core_realize() and spapr_cpu_core_unrealize() From: Greg Kurz To: David Gibson Date: Thu, 15 Oct 2020 23:18:53 +0200 Message-ID: <160279673321.1808373.2248221100790367912.stgit@bahia.lan> In-Reply-To: <160279669833.1808373.9524145092720289601.stgit@bahia.lan> References: <160279669833.1808373.9524145092720289601.stgit@bahia.lan> User-Agent: StGit/0.21 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 17:18:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Now that the error path of spapr_cpu_core_realize() is just to call idempotent spapr_cpu_core_unrealize() for rollback, no need to create and realize the vCPUs in two separate loops. Merge them and do them same in spapr_cpu_core_unrealize() for symmetry. Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 317fb9934f58..2f7dc3c23ded 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -238,10 +238,6 @@ static void spapr_cpu_core_unrealize(DeviceState *dev) &error_abort)) { spapr_unrealize_vcpu(sc->threads[i], sc); } - } - } - for (i =3D 0; i < cc->nr_threads; i++) { - if (sc->threads[i]) { spapr_delete_vcpu(sc->threads[i]); } } @@ -326,7 +322,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Er= ror **errp) TYPE_SPAPR_MACHINE); SpaprCpuCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); CPUCore *cc =3D CPU_CORE(OBJECT(dev)); - int i, j; + int i; =20 if (!spapr) { error_setg(errp, TYPE_SPAPR_CPU_CORE " needs a pseries machine"); @@ -337,14 +333,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, E= rror **errp) sc->threads =3D g_new0(PowerPCCPU *, cc->nr_threads); for (i =3D 0; i < cc->nr_threads; i++) { sc->threads[i] =3D spapr_create_vcpu(sc, i, errp); - if (!sc->threads[i]) { - spapr_cpu_core_unrealize(dev); - return; - } - } - - for (j =3D 0; j < cc->nr_threads; j++) { - if (!spapr_realize_vcpu(sc->threads[j], spapr, sc, errp)) { + if (!sc->threads[i] || + !spapr_realize_vcpu(sc->threads[i], spapr, sc, errp)) { spapr_cpu_core_unrealize(dev); return; }