From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMG1C-0006ZV-Iv for qemu-devel@nongnu.org; Sun, 10 Jul 2016 10:47:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMG17-0000C9-Nx for qemu-devel@nongnu.org; Sun, 10 Jul 2016 10:47:37 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:14995) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMG17-0000BL-FL for qemu-devel@nongnu.org; Sun, 10 Jul 2016 10:47:33 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u6AEi9dr061332 for ; Sun, 10 Jul 2016 10:47:30 -0400 Received: from e28smtp04.in.ibm.com (e28smtp04.in.ibm.com [125.16.236.4]) by mx0a-001b2d01.pphosted.com with ESMTP id 242vjuf6xn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 10 Jul 2016 10:47:29 -0400 Received: from localhost by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 10 Jul 2016 20:17:26 +0530 Date: Sun, 10 Jul 2016 20:17:20 +0530 From: Bharata B Rao Reply-To: bharata@linux.vnet.ibm.com References: <146798352770.17402.11063109294574588761.stgit@bahia.lan> <20160708174701.2686c00b@bahia.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160708174701.2686c00b@bahia.lan> Message-Id: <20160710144720.GL25522@in.ibm.com> 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: Greg Kurz Cc: David Gibson , qemu-ppc@nongnu.org, qemu-devel@nongnu.org On Fri, Jul 08, 2016 at 05:47:01PM +0200, Greg Kurz wrote: > 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 Reviewed-by: Bharata B Rao This prevents the crash, but unplug still fails and that will be fixed only by having your patchset where device tree id is derived from core index. Regards, Bharata.