From nobody Sun May 5 06:52:06 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 1495139904009582.0770838050792; Thu, 18 May 2017 13:38:24 -0700 (PDT) Received: from localhost ([::1]:55426 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBSBi-0003x9-Hz for importer@patchew.org; Thu, 18 May 2017 16:38:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBS9d-0002Wz-1H for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBS9Y-0005su-0g for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:13 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47245) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBS9X-0005sa-NA for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:07 -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 v4IKYQWX115945 for ; Thu, 18 May 2017 16:36:06 -0400 Received: from e24smtp04.br.ibm.com (e24smtp04.br.ibm.com [32.104.18.25]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ahd7pyyge-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 18 May 2017 16:36:05 -0400 Received: from localhost by e24smtp04.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 May 2017 17:36:03 -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; Thu, 18 May 2017 17:36:00 -0300 Received: from d24av03.br.ibm.com (d24av03.br.ibm.com [9.8.31.95]) by d24relay03.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4IKa0Ks34996292; Thu, 18 May 2017 17:36:00 -0300 Received: from d24av03.br.ibm.com (localhost [127.0.0.1]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v4IKa0LV021572; Thu, 18 May 2017 17:36:01 -0300 Received: from localhost.localdomain ([9.80.214.94]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v4IKZsrQ021455; Thu, 18 May 2017 17:35:59 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Thu, 18 May 2017 17:35:44 -0300 X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170518203548.14207-1-danielhb@linux.vnet.ibm.com> References: <20170518203548.14207-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17051820-0028-0000-0000-000001B605D9 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051820-0029-0000-0000-000014B6652A Message-Id: <20170518203548.14207-2-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-18_04:, , 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-1705180140 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 v10 1/5] hw/ppc/spapr.c: adding pending_dimm_unplugs to sPAPRMachineState 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, mdroth@linux.vnet.ibm.com, 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 LMB DRC release callback, spapr_lmb_release(), uses an opaque parameter, a sPAPRDIMMState struct that stores the current LMBs that are allocated to a DIMM (nr_lmbs). After each call to this callback, the nr_lmbs is decremented by one and, when it reaches zero, the callback proceeds with the qdev calls to hot unplug the LMB. Using drc->detach_cb_opaque is problematic because it can't be migrated in the future DRC migration work. This patch makes the following changes to eliminate the usage of this opaque callback inside spapr_lmb_release: - sPAPRDIMMState was moved from spapr.c and added to spapr.h. A new attribute called 'addr' was added to it. This is used as an unique identifier to associate a sPAPRDIMMState to a PCDIMM element. - sPAPRMachineState now hosts a new QTAILQ called 'pending_dimm_unplugs'. This queue of sPAPRDIMMState elements will store the DIMM state of DIMMs that are currently going under an unplug process. - spapr_lmb_release() will now retrieve the nr_lmbs value by getting the correspondent sPAPRDIMMState. A helper function called spapr_dimm_get_addre= ss was created to fetch the address of a PCDIMM device inside spapr_lmb_releas= e. When nr_lmbs reaches zero and the callback proceeds with the qdev hot unplug calls, the sPAPRDIMMState struct is removed from spapr->pending_dimm_unplug= s. After these changes, the opaque argument for spapr_lmb_release is now unused and is passed as NULL inside spapr_del_lmbs. This and the other opaque arguments can now be safely removed from the code. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 57 +++++++++++++++++++++++++++++++++++++++++++++-= ---- include/hw/ppc/spapr.h | 4 ++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 0980d73..b05abe5 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2050,6 +2050,7 @@ static void ppc_spapr_init(MachineState *machine) msi_nonbroken =3D true; =20 QLIST_INIT(&spapr->phbs); + QTAILQ_INIT(&spapr->pending_dimm_unplugs); =20 /* Allocate RMA if necessary */ rma_alloc_size =3D kvmppc_alloc_rma(&rma); @@ -2603,20 +2604,63 @@ out: error_propagate(errp, local_err); } =20 -typedef struct sPAPRDIMMState { +struct sPAPRDIMMState { + uint64_t addr; uint32_t nr_lmbs; -} sPAPRDIMMState; + QTAILQ_ENTRY(sPAPRDIMMState) next; +}; + +static sPAPRDIMMState *spapr_pending_dimm_unplugs_find(sPAPRMachineState *= s, + uint64_t addr) +{ + sPAPRDIMMState *dimm_state =3D NULL; + QTAILQ_FOREACH(dimm_state, &s->pending_dimm_unplugs, next) { + if (dimm_state->addr =3D=3D addr) { + break; + } + } + return dimm_state; +} + +static void spapr_pending_dimm_unplugs_add(sPAPRMachineState *spapr, + sPAPRDIMMState *dimm_state) +{ + g_assert(!spapr_pending_dimm_unplugs_find(spapr, dimm_state->addr)); + QTAILQ_INSERT_HEAD(&spapr->pending_dimm_unplugs, dimm_state, next); +} + +static void spapr_pending_dimm_unplugs_remove(sPAPRMachineState *spapr, + sPAPRDIMMState *dimm_state) +{ + QTAILQ_REMOVE(&spapr->pending_dimm_unplugs, dimm_state, next); + g_free(dimm_state); +} + +static uint64_t spapr_dimm_get_address(PCDIMMDevice *dimm) +{ + Error *local_err =3D NULL; + uint64_t addr; + addr =3D object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, + &local_err); + if (local_err) { + error_propagate(&error_abort, local_err); + return 0; + } + return addr; +} =20 static void spapr_lmb_release(DeviceState *dev, void *opaque) { - sPAPRDIMMState *ds =3D (sPAPRDIMMState *)opaque; HotplugHandler *hotplug_ctrl; + uint64_t addr =3D spapr_dimm_get_address(PC_DIMM(dev)); + sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); + sPAPRDIMMState *ds =3D spapr_pending_dimm_unplugs_find(spapr, addr); =20 if (--ds->nr_lmbs) { return; } =20 - g_free(ds); + spapr_pending_dimm_unplugs_remove(spapr, ds); =20 /* * Now that all the LMBs have been removed by the guest, call the @@ -2633,17 +2677,20 @@ 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; + sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); sPAPRDIMMState *ds =3D g_malloc0(sizeof(sPAPRDIMMState)); uint64_t addr =3D addr_start; =20 ds->nr_lmbs =3D nr_lmbs; + ds->addr =3D addr_start; + spapr_pending_dimm_unplugs_add(spapr, ds); 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, spapr_lmb_release, ds, errp); + drck->detach(drc, dev, spapr_lmb_release, NULL, errp); addr +=3D SPAPR_MEMORY_BLOCK_SIZE; } =20 diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 5802f88..9823296 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -32,6 +32,7 @@ struct sPAPRRTCState { int64_t ns_offset; }; =20 +typedef struct sPAPRDIMMState sPAPRDIMMState; typedef struct sPAPRMachineClass sPAPRMachineClass; =20 #define TYPE_SPAPR_MACHINE "spapr-machine" @@ -104,6 +105,9 @@ struct sPAPRMachineState { /* RTAS state */ QTAILQ_HEAD(, sPAPRConfigureConnectorState) ccs_list; =20 + /* pending DIMM unplug queue */ + QTAILQ_HEAD(, sPAPRDIMMState) pending_dimm_unplugs; + /*< public >*/ char *kvm_type; MemoryHotplugState hotplug_memory; --=20 2.9.4 From nobody Sun May 5 06:52:06 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 1495140061206646.5257710024538; Thu, 18 May 2017 13:41:01 -0700 (PDT) Received: from localhost ([::1]:55444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBSEF-0005kv-OZ for importer@patchew.org; Thu, 18 May 2017 16:40:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBS9e-0002YQ-Uq for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBS9Z-0005tn-Ub for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:14 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:58278 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 1dBS9Z-0005tS-Ox for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:09 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4IKZ2Hk017864 for ; Thu, 18 May 2017 16:36:09 -0400 Received: from e24smtp02.br.ibm.com (e24smtp02.br.ibm.com [32.104.18.86]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ahhndjvkf-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 18 May 2017 16:36:08 -0400 Received: from localhost by e24smtp02.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 May 2017 17:36:05 -0300 Received: from d24relay02.br.ibm.com (9.18.232.42) by e24smtp02.br.ibm.com (10.172.0.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 18 May 2017 17:36:03 -0300 Received: from d24av03.br.ibm.com (d24av03.br.ibm.com [9.8.31.95]) by d24relay02.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4IKa2XX29819094; Thu, 18 May 2017 17:36:03 -0300 Received: from d24av03.br.ibm.com (localhost [127.0.0.1]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v4IKa3c1021662; Thu, 18 May 2017 17:36:03 -0300 Received: from localhost.localdomain ([9.80.214.94]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v4IKZsrR021455; Thu, 18 May 2017 17:36:01 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Thu, 18 May 2017 17:35:45 -0300 X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170518203548.14207-1-danielhb@linux.vnet.ibm.com> References: <20170518203548.14207-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17051820-0020-0000-0000-000002AAB830 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051820-0021-0000-0000-000030C82C15 Message-Id: <20170518203548.14207-3-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-18_04:, , 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-1705180140 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 v10 2/5] hw/ppc: removing drc->detach_cb and drc->detach_cb_opaque 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, mdroth@linux.vnet.ibm.com, 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 pointer drc->detach_cb is being used as a way of informing the detach() function inside spapr_drc.c which cb to execute. This information can also be retrieved simply by checking drc->type and choosing the right callback based on it. In this context, detach_cb is redundant information that must be managed. After the previous spapr_lmb_release change, no detach_cb_opaques are being used by any of the three callbacks functions. This is yet another information that is now unused and, on top of that, can't be migrated either. This patch makes the following changes: - removal of detach_cb_opaque. the 'opaque' argument was removed from the callbacks and from the detach() function of sPAPRConnectorClass. The attribute detach_cb_opaque of sPAPRConnector was removed. - removal of detach_cb from the detach() call. The function pointer detach_cb of sPAPRConnector was removed. detach() now uses a switch(drc->type) to execute the apropriate callback. To achieve this, spapr_core_release, spapr_lmb_release and spapr_phb_remove_pci_device_cb callbacks were made public to be visible inside detach(). Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 10 ++++++---- hw/ppc/spapr_drc.c | 36 ++++++++++++++++++++---------------- hw/ppc/spapr_pci.c | 5 +++-- include/hw/pci-host/spapr.h | 3 +++ include/hw/ppc/spapr.h | 4 ++++ include/hw/ppc/spapr_drc.h | 8 +------- 6 files changed, 37 insertions(+), 29 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b05abe5..5602cfc 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2649,7 +2649,8 @@ static uint64_t spapr_dimm_get_address(PCDIMMDevice *= dimm) return addr; } =20 -static void spapr_lmb_release(DeviceState *dev, void *opaque) +/* Callback to be called during DRC release. */ +void spapr_lmb_release(DeviceState *dev) { HotplugHandler *hotplug_ctrl; uint64_t addr =3D spapr_dimm_get_address(PC_DIMM(dev)); @@ -2690,7 +2691,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, NULL, errp); + drck->detach(drc, dev, errp); addr +=3D SPAPR_MEMORY_BLOCK_SIZE; } =20 @@ -2766,7 +2767,8 @@ static void spapr_core_unplug(HotplugHandler *hotplug= _dev, DeviceState *dev, object_unparent(OBJECT(dev)); } =20 -static void spapr_core_release(DeviceState *dev, void *opaque) +/* Callback to be called during DRC release. */ +void spapr_core_release(DeviceState *dev) { HotplugHandler *hotplug_ctrl; =20 @@ -2799,7 +2801,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, &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..976f71f 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -20,6 +20,7 @@ #include "qapi/visitor.h" #include "qemu/error-report.h" #include "hw/ppc/spapr.h" /* for RTAS return codes */ +#include "hw/pci-host/spapr.h" /* spapr_phb_remove_pci_device_cb callback = */ #include "trace.h" =20 #define DRC_CONTAINER_PATH "/dr-connector" @@ -99,8 +100,7 @@ static uint32_t set_isolation_state(sPAPRDRConnector *dr= c, 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), NULL); } else { trace_spapr_drc_set_isolation_state_deferring(get_index(dr= c)); } @@ -153,8 +153,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, - 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,15 +403,10 @@ static void attach(sPAPRDRConnector *drc, DeviceState= *d, void *fdt, NULL, 0, NULL); } =20 -static void detach(sPAPRDRConnector *drc, DeviceState *d, - spapr_drc_detach_cb *detach_cb, - 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 =3D detach_cb; - 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 @@ -456,8 +450,21 @@ static void detach(sPAPRDRConnector *drc, DeviceState = *d, =20 drc->indicator_state =3D SPAPR_DR_INDICATOR_STATE_INACTIVE; =20 - if (drc->detach_cb) { - drc->detach_cb(drc->dev, drc->detach_cb_opaque); + /* Calling release callbacks based on drc->type. */ + switch (drc->type) { + case SPAPR_DR_CONNECTOR_TYPE_CPU: + spapr_core_release(drc->dev); + break; + case SPAPR_DR_CONNECTOR_TYPE_PCI: + spapr_phb_remove_pci_device_cb(drc->dev); + break; + case SPAPR_DR_CONNECTOR_TYPE_LMB: + spapr_lmb_release(drc->dev); + break; + case SPAPR_DR_CONNECTOR_TYPE_PHB: + case SPAPR_DR_CONNECTOR_TYPE_VIO: + default: + g_assert(false); } =20 drc->awaiting_release =3D false; @@ -467,8 +474,6 @@ static void detach(sPAPRDRConnector *drc, DeviceState *= d, drc->fdt_start_offset =3D 0; 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) @@ -498,8 +503,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), 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 e7567e2..5775db8 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1369,7 +1369,8 @@ out: } } =20 -static void spapr_phb_remove_pci_device_cb(DeviceState *dev, void *opaque) +/* Callback to be called during DRC release. */ +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 +1393,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), errp); } =20 static sPAPRDRConnector *spapr_phb_get_pci_func_drc(sPAPRPHBState *phb, diff --git a/include/hw/pci-host/spapr.h b/include/hw/pci-host/spapr.h index 1c2e970..38470b2 100644 --- a/include/hw/pci-host/spapr.h +++ b/include/hw/pci-host/spapr.h @@ -123,6 +123,9 @@ sPAPRPHBState *spapr_pci_find_phb(sPAPRMachineState *sp= apr, uint64_t buid); PCIDevice *spapr_pci_find_dev(sPAPRMachineState *spapr, uint64_t buid, uint32_t config_addr); =20 +/* PCI release callback. */ +void spapr_phb_remove_pci_device_cb(DeviceState *dev); + /* VFIO EEH hooks */ #ifdef CONFIG_LINUX bool spapr_phb_eeh_available(sPAPRPHBState *sphb); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 9823296..4651d19 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -640,6 +640,10 @@ void spapr_hotplug_req_remove_by_count_indexed(sPAPRDR= ConnectorType drc_type, void *spapr_populate_hotplug_cpu_dt(CPUState *cs, int *fdt_offset, sPAPRMachineState *spapr); =20 +/* CPU and LMB DRC release callbacks. */ +void spapr_core_release(DeviceState *dev); +void spapr_lmb_release(DeviceState *dev); + /* rtas-configure-connector state */ struct sPAPRConfigureConnectorState { uint32_t drc_index; diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 5524247..813b9ff 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -130,8 +130,6 @@ typedef enum { SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE =3D -9003, } sPAPRDRCCResponse; =20 -typedef void (spapr_drc_detach_cb)(DeviceState *d, void *opaque); - typedef struct sPAPRDRConnector { /*< private >*/ DeviceState parent; @@ -158,8 +156,6 @@ typedef struct sPAPRDRConnector { =20 /* device pointer, via link property */ DeviceState *dev; - spapr_drc_detach_cb *detach_cb; - void *detach_cb_opaque; } sPAPRDRConnector; =20 typedef struct sPAPRDRConnectorClass { @@ -188,9 +184,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, - spapr_drc_detach_cb *detach_cb, - 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.4 From nobody Sun May 5 06:52:06 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 1495139913457156.12919796106382; Thu, 18 May 2017 13:38:33 -0700 (PDT) Received: from localhost ([::1]:55427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBSBr-00043l-38 for importer@patchew.org; Thu, 18 May 2017 16:38:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBS9g-0002YV-Hm for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBS9d-0005ui-FM for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:16 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBS9d-0005uT-5h for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:13 -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 v4IKY4jt083312 for ; Thu, 18 May 2017 16:36:11 -0400 Received: from e24smtp05.br.ibm.com (e24smtp05.br.ibm.com [32.104.18.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ahh6vv2m1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 18 May 2017 16:36:11 -0400 Received: from localhost by e24smtp05.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 May 2017 17:36:08 -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; Thu, 18 May 2017 17:36:06 -0300 Received: from d24av03.br.ibm.com (d24av03.br.ibm.com [9.8.31.95]) by d24relay02.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4IKa5Tm15204784; Thu, 18 May 2017 17:36:05 -0300 Received: from d24av03.br.ibm.com (localhost [127.0.0.1]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v4IKa69l021694; Thu, 18 May 2017 17:36:06 -0300 Received: from localhost.localdomain ([9.80.214.94]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v4IKZsrS021455; Thu, 18 May 2017 17:36:04 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Thu, 18 May 2017 17:35:46 -0300 X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170518203548.14207-1-danielhb@linux.vnet.ibm.com> References: <20170518203548.14207-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17051820-0032-0000-0000-000005600493 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051820-0033-0000-0000-000011E564C6 Message-Id: <20170518203548.14207-4-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-18_04:, , 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-1705180140 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 v10 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, mdroth@linux.vnet.ibm.com, 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 'indicator_state' are involved in the DR state transition diagram from PAPR+ 2.7, 13.4; - 'configured', 'signalled', 'awaiting_release' and 'awaiting_allocation' 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 | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++= +++ 1 file changed, 53 insertions(+) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 976f71f..3c3e9e9 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -519,6 +519,57 @@ 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= ); + return rc; + case SPAPR_DR_CONNECTOR_TYPE_CPU: + 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= ); + return rc; + default: + g_assert(false); + } +} + +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(awaiting_allocation, sPAPRDRConnector), + VMSTATE_BOOL(signalled, sPAPRDRConnector), + VMSTATE_END_OF_LIST() + } +}; + static void realize(DeviceState *d, Error **errp) { sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(d); @@ -547,6 +598,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 --=20 2.9.4 From nobody Sun May 5 06:52:06 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 149514006185532.72246571936091; Thu, 18 May 2017 13:41:01 -0700 (PDT) Received: from localhost ([::1]:55445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBSEG-0005m5-Bl for importer@patchew.org; Thu, 18 May 2017 16:41:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBS9j-0002as-Cc for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBS9e-0005vD-DD for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:19 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36395 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 1dBS9e-0005uv-8A for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:14 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4IKY4Zr099777 for ; Thu, 18 May 2017 16:36:13 -0400 Received: from e24smtp02.br.ibm.com (e24smtp02.br.ibm.com [32.104.18.86]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ahjca10ch-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 18 May 2017 16:36:13 -0400 Received: from localhost by e24smtp02.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 May 2017 17:36: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; Thu, 18 May 2017 17:36:08 -0300 Received: from d24av03.br.ibm.com (d24av03.br.ibm.com [9.8.31.95]) by d24relay03.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4IKa8Ln27852932; Thu, 18 May 2017 17:36:08 -0300 Received: from d24av03.br.ibm.com (localhost [127.0.0.1]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v4IKa8np021720; Thu, 18 May 2017 17:36:09 -0300 Received: from localhost.localdomain ([9.80.214.94]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v4IKZsrT021455; Thu, 18 May 2017 17:36:07 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Thu, 18 May 2017 17:35:47 -0300 X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170518203548.14207-1-danielhb@linux.vnet.ibm.com> References: <20170518203548.14207-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17051820-0020-0000-0000-000002AAB836 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051820-0021-0000-0000-000030C82C18 Message-Id: <20170518203548.14207-5-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-18_04:, , 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-1705180140 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 v10 4/5] hw/ppc/spapr.c: recover pending LMB unplug info in spapr_lmb_release 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, mdroth@linux.vnet.ibm.com, 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" When a LMB hot unplug starts, the current DRC LMB status is stored at spapr->pending_dimm_unplugs QTAILQ. This queue isn't migrated, thus if a migration occurs in the middle of a LMB unplug the spapr_lmb_release callback will lost track of the LMB unplug progress. This patch implements a new recover function spapr_recover_pending_dimm_sta= te that is used inside spapr_lmb_release to recover this DRC LMB release status that is lost during the migration. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 5602cfc..7d304fc 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2649,6 +2649,36 @@ static uint64_t spapr_dimm_get_address(PCDIMMDevice = *dimm) return addr; } =20 +static sPAPRDIMMState *spapr_recover_pending_dimm_state(PCDIMMDevice *dimm, + uint64_t addr) +{ + sPAPRDRConnector *drc; + PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + MemoryRegion *mr =3D ddc->get_memory_region(dimm); + uint64_t curr_addr =3D addr; + uint64_t size =3D memory_region_size(mr); + uint32_t nr_lmbs =3D size / SPAPR_MEMORY_BLOCK_SIZE; + uint32_t avail_lmbs =3D 0; + int i =3D 0; + + for (i =3D 0; i < nr_lmbs; i++) { + drc =3D spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB, + curr_addr / SPAPR_MEMORY_BLOCK_SIZE= ); + g_assert(drc); + if (drc->indicator_state !=3D SPAPR_DR_INDICATOR_STATE_INACTIVE) { + avail_lmbs++; + } + curr_addr +=3D SPAPR_MEMORY_BLOCK_SIZE; + } + + sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); + sPAPRDIMMState *ds =3D g_malloc0(sizeof(sPAPRDIMMState)); + ds->nr_lmbs =3D avail_lmbs; + ds->addr =3D addr; + spapr_pending_dimm_unplugs_add(spapr, ds); + return ds; +} + /* Callback to be called during DRC release. */ void spapr_lmb_release(DeviceState *dev) { @@ -2657,7 +2687,14 @@ void spapr_lmb_release(DeviceState *dev) sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); sPAPRDIMMState *ds =3D spapr_pending_dimm_unplugs_find(spapr, addr); =20 - if (--ds->nr_lmbs) { + /* This information will get lost if a migration occurs + * during the unplug process. In this case recover it. */ + if (ds =3D=3D NULL) { + ds =3D spapr_recover_pending_dimm_state(PC_DIMM(dev), addr); + if (ds->nr_lmbs) { + return; + } + } else if (--ds->nr_lmbs) { return; } =20 --=20 2.9.4 From nobody Sun May 5 06:52:06 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 1495140175861686.5038013717783; Thu, 18 May 2017 13:42:55 -0700 (PDT) Received: from localhost ([::1]:55451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBSG6-0007SW-Jx for importer@patchew.org; Thu, 18 May 2017 16:42:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBS9z-0002lK-5K for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBS9t-0005y6-V8 for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:35 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38440 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 1dBS9t-0005xz-Pd for qemu-devel@nongnu.org; Thu, 18 May 2017 16:36:29 -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 v4IKY3in036132 for ; Thu, 18 May 2017 16:36:29 -0400 Received: from e24smtp03.br.ibm.com (e24smtp03.br.ibm.com [32.104.18.24]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ahjhprk5w-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 18 May 2017 16:36:28 -0400 Received: from localhost by e24smtp03.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 May 2017 17:36:27 -0300 Received: from d24relay03.br.ibm.com (9.18.232.225) by e24smtp03.br.ibm.com (10.172.0.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 18 May 2017 17:36:25 -0300 Received: from d24av03.br.ibm.com (d24av03.br.ibm.com [9.8.31.95]) by d24relay03.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4IKaPto24182868; Thu, 18 May 2017 17:36:25 -0300 Received: from d24av03.br.ibm.com (localhost [127.0.0.1]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v4IKaBLI021736; Thu, 18 May 2017 17:36:11 -0300 Received: from localhost.localdomain ([9.80.214.94]) by d24av03.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v4IKZsrU021455; Thu, 18 May 2017 17:36:09 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Thu, 18 May 2017 17:35:48 -0300 X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170518203548.14207-1-danielhb@linux.vnet.ibm.com> References: <20170518203548.14207-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17051820-0024-0000-0000-0000017605BE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051820-0025-0000-0000-0000163D52F3 Message-Id: <20170518203548.14207-6-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-18_04:, , 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-1705180140 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 v10 5/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, mdroth@linux.vnet.ibm.com, 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 7d304fc..ec1605a 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1444,6 +1444,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; @@ -1542,6 +1573,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.4