From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqAg8-0005pz-LR for qemu-devel@nongnu.org; Wed, 06 May 2015 21:32:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqAg3-0005zs-Pc for qemu-devel@nongnu.org; Wed, 06 May 2015 21:32:44 -0400 Date: Thu, 7 May 2015 11:09:56 +1000 From: David Gibson Message-ID: <20150507010956.GH1407@voom.redhat.com> References: <1429858066-12088-1-git-send-email-bharata@linux.vnet.ibm.com> <1429858066-12088-21-git-send-email-bharata@linux.vnet.ibm.com> <20150505072838.GQ14090@voom.redhat.com> <20150506075555.GQ18380@in.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="kHRd/tpU31Zn62xO" Content-Disposition: inline In-Reply-To: <20150506075555.GQ18380@in.ibm.com> Subject: Re: [Qemu-devel] [RFC PATCH v3 20/24] spapr: CPU hot unplug support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao Cc: mdroth@linux.vnet.ibm.com, aik@ozlabs.ru, agraf@suse.de, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, imammedo@redhat.com, afaerber@suse.de --kHRd/tpU31Zn62xO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 06, 2015 at 01:25:55PM +0530, Bharata B Rao wrote: > On Tue, May 05, 2015 at 05:28:38PM +1000, David Gibson wrote: > > On Fri, Apr 24, 2015 at 12:17:42PM +0530, Bharata B Rao wrote: > > > Support hot removal of CPU for sPAPR guests by sending the hot unplug > > > notification to the guest via EPOW interrupt. Release the vCPU object > > > after CPU hot unplug so that vCPU fd can be parked and reused. > > >=20 > > > Signed-off-by: Bharata B Rao > > > --- > > > hw/ppc/spapr.c | 101 ++++++++++++++++++++++++++++++++++= +++++++++- > > > target-ppc/translate_init.c | 10 +++++ > > > 2 files changed, 110 insertions(+), 1 deletion(-) > > >=20 > > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > > > index 9b0701c..910a50f 100644 > > > --- a/hw/ppc/spapr.c > > > +++ b/hw/ppc/spapr.c > > > @@ -1481,6 +1481,12 @@ static void spapr_cpu_init(PowerPCCPU *cpu) > > > qemu_register_reset(spapr_cpu_reset, cpu); > > > } > > > =20 > > > +static void spapr_cpu_destroy(PowerPCCPU *cpu) > > > +{ > > > + xics_cpu_destroy(spapr->icp, cpu); > > > + qemu_unregister_reset(spapr_cpu_reset, cpu); > > > +} > > > + > > > /* pSeries LPAR / sPAPR hardware init */ > > > static void ppc_spapr_init(MachineState *machine) > > > { > > > @@ -1883,6 +1889,24 @@ static void *spapr_populate_hotplug_cpu_dt(Dev= iceState *dev, CPUState *cs, > > > return fdt; > > > } > > > =20 > > > +static void spapr_cpu_release(DeviceState *dev, void *opaque) > > > +{ > > > + CPUState *cs; > > > + int i; > > > + int id =3D ppc_get_vcpu_dt_id(POWERPC_CPU(CPU(dev))); > > > + > > > + for (i =3D id; i < id + smp_threads; i++) { > > > + CPU_FOREACH(cs) { > > > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); > > > + > > > + if (i =3D=3D ppc_get_vcpu_dt_id(cpu)) { > > > + spapr_cpu_destroy(cpu); > > > + cpu_remove(cs); > > > + } > > > + } > > > + } > > > +} > > > + > > > static void spapr_cpu_plug(HotplugHandler *hotplug_dev, DeviceState = *dev, > > > Error **errp) > > > { > > > @@ -1970,6 +1994,59 @@ static void spapr_cpu_plug(HotplugHandler *hot= plug_dev, DeviceState *dev, > > > return; > > > } > > > =20 > > > +static int spapr_cpu_unplug(Object *obj, void *opaque) > > > +{ > > > + Error **errp =3D opaque; > > > + DeviceState *dev =3D DEVICE(obj); > > > + CPUState *cs =3D CPU(dev); > > > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); > > > + int id =3D ppc_get_vcpu_dt_id(cpu); > > > + int smt =3D kvmppc_smt_threads(); > > > + sPAPRDRConnector *drc =3D > > > + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id); > > > + sPAPRDRConnectorClass *drck; > > > + Error *local_err =3D NULL; > > > + > > > + /* > > > + * SMT threads return from here, only main thread (core) will > > > + * continue and signal hot unplug event to the guest. > > > + */ > > > + if ((id % smt) !=3D 0) { > > > + return 0; > > > + } > >=20 > > As with the in-plug side couldn't this be done more naturally by > > attaching this function to the cpu core object rather than the thread? >=20 > When I switch to core level addition in the next version, I will see > how best this can be handled. >=20 > >=20 > > > + g_assert(drc); > > > + > > > + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); > > > + drck->detach(drc, dev, spapr_cpu_release, NULL, &local_err); > > > + if (local_err) { > > > + error_propagate(errp, local_err); > > > + return -1; > > > + } > > > + > > > + /* > > > + * In addition to hotplugged CPUs, send the hot-unplug notificat= ion > > > + * interrupt to the guest for coldplugged CPUs started via -devi= ce > > > + * option too. > > > + */ > > > + spapr_hotplug_req_remove_event(drc); > >=20 > > Um.. doesn't the remove notification need to go *before* the > > "physical" unplug? Along with a wait for acknowledgement from the > > guest? >=20 > If I am reading it right, PCI hotplug is also following the same order > (detach followed by guest notification). So for PCI that might work. Attempting to access an unplugged device should mean IO reads return 0xff. PCI drivers are supposed to be able to cope with that at least long enough for the unplug notification to come through. You absolutely can't unplug CPUs without the OS relinquishing them first though. > Let me experiment with this in the next version. >=20 > Regards, > Bharata. >=20 --=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 --kHRd/tpU31Zn62xO Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVSrtkAAoJEGw4ysog2bOSVYwQANDoQY9Ip2RdKIkbnt1HqR+g EupXmIjoMwtIodScX5AIPkJazF21THVyiMqslSvO4IeBI/IFi4JtTkWtSnDGRDlS Ws+QUnkyAArK7dtPhhkk710UOLU1/0btk1iE+9HUScuXxoiFTCml+73QAI89o0Ww FPtxYNiOIy0mRzg1bLZQXQphbdJK1CdxmrAurvtMMmfLrog4BvyZH9mOm+rvgZT+ niUIDt6CaDRzyNqwAV5yFvzq90Fb8GY6se4ABOCY0F4xJ1fkyzzhbto/df6QegxZ 1Gfa4ZzxDgnUwyVoG8Nym/5Hik05iuxXkRuXl4nVxZmMDn7xDy1unRnN+O3Fhlh/ bzdWs3HYd5A2FezFeMD2a6xdpR45t118eu6hQOaggSaMsDTmwaBNL1lhjpqki35y NGO0o1BQ0f7AKnBFLtwMAqSn+bCulXPeQAXk5QVapnv6DQn2LFwG3ZHKEywXn2ta xR5uChVZk2quQTE6ZHLxpj7bTAY2hrci/cnAOm6CveVeg6AFU8p6AHz9IVpFmXF5 l1rvWN57yY3/KSMMlvvD8EIhFf5C/aChOJ+VS5z2KU8s0U5QH/jAb2IXyeZnmx+3 C40cg92c4aAdAD3BUolB02NZcSOXTL2ygmGnFIxwR26FZqDL7cjCLf1IfRrhYCC/ Nr4EoA9kXYFcq3X7/4+a =W4kP -----END PGP SIGNATURE----- --kHRd/tpU31Zn62xO--