From nobody Sun Feb 8 14:52:56 2026 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 1495481889392937.8286406854259; Mon, 22 May 2017 12:38:09 -0700 (PDT) Received: from localhost ([::1]:44562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dCt9a-0006Y5-SH for importer@patchew.org; Mon, 22 May 2017 15:38:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dCt7q-0005DA-Jz for qemu-devel@nongnu.org; Mon, 22 May 2017 15:36:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dCt7m-0000CK-Qv for qemu-devel@nongnu.org; Mon, 22 May 2017 15:36:18 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:35318) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dCt7m-0000Bq-HL for qemu-devel@nongnu.org; Mon, 22 May 2017 15:36:14 -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 v4MJ9DjE113078 for ; Mon, 22 May 2017 15:36:13 -0400 Received: from e24smtp05.br.ibm.com (e24smtp05.br.ibm.com [32.104.18.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 2am3rw5pxv-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 22 May 2017 15:36:13 -0400 Received: from localhost by e24smtp05.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 May 2017 16:36:10 -0300 Received: from d24relay04.br.ibm.com (9.18.232.146) by e24smtp05.br.ibm.com (10.172.0.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 22 May 2017 16:36:09 -0300 Received: from d24av02.br.ibm.com (d24av02.br.ibm.com [9.8.31.93]) by d24relay04.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4MJa8Bx47841500; Mon, 22 May 2017 16:36:09 -0300 Received: from d24av02.br.ibm.com (localhost [127.0.0.1]) by d24av02.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v4MJa8iK017091; Mon, 22 May 2017 16:36:08 -0300 Received: from localhost.localdomain ([9.85.129.159]) by d24av02.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v4MJa2uU017026; Mon, 22 May 2017 16:36:06 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Mon, 22 May 2017 16:35:47 -0300 X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170522193551.826-1-danielhb@linux.vnet.ibm.com> References: <20170522193551.826-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17052219-0032-0000-0000-00000560FBA8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052219-0033-0000-0000-000011E661DE Message-Id: <20170522193551.826-2-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-22_10:, , 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-1705220098 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 v11 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. As an additional cleanup made by this patch, the spapr_del_lmbs function was merged with spapr_memory_unplug_request. The former was being called only by the latter and both were small enough to fit one single function. Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 98 +++++++++++++++++++++++++++++++---------------= ---- include/hw/ppc/spapr.h | 6 ++++ 2 files changed, 68 insertions(+), 36 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 75e298b..5743b78 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2059,6 +2059,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); @@ -2612,58 +2613,57 @@ out: error_propagate(errp, local_err); } =20 -typedef struct sPAPRDIMMState { +struct sPAPRDIMMState { + PCDIMMDevice *dimm; uint32_t nr_lmbs; -} sPAPRDIMMState; + QTAILQ_ENTRY(sPAPRDIMMState) next; +}; + +static sPAPRDIMMState *spapr_pending_dimm_unplugs_find(sPAPRMachineState *= s, + PCDIMMDevice *dimm) +{ + sPAPRDIMMState *dimm_state =3D NULL; + QTAILQ_FOREACH(dimm_state, &s->pending_dimm_unplugs, next) { + if (dimm_state->dimm =3D=3D dimm) { + 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->dimm)); + 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); +} =20 static void spapr_lmb_release(DeviceState *dev, void *opaque) { - sPAPRDIMMState *ds =3D (sPAPRDIMMState *)opaque; - HotplugHandler *hotplug_ctrl; + HotplugHandler *hotplug_ctrl =3D qdev_get_hotplug_handler(dev); + sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_ctrl); + sPAPRDIMMState *ds =3D spapr_pending_dimm_unplugs_find(spapr, PC_DIMM(= dev)); =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 * 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); } =20 -static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t= size, - Error **errp) -{ - sPAPRDRConnector *drc; - 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; - - 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); - - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->detach(drc, dev, spapr_lmb_release, ds, errp); - addr +=3D SPAPR_MEMORY_BLOCK_SIZE; - } - - drc =3D spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB, - addr_start / SPAPR_MEMORY_BLOCK_SIZE); - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - spapr_hotplug_req_remove_by_count_indexed(SPAPR_DR_CONNECTOR_TYPE_LMB, - nr_lmbs, - drck->get_index(drc)); -} - static void spapr_memory_unplug(HotplugHandler *hotplug_dev, DeviceState *= dev, Error **errp) { @@ -2684,14 +2684,40 @@ static void spapr_memory_unplug_request(HotplugHand= ler *hotplug_dev, PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *mr =3D ddc->get_memory_region(dimm); uint64_t size =3D memory_region_size(mr); + uint32_t nr_lmbs =3D size / SPAPR_MEMORY_BLOCK_SIZE; uint64_t addr; + sPAPRDRConnector *drc; + sPAPRDRConnectorClass *drck; =20 addr =3D object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &loc= al_err); if (local_err) { goto out; } =20 - spapr_del_lmbs(dev, addr, size, &error_abort); + sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_dev); + sPAPRDIMMState *ds =3D g_malloc0(sizeof(sPAPRDIMMState)); + ds->nr_lmbs =3D nr_lmbs; + ds->dimm =3D dimm; + spapr_pending_dimm_unplugs_add(spapr, ds); + + uint64_t addr_start =3D addr; + int i; + 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); + + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + drck->detach(drc, dev, spapr_lmb_release, NULL, errp); + addr +=3D SPAPR_MEMORY_BLOCK_SIZE; + } + + drc =3D spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB, + addr_start / SPAPR_MEMORY_BLOCK_SIZE); + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + spapr_hotplug_req_remove_by_count_indexed(SPAPR_DR_CONNECTOR_TYPE_LMB, + nr_lmbs, + drck->get_index(drc)); out: error_propagate(errp, local_err); } diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index be2b3b8..87af2f1 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" @@ -105,6 +106,11 @@ struct sPAPRMachineState { /* RTAS state */ QTAILQ_HEAD(, sPAPRConfigureConnectorState) ccs_list; =20 + /* Pending DIMM unplug cache. It is populated when a LMB + * unplug starts. It can be regenerated if a migration + * occurs during the unplug process. */ + QTAILQ_HEAD(, sPAPRDIMMState) pending_dimm_unplugs; + /*< public >*/ char *kvm_type; MemoryHotplugState hotplug_memory; --=20 2.9.4