From nobody Tue Feb 10 17:31:03 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; dkim=fail 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 1495685074223142.8796955207779; Wed, 24 May 2017 21:04:34 -0700 (PDT) Received: from localhost ([::1]:58050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDk0m-0002SB-Sj for importer@patchew.org; Thu, 25 May 2017 00:04:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDjoU-0006at-7R for qemu-devel@nongnu.org; Wed, 24 May 2017 23:51:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDjoR-0007WZ-GO for qemu-devel@nongnu.org; Wed, 24 May 2017 23:51:50 -0400 Received: from ozlabs.org ([103.22.144.67]:34115) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dDjoQ-0007UG-S2; Wed, 24 May 2017 23:51:47 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wYFgZ3H8Zz9sNb; Thu, 25 May 2017 13:51:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1495684298; bh=vq5WQZ0EQldLXs1Zg9/dy/C7z+GYbXvSjcUxfg+Wqds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ONCUYyHPhwjDRzFfoMIpDEgWfnp8vE9ajVE+oaIKvYAuRc5pv523agE0/Y9FUMbG2 gYeQX/WI2W1UitBOXGd6K05A+6YfbIQjUFyAAukLp4YpkrrOcTQGSqBEqsHtRZijbI AokRebxFvRI7VEYPcW83gR2bLDBKA71lEFrptdsU= From: David Gibson To: peter.maydell@linaro.org Date: Thu, 25 May 2017 13:51:28 +1000 Message-Id: <20170525035132.24268-15-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170525035132.24268-1-david@gibson.dropbear.id.au> References: <20170525035132.24268-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 14/18] 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-devel@nongnu.org, aik@ozlabs.ru, sursingh@redhat.com, agraf@suse.de, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Daniel Henrique Barboza , sbobroff@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 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 [dwg: Minor stylistic cleanups] Signed-off-by: David Gibson --- hw/ppc/spapr.c | 105 +++++++++++++++++++++++++++++++--------------= ---- include/hw/ppc/spapr.h | 6 +++ 2 files changed, 73 insertions(+), 38 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 3760d37..3a79dab 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); @@ -2621,58 +2622,58 @@ static void spapr_memory_pre_plug(HotplugHandler *h= otplug_dev, DeviceState *dev, } } =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) { @@ -2688,19 +2689,47 @@ static void spapr_memory_unplug(HotplugHandler *hot= plug_dev, DeviceState *dev, static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_dev); Error *local_err =3D NULL; PCDIMMDevice *dimm =3D PC_DIMM(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); - uint64_t addr; + uint32_t nr_lmbs =3D size / SPAPR_MEMORY_BLOCK_SIZE; + uint64_t addr_start, addr; + int i; + sPAPRDRConnector *drc; + sPAPRDRConnectorClass *drck; + sPAPRDIMMState *ds; =20 - addr =3D object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &loc= al_err); + addr_start =3D object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, + &local_err); if (local_err) { goto out; } =20 - spapr_del_lmbs(dev, addr, size, &error_abort); + ds =3D g_malloc0(sizeof(sPAPRDIMMState)); + ds->nr_lmbs =3D nr_lmbs; + ds->dimm =3D dimm; + spapr_pending_dimm_unplugs_add(spapr, ds); + + addr =3D addr_start; + 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 8f424ca..777b5de 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,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