From nobody Sun Apr 28 19:09:30 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 1493573288543675.4506719601355; Sun, 30 Apr 2017 10:28:08 -0700 (PDT) Received: from localhost ([::1]:45371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4sdj-0006a6-69 for importer@patchew.org; Sun, 30 Apr 2017 13:28:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4sbu-0005N7-BY for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4sbs-0005s6-Ka for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:14 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46468) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d4sbs-0005rQ-CJ for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:12 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3UHNf5M019231 for ; Sun, 30 Apr 2017 13:26:10 -0400 Received: from e24smtp02.br.ibm.com (e24smtp02.br.ibm.com [32.104.18.86]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a4n5evsrv-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 30 Apr 2017 13:26:10 -0400 Received: from localhost by e24smtp02.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 30 Apr 2017 14:26:07 -0300 Received: from d24relay03.br.ibm.com (9.18.232.225) by e24smtp02.br.ibm.com (10.172.0.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 30 Apr 2017 14:26:04 -0300 Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.8.31.91]) by d24relay03.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3UHQ49931064190; Sun, 30 Apr 2017 14:26:04 -0300 Received: from d24av01.br.ibm.com (localhost [127.0.0.1]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3UHQ33g024601; Sun, 30 Apr 2017 14:26:03 -0300 Received: from localhost.localdomain ([9.85.167.102]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3UHPwCS024582; Sun, 30 Apr 2017 14:26:01 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Sun, 30 Apr 2017 14:25:43 -0300 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170430172547.13415-1-danielhb@linux.vnet.ibm.com> References: <20170430172547.13415-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17043017-0020-0000-0000-000002A4AA30 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17043017-0021-0000-0000-000030C1E45D Message-Id: <20170430172547.13415-2-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-30_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704300140 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 1/5] hw/ppc: setting spapr_drc_detach_cb in spapr_dr_connector_new 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.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The idea of moving the detach callback functions to the constructor of the dr_connector is to set them statically at init time, avoiding any post-load hooks to restore it (after a migration, for example). Summary of changes: - hw/ppc/spapr_drc.c and include/hw/ppc/spapr_drc.h: * spapr_dr_connector_new() now has an additional parameter, spapr_drc_detach_cb *detach_cb * 'spapr_drc_detach_cb *detach_cb' parameter was removed of the detach function pointer in sPAPRDRConnectorClass - hw/ppc/spapr_pci.c: * the callback 'spapr_phb_remove_pci_device_cb' is now passed as a parameter in 'spapr_dr_connector_new' instead of 'drck->detach()' - hw/ppc/spapr.c: * 'spapr_create_lmb_dr_connectors' now passes the callback 'spapr_lmb_release' to 'spapr_dr_connector_new' instead of 'drck-detach()' * 'spapr_init_cpus' now passes the callback 'spapr_core_release' to 'spapr_dr_connector_new' instead of 'drck-detach()' * moved the callback functions up in the code so they can be referenced by 'spapr_create_lmb_dr_connectors' and 'spapr_init_cpus' Signed-off-by: Daniel Henrique Barboza Reviewed-by: Laurent Vivier --- hw/ppc/spapr.c | 71 +++++++++++++++++++++++-------------------= ---- hw/ppc/spapr_drc.c | 17 ++++++----- hw/ppc/spapr_pci.c | 5 ++-- include/hw/ppc/spapr_drc.h | 4 +-- 4 files changed, 49 insertions(+), 48 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 80d12d0..bc11757 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1887,6 +1887,29 @@ static void spapr_drc_reset(void *opaque) } } =20 +typedef struct sPAPRDIMMState { + uint32_t nr_lmbs; +} sPAPRDIMMState; + +static void spapr_lmb_release(DeviceState *dev, void *opaque) +{ + sPAPRDIMMState *ds =3D (sPAPRDIMMState *)opaque; + HotplugHandler *hotplug_ctrl; + + if (--ds->nr_lmbs) { + return; + } + + g_free(ds); + + /* + * Now that all the LMBs have been removed by the guest, call the + * pc-dimm unplug handler to cleanup up the pc-dimm device. + */ + hotplug_ctrl =3D qdev_get_hotplug_handler(dev); + hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); +} + static void spapr_create_lmb_dr_connectors(sPAPRMachineState *spapr) { MachineState *machine =3D MACHINE(spapr); @@ -1900,7 +1923,7 @@ static void spapr_create_lmb_dr_connectors(sPAPRMachi= neState *spapr) =20 addr =3D i * lmb_size + spapr->hotplug_memory.base; drc =3D spapr_dr_connector_new(OBJECT(spapr), SPAPR_DR_CONNECTOR_T= YPE_LMB, - addr/lmb_size); + (addr / lmb_size), spapr_lmb_release); qemu_register_reset(spapr_drc_reset, drc); } } @@ -1956,6 +1979,14 @@ static CPUArchId *spapr_find_cpu_slot(MachineState *= ms, uint32_t id, int *idx) return &ms->possible_cpus->cpus[index]; } =20 +static void spapr_core_release(DeviceState *dev, void *opaque) +{ + HotplugHandler *hotplug_ctrl; + + hotplug_ctrl =3D qdev_get_hotplug_handler(dev); + hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); +} + static void spapr_init_cpus(sPAPRMachineState *spapr) { MachineState *machine =3D MACHINE(spapr); @@ -1998,7 +2029,8 @@ 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); + (core_id / smp_threads) * smt, + spapr_core_release); =20 qemu_register_reset(spapr_drc_reset, drc); } @@ -2596,29 +2628,6 @@ out: error_propagate(errp, local_err); } =20 -typedef struct sPAPRDIMMState { - uint32_t nr_lmbs; -} sPAPRDIMMState; - -static void spapr_lmb_release(DeviceState *dev, void *opaque) -{ - sPAPRDIMMState *ds =3D (sPAPRDIMMState *)opaque; - HotplugHandler *hotplug_ctrl; - - if (--ds->nr_lmbs) { - return; - } - - g_free(ds); - - /* - * Now that all the LMBs have been removed by the guest, call the - * pc-dimm unplug handler to cleanup up the pc-dimm device. - */ - hotplug_ctrl =3D qdev_get_hotplug_handler(dev); - hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); -} - static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t= size, Error **errp) { @@ -2636,7 +2645,7 @@ static void spapr_del_lmbs(DeviceState *dev, uint64_t= addr_start, uint64_t size, g_assert(drc); =20 drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->detach(drc, dev, spapr_lmb_release, ds, errp); + drck->detach(drc, dev, ds, errp); addr +=3D SPAPR_MEMORY_BLOCK_SIZE; } =20 @@ -2712,14 +2721,6 @@ static void spapr_core_unplug(HotplugHandler *hotplu= g_dev, DeviceState *dev, object_unparent(OBJECT(dev)); } =20 -static void spapr_core_release(DeviceState *dev, void *opaque) -{ - HotplugHandler *hotplug_ctrl; - - hotplug_ctrl =3D qdev_get_hotplug_handler(dev); - hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); -} - static void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *d= ev, Error **errp) @@ -2745,7 +2746,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplu= g_dev, DeviceState *dev, g_assert(drc); =20 drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->detach(drc, dev, spapr_core_release, NULL, &local_err); + drck->detach(drc, dev, NULL, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index a1cdc87..afe5d82 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -99,8 +99,8 @@ static uint32_t set_isolation_state(sPAPRDRConnector *drc, if (drc->awaiting_release) { if (drc->configured) { trace_spapr_drc_set_isolation_state_finalizing(get_index(d= rc)); - drck->detach(drc, DEVICE(drc->dev), drc->detach_cb, - drc->detach_cb_opaque, NULL); + drck->detach(drc, DEVICE(drc->dev), drc->detach_cb_opaque, + NULL); } else { trace_spapr_drc_set_isolation_state_deferring(get_index(dr= c)); } @@ -153,8 +153,8 @@ static uint32_t set_allocation_state(sPAPRDRConnector *= drc, if (drc->awaiting_release && drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNUSABL= E) { trace_spapr_drc_set_allocation_state_finalizing(get_index(drc)= ); - drck->detach(drc, DEVICE(drc->dev), drc->detach_cb, - drc->detach_cb_opaque, NULL); + drck->detach(drc, DEVICE(drc->dev), drc->detach_cb_opaque, + NULL); } else if (drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_= USABLE) { drc->awaiting_allocation =3D false; } @@ -405,12 +405,10 @@ static void attach(sPAPRDRConnector *drc, DeviceState= *d, void *fdt, } =20 static void detach(sPAPRDRConnector *drc, DeviceState *d, - spapr_drc_detach_cb *detach_cb, void *detach_cb_opaque, Error **errp) { trace_spapr_drc_detach(get_index(drc)); =20 - drc->detach_cb =3D detach_cb; drc->detach_cb_opaque =3D detach_cb_opaque; =20 /* if we've signalled device presence to the guest, or if the guest @@ -498,8 +496,7 @@ static void reset(DeviceState *d) * force removal if we are */ if (drc->awaiting_release) { - drck->detach(drc, DEVICE(drc->dev), drc->detach_cb, - drc->detach_cb_opaque, NULL); + drck->detach(drc, DEVICE(drc->dev), drc->detach_cb_opaque, NUL= L); } =20 /* non-PCI devices may be awaiting a transition to UNUSABLE */ @@ -566,7 +563,8 @@ static void unrealize(DeviceState *d, Error **errp) =20 sPAPRDRConnector *spapr_dr_connector_new(Object *owner, sPAPRDRConnectorType type, - uint32_t id) + uint32_t id, + spapr_drc_detach_cb *detach_cb) { sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(object_new(TYPE_SPAPR_DR_CONNECTOR)); @@ -577,6 +575,7 @@ sPAPRDRConnector *spapr_dr_connector_new(Object *owner, drc->type =3D type; drc->id =3D id; drc->owner =3D owner; + drc->detach_cb =3D detach_cb; prop_name =3D g_strdup_printf("dr-connector[%"PRIu32"]", get_index(drc= )); object_property_add_child(owner, prop_name, OBJECT(drc), NULL); object_property_set_bool(OBJECT(drc), true, "realized", NULL); diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index e7567e2..935e65e 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1392,7 +1392,7 @@ static void spapr_phb_remove_pci_device(sPAPRDRConnec= tor *drc, { sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); =20 - drck->detach(drc, DEVICE(pdev), spapr_phb_remove_pci_device_cb, phb, e= rrp); + drck->detach(drc, DEVICE(pdev), phb, errp); } =20 static sPAPRDRConnector *spapr_phb_get_pci_func_drc(sPAPRPHBState *phb, @@ -1764,7 +1764,8 @@ static void spapr_phb_realize(DeviceState *dev, Error= **errp) for (i =3D 0; i < PCI_SLOT_MAX * 8; i++) { spapr_dr_connector_new(OBJECT(phb), SPAPR_DR_CONNECTOR_TYPE_PCI, - (sphb->index << 16) | i); + (sphb->index << 16) | i, + spapr_phb_remove_pci_device_cb); } } =20 diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 5524247..0a2c173 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -189,7 +189,6 @@ typedef struct sPAPRDRConnectorClass { void (*attach)(sPAPRDRConnector *drc, DeviceState *d, void *fdt, int fdt_start_offset, bool coldplug, Error **errp); void (*detach)(sPAPRDRConnector *drc, DeviceState *d, - spapr_drc_detach_cb *detach_cb, void *detach_cb_opaque, Error **errp); bool (*release_pending)(sPAPRDRConnector *drc); void (*set_signalled)(sPAPRDRConnector *drc); @@ -197,7 +196,8 @@ typedef struct sPAPRDRConnectorClass { =20 sPAPRDRConnector *spapr_dr_connector_new(Object *owner, sPAPRDRConnectorType type, - uint32_t id); + uint32_t id, + spapr_drc_detach_cb *detach_cb); sPAPRDRConnector *spapr_dr_connector_by_index(uint32_t index); sPAPRDRConnector *spapr_dr_connector_by_id(sPAPRDRConnectorType type, uint32_t id); --=20 2.9.3 From nobody Sun Apr 28 19:09:30 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 1493573383760180.99009480468305; Sun, 30 Apr 2017 10:29:43 -0700 (PDT) Received: from localhost ([::1]:45380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4sfG-0007pf-18 for importer@patchew.org; Sun, 30 Apr 2017 13:29:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4sbw-0005OE-DD for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4sbt-0005tQ-8S for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:16 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:53292 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 1d4sbt-0005sI-2c for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:13 -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 v3UHNgic060510 for ; Sun, 30 Apr 2017 13:26:12 -0400 Received: from e24smtp01.br.ibm.com (e24smtp01.br.ibm.com [32.104.18.85]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a4ptx1ss8-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 30 Apr 2017 13:26:12 -0400 Received: from localhost by e24smtp01.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 30 Apr 2017 14:26:10 -0300 Received: from d24relay02.br.ibm.com (9.18.232.42) by e24smtp01.br.ibm.com (10.172.0.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 30 Apr 2017 14:26:07 -0300 Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.8.31.91]) by d24relay02.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3UHQ7AF27263110; Sun, 30 Apr 2017 14:26:07 -0300 Received: from d24av01.br.ibm.com (localhost [127.0.0.1]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3UHQ6BW024655; Sun, 30 Apr 2017 14:26:06 -0300 Received: from localhost.localdomain ([9.85.167.102]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3UHPwCT024582; Sun, 30 Apr 2017 14:26:04 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Sun, 30 Apr 2017 14:25:44 -0300 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170430172547.13415-1-danielhb@linux.vnet.ibm.com> References: <20170430172547.13415-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17043017-1523-0000-0000-0000029AACD2 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17043017-1524-0000-0000-00002A30EC4E Message-Id: <20170430172547.13415-3-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-30_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704300140 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 2/5] hw/ppc: removing spapr_drc_detach_cb opaques 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.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Following up the previous detach_cb change, this patch removes the detach_cb_opaque entirely from the code. The reason is that the drc->detach_cb_opaque object can't be restored in the post load of the upcoming DRC migration and no detach callbacks actually need this opaque. 'spapr_core_release' is receiving it as NULL, 'spapr_phb_remove_pci_device_cb' is receiving a phb object as opaque but is't using it. These were trivial removal cases. However, the LM removal callback 'spapr_lmb_release' is receiving and using the opaque object, a 'sPAPRDIMMState' struct. This struct holds the number of LMBs the DIMM object contains and the callback was using this counter as a countdown to check if all LMB DRCs were release before proceeding to the DIMM unplug. To remove the need of this callback we have choices such as: - migrate the 'sPAPRDIMMState' struct. This would require creating a QTAILQ to store all DIMMStates and an additional 'dimm_id' field to associate the DIMMState with the DIMM object. We could attach this QTAILQ to the 'sPAPRPHBState' and retrieve it later in the callback. - fetch the state of the LMB DRCs directly by scanning the state of them and, if all of them are released, proceed with the DIMM unplug. The second approach was chosen. The new 'spapr_all_lmbs_drcs_released' function scans all LMBs of a given DIMM device to see if their DRC state are inactive. If all of them are inactive return 'true', 'false' otherwise. This function is being called inside the 'spapr_lmb_release' callback, replacing the role of the 'sPAPRDIMMState' opaque. The 'sPAPRDIMMState' struct was removed from the code given that there are no more uses for it. After all these changes, there are no roles left for the 'detach_cb_opaque' attribute of the 'sPAPRDRConnector' as well, so we can safely remove it from the code too. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 46 +++++++++++++++++++++++++++++++++---------= ---- hw/ppc/spapr_drc.c | 16 +++++----------- hw/ppc/spapr_pci.c | 4 ++-- include/hw/ppc/spapr_drc.h | 6 ++---- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index bc11757..8b9a6cf 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1887,21 +1887,43 @@ static void spapr_drc_reset(void *opaque) } } =20 -typedef struct sPAPRDIMMState { - uint32_t nr_lmbs; -} sPAPRDIMMState; +static bool spapr_all_lmbs_drcs_released(PCDIMMDevice *dimm) +{ + Error *local_err =3D NULL; + PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + MemoryRegion *mr =3D ddc->get_memory_region(dimm); + uint64_t size =3D memory_region_size(mr); + + uint64_t addr; + addr =3D object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &loc= al_err); + if (local_err) { + error_propagate(&error_abort, local_err); + return false; + } + uint32_t nr_lmbs =3D size / SPAPR_MEMORY_BLOCK_SIZE; =20 -static void spapr_lmb_release(DeviceState *dev, void *opaque) + sPAPRDRConnector *drc; + int i =3D 0; + for (i =3D 0; i < nr_lmbs; i++) { + drc =3D spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB, + addr / SPAPR_MEMORY_BLOCK_SIZE); + g_assert(drc); + if (drc->indicator_state !=3D SPAPR_DR_INDICATOR_STATE_INACTIVE) { + return false; + } + addr +=3D SPAPR_MEMORY_BLOCK_SIZE; + } + return true; +} + +static void spapr_lmb_release(DeviceState *dev) { - sPAPRDIMMState *ds =3D (sPAPRDIMMState *)opaque; HotplugHandler *hotplug_ctrl; =20 - if (--ds->nr_lmbs) { + if (!spapr_all_lmbs_drcs_released(PC_DIMM(dev))) { return; } =20 - g_free(ds); - /* * Now that all the LMBs have been removed by the guest, call the * pc-dimm unplug handler to cleanup up the pc-dimm device. @@ -1979,7 +2001,7 @@ static CPUArchId *spapr_find_cpu_slot(MachineState *m= s, uint32_t id, int *idx) return &ms->possible_cpus->cpus[index]; } =20 -static void spapr_core_release(DeviceState *dev, void *opaque) +static void spapr_core_release(DeviceState *dev) { HotplugHandler *hotplug_ctrl; =20 @@ -2635,17 +2657,15 @@ static void spapr_del_lmbs(DeviceState *dev, uint64= _t addr_start, uint64_t size, sPAPRDRConnectorClass *drck; uint32_t nr_lmbs =3D size / SPAPR_MEMORY_BLOCK_SIZE; int i; - sPAPRDIMMState *ds =3D g_malloc0(sizeof(sPAPRDIMMState)); uint64_t addr =3D addr_start; =20 - ds->nr_lmbs =3D nr_lmbs; for (i =3D 0; i < nr_lmbs; i++) { drc =3D spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB, addr / SPAPR_MEMORY_BLOCK_SIZE); g_assert(drc); =20 drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->detach(drc, dev, ds, errp); + drck->detach(drc, dev, errp); addr +=3D SPAPR_MEMORY_BLOCK_SIZE; } =20 @@ -2746,7 +2766,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplu= g_dev, DeviceState *dev, g_assert(drc); =20 drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->detach(drc, dev, NULL, &local_err); + drck->detach(drc, dev, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index afe5d82..6f98242 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -99,8 +99,7 @@ static uint32_t set_isolation_state(sPAPRDRConnector *drc, if (drc->awaiting_release) { if (drc->configured) { trace_spapr_drc_set_isolation_state_finalizing(get_index(d= rc)); - drck->detach(drc, DEVICE(drc->dev), drc->detach_cb_opaque, - NULL); + drck->detach(drc, DEVICE(drc->dev), NULL); } else { trace_spapr_drc_set_isolation_state_deferring(get_index(dr= c)); } @@ -153,8 +152,7 @@ static uint32_t set_allocation_state(sPAPRDRConnector *= drc, if (drc->awaiting_release && drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNUSABL= E) { trace_spapr_drc_set_allocation_state_finalizing(get_index(drc)= ); - drck->detach(drc, DEVICE(drc->dev), drc->detach_cb_opaque, - NULL); + drck->detach(drc, DEVICE(drc->dev), NULL); } else if (drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_= USABLE) { drc->awaiting_allocation =3D false; } @@ -404,13 +402,10 @@ static void attach(sPAPRDRConnector *drc, DeviceState= *d, void *fdt, NULL, 0, NULL); } =20 -static void detach(sPAPRDRConnector *drc, DeviceState *d, - void *detach_cb_opaque, Error **errp) +static void detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp) { trace_spapr_drc_detach(get_index(drc)); =20 - drc->detach_cb_opaque =3D detach_cb_opaque; - /* if we've signalled device presence to the guest, or if the guest * has gone ahead and configured the device (via manually-executed * device add via drmgr in guest, namely), we need to wait @@ -455,7 +450,7 @@ static void detach(sPAPRDRConnector *drc, DeviceState *= d, drc->indicator_state =3D SPAPR_DR_INDICATOR_STATE_INACTIVE; =20 if (drc->detach_cb) { - drc->detach_cb(drc->dev, drc->detach_cb_opaque); + drc->detach_cb(drc->dev); } =20 drc->awaiting_release =3D false; @@ -466,7 +461,6 @@ static void detach(sPAPRDRConnector *drc, DeviceState *= d, object_property_del(OBJECT(drc), "device", NULL); drc->dev =3D NULL; drc->detach_cb =3D NULL; - drc->detach_cb_opaque =3D NULL; } =20 static bool release_pending(sPAPRDRConnector *drc) @@ -496,7 +490,7 @@ static void reset(DeviceState *d) * force removal if we are */ if (drc->awaiting_release) { - drck->detach(drc, DEVICE(drc->dev), drc->detach_cb_opaque, NUL= L); + drck->detach(drc, DEVICE(drc->dev), NULL); } =20 /* non-PCI devices may be awaiting a transition to UNUSABLE */ diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 935e65e..c620eee 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1369,7 +1369,7 @@ out: } } =20 -static void spapr_phb_remove_pci_device_cb(DeviceState *dev, void *opaque) +static void spapr_phb_remove_pci_device_cb(DeviceState *dev) { /* some version guests do not wait for completion of a device * cleanup (generally done asynchronously by the kernel) before @@ -1392,7 +1392,7 @@ static void spapr_phb_remove_pci_device(sPAPRDRConnec= tor *drc, { sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); =20 - drck->detach(drc, DEVICE(pdev), phb, errp); + drck->detach(drc, DEVICE(pdev), errp); } =20 static sPAPRDRConnector *spapr_phb_get_pci_func_drc(sPAPRPHBState *phb, diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 0a2c173..f68c90e 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -130,7 +130,7 @@ typedef enum { SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE =3D -9003, } sPAPRDRCCResponse; =20 -typedef void (spapr_drc_detach_cb)(DeviceState *d, void *opaque); +typedef void (spapr_drc_detach_cb)(DeviceState *d); =20 typedef struct sPAPRDRConnector { /*< private >*/ @@ -159,7 +159,6 @@ typedef struct sPAPRDRConnector { /* device pointer, via link property */ DeviceState *dev; spapr_drc_detach_cb *detach_cb; - void *detach_cb_opaque; } sPAPRDRConnector; =20 typedef struct sPAPRDRConnectorClass { @@ -188,8 +187,7 @@ typedef struct sPAPRDRConnectorClass { /* QEMU interfaces for managing hotplug operations */ void (*attach)(sPAPRDRConnector *drc, DeviceState *d, void *fdt, int fdt_start_offset, bool coldplug, Error **errp); - void (*detach)(sPAPRDRConnector *drc, DeviceState *d, - void *detach_cb_opaque, Error **errp); + void (*detach)(sPAPRDRConnector *drc, DeviceState *d, Error **errp); bool (*release_pending)(sPAPRDRConnector *drc); void (*set_signalled)(sPAPRDRConnector *drc); } sPAPRDRConnectorClass; --=20 2.9.3 From nobody Sun Apr 28 19:09:30 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 1493573273811861.3996878720654; Sun, 30 Apr 2017 10:27:53 -0700 (PDT) Received: from localhost ([::1]:45370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4sdU-0006Nf-77 for importer@patchew.org; Sun, 30 Apr 2017 13:27:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4sbv-0005NZ-MQ for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4sbu-0005uV-8z for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:15 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45054 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 1d4sbu-0005ty-3A for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:14 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3UHNfeN027614 for ; Sun, 30 Apr 2017 13:26:13 -0400 Received: from e24smtp02.br.ibm.com (e24smtp02.br.ibm.com [32.104.18.86]) by mx0b-001b2d01.pphosted.com with ESMTP id 2a5m2q8avd-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 30 Apr 2017 13:26:13 -0400 Received: from localhost by e24smtp02.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 30 Apr 2017 14:26:11 -0300 Received: from d24relay03.br.ibm.com (9.18.232.225) by e24smtp02.br.ibm.com (10.172.0.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 30 Apr 2017 14:26:10 -0300 Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.8.31.91]) by d24relay03.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3UHQ9BI31064198; Sun, 30 Apr 2017 14:26:09 -0300 Received: from d24av01.br.ibm.com (localhost [127.0.0.1]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3UHQ9W8024664; Sun, 30 Apr 2017 14:26:09 -0300 Received: from localhost.localdomain ([9.85.167.102]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3UHPwCU024582; Sun, 30 Apr 2017 14:26:07 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Sun, 30 Apr 2017 14:25:45 -0300 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170430172547.13415-1-danielhb@linux.vnet.ibm.com> References: <20170430172547.13415-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17043017-0020-0000-0000-000002A4AA31 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17043017-0021-0000-0000-000030C1E45E Message-Id: <20170430172547.13415-4-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-30_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704300140 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 3/5] hw/ppc: migrating the DRC state of hotplugged devices 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.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In pseries, a firmware abstraction called Dynamic Reconfiguration Connector (DRC) is used to assign a particular dynamic resource to the guest and provide an interface to manage configuration/removal of the resource associated with it. In other words, DRC is the 'plugged state' of a device. Before this patch, DRC wasn't being migrated. This causes post-migration problems due to DRC state mismatch between source and target. The DRC state of a device X in the source might change, while in the target the DRC state of X is still fresh. When migrating the guest, X will not have the same hotplugged state as it did in the source. This means that we can't hot unplug X in the target after migration is completed because its DRC state is not consistent. https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1677552 is one bug that is caused by this DRC state mismatch between source and target. To migrate the DRC state, we defined the VMStateDescription struct for spapr_drc to enable the transmission of spapr_drc state in migration. Not all the elements in the DRC state are migrated - only those that can be modified by guest actions or device add/remove operations: - 'isolation_state', 'allocation_state' and 'configured' are involved in the DR state transition diagram from PAPR+ 2.7, 13.4; - 'configured' and 'signalled' are needed in attaching and detaching devices; - 'indicator_state' provides users with hardware state information. These are the DRC elements that are migrated. In this patch the DRC state is migrated for PCI, LMB and CPU connector types. At this moment there is no support to migrate DRC for the PHB (PCI Host Bridge) type. In the 'realize' function the DRC is registered using vmstate_register, similar to what hw/ppc/spapr_iommu.c does in 'spapr_tce_table_realize'. This approach works because DRCs are bus-less and do not sit on a BusClass that implements bc->get_dev_path, so as a fallback the VMSD gets identified via "spapr_drc"/get_index(drc). Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr_drc.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 61 insertions(+) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 6f98242..0da5f02 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -506,6 +506,64 @@ static void reset(DeviceState *d) } } =20 +static bool spapr_drc_needed(void *opaque) +{ + sPAPRDRConnector *drc =3D (sPAPRDRConnector *)opaque; + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + bool rc =3D false; + sPAPRDREntitySense value; + drck->entity_sense(drc, &value); + /* If no dev is plugged in there is no need to migrate the DRC state */ + if (value !=3D SPAPR_DR_ENTITY_SENSE_PRESENT) { + return false; + } + + /* + * If there is dev plugged in, we need to migrate the DRC state when + * it is different from cold-plugged state + */ + switch (drc->type) { + + case SPAPR_DR_CONNECTOR_TYPE_PCI: + rc =3D !((drc->isolation_state =3D=3D SPAPR_DR_ISOLATION_STATE_UNI= SOLATED) && + (drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_USA= BLE) && + drc->configured && drc->signalled && !drc->awaiting_release= ); + break; + + case SPAPR_DR_CONNECTOR_TYPE_LMB: + rc =3D !((drc->isolation_state =3D=3D SPAPR_DR_ISOLATION_STATE_ISO= LATED) && + (drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNU= SABLE) && + drc->configured && drc->signalled && !drc->awaiting_release= ); + break; + + case SPAPR_DR_CONNECTOR_TYPE_CPU: + rc =3D !((drc->isolation_state =3D=3D SPAPR_DR_ISOLATION_STATE_ISO= LATED) && + (drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNU= SABLE) && + drc->configured && drc->signalled && !drc->awaiting_releas= e); + break; + + default: + ; + } + return rc; +} + +static const VMStateDescription vmstate_spapr_drc =3D { + .name =3D "spapr_drc", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D spapr_drc_needed, + .fields =3D (VMStateField []) { + VMSTATE_UINT32(isolation_state, sPAPRDRConnector), + VMSTATE_UINT32(allocation_state, sPAPRDRConnector), + VMSTATE_UINT32(indicator_state, sPAPRDRConnector), + VMSTATE_BOOL(configured, sPAPRDRConnector), + VMSTATE_BOOL(awaiting_release, sPAPRDRConnector), + VMSTATE_BOOL(signalled, sPAPRDRConnector), + VMSTATE_END_OF_LIST() + } +}; + static void realize(DeviceState *d, Error **errp) { sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(d); @@ -534,6 +592,8 @@ static void realize(DeviceState *d, Error **errp) object_unref(OBJECT(drc)); } g_free(child_name); + vmstate_register(DEVICE(drc), drck->get_index(drc), &vmstate_spapr_drc, + drc); trace_spapr_drc_realize_complete(drck->get_index(drc)); } =20 @@ -652,6 +712,7 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) dk->reset =3D reset; dk->realize =3D realize; dk->unrealize =3D unrealize; + dk->vmsd =3D &vmstate_spapr_drc; drck->set_isolation_state =3D set_isolation_state; drck->set_indicator_state =3D set_indicator_state; drck->set_allocation_state =3D set_allocation_state; --=20 2.9.3 From nobody Sun Apr 28 19:09:30 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 1493573410202171.36764873113498; Sun, 30 Apr 2017 10:30:10 -0700 (PDT) Received: from localhost ([::1]:45381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4sfg-00087m-Sc for importer@patchew.org; Sun, 30 Apr 2017 13:30:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4sby-0005Qb-EK for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4sbw-0005wP-Ou for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:18 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36325 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 1d4sbw-0005vX-IK for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:16 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3UHNpEj075927 for ; Sun, 30 Apr 2017 13:26:15 -0400 Received: from e24smtp04.br.ibm.com (e24smtp04.br.ibm.com [32.104.18.25]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a5ja9bc4u-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 30 Apr 2017 13:26:15 -0400 Received: from localhost by e24smtp04.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 30 Apr 2017 14:26:14 -0300 Received: from d24relay03.br.ibm.com (9.18.232.225) by e24smtp04.br.ibm.com (10.172.0.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 30 Apr 2017 14:26:12 -0300 Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.8.31.91]) by d24relay03.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3UHQBMm32112678; Sun, 30 Apr 2017 14:26:12 -0300 Received: from d24av01.br.ibm.com (localhost [127.0.0.1]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3UHQBiF024677; Sun, 30 Apr 2017 14:26:11 -0300 Received: from localhost.localdomain ([9.85.167.102]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3UHPwCV024582; Sun, 30 Apr 2017 14:26:10 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Sun, 30 Apr 2017 14:25:46 -0300 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170430172547.13415-1-danielhb@linux.vnet.ibm.com> References: <20170430172547.13415-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17043017-0028-0000-0000-000001AFF09E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17043017-0029-0000-0000-000014B00386 Message-Id: <20170430172547.13415-5-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-30_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704300140 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 4/5] migration: spapr: migrate ccs_list in spapr state 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.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jianjun Duan ccs_list in spapr state maintains the device tree related information on the rtas side for hotplugged devices. In racing situations between hotplug events and migration operation, a rtas hotplug event could be migrated from the source guest to target guest, or the source guest could have not yet finished fetching the device tree when migration is started, the target will try to finish fetching the device tree. By migrating ccs_list, the target can fetch the device tree properly. In theory there would be other alternatives besides migrating the css_list to fix this. For example, we could add a flag that indicates whether a device is in the middle of the configure_connector during the migration process, in the post_load we can detect if this flag is active and then return an error informing the guest to restart the hotplug process. However, the DRC state can still be modified outside of hotplug. Using: drmgr -c pci -s -r drmgr -c pci -s -a it is possible to return a device to firmware and then later take it back and reconfigure it. This is not a common case but it's not prohibited, and performing a migration between these 2 operations would fail because the default coldplug state on target assumes a configured state in the source*. Migrating ccs_list is one solution that cover this case as well. ccs_list is put in a subsection in the spapr state VMSD to make sure migration across different versions is not broken. * see http://lists.nongnu.org/archive/html/qemu-devel/2016-10/msg01763.html for more information on this discussion. Signed-off-by: Jianjun Duan Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 8b9a6cf..cb3f0e8 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1437,6 +1437,37 @@ static bool version_before_3(void *opaque, int versi= on_id) return version_id < 3; } =20 +static bool spapr_ccs_list_needed(void *opaque) +{ + sPAPRMachineState *spapr =3D (sPAPRMachineState *)opaque; + return !QTAILQ_EMPTY(&spapr->ccs_list); +} + +static const VMStateDescription vmstate_spapr_ccs =3D { + .name =3D "spapr_configure_connector_state", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(drc_index, sPAPRConfigureConnectorState), + VMSTATE_INT32(fdt_offset, sPAPRConfigureConnectorState), + VMSTATE_INT32(fdt_depth, sPAPRConfigureConnectorState), + VMSTATE_END_OF_LIST() + }, +}; + +static const VMStateDescription vmstate_spapr_ccs_list =3D { + .name =3D "spapr_ccs_list", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D spapr_ccs_list_needed, + .fields =3D (VMStateField[]) { + VMSTATE_QTAILQ_V(ccs_list, sPAPRMachineState, 1, + vmstate_spapr_ccs, sPAPRConfigureConnectorState, + next), + VMSTATE_END_OF_LIST() + }, +}; + static bool spapr_ov5_cas_needed(void *opaque) { sPAPRMachineState *spapr =3D opaque; @@ -1535,6 +1566,7 @@ static const VMStateDescription vmstate_spapr =3D { .subsections =3D (const VMStateDescription*[]) { &vmstate_spapr_ov5_cas, &vmstate_spapr_patb_entry, + &vmstate_spapr_ccs_list, NULL } }; --=20 2.9.3 From nobody Sun Apr 28 19:09:30 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 1493573480068162.80173534279288; Sun, 30 Apr 2017 10:31:20 -0700 (PDT) Received: from localhost ([::1]:45391 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4sgo-0000RD-MY for importer@patchew.org; Sun, 30 Apr 2017 13:31:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4sc3-0005W9-Ib for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4sc0-000608-DS for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:23 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48723) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d4sc0-0005zs-4h for qemu-devel@nongnu.org; Sun, 30 Apr 2017 13:26:20 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3UHNsHc090785 for ; Sun, 30 Apr 2017 13:26:19 -0400 Received: from e24smtp02.br.ibm.com (e24smtp02.br.ibm.com [32.104.18.86]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a5hehw3q5-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 30 Apr 2017 13:26:18 -0400 Received: from localhost by e24smtp02.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 30 Apr 2017 14:26:16 -0300 Received: from d24relay03.br.ibm.com (9.18.232.225) by e24smtp02.br.ibm.com (10.172.0.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 30 Apr 2017 14:26:15 -0300 Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.8.31.91]) by d24relay03.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3UHQEU824707182; Sun, 30 Apr 2017 14:26:14 -0300 Received: from d24av01.br.ibm.com (localhost [127.0.0.1]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3UHQEVY024689; Sun, 30 Apr 2017 14:26:14 -0300 Received: from localhost.localdomain ([9.85.167.102]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3UHPwCW024582; Sun, 30 Apr 2017 14:26:12 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Sun, 30 Apr 2017 14:25:47 -0300 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170430172547.13415-1-danielhb@linux.vnet.ibm.com> References: <20170430172547.13415-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17043017-0020-0000-0000-000002A4AA34 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17043017-0021-0000-0000-000030C1E461 Message-Id: <20170430172547.13415-6-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-30_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704300140 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 5/5] migration: spapr: migrate pending_events of spapr state 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.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jianjun Duan In racing situations between hotplug events and migration operation, a rtas hotplug event could have not yet be delivered to the source guest when migration is started. In this case the pending_events of spapr state need be transmitted to the target so that the hotplug event can be finished on the target. All the different fields of the events are encoded as defined by PAPR. We can migrate them as uint8_t binary stream without any concerns about data padding or endianess. pending_events is put in a subsection in the spapr state VMSD to make sure migration across different versions is not broken. Signed-off-by: Jianjun Duan Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 33 +++++++++++++++++++++++++++++++++ hw/ppc/spapr_events.c | 24 +++++++++++++----------- include/hw/ppc/spapr.h | 3 ++- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index cb3f0e8..cd42449 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1468,6 +1468,38 @@ static const VMStateDescription vmstate_spapr_ccs_li= st =3D { }, }; =20 +static bool spapr_pending_events_needed(void *opaque) +{ + sPAPRMachineState *spapr =3D (sPAPRMachineState *)opaque; + return !QTAILQ_EMPTY(&spapr->pending_events); +} + +static const VMStateDescription vmstate_spapr_event_entry =3D { + .name =3D "spapr_event_log_entry", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_INT32(log_type, sPAPREventLogEntry), + VMSTATE_BOOL(exception, sPAPREventLogEntry), + VMSTATE_UINT32(data_size, sPAPREventLogEntry), + VMSTATE_VARRAY_UINT32_ALLOC(data, sPAPREventLogEntry, data_size, + 0, vmstate_info_uint8, uint8_t), + VMSTATE_END_OF_LIST() + }, +}; + +static const VMStateDescription vmstate_spapr_pending_events =3D { + .name =3D "spapr_pending_events", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D spapr_pending_events_needed, + .fields =3D (VMStateField[]) { + VMSTATE_QTAILQ_V(pending_events, sPAPRMachineState, 1, + vmstate_spapr_event_entry, sPAPREventLogEntry, ne= xt), + VMSTATE_END_OF_LIST() + }, +}; + static bool spapr_ov5_cas_needed(void *opaque) { sPAPRMachineState *spapr =3D opaque; @@ -1567,6 +1599,7 @@ static const VMStateDescription vmstate_spapr =3D { &vmstate_spapr_ov5_cas, &vmstate_spapr_patb_entry, &vmstate_spapr_ccs_list, + &vmstate_spapr_pending_events, NULL } }; diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c index f0b28d8..70c7cfc 100644 --- a/hw/ppc/spapr_events.c +++ b/hw/ppc/spapr_events.c @@ -342,7 +342,8 @@ static int rtas_event_log_to_irq(sPAPRMachineState *spa= pr, int log_type) return source->irq; } =20 -static void rtas_event_log_queue(int log_type, void *data, bool exception) +static void rtas_event_log_queue(int log_type, void *data, bool exception, + int data_size) { sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); sPAPREventLogEntry *entry =3D g_new(sPAPREventLogEntry, 1); @@ -351,6 +352,7 @@ static void rtas_event_log_queue(int log_type, void *da= ta, bool exception) entry->log_type =3D log_type; entry->exception =3D exception; entry->data =3D data; + entry->data_size =3D data_size; QTAILQ_INSERT_TAIL(&spapr->pending_events, entry, next); } =20 @@ -445,6 +447,7 @@ static void spapr_powerdown_req(Notifier *n, void *opaq= ue) struct rtas_event_log_v6_mainb *mainb; struct rtas_event_log_v6_epow *epow; struct epow_log_full *new_epow; + uint32_t data_size; =20 new_epow =3D g_malloc0(sizeof(*new_epow)); hdr =3D &new_epow->hdr; @@ -453,14 +456,13 @@ static void spapr_powerdown_req(Notifier *n, void *op= aque) mainb =3D &new_epow->mainb; epow =3D &new_epow->epow; =20 + data_size =3D sizeof(*new_epow); hdr->summary =3D cpu_to_be32(RTAS_LOG_VERSION_6 | RTAS_LOG_SEVERITY_EVENT | RTAS_LOG_DISPOSITION_NOT_RECOVERED | RTAS_LOG_OPTIONAL_PART_PRESENT | RTAS_LOG_TYPE_EPOW); - hdr->extended_length =3D cpu_to_be32(sizeof(*new_epow) - - sizeof(new_epow->hdr)); - + hdr->extended_length =3D cpu_to_be32(data_size - sizeof(new_epow->hdr)= ); spapr_init_v6hdr(v6hdr); spapr_init_maina(maina, 3 /* Main-A, Main-B and EPOW */); =20 @@ -479,7 +481,7 @@ static void spapr_powerdown_req(Notifier *n, void *opaq= ue) epow->event_modifier =3D RTAS_LOG_V6_EPOW_MODIFIER_NORMAL; epow->extended_modifier =3D RTAS_LOG_V6_EPOW_XMODIFIER_PARTITION_SPECI= FIC; =20 - rtas_event_log_queue(RTAS_LOG_TYPE_EPOW, new_epow, true); + rtas_event_log_queue(RTAS_LOG_TYPE_EPOW, new_epow, true, data_size); =20 qemu_irq_pulse(xics_get_qirq(XICS_FABRIC(spapr), rtas_event_log_to_irq(spapr, @@ -504,6 +506,7 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint= 8_t hp_action, struct rtas_event_log_v6_maina *maina; struct rtas_event_log_v6_mainb *mainb; struct rtas_event_log_v6_hp *hp; + uint32_t data_size; =20 new_hp =3D g_malloc0(sizeof(struct hp_log_full)); hdr =3D &new_hp->hdr; @@ -512,14 +515,14 @@ static void spapr_hotplug_req_event(uint8_t hp_id, ui= nt8_t hp_action, mainb =3D &new_hp->mainb; hp =3D &new_hp->hp; =20 + data_size =3D sizeof(*new_hp); hdr->summary =3D cpu_to_be32(RTAS_LOG_VERSION_6 | RTAS_LOG_SEVERITY_EVENT | RTAS_LOG_DISPOSITION_NOT_RECOVERED | RTAS_LOG_OPTIONAL_PART_PRESENT | RTAS_LOG_INITIATOR_HOTPLUG | RTAS_LOG_TYPE_HOTPLUG); - hdr->extended_length =3D cpu_to_be32(sizeof(*new_hp) - - sizeof(new_hp->hdr)); + hdr->extended_length =3D cpu_to_be32(data_size - sizeof(new_hp->hdr)); =20 spapr_init_v6hdr(v6hdr); spapr_init_maina(maina, 3 /* Main-A, Main-B, HP */); @@ -572,7 +575,7 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint= 8_t hp_action, cpu_to_be32(drc_id->count_indexed.index); } =20 - rtas_event_log_queue(RTAS_LOG_TYPE_HOTPLUG, new_hp, true); + rtas_event_log_queue(RTAS_LOG_TYPE_HOTPLUG, new_hp, true, data_size); =20 qemu_irq_pulse(xics_get_qirq(XICS_FABRIC(spapr), rtas_event_log_to_irq(spapr, @@ -671,8 +674,7 @@ static void check_exception(PowerPCCPU *cpu, sPAPRMachi= neState *spapr, if (!event) { goto out_no_events; } - - hdr =3D event->data; + hdr =3D (struct rtas_error_log *)event->data; event_len =3D be32_to_cpu(hdr->extended_length) + sizeof(*hdr); =20 if (event_len < len) { @@ -728,7 +730,7 @@ static void event_scan(PowerPCCPU *cpu, sPAPRMachineSta= te *spapr, goto out_no_events; } =20 - hdr =3D event->data; + hdr =3D (struct rtas_error_log *)event->data; event_len =3D be32_to_cpu(hdr->extended_length) + sizeof(*hdr); =20 if (event_len < len) { diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 5802f88..fbe1d93 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -599,7 +599,8 @@ sPAPRTCETable *spapr_tce_find_by_liobn(target_ulong lio= bn); struct sPAPREventLogEntry { int log_type; bool exception; - void *data; + uint8_t *data; + uint32_t data_size; QTAILQ_ENTRY(sPAPREventLogEntry) next; }; =20 --=20 2.9.3