From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzDAq-0003V6-8a for qemu-devel@nongnu.org; Tue, 25 Oct 2016 21:38:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzDAo-0006N6-1C for qemu-devel@nongnu.org; Tue, 25 Oct 2016 21:38:36 -0400 Date: Wed, 26 Oct 2016 11:57:33 +1100 From: David Gibson Message-ID: <20161026005733.GR11052@umbus.fritz.box> References: <1477370856-8940-1-git-send-email-mdroth@linux.vnet.ibm.com> <1477370856-8940-11-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="C6e6/dnRACxPVebH" Content-Disposition: inline In-Reply-To: <1477370856-8940-11-git-send-email-mdroth@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH 10/10] spapr: Memory hot-unplug support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth Cc: qemu-devel@nongnu.org, nfont@linux.vnet.ibm.com, qemu-ppc@nongnu.org, jallen@linux.vnet.ibm.com, bharata@linux.vnet.ibm.com --C6e6/dnRACxPVebH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Oct 24, 2016 at 11:47:36PM -0500, Michael Roth wrote: > From: Bharata B Rao >=20 > Add support to hot remove pc-dimm memory devices. >=20 > Since we're introducing a machine-level unplug_request hook, we also > had handling for CPU unplug there as well to ensure CPU unplug > continues to work as it did before. >=20 > Signed-off-by: Bharata B Rao > * add hooks to CAS/cmdline enablement of hotplug ACR support > * add hook for CPU unplug > Signed-off-by: Michael Roth > --- > hw/ppc/spapr.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++= +++++- > hw/ppc/spapr_drc.c | 17 ++++++++ > 2 files changed, 135 insertions(+), 1 deletion(-) >=20 > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index 0b3aa2f..a4a6058 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -2281,6 +2281,90 @@ out: > error_propagate(errp, local_err); > } > =20 > +typedef struct sPAPRDIMMState { > + uint32_t nr_lmbs; > +} sPAPRDIMMState; > + > +static void spapr_lmb_release(DeviceState *dev, void *opaque) > +{ > + sPAPRDIMMState *ds =3D (sPAPRDIMMState *)opaque; > + HotplugHandler *hotplug_ctrl =3D NULL; No reason for the NULL initializer here - you set the variable unconditionally below. Otherwise, Reviewed-by: David Gibson > + if (--ds->nr_lmbs) { > + return; > + } > + > + g_free(ds); > + > + /* > + * Now that all the LMBs have been removed by the guest, call the > + * pc-dimm unplug handler to cleanup up the pc-dimm device. > + */ > + hotplug_ctrl =3D qdev_get_hotplug_handler(dev); > + hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); > +} > + > +static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64= _t size, > + Error **errp) > +{ > + 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_LM= B, > + nr_lmbs, > + drck->get_index(drc)); > +} > + > +static void spapr_memory_unplug(HotplugHandler *hotplug_dev, DeviceState= *dev, > + Error **errp) > +{ > + sPAPRMachineState *ms =3D SPAPR_MACHINE(hotplug_dev); > + PCDIMMDevice *dimm =3D PC_DIMM(dev); > + PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); > + MemoryRegion *mr =3D ddc->get_memory_region(dimm); > + > + pc_dimm_memory_unplug(dev, &ms->hotplug_memory, mr); > + object_unparent(OBJECT(dev)); > +} > + > +static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev, > + DeviceState *dev, Error **errp) > +{ > + 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; > + > + addr =3D object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &l= ocal_err); > + if (local_err) { > + goto out; > + } > + > + spapr_del_lmbs(dev, addr, size, &error_abort); > +out: > + error_propagate(errp, local_err); > +} > + > void *spapr_populate_hotplug_cpu_dt(CPUState *cs, int *fdt_offset, > sPAPRMachineState *spapr) > { > @@ -2354,10 +2438,42 @@ static void spapr_machine_device_plug(HotplugHand= ler *hotplug_dev, > static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev, > DeviceState *dev, Error **errp) > { > + sPAPRMachineState *sms =3D SPAPR_MACHINE(qdev_get_machine()); > MachineClass *mc =3D MACHINE_GET_CLASS(qdev_get_machine()); > =20 > if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { > - error_setg(errp, "Memory hot unplug not supported by sPAPR"); > + if (spapr_ovec_test(sms->ov5_cas, OV5_HP_EVT)) { > + spapr_memory_unplug(hotplug_dev, dev, errp); > + } else { > + error_setg(errp, "Memory hot unplug not supported for this g= uest"); > + } > + } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { > + if (!mc->query_hotpluggable_cpus) { > + error_setg(errp, "CPU hot unplug not supported on this machi= ne"); > + return; > + } > + spapr_core_unplug(hotplug_dev, dev, errp); > + } > +} > + > +static void spapr_machine_device_unplug_request(HotplugHandler *hotplug_= dev, > + DeviceState *dev, Error = **errp) > +{ > + sPAPRMachineState *sms =3D SPAPR_MACHINE(qdev_get_machine()); > + MachineClass *mc =3D MACHINE_GET_CLASS(qdev_get_machine()); > + > + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { > + if (spapr_ovec_test(sms->ov5_cas, OV5_HP_EVT)) { > + spapr_memory_unplug_request(hotplug_dev, dev, errp); > + } else { > + /* NOTE: this means there is a window after guest reset, pri= or to > + * CAS negotiation, where unplug requests will fail due to t= he > + * capability not being detected yet. This is a bit differen= t than > + * the case with PCI unplug, where the events will be queued= and > + * eventually handled by the guest after boot > + */ > + error_setg(errp, "Memory hot unplug not supported for this g= uest"); > + } > } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { > if (!mc->query_hotpluggable_cpus) { > error_setg(errp, "CPU hot unplug not supported on this machi= ne"); > @@ -2503,6 +2619,7 @@ static void spapr_machine_class_init(ObjectClass *o= c, void *data) > hc->plug =3D spapr_machine_device_plug; > hc->unplug =3D spapr_machine_device_unplug; > mc->cpu_index_to_socket_id =3D spapr_cpu_index_to_socket_id; > + hc->unplug_request =3D spapr_machine_device_unplug_request; > =20 > smc->dr_lmb_enabled =3D true; > smc->tcg_default_cpu =3D "POWER8"; > diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c > index 6e54fd4..a0c44ee 100644 > --- a/hw/ppc/spapr_drc.c > +++ b/hw/ppc/spapr_drc.c > @@ -68,6 +68,23 @@ static uint32_t set_isolation_state(sPAPRDRConnector *= drc, > } > } > =20 > + /* > + * Fail any requests to ISOLATE the LMB DRC if this LMB doesn't > + * belong to a DIMM device that is marked for removal. > + * > + * Currently the guest userspace tool drmgr that drives the memory > + * hotplug/unplug will just try to remove a set of 'removable' LMBs > + * in response to a hot unplug request that is based on drc-count. > + * If the LMB being removed doesn't belong to a DIMM device that is > + * actually being unplugged, fail the isolation request here. > + */ > + if (drc->type =3D=3D SPAPR_DR_CONNECTOR_TYPE_LMB) { > + if ((state =3D=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) && > + !drc->awaiting_release) { > + return RTAS_OUT_HW_ERROR; > + } > + } > + > drc->isolation_state =3D state; > =20 > if (drc->isolation_state =3D=3D SPAPR_DR_ISOLATION_STATE_ISOLATED) { --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --C6e6/dnRACxPVebH Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYD/99AAoJEGw4ysog2bOSyrwP/iDnLgJjD/GtfpP1LrJtFD1a C+lHhINVEcUhKCQxPm92R9k7dFKomunyZfmCt0kd+RWXPWlrlffQR25H8vuFOw83 XJ+NFktnBEY3WEou3koZ0kqotjyMnTKNNKm6A6CprUSkMFjanmczVonTpnpVw6/D ZakhQkXiWC9rkVMJqNy7ZlkTEXvBzSEHx/fnxtDk/QfnvQRbKzxwaAP60FTQtGHA h4RafglycE80/4yi8FyVlc9h1BpcL/Sozrtj/HE5YiyCzKfoXptaKzqS7nIVObjJ pTGf+58jDJGlYfubYyRTHkB8g8/UYOFKGmdsh6zzHhiX4/9MUGcHpN3yhMpHqEKg 0FV7cjDyRZrWHEDx81Xku9A/vpIuilYcV2aUEGXeo1Wp5NJj967/VX1+7pPgxWi2 ltqYPFV8GVY37WzKl8rucN27MwrcgDPmsvJcR7EuCu4bMgMxQ5aJ+vdLFBjaIkrf SYNwaqajEXnOZzzXve4EBh6Tty/KDqexjkGbv42Hmu5hnp4y51lKlhEney2lLUvh HCJz5h4yG42F/8D45br9VTWuj9bUr6zhYrJn5UM5xeeP2KfL+r4EhHD/ct/TLpQt JOsceEgAmKS5f0OyYNmMjw1VMwJrLXTpFjy258V/5yMboyro5FsicuKFq4zEqpQS Qcym1PX3TjmR/8xQBeb1 =ztMq -----END PGP SIGNATURE----- --C6e6/dnRACxPVebH--