From nobody Mon Nov 17 12:08:26 2025 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=1603808778; cv=none; d=zohomail.com; s=zohoarc; b=X1l47FYr3DYEIiNIBhca1vAe+4NWx4oxVgsMBur2NjMMaHFS6c8AcisVxbopXiyL9BCKV2MJATZB85brkewRlkABry/yyPAKAdHAKCA+Bz3eDParzz7Cm7CQ4KTy/K74NksXErDXDMiAW86tdfDapJa5GG+ErO+UtuwjIsYGEsI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603808778; h=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=NRhXGcwCkZEY02GS2fzs5KTTH6QMNs9P9UMIcSfXWIE=; b=k/6B5GYMJwy9K0mLBZZ/0aq93c2pM7X+BaKpEkU2ZQiI41mCsVAxjlTqqXePWp+7EFBCqwjzFpYg7uPnMCZugC8rHzRtuuYookqdlzqOJoo3FjQGBvpS7Q2OgALDH053Hke8o5AT2aBNXh/qbmXCamwUGt+ekfuCcu0qYEvnZzk= 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 1603808776544590.2620939923936; Tue, 27 Oct 2020 07:26:16 -0700 (PDT) Received: from localhost ([::1]:43056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXPvT-00043N-PI for importer@patchew.org; Tue, 27 Oct 2020 10:26:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXPnX-0001yS-Gz; Tue, 27 Oct 2020 10:18:03 -0400 Received: from ozlabs.org ([203.11.71.1]:42485) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXPnV-0007aX-KK; Tue, 27 Oct 2020 10:18:03 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4CLDLg5K0vz9shj; Wed, 28 Oct 2020 01:17:46 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1603808267; bh=Pf4juhFstmmAMYCHTE12mN63e/5PUNwa8GocFdwzAdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vam4PjeBKkjJv5jzYBfc4sTXJiRdS7lmkJlKJrsrgy2ChO/p7RxA8QjcLVWvOLJmO Nta6dRjJZMr3IeY5qdQurkeNJEqSw4V7sJVnJMGHlo+L6wRpF8dNUDStDRrZ+5ZDF9 f7VRiCrbA/fbG0kIlUcWI5TMjRLXl+WuqLNTFshA= From: David Gibson To: peter.maydell@linaro.org Subject: [PULL 08/18] spapr: Make spapr_cpu_core_unrealize() idempotent Date: Wed, 28 Oct 2020 01:17:25 +1100 Message-Id: <20201027141735.728821-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201027141735.728821-1-david@gibson.dropbear.id.au> References: <20201027141735.728821-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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: pass client-ip=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 10:17:43 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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: David Gibson , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, groug@kaod.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Greg Kurz 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 Message-Id: <160279672626.1808373.14142129300586424514.stgit@bahia.lan> Signed-off-by: David Gibson --- 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 =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 { --=20 2.26.2