From nobody Mon Feb 9 20:10:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1571729471; cv=none; d=zoho.com; s=zohoarc; b=OBDDSsTyhNwGVrQdWS1R/lhPspgVs/Mzm+HJkFLGxiQQ5En1/N391VOqkrwbmbRwxr3yFQRUAZEvYqemqUWTmCf1/nw8ilQpwVjtLt02BNlNzZhm7tRuuALBaI0IRF0XG7dgM7U6iVO7YRl9riu5IZIdHvSCSK+sobZmp/ViTd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571729471; 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=1f1mFsdO0OVnLalNAFqQ4h4mBeXZpsO+PColetJULbk=; b=BrXovgp6k4unuEr0Trihgpajqb9Ivhto+UyTXVYdNZIDfE+KAcx531MOEp0D5n70w1gmyaNPsoPWzhd/Cec6oqkwMw472mol9LnnUWURbCaU0Z3GwLm6zmfNjTAh9s/sX9nUDUy0immYe2vzpWzuYZ9AuFMFgRPHkGr7nb+t4wo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1571729471737202.92320375724194; Tue, 22 Oct 2019 00:31:11 -0700 (PDT) Received: from localhost ([::1]:51068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iModK-0008H8-HC for importer@patchew.org; Tue, 22 Oct 2019 03:31:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39352) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMoVj-0006fO-CG for qemu-devel@nongnu.org; Tue, 22 Oct 2019 03:23:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iMoVi-0005lh-4s for qemu-devel@nongnu.org; Tue, 22 Oct 2019 03:23:19 -0400 Received: from 5.mo4.mail-out.ovh.net ([188.165.44.50]:50711) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iMoVh-0005kl-Uz for qemu-devel@nongnu.org; Tue, 22 Oct 2019 03:23:18 -0400 Received: from player786.ha.ovh.net (unknown [10.109.160.230]) by mo4.mail-out.ovh.net (Postfix) with ESMTP id E195F20C911 for ; Tue, 22 Oct 2019 09:23:15 +0200 (CEST) Received: from kaod.org (lfbn-1-2229-223.w90-76.abo.wanadoo.fr [90.76.50.223]) (Authenticated sender: clg@kaod.org) by player786.ha.ovh.net (Postfix) with ESMTPSA id 36FF6B518B08; Tue, 22 Oct 2019 07:23:10 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Subject: [PATCH v3 2/4] spapr_cpu_core: Implement DeviceClass::reset Date: Tue, 22 Oct 2019 09:22:44 +0200 Message-Id: <20191022072246.9200-3-clg@kaod.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191022072246.9200-1-clg@kaod.org> References: <20191022072246.9200-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 12565887388731542502 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedufedrkeeigdduudelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.44.50 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: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Greg Kurz Since vCPUs aren't plugged into a bus, we manually register a reset handler for each vCPU. We also call this handler at realize time to ensure hot plugged vCPUs are reset before being exposed to the guest. This results in vCPUs being reset twice at machine reset. It doesn't break anything but it is slightly suboptimal and above all confusing. The hotplug path in device_set_realized() already knows how to reset a hotplugged device if the device reset handler is present. Implement one for sPAPR CPU cores that resets all vCPUs under a core. While here rename spapr_cpu_reset() to spapr_reset_vcpu() for consistency with spapr_realize_vcpu() and spapr_unrealize_vcpu(). Signed-off-by: Greg Kurz Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/ppc/spapr_cpu_core.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 992f00da6540..5947e39b36ad 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -25,9 +25,8 @@ #include "sysemu/hw_accel.h" #include "qemu/error-report.h" =20 -static void spapr_cpu_reset(void *opaque) +static void spapr_reset_vcpu(PowerPCCPU *cpu) { - PowerPCCPU *cpu =3D opaque; CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); @@ -193,7 +192,6 @@ static void spapr_unrealize_vcpu(PowerPCCPU *cpu, Spapr= CpuCore *sc) if (!sc->pre_3_0_migration) { vmstate_unregister(NULL, &vmstate_spapr_cpu_state, cpu->machine_da= ta); } - qemu_unregister_reset(spapr_cpu_reset, cpu); if (spapr_cpu_state(cpu)->icp) { object_unparent(OBJECT(spapr_cpu_state(cpu)->icp)); } @@ -204,12 +202,30 @@ static void spapr_unrealize_vcpu(PowerPCCPU *cpu, Spa= prCpuCore *sc) object_unparent(OBJECT(cpu)); } =20 +static void spapr_cpu_core_reset(DeviceState *dev) +{ + CPUCore *cc =3D CPU_CORE(dev); + SpaprCpuCore *sc =3D SPAPR_CPU_CORE(dev); + int i; + + for (i =3D 0; i < cc->nr_threads; i++) { + spapr_reset_vcpu(sc->threads[i]); + } +} + +static void spapr_cpu_core_reset_handler(void *opaque) +{ + spapr_cpu_core_reset(opaque); +} + static void spapr_cpu_core_unrealize(DeviceState *dev, Error **errp) { SpaprCpuCore *sc =3D SPAPR_CPU_CORE(OBJECT(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); } @@ -238,12 +254,6 @@ static void spapr_realize_vcpu(PowerPCCPU *cpu, SpaprM= achineState *spapr, goto error_intc_create; } =20 - /* - * FIXME: Hot-plugged CPUs are not reseted. Do it at realize. - */ - qemu_register_reset(spapr_cpu_reset, cpu); - spapr_cpu_reset(cpu); - if (!sc->pre_3_0_migration) { vmstate_register(NULL, cs->cpu_index, &vmstate_spapr_cpu_state, cpu->machine_data); @@ -338,6 +348,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, Er= ror **errp) goto err_unrealize; } } + + qemu_register_reset(spapr_cpu_core_reset_handler, sc); return; =20 err_unrealize: @@ -366,6 +378,7 @@ static void spapr_cpu_core_class_init(ObjectClass *oc, = void *data) =20 dc->realize =3D spapr_cpu_core_realize; dc->unrealize =3D spapr_cpu_core_unrealize; + dc->reset =3D spapr_cpu_core_reset; dc->props =3D spapr_cpu_core_properties; scc->cpu_type =3D data; } --=20 2.21.0