From nobody Sun May 5 23:48:48 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 1493071853734200.2515052131455; Mon, 24 Apr 2017 15:10:53 -0700 (PDT) Received: from localhost ([::1]:46148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2mC4-00021x-2s for importer@patchew.org; Mon, 24 Apr 2017 18:10:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2mAL-0000uh-6F for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2mAI-0008Fi-K3 for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:05 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53136) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d2mAI-0008Ed-CG for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:02 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3OM3sb6122065 for ; Mon, 24 Apr 2017 18:09:00 -0400 Received: from e24smtp04.br.ibm.com (e24smtp04.br.ibm.com [32.104.18.25]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a1qnw4w31-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 24 Apr 2017 18:08:59 -0400 Received: from localhost by e24smtp04.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Apr 2017 19:08:57 -0300 Received: from d24relay04.br.ibm.com (9.18.232.146) by e24smtp04.br.ibm.com (10.172.0.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 24 Apr 2017 19:08:55 -0300 Received: from d24av04.br.ibm.com (d24av04.br.ibm.com [9.8.31.97]) by d24relay04.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3OM8s633539388; Mon, 24 Apr 2017 19:08:54 -0300 Received: from d24av04.br.ibm.com (localhost [127.0.0.1]) by d24av04.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3OM8sMN024936; Mon, 24 Apr 2017 19:08:54 -0300 Received: from arthas.ibm.com ([9.80.236.3]) by d24av04.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3OM8gkJ024871; Mon, 24 Apr 2017 19:08:52 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Mon, 24 Apr 2017 19:08:25 -0300 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170424220828.1472-1-danielhb@linux.vnet.ibm.com> References: <20170424220828.1472-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17042422-0028-0000-0000-000001ADC136 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042422-0029-0000-0000-000014ADFF52 Message-Id: <20170424220828.1472-2-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-24_18:, , 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-1704240371 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/4] migration: alternative way to set instance_id in SaveStateEntry 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 QOM (QEMU Object Model) migrated objects are identified with instance_id which is calculated automatically using their path in the QOM composition tree. For some objects, this path could change from source to target in migration. To migrate such objects, we need to make sure the instance_id do= es not change from source to target. We add a hook in DeviceClass to do custom= ized instance_id calculation in such cases. As a result, in these cases compat will not be set in the concerned SaveStateEntry. This will prevent the inconsistent idstr to be sent over in migration. We could have set alias_id in a similar way. But that will be overloading the purpose of alias_id. The first application will be setting instance_id for pseries DRC objects u= sing its unique index. Doing this makes the instance_id of DRC to be consistent across migration and supports flexible management of DRC objects in migrati= on. Signed-off-by: Jianjun Duan Signed-off-by: Daniel Henrique Barboza --- include/hw/qdev-core.h | 6 ++++++ migration/savevm.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 4bf86b0..9b3914c 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -127,6 +127,12 @@ typedef struct DeviceClass { qdev_initfn init; /* TODO remove, once users are converted to realize = */ qdev_event exit; /* TODO remove, once users are converted to unrealize= */ const char *bus_type; + + /* When this field is set, qemu will use it to get an unique instance_= id + * instead of calculating an auto idstr and instance_id for the releva= nt + * SaveStateEntry + */ + int (*dev_get_instance_id)(DeviceState *dev); } DeviceClass; =20 typedef struct NamedGPIOList NamedGPIOList; diff --git a/migration/savevm.c b/migration/savevm.c index 03ae1bd..5d8135f 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -606,6 +606,9 @@ int register_savevm_live(DeviceState *dev, calculate_compat_instance_id(idstr) : instance_id; instance_id =3D -1; } + if (DEVICE_GET_CLASS(dev)->dev_get_instance_id) { + instance_id =3D DEVICE_GET_CLASS(dev)->dev_get_instance_id(dev= ); + } } pstrcat(se->idstr, sizeof(se->idstr), idstr); =20 @@ -696,6 +699,9 @@ int vmstate_register_with_alias_id(DeviceState *dev, in= t instance_id, calculate_compat_instance_id(vmsd->name) : instan= ce_id; instance_id =3D -1; } + if (DEVICE_GET_CLASS(dev)->dev_get_instance_id) { + instance_id =3D DEVICE_GET_CLASS(dev)->dev_get_instance_id(dev= ); + } } pstrcat(se->idstr, sizeof(se->idstr), vmsd->name); =20 --=20 2.9.3 From nobody Sun May 5 23:48:48 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 149307186603527.90633718547815; Mon, 24 Apr 2017 15:11:06 -0700 (PDT) Received: from localhost ([::1]:46149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2mCG-00025t-FZ for importer@patchew.org; Mon, 24 Apr 2017 18:11:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2mAP-0000y1-1m for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2mAL-0008IC-MA for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:09 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39369 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 1d2mAL-0008Hc-GQ for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:05 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3OM3ufP127400 for ; Mon, 24 Apr 2017 18:09:04 -0400 Received: from e24smtp01.br.ibm.com (e24smtp01.br.ibm.com [32.104.18.85]) by mx0b-001b2d01.pphosted.com with ESMTP id 2a1hwtf49p-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 24 Apr 2017 18:09:04 -0400 Received: from localhost by e24smtp01.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Apr 2017 19:09:02 -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; Mon, 24 Apr 2017 19:08:58 -0300 Received: from d24av04.br.ibm.com (d24av04.br.ibm.com [9.8.31.97]) by d24relay02.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3OM8uPG18219372; Mon, 24 Apr 2017 19:08:57 -0300 Received: from d24av04.br.ibm.com (localhost [127.0.0.1]) by d24av04.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3OM8u9L024945; Mon, 24 Apr 2017 19:08:56 -0300 Received: from arthas.ibm.com ([9.80.236.3]) by d24av04.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3OM8gkK024871; Mon, 24 Apr 2017 19:08:54 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Mon, 24 Apr 2017 19:08:26 -0300 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170424220828.1472-1-danielhb@linux.vnet.ibm.com> References: <20170424220828.1472-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17042422-1523-0000-0000-00000298C286 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042422-1524-0000-0000-00002A2EEE6D Message-Id: <20170424220828.1472-3-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-24_18:, , 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-1704240371 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/4] 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. The instance_id is used to identify objects in migration. We set instance_id of DRC using the unique index so that it is the same across migration. In hw/ppc/spapr_pci.c, a function called spapr_pci_set_detach_cb was created to set the detach_cb of the migrated DRC in the spapr_pci_post_load. The reason is that detach_cb is a DRC function pointer that can't be migrated but we need it set in the target so a ongoing hot-unplug event can properly finish. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr_drc.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/ppc/spapr_pci.c | 22 ++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index a1cdc87..5c2baad 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -651,6 +651,70 @@ static void spapr_dr_connector_instance_init(Object *o= bj) NULL, NULL, NULL, NULL); } =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; +} + +/* return the unique drc index as instance_id for qom interfaces*/ +static int get_instance_id(DeviceState *dev) +{ + return (int)get_index(SPAPR_DR_CONNECTOR(OBJECT(dev))); +} + +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 spapr_dr_connector_class_init(ObjectClass *k, void *data) { DeviceClass *dk =3D DEVICE_CLASS(k); @@ -659,6 +723,8 @@ 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; + dk->dev_get_instance_id =3D get_instance_id; drck->set_isolation_state =3D set_isolation_state; drck->set_indicator_state =3D set_indicator_state; drck->set_allocation_state =3D set_allocation_state; @@ -672,6 +738,7 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) drck->detach =3D detach; drck->release_pending =3D release_pending; drck->set_signalled =3D set_signalled; + /* * Reason: it crashes FIXME find and document the real reason */ diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 98c52e4..639dad2 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1922,12 +1922,34 @@ static void spapr_pci_pre_save(void *opaque) } } =20 +/* + * detach_cb in the DRC state is a function pointer that cannot be + * migrated. We set it right after migration so that a migrated + * hot-unplug event could finish its work. + */ +static void spapr_pci_set_detach_cb(PCIBus *bus, PCIDevice *pdev, + void *opaque) +{ + sPAPRPHBState *sphb =3D opaque; + sPAPRDRConnector *drc =3D spapr_phb_get_pci_drc(sphb, pdev); + drc->detach_cb =3D spapr_phb_remove_pci_device_cb; +} + static int spapr_pci_post_load(void *opaque, int version_id) { sPAPRPHBState *sphb =3D opaque; gpointer key, value; int i; =20 + PCIBus *bus =3D PCI_HOST_BRIDGE(sphb)->bus; + unsigned int bus_no =3D 0; + + /* Set detach_cb for the drc unconditionally after migration */ + if (bus) { + pci_for_each_device(bus, pci_bus_num(bus), spapr_pci_set_detach_cb, + &bus_no); + } + for (i =3D 0; i < sphb->msi_devs_num; ++i) { key =3D g_memdup(&sphb->msi_devs[i].key, sizeof(sphb->msi_devs[i].key)); --=20 2.9.3 From nobody Sun May 5 23:48:48 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 1493071985880350.41359335202185; Mon, 24 Apr 2017 15:13:05 -0700 (PDT) Received: from localhost ([::1]:46156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2mEC-0003iQ-EM for importer@patchew.org; Mon, 24 Apr 2017 18:13:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2mAP-0000yg-N5 for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2mAM-0008Io-Bz for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:09 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:49071 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 1d2mAM-0008IK-4h for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:06 -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 v3OM3uTX112468 for ; Mon, 24 Apr 2017 18:09:05 -0400 Received: from e24smtp02.br.ibm.com (e24smtp02.br.ibm.com [32.104.18.86]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a1nx698th-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 24 Apr 2017 18:09:05 -0400 Received: from localhost by e24smtp02.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Apr 2017 19:09:03 -0300 Received: from d24relay04.br.ibm.com (9.18.232.146) by e24smtp02.br.ibm.com (10.172.0.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 24 Apr 2017 19:09:00 -0300 Received: from d24av04.br.ibm.com (d24av04.br.ibm.com [9.8.31.97]) by d24relay04.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3OM8xLF66650274; Mon, 24 Apr 2017 19:08:59 -0300 Received: from d24av04.br.ibm.com (localhost [127.0.0.1]) by d24av04.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3OM8xto024954; Mon, 24 Apr 2017 19:08:59 -0300 Received: from arthas.ibm.com ([9.80.236.3]) by d24av04.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3OM8gkL024871; Mon, 24 Apr 2017 19:08:57 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Mon, 24 Apr 2017 19:08:27 -0300 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170424220828.1472-1-danielhb@linux.vnet.ibm.com> References: <20170424220828.1472-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17042422-0020-0000-0000-000002A2BEF4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042422-0021-0000-0000-000030BFE5D7 Message-Id: <20170424220828.1472-4-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-24_18:, , 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-1704240371 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/4] 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 35db949..22f351c 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1388,6 +1388,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 "spaprconfigureconnectorstate", + .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 "spaprccslist", + .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; @@ -1486,6 +1517,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 May 5 23:48:48 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 1493072055000691.9875174051002; Mon, 24 Apr 2017 15:14:15 -0700 (PDT) Received: from localhost ([::1]:46160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2mFJ-0004IH-Eo for importer@patchew.org; Mon, 24 Apr 2017 18:14:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2mAQ-0000zL-E5 for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2mAN-0008JM-4X for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39391 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 1d2mAM-0008J2-Tg for qemu-devel@nongnu.org; Mon, 24 Apr 2017 18:09:07 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3OM3to1127355 for ; Mon, 24 Apr 2017 18:09:06 -0400 Received: from e24smtp05.br.ibm.com (e24smtp05.br.ibm.com [32.104.18.26]) by mx0b-001b2d01.pphosted.com with ESMTP id 2a1hwtf4af-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 24 Apr 2017 18:09:06 -0400 Received: from localhost by e24smtp05.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Apr 2017 19:09:04 -0300 Received: from d24relay02.br.ibm.com (9.18.232.42) by e24smtp05.br.ibm.com (10.172.0.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 24 Apr 2017 19:09:02 -0300 Received: from d24av04.br.ibm.com (d24av04.br.ibm.com [9.8.31.97]) by d24relay02.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3OM91Pu20185348; Mon, 24 Apr 2017 19:09:01 -0300 Received: from d24av04.br.ibm.com (localhost [127.0.0.1]) by d24av04.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3OM91fO024975; Mon, 24 Apr 2017 19:09:01 -0300 Received: from arthas.ibm.com ([9.80.236.3]) by d24av04.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3OM8gkM024871; Mon, 24 Apr 2017 19:08:59 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Mon, 24 Apr 2017 19:08:28 -0300 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170424220828.1472-1-danielhb@linux.vnet.ibm.com> References: <20170424220828.1472-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17042422-0032-0000-0000-00000557BEF6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042422-0033-0000-0000-000011DCF946 Message-Id: <20170424220828.1472-5-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-24_18:, , 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-1704240371 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/4] 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 22f351c..a3e939b 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1419,6 +1419,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 "spapreventlogentry", + .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 "spaprpendingevents", + .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; @@ -1518,6 +1550,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 24a5758..399dd49 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 808aac8..c60dbd2 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -584,7 +584,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