From nobody Sat Apr 27 17:14:55 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.zoho.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 1495190205778587.8387626486441; Fri, 19 May 2017 03:36:45 -0700 (PDT) Received: from localhost ([::1]:57691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBfH2-0003hx-Ay for importer@patchew.org; Fri, 19 May 2017 06:36:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBfCh-0000IX-Px for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBfCe-0007iK-Hp for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:15 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56902) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBfCe-0007i4-8Y for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:12 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4JAO3CL097568 for ; Fri, 19 May 2017 06:32:10 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ahw45nbq6-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 19 May 2017 06:32:10 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 19 May 2017 04:32:10 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 19 May 2017 04:32:07 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4JAW6ld12910888; Fri, 19 May 2017 03:32:06 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B460CBE038; Fri, 19 May 2017 04:32:06 -0600 (MDT) Received: from bahia.lan (unknown [9.164.171.209]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 48B7BBE039; Fri, 19 May 2017 04:32:05 -0600 (MDT) From: Greg Kurz To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Date: Fri, 19 May 2017 12:32:04 +0200 In-Reply-To: <149518991537.24289.6673616934370284758.stgit@bahia.lan> References: <149518991537.24289.6673616934370284758.stgit@bahia.lan> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 x-cbid: 17051910-0028-0000-0000-0000079F5BCE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007084; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000212; SDB=6.00862547; UDB=6.00427978; IPR=6.00642296; BA=6.00005358; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015508; XFM=3.00000015; UTC=2017-05-19 10:32:09 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051910-0029-0000-0000-000035D29ACD Message-Id: <149518992406.24289.10624548011389715164.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-19_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705190064 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 1/4] spapr_cpu_core: drop reference on ICP object during CPU 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: Laurent Vivier , David Gibson , Cedric Le Goater , Bharata B Rao Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 When a piece of code allocates an object, it implicitely gets a reference on it. If it then makes that object a child property of another object, it should drop its own reference at some point otherwise the child object can never be finalized. The current code hence leaks one ICP object per CPU when hot-removing a core. Failing to add a newly allocated ICP object to the CPU is a bug. While here, let's ensure QEMU aborts if this ever happens. Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 1df1404ea52d..ff7058ecc00e 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -143,7 +143,8 @@ static void spapr_cpu_core_realize_child(Object *child,= Error **errp) Object *obj; =20 obj =3D object_new(spapr->icp_type); - object_property_add_child(OBJECT(cpu), "icp", obj, NULL); + object_property_add_child(OBJECT(cpu), "icp", obj, &error_abort); + object_unref(obj); object_property_add_const_link(obj, "xics", OBJECT(spapr), &error_abor= t); object_property_set_bool(obj, true, "realized", &local_err); if (local_err) { From nobody Sat Apr 27 17:14:55 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.zoho.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 1495190056909706.2914408279595; Fri, 19 May 2017 03:34:16 -0700 (PDT) Received: from localhost ([::1]:57677 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBfEd-0001iD-Fa for importer@patchew.org; Fri, 19 May 2017 06:34:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBfCp-0000NV-OQ for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBfCm-0007l2-JL for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:23 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57742 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBfCm-0007kj-Ed for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:20 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4JAO5c9061214 for ; Fri, 19 May 2017 06:32:19 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ahr3j21nc-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 19 May 2017 06:32:18 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 19 May 2017 04:32:18 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 19 May 2017 04:32:15 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4JAWEvv15073600; Fri, 19 May 2017 03:32:14 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B3167C604A; Fri, 19 May 2017 04:32:14 -0600 (MDT) Received: from bahia.lan (unknown [9.164.171.209]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 2E9DBC6047; Fri, 19 May 2017 04:32:12 -0600 (MDT) From: Greg Kurz To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Date: Fri, 19 May 2017 12:32:12 +0200 In-Reply-To: <149518991537.24289.6673616934370284758.stgit@bahia.lan> References: <149518991537.24289.6673616934370284758.stgit@bahia.lan> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 x-cbid: 17051910-0004-0000-0000-0000122E4C2D X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007084; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000212; SDB=6.00862547; UDB=6.00427978; IPR=6.00642296; BA=6.00005358; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015508; XFM=3.00000015; UTC=2017-05-19 10:32:16 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051910-0005-0000-0000-00007F5B1320 Message-Id: <149518993198.24289.7946457258780782948.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-19_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705190064 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v2 2/4] spapr: fix error reporting in xics_system_init() 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: Laurent Vivier , David Gibson , Cedric Le Goater , Bharata B Rao Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 If the user explicitely asked for kernel-irqchip support and "xics-kvm" initialization fails, we shouldn't fallback to emulated "xics" as we do now. It is also awkward to print an error message when we have an errp pointer argument. Let's use the errp argument to report the error and let the caller decide. This simplifies the code as we don't need a local Error * here. Signed-off-by: Greg Kurz --- v2: - total rewrite --- hw/ppc/spapr.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 91f7434861a8..75e298b4c6be 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -128,18 +128,14 @@ static void xics_system_init(MachineState *machine, i= nt nr_irqs, Error **errp) sPAPRMachineState *spapr =3D SPAPR_MACHINE(machine); =20 if (kvm_enabled()) { - Error *err =3D NULL; - if (machine_kernel_irqchip_allowed(machine) && !xics_kvm_init(spapr, errp)) { spapr->icp_type =3D TYPE_KVM_ICP; - spapr->ics =3D spapr_ics_create(spapr, TYPE_ICS_KVM, nr_irqs, = &err); + spapr->ics =3D spapr_ics_create(spapr, TYPE_ICS_KVM, nr_irqs, = errp); } if (machine_kernel_irqchip_required(machine) && !spapr->ics) { - error_reportf_err(err, - "kernel_irqchip requested but unavailable: "= ); - } else { - error_free(err); + error_prepend(errp, "kernel_irqchip requested but unavailable:= "); + return; } } =20 @@ -147,6 +143,9 @@ static void xics_system_init(MachineState *machine, int= nr_irqs, Error **errp) xics_spapr_init(spapr); spapr->icp_type =3D TYPE_ICP; spapr->ics =3D spapr_ics_create(spapr, TYPE_ICS_SIMPLE, nr_irqs, e= rrp); + if (!spapr->ics) { + return; + } } } =20 From nobody Sat Apr 27 17:14:55 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.zoho.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 14951900686708.25002763937755; Fri, 19 May 2017 03:34:28 -0700 (PDT) Received: from localhost ([::1]:57678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBfEp-0001sZ-4G for importer@patchew.org; Fri, 19 May 2017 06:34:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBfCw-0000W9-N6 for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBfCt-0007mP-FP for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:30 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47994) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBfCt-0007mB-5G for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:27 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4JAUFSv058363 for ; Fri, 19 May 2017 06:32:26 -0400 Received: from e16.ny.us.ibm.com (e16.ny.us.ibm.com [129.33.205.206]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ahnff7gac-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 19 May 2017 06:32:25 -0400 Received: from localhost by e16.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 19 May 2017 06:32:24 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e16.ny.us.ibm.com (146.89.104.203) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 19 May 2017 06:32:22 -0400 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4JAWNvh43254002; Fri, 19 May 2017 10:32:23 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CDD082803E; Fri, 19 May 2017 06:32:16 -0400 (EDT) Received: from bahia.lan (unknown [9.164.171.209]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id AEEC92803A; Fri, 19 May 2017 06:32:15 -0400 (EDT) From: Greg Kurz To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Date: Fri, 19 May 2017 12:32:20 +0200 In-Reply-To: <149518991537.24289.6673616934370284758.stgit@bahia.lan> References: <149518991537.24289.6673616934370284758.stgit@bahia.lan> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 x-cbid: 17051910-0024-0000-0000-000002745140 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007084; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000212; SDB=6.00862547; UDB=6.00427978; IPR=6.00642296; BA=6.00005358; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015508; XFM=3.00000015; UTC=2017-05-19 10:32:24 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051910-0025-0000-0000-0000440E7AEA Message-Id: <149518994010.24289.12584852638589552255.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-19_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705190064 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 3/4] target/ppc: consolidate CPU device-tree id computation in helper 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: Laurent Vivier , David Gibson , Cedric Le Goater , Bharata B Rao Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 For historical reasons, we compute CPU device-tree ids with a non-trivial logic. This patch consolidate the logic in a single helper to be used in various places where it is currently open-coded. It is okay to get rid of DIV_ROUND_UP() because we're sure that the number of threads per core in the guest cannot exceed the number of threads per core in the host. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 6 ++---- target/ppc/cpu.h | 17 +++++++++++++++++ target/ppc/translate_init.c | 3 +-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 75e298b4c6be..1bb05a9a6b07 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -981,7 +981,6 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr, void *fdt; sPAPRPHBState *phb; char *buf; - int smt =3D kvmppc_smt_threads(); =20 fdt =3D g_malloc0(FDT_MAX_SIZE); _FDT((fdt_create_empty_tree(fdt, FDT_MAX_SIZE))); @@ -1021,7 +1020,7 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr, _FDT(fdt_setprop_cell(fdt, 0, "#size-cells", 2)); =20 /* /interrupt controller */ - spapr_dt_xics(DIV_ROUND_UP(max_cpus * smt, smp_threads), fdt, PHANDLE_= XICP); + spapr_dt_xics(ppc_cpu_dt_id_from_index(max_cpus), fdt, PHANDLE_XICP); =20 ret =3D spapr_populate_memory(spapr, fdt); if (ret < 0) { @@ -1977,7 +1976,6 @@ static void spapr_init_cpus(sPAPRMachineState *spapr) MachineState *machine =3D MACHINE(spapr); MachineClass *mc =3D MACHINE_GET_CLASS(machine); char *type =3D spapr_get_cpu_core_type(machine->cpu_model); - int smt =3D kvmppc_smt_threads(); const CPUArchIdList *possible_cpus; int boot_cores_nr =3D smp_cpus / smp_threads; int i; @@ -2014,7 +2012,7 @@ static void spapr_init_cpus(sPAPRMachineState *spapr) sPAPRDRConnector *drc =3D spapr_dr_connector_new(OBJECT(spapr), SPAPR_DR_CONNECTOR_TYPE_CPU, - (core_id / smp_threads) * smt); + ppc_cpu_dt_id_from_index(core_id)); =20 qemu_register_reset(spapr_drc_reset, drc); } diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 401e10e7dad8..47fe6c64698f 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -2529,4 +2529,21 @@ int ppc_get_vcpu_dt_id(PowerPCCPU *cpu); PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id); =20 void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len); + +#if !defined(CONFIG_USER_ONLY) +#include "sysemu/cpus.h" +#include "target/ppc/kvm_ppc.h" + +static inline int ppc_cpu_dt_id_from_index(int cpu_index) +{ + /* POWER HV support has an historical limitation that different threads + * on a single core cannot be in different guests at the same time. In + * order to allow KVM to assign guest threads to host cores accordingl= y, + * CPU device tree ids are spaced by the number of threads per host co= res. + */ + return (cpu_index / smp_threads) * kvmppc_smt_threads() + + (cpu_index % smp_threads); +} +#endif + #endif /* PPC_CPU_H */ diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index 56a0ab22cfbe..837a9a496a65 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -9851,8 +9851,7 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error= **errp) } =20 #if !defined(CONFIG_USER_ONLY) - cpu->cpu_dt_id =3D (cs->cpu_index / smp_threads) * max_smt - + (cs->cpu_index % smp_threads); + cpu->cpu_dt_id =3D ppc_cpu_dt_id_from_index(cs->cpu_index); =20 if (kvm_enabled() && !kvm_vcpu_id_is_valid(cpu->cpu_dt_id)) { error_setg(errp, "Can't create CPU with id %d in KVM", cpu->cpu_dt= _id); From nobody Sat Apr 27 17:14:55 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.zoho.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 1495190218680842.4065048210235; Fri, 19 May 2017 03:36:58 -0700 (PDT) Received: from localhost ([::1]:57692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBfHF-0003sB-89 for importer@patchew.org; Fri, 19 May 2017 06:36:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBfD3-0000f2-Ts for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBfD0-0007us-KS for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:37 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47525 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBfD0-0007ue-F9 for qemu-devel@nongnu.org; Fri, 19 May 2017 06:32:34 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4JAO8tJ171716 for ; Fri, 19 May 2017 06:32:33 -0400 Received: from e16.ny.us.ibm.com (e16.ny.us.ibm.com [129.33.205.206]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ahvaxg1dy-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 19 May 2017 06:32:33 -0400 Received: from localhost by e16.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 19 May 2017 06:32:33 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e16.ny.us.ibm.com (146.89.104.203) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 19 May 2017 06:32:30 -0400 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4JAWTQI43253766; Fri, 19 May 2017 10:32:29 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38E6F124037; Fri, 19 May 2017 06:32:24 -0400 (EDT) Received: from bahia.lan (unknown [9.164.171.209]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP id 0A71912403F; Fri, 19 May 2017 06:32:22 -0400 (EDT) From: Greg Kurz To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Date: Fri, 19 May 2017 12:32:27 +0200 In-Reply-To: <149518991537.24289.6673616934370284758.stgit@bahia.lan> References: <149518991537.24289.6673616934370284758.stgit@bahia.lan> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 x-cbid: 17051910-0024-0000-0000-000002745143 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007084; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000212; SDB=6.00862547; UDB=6.00427978; IPR=6.00642296; BA=6.00005358; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015508; XFM=3.00000015; UTC=2017-05-19 10:32:32 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051910-0025-0000-0000-0000440E7AFB Message-Id: <149518994738.24289.215239362416048889.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-19_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705190064 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v2 4/4] spapr: fix migration of ICP objects from/to older QEMU 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: Laurent Vivier , David Gibson , Cedric Le Goater , Bharata B Rao Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Commit 5bc8d26de20c ("spapr: allocate the ICPState object from under sPAPRCPUCore") moved ICP objects from the machine to CPU cores. This is an improvement since we no longer allocate ICP objects that will never be used. But it has the side-effect of breaking migration of older machine types from older QEMU versions. This patch introduces a compat flag in the sPAPR machine class so that all pseries machine up to 2.9 go on with the previous behavior of pre-allocating ICP objects. Signed-off-by: Greg Kurz --- v2: - s/void* /void * in xics_system_init() - don't use "[*]" in the ICP object name - use pre_2_10_ prefix in field names - added xics_nr_servers() helper --- hw/ppc/spapr.c | 40 +++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_cpu_core.c | 29 ++++++++++++++++++++--------- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 1bb05a9a6b07..182262257c60 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -123,9 +123,15 @@ error: return NULL; } =20 +static inline int xics_nr_servers(void) +{ + return ppc_cpu_dt_id_from_index(max_cpus); +} + static void xics_system_init(MachineState *machine, int nr_irqs, Error **e= rrp) { sPAPRMachineState *spapr =3D SPAPR_MACHINE(machine); + sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(spapr); =20 if (kvm_enabled()) { if (machine_kernel_irqchip_allowed(machine) && @@ -147,6 +153,35 @@ static void xics_system_init(MachineState *machine, in= t nr_irqs, Error **errp) return; } } + + if (smc->pre_2_10_icp_allocation) { + int nr_servers =3D xics_nr_servers(); + Error *local_err =3D NULL; + int i; + + spapr->pre_2_10_icps =3D g_malloc0(nr_servers * sizeof(ICPState)); + + for (i =3D 0; i < nr_servers; i++) { + void *obj =3D &spapr->pre_2_10_icps[i]; + char *name =3D g_strdup_printf("icp[%d]", i); + + object_initialize(obj, sizeof(ICPState), spapr->icp_type); + object_property_add_child(OBJECT(spapr), name, obj, &error_abo= rt); + g_free(name); + object_unref(obj); + object_property_add_const_link(obj, "xics", OBJECT(spapr), + &error_abort); + object_property_set_bool(obj, true, "realized", &local_err); + if (local_err) { + while (i--) { + object_unparent(obj); + } + g_free(spapr->pre_2_10_icps); + error_propagate(errp, local_err); + break; + } + } + } } =20 static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu, @@ -1020,7 +1055,7 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr, _FDT(fdt_setprop_cell(fdt, 0, "#size-cells", 2)); =20 /* /interrupt controller */ - spapr_dt_xics(ppc_cpu_dt_id_from_index(max_cpus), fdt, PHANDLE_XICP); + spapr_dt_xics(xics_nr_servers(), fdt, PHANDLE_XICP); =20 ret =3D spapr_populate_memory(spapr, fdt); if (ret < 0) { @@ -3286,9 +3321,12 @@ static void spapr_machine_2_9_instance_options(Machi= neState *machine) =20 static void spapr_machine_2_9_class_options(MachineClass *mc) { + sPAPRMachineClass *smc =3D SPAPR_MACHINE_CLASS(mc); + spapr_machine_2_10_class_options(mc); SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_9); mc->numa_auto_assign_ram =3D numa_legacy_auto_assign_ram; + smc->pre_2_10_icp_allocation =3D true; } =20 DEFINE_SPAPR_MACHINE(2_9, "2.9", false); diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index ff7058ecc00e..13c4916aa5e6 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -119,6 +119,7 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev= , Error **errp) size_t size =3D object_type_get_instance_size(typename); CPUCore *cc =3D CPU_CORE(dev); int i; + sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); =20 for (i =3D 0; i < cc->nr_threads; i++) { void *obj =3D sc->threads + i * size; @@ -127,7 +128,9 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev= , Error **errp) PowerPCCPU *cpu =3D POWERPC_CPU(cs); =20 spapr_cpu_destroy(cpu); - object_unparent(cpu->intc); + if (!spapr->pre_2_10_icps) { + object_unparent(cpu->intc); + } cpu_remove_sync(cs); object_unparent(obj); } @@ -142,13 +145,19 @@ static void spapr_cpu_core_realize_child(Object *chil= d, Error **errp) PowerPCCPU *cpu =3D POWERPC_CPU(cs); Object *obj; =20 - obj =3D object_new(spapr->icp_type); - object_property_add_child(OBJECT(cpu), "icp", obj, &error_abort); - object_unref(obj); - object_property_add_const_link(obj, "xics", OBJECT(spapr), &error_abor= t); - object_property_set_bool(obj, true, "realized", &local_err); - if (local_err) { - goto error; + if (spapr->pre_2_10_icps) { + int index =3D cpu->parent_obj.cpu_index; + + obj =3D OBJECT(&spapr->pre_2_10_icps[index]); + } else { + obj =3D object_new(spapr->icp_type); + object_property_add_child(OBJECT(cpu), "icp", obj, &error_abort); + object_property_add_const_link(obj, "xics", OBJECT(spapr), + &error_abort); + object_property_set_bool(obj, true, "realized", &local_err); + if (local_err) { + goto error; + } } =20 object_property_set_bool(child, true, "realized", &local_err); @@ -165,7 +174,9 @@ static void spapr_cpu_core_realize_child(Object *child,= Error **errp) return; =20 error: - object_unparent(obj); + if (!spapr->pre_2_10_icps) { + object_unparent(obj); + } error_propagate(errp, local_err); } =20 diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index f875dc41d811..d1dcf0c8bddf 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -54,6 +54,7 @@ struct sPAPRMachineClass { bool use_ohci_by_default; /* use USB-OHCI instead of XHCI */ bool pre_2_9_cas_pvr; /* Use old logic for PVR compat negotiation= */ const char *tcg_default_cpu; /* which (TCG) CPU to simulate by default= */ + bool pre_2_10_icp_allocation; void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio,=20 hwaddr *mmio32, hwaddr *mmio64, @@ -110,6 +111,7 @@ struct sPAPRMachineState { MemoryHotplugState hotplug_memory; =20 const char *icp_type; + ICPState *pre_2_10_icps; }; =20 #define H_SUCCESS 0