From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLXzk-0004b4-9z for qemu-devel@nongnu.org; Fri, 08 Jul 2016 11:47:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bLXzg-0004gX-66 for qemu-devel@nongnu.org; Fri, 08 Jul 2016 11:47:11 -0400 Received: from 4.mo69.mail-out.ovh.net ([46.105.42.102]:55292) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLXzf-0004gA-V0 for qemu-devel@nongnu.org; Fri, 08 Jul 2016 11:47:08 -0400 Received: from player779.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo69.mail-out.ovh.net (Postfix) with ESMTP id DF0D71014368 for ; Fri, 8 Jul 2016 17:47:06 +0200 (CEST) Date: Fri, 8 Jul 2016 17:47:01 +0200 From: Greg Kurz Message-ID: <20160708174701.2686c00b@bahia.lan> In-Reply-To: <146798352770.17402.11063109294574588761.stgit@bahia.lan> References: <146798352770.17402.11063109294574588761.stgit@bahia.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr: fix core unplug crash List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Bharata B Rao On Fri, 08 Jul 2016 15:12:07 +0200 Greg Kurz wrote: > If the host has 8 threads/core and the guest is started with: > > -smp cores=1,threads=4,maxcpus=12 > > It is possible to crash QEMU by doing: > > (qemu) device_add host-spapr-cpu-core,core-id=16,id=foo > (qemu) device_del foo > Segmentation fault > > This is caused because spapr_core_unplug() assumes cpu_dt_id == core_id. > Even if it happens to be the case when the host and guest have the same > number of threads per core, it is conceptually wrong and we may pass a > bogus id to spapr_dr_connector_by_id() and spapr_core_release() crashes. > > Let's use cc->core_id, which is the id that was used to create th DR > connector. My bad, I got excited and pointed out the wrong culprit... it is cpu_index again of course ! Please find an updated explanation to be put in the changelog after "Segmentation fault": ======================================================================== This happens because spapr_core_unplug() assumes cpu_dt_id == core_id. As long as cpu_dt_id is derived from the non-table cpu_index, this is only true when you plug cores with contiguous ids. It is safer to be consistent: the DR connector was created with an index that is immediately written to cc->core_id, and spapr_core_plug() also relies on cc->core_id. Let's use it also in spapr_core_unplug(). ======================================================================== > > Signed-off-by: Greg Kurz > --- > hw/ppc/spapr_cpu_core.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c > index 70b6b0b5ee17..106eaf45b399 100644 > --- a/hw/ppc/spapr_cpu_core.c > +++ b/hw/ppc/spapr_cpu_core.c > @@ -126,11 +126,9 @@ static void spapr_core_release(DeviceState *dev, void *opaque) > void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, > Error **errp) > { > - sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev)); > - PowerPCCPU *cpu = POWERPC_CPU(core->threads); > - int id = ppc_get_vcpu_dt_id(cpu); > + CPUCore *cc = CPU_CORE(dev); > sPAPRDRConnector *drc = > - spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id); > + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, cc->core_id); > sPAPRDRConnectorClass *drck; > Error *local_err = NULL; > > >