From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ag1i3-0006xP-UD for qemu-devel@nongnu.org; Tue, 15 Mar 2016 23:01:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ag1i2-00060s-Cq for qemu-devel@nongnu.org; Tue, 15 Mar 2016 23:01:19 -0400 Date: Wed, 16 Mar 2016 12:36:05 +1100 From: David Gibson Message-ID: <20160316013605.GC9032@voom> References: <1458016736-10544-1-git-send-email-bharata@linux.vnet.ibm.com> <1458016736-10544-3-git-send-email-bharata@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="/+TVfO13bGamJ+u9" Content-Disposition: inline In-Reply-To: <1458016736-10544-3-git-send-email-bharata@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [RFC PATCH v2 2/2] spapr: Memory hot-unplug support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao Cc: thuth@redhat.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, nfont@linux.vnet.ibm.com, imammedo@redhat.com --/+TVfO13bGamJ+u9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 15, 2016 at 10:08:56AM +0530, Bharata B Rao wrote: > Add support to hot remove pc-dimm memory devices. >=20 > Signed-off-by: Bharata B Rao Reviewed-by: David Gibson Looks correct, but again, needs to wait on the PAPR change. Have you thought any further on the idea of sending an index message, then a count message as an interim approach to fixing this without requiring a PAPR change? > --- > hw/ppc/spapr.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++= +++++- > hw/ppc/spapr_drc.c | 18 +++++++++++ > 2 files changed, 110 insertions(+), 1 deletion(-) >=20 > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index 43708a2..cdf268a 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -2197,6 +2197,88 @@ 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; > + > + 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, uint64_t siz= e, > + 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)); > + uint32_t start_index; > + > + 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); > + if (!i) { > + start_index =3D drck->get_index(drc); > + } > + addr +=3D SPAPR_MEMORY_BLOCK_SIZE; > + } > + spapr_hotplug_req_remove_by_count_indexed(SPAPR_DR_CONNECTOR_TYPE_LM= B, > + nr_lmbs, start_index); > +} > + > +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); > +} > + > static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, > DeviceState *dev, Error **errp) > { > @@ -2244,7 +2326,15 @@ static void spapr_machine_device_unplug(HotplugHan= dler *hotplug_dev, > DeviceState *dev, Error **errp) > { > if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { > - error_setg(errp, "Memory hot unplug not supported by sPAPR"); > + spapr_memory_unplug(hotplug_dev, dev, errp); > + } > +} > + > +static void spapr_machine_device_unplug_request(HotplugHandler *hotplug_= dev, > + DeviceState *dev, Error = **errp) > +{ > + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { > + spapr_memory_unplug_request(hotplug_dev, dev, errp); > } > } > =20 > @@ -2293,6 +2383,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; > fwc->get_dev_path =3D spapr_get_fw_dev_path; > diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c > index ef063c0..740b9d4 100644 > --- a/hw/ppc/spapr_drc.c > +++ b/hw/ppc/spapr_drc.c > @@ -12,6 +12,7 @@ > =20 > #include "qemu/osdep.h" > #include "hw/ppc/spapr_drc.h" > +#include "hw/ppc/spapr.h" > #include "qom/object.h" > #include "hw/qdev.h" > #include "qapi/visitor.h" > @@ -78,6 +79,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 --/+TVfO13bGamJ+u9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJW6LiFAAoJEGw4ysog2bOSxWEP/Rhwa/1q2x6cSrtnV/zDhjxt WqO4IgdP0d3ORMGqNL9pnDBw35QR4nOn9bljJaqZQcWyQP46G/CsnbMrv2Vd3FQB eInmCLuc0avSVN5XExBfwWn7KbntsRfoi7REXMteWr53Vky20cDBjYV1pWPy+6uw px/q2NE0GzpUNLtRQdvxqxoyyxrouIHcoLbRxOc9pVuXDz7H+kfqBtgdtiZ+c5kl gntM5ItQVO3EBjr8meF6oWGuKa2J7if+bJavE70/ECLUtfyxaYfm0Df/bbuRnSKP T3EaXXVMTYaAoQJMRe36WGg+Gk4i4HcwtOFGDGtyGkQLc6wCOxFQr3Au4tgUfngM tu/Gk2Ekc77B4cCJ55ozcNbl4xjOpi6kT7MUWd7Xo26sHi8NrhsIMoNnqlf+K5KV 0Q2dXGZ4pckxcT6QeDKD49p+OQZr8gB3spw2mrV+zoUkm9m2c+9t3F69r0T+haLq PUmQsy9juc+yaOfM0GVYDn2OWVxmYFDFPr9XLB2TXdZPXvz4u+m3H2PvJo44+Ojp 6kBA0pXXWJKv+qxNU6UEZ287Nre0DpRUQiMYto3Pw85XkxiGLFQLYb1vYuAKb6bo NAVp3TYJdW1y4AD73yE5qtbJCt22Xckap0MOFdeAlF4mogkAYCBNmVX+3SJR46XB fEysOA8tH25JNGyoZi8b =+4MV -----END PGP SIGNATURE----- --/+TVfO13bGamJ+u9--