From nobody Sat Oct 25 23:42:21 2025 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 1516180958244150.8845131481761; Wed, 17 Jan 2018 01:22:38 -0800 (PST) Received: from localhost ([::1]:49906 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebjvZ-0001zH-CN for importer@patchew.org; Wed, 17 Jan 2018 04:22:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebjtb-0000fS-61 for qemu-devel@nongnu.org; Wed, 17 Jan 2018 04:20:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebjtX-0006l8-U6 for qemu-devel@nongnu.org; Wed, 17 Jan 2018 04:20:35 -0500 Received: from 4.mo179.mail-out.ovh.net ([46.105.36.149]:60724) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebjtX-0006k2-No for qemu-devel@nongnu.org; Wed, 17 Jan 2018 04:20:31 -0500 Received: from player716.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id 395A78F163 for ; Wed, 17 Jan 2018 10:20:30 +0100 (CET) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player716.ha.ovh.net (Postfix) with ESMTPA id EAB525600C7; Wed, 17 Jan 2018 10:20:27 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 17 Jan 2018 10:20:27 +0100 Message-ID: <151618082784.20461.10973754439669848191.stgit@bahia.lan> In-Reply-To: <151618081462.20461.3393245354775542888.stgit@bahia.lan> References: <151618081462.20461.3393245354775542888.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: 1539668126166718803 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtvddrtddugddufeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.36.149 Subject: [Qemu-devel] [PATCH 1/3] spapr: drop duplicate variable in spapr_core_plug() 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, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 A variable is already defined at the begining of the function to hold a pointer to the CPU core object: sPAPRCPUCore *core =3D SPAPR_CPU_CORE(OBJECT(dev)); No need to define it again in the pre-2.10 compatibility code snipplet. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 499ab647d882..bca838fce638 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3362,9 +3362,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev, int i; =20 for (i =3D 0; i < cc->nr_threads; i++) { - sPAPRCPUCore *sc =3D SPAPR_CPU_CORE(dev); - - cs =3D CPU(sc->threads[i]); + cs =3D CPU(core->threads[i]); pre_2_10_vmstate_unregister_dummy_icp(cs->cpu_index); } } From nobody Sat Oct 25 23:42:21 2025 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 1516181075273174.36158837919152; Wed, 17 Jan 2018 01:24:35 -0800 (PST) Received: from localhost ([::1]:50006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebjxS-0003tq-Hi for importer@patchew.org; Wed, 17 Jan 2018 04:24:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebjtm-0000qM-7R for qemu-devel@nongnu.org; Wed, 17 Jan 2018 04:20:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebjti-0006ra-Up for qemu-devel@nongnu.org; Wed, 17 Jan 2018 04:20:46 -0500 Received: from 6.mo179.mail-out.ovh.net ([46.105.56.76]:57945) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebjti-0006pS-OO for qemu-devel@nongnu.org; Wed, 17 Jan 2018 04:20:42 -0500 Received: from player716.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id B888E913C1 for ; Wed, 17 Jan 2018 10:20:37 +0100 (CET) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player716.ha.ovh.net (Postfix) with ESMTPA id 2A2D25600C3; Wed, 17 Jan 2018 10:20:35 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 17 Jan 2018 10:20:35 +0100 Message-ID: <151618083506.20461.14178623580944316317.stgit@bahia.lan> In-Reply-To: <151618081462.20461.3393245354775542888.stgit@bahia.lan> References: <151618081462.20461.3393245354775542888.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: 1541638449612429651 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtvddrtddugddufeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.56.76 Subject: [Qemu-devel] [PATCH 2/3] spapr_cpu_core: don't reset CPUs during realization 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, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 When QEMU is started, all cold-plugged CPUs are reset twice: first during initialization and then during machine reset. This is sub- optimal. The first reset is only needed for hot-plugged CPUs because the CPU hotplug code doesn't reset them. This patch adds the necessary code to reset hot-plugged CPUs on the CPU core hotplug path, and removes the now useless initial CPU reset. We just need to mark the newly created CPU as halted to prevent it to run until it is put online later. Full CPU reset is now explicitely triggered from the machine code only, either during system reset or during CPU hotplug. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 8 ++++++++ hw/ppc/spapr_cpu_core.c | 8 ++++++-- include/hw/ppc/spapr_cpu_core.h | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index bca838fce638..a2ff401f738a 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3336,6 +3336,14 @@ static void spapr_core_plug(HotplugHandler *hotplug_= dev, DeviceState *dev, void *fdt; int fdt_offset; =20 + if (hotplugged) { + int i; + + for (i =3D 0; i < cc->nr_threads; i++) { + spapr_cpu_reset(core->threads[i]); + } + } + fdt =3D spapr_populate_hotplug_cpu_dt(cs, &fdt_offset, spapr); =20 spapr_drc_attach(drc, dev, fdt, fdt_offset, &local_err); diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index ac19b2e0b72c..268be7784efb 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -22,7 +22,7 @@ #include "sysemu/hw_accel.h" #include "qemu/error-report.h" =20 -static void spapr_cpu_reset(void *opaque) +void spapr_cpu_reset(void *opaque) { PowerPCCPU *cpu =3D opaque; CPUState *cs =3D CPU(cpu); @@ -63,7 +63,11 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, Pow= erPCCPU *cpu, cpu_ppc_set_papr(cpu, PPC_VIRTUAL_HYPERVISOR(spapr)); =20 qemu_register_reset(spapr_cpu_reset, cpu); - spapr_cpu_reset(cpu); + + /* CPU must not execute anything until explicitely started otherwise t= he + * guest will crash. + */ + CPU(cpu)->halted =3D 1; } =20 /* diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_cor= e.h index 1129f344aa0c..763a2168461e 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -38,4 +38,6 @@ typedef struct sPAPRCPUCoreClass { } sPAPRCPUCoreClass; =20 const char *spapr_get_cpu_core_type(const char *cpu_type); +void spapr_cpu_reset(void *opaque); + #endif From nobody Sat Oct 25 23:42:21 2025 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 151618097902974.45314591814974; Wed, 17 Jan 2018 01:22:59 -0800 (PST) Received: from localhost ([::1]:49919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebjvu-0002Fw-4f for importer@patchew.org; Wed, 17 Jan 2018 04:22:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebjtq-0000v3-Qb for qemu-devel@nongnu.org; Wed, 17 Jan 2018 04:20:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebjtn-0006vb-5p for qemu-devel@nongnu.org; Wed, 17 Jan 2018 04:20:50 -0500 Received: from 7.mo179.mail-out.ovh.net ([46.105.61.94]:44205) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebjtm-0006u3-Rn for qemu-devel@nongnu.org; Wed, 17 Jan 2018 04:20:47 -0500 Received: from player716.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id 35DB38FB11 for ; Wed, 17 Jan 2018 10:20:45 +0100 (CET) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player716.ha.ovh.net (Postfix) with ESMTPA id 95FD55600B6; Wed, 17 Jan 2018 10:20:42 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 17 Jan 2018 10:20:42 +0100 Message-ID: <151618084250.20461.13884400486623011064.stgit@bahia.lan> In-Reply-To: <151618081462.20461.3393245354775542888.stgit@bahia.lan> References: <151618081462.20461.3393245354775542888.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: 1543608775356815699 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtvddrtddugddufeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.61.94 Subject: [Qemu-devel] [PATCH 3/3] spapr: fix device tree properties when using compatibility mode 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, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Commit 51f84465dd98 changed the compatility mode setting logic: - machine reset only sets compatibility mode for the boot CPU - compatibility mode is set for other CPUs when they are put online by the guest with the "start-cpu" RTAS call This causes a regression for machines started with max-compat-cpu: the device tree nodes related to secondary CPU cores contain wrong "cpu-version" and "ibm,pa-features" values, as shown below. Guest started on a POWER8 host with: -smp cores=3D2 -machine pseries,max-cpu-compat=3Dcompat7 # dtc -f -I fs -O dts /proc/device-tree | egrep 'cpu-version|pa-features' ibm,pa-features =3D [18 00 f6 3f c7 c0 80 f0 80 00 00 00 00 00 00 00 00 00 80 00 80 00 80 00 00 00]; cpu-version =3D <0x4d0200>; ^^^ second CPU core ibm,pa-features =3D <0x600f63f 0xc70080c0>; cpu-version =3D <0xf000003>; ^^^ boot CPU core The second core is advertised in raw POWER8 mode. This happens because CAS assumes all CPUs to have the same compatibility mode. Since the boot CPU already has the requested compatibility mode, the CAS code does not set it for the secondary one, and exposes the bogus device tree properties in in the CAS response to the guest. A similar situation is observed when hot-plugging a CPU core. The related device tree properties are generated and exposed to guest with the "ibm,configure-connector" RTAS before "start-cpu" is called. The CPU core is advertised to the guest in raw mode as well. It both cases, it boils down to the fact that "start-cpu" happens too late. This can be fixed globally by propagating the compatibility mode of the boot CPU to the other CPUs during reset. For this to work, the compatibility mode of the boot CPU must be set before the machine code actually resets all CPUs. It is not needed to set the compatibility mode in "start-cpu" anymore, so the code is dropped. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 18 +++++++++--------- hw/ppc/spapr_cpu_core.c | 7 +++++++ hw/ppc/spapr_rtas.c | 9 --------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a2ff401f738a..a00bff823f95 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1484,6 +1484,15 @@ static void spapr_machine_reset(void) spapr_setup_hpt_and_vrma(spapr); } =20 + /* if this reset wasn't generated by CAS, we should reset our + * negotiated options and start from scratch */ + if (!spapr->cas_reboot) { + spapr_ovec_cleanup(spapr->ov5_cas); + spapr->ov5_cas =3D spapr_ovec_new(); + + ppc_set_compat(first_ppc_cpu, spapr->max_compat_pvr, &error_fatal); + } + qemu_devices_reset(); =20 /* DRC reset may cause a device to be unplugged. This will cause troub= les @@ -1504,15 +1513,6 @@ static void spapr_machine_reset(void) rtas_addr =3D rtas_limit - RTAS_MAX_SIZE; fdt_addr =3D rtas_addr - FDT_MAX_SIZE; =20 - /* if this reset wasn't generated by CAS, we should reset our - * negotiated options and start from scratch */ - if (!spapr->cas_reboot) { - spapr_ovec_cleanup(spapr->ov5_cas); - spapr->ov5_cas =3D spapr_ovec_new(); - - ppc_set_compat(first_ppc_cpu, spapr->max_compat_pvr, &error_fatal); - } - fdt =3D spapr_build_fdt(spapr, rtas_addr, spapr->rtas_size); =20 spapr_load_rtas(spapr, fdt, rtas_addr); diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 268be7784efb..f5e5ead5f4b0 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -44,6 +44,13 @@ void spapr_cpu_reset(void *opaque) if (cs !=3D first_cpu) { env->spr[SPR_LPCR] &=3D ~pcc->lpcr_pm; } + + /* Set compatibility mode to match the boot CPU, which was either set + * by the machine reset code or by CAS. This should never fail. + */ + if (cs !=3D first_cpu) { + ppc_set_compat(cpu, POWERPC_CPU(first_cpu)->compat_pvr, &error_abo= rt); + } } =20 static void spapr_cpu_destroy(PowerPCCPU *cpu) diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 2b89e1d448e4..4bb939d3d111 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -163,7 +163,6 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachi= neState *spapr, CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); - Error *local_err =3D NULL; =20 if (!cs->halted) { rtas_st(rets, 0, RTAS_OUT_HW_ERROR); @@ -175,14 +174,6 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMach= ineState *spapr, * new cpu enters */ kvm_cpu_synchronize_state(cs); =20 - /* Set compatibility mode to match existing cpus */ - ppc_set_compat(cpu, POWERPC_CPU(first_cpu)->compat_pvr, &local_err= ); - if (local_err) { - error_report_err(local_err); - rtas_st(rets, 0, RTAS_OUT_HW_ERROR); - return; - } - env->msr =3D (1ULL << MSR_SF) | (1ULL << MSR_ME); =20 /* Enable Power-saving mode Exit Cause exceptions for the new CPU = */