From patchwork Thu Aug 6 05:27:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 504566 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B7FB11402B5 for ; Thu, 6 Aug 2015 15:35:20 +1000 (AEST) Received: from localhost ([::1]:43448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNDpm-0003tv-2m for incoming@patchwork.ozlabs.org; Thu, 06 Aug 2015 01:35:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNDiN-0001kV-68 for qemu-devel@nongnu.org; Thu, 06 Aug 2015 01:27:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZNDiG-0007sz-0x for qemu-devel@nongnu.org; Thu, 06 Aug 2015 01:27:39 -0400 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:34038) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNDiF-0007r0-Az for qemu-devel@nongnu.org; Thu, 06 Aug 2015 01:27:31 -0400 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 6 Aug 2015 10:57:29 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp07.in.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 6 Aug 2015 10:57:26 +0530 X-Helo: d28dlp01.in.ibm.com X-MailFrom: bharata@linux.vnet.ibm.com X-RcptTo: qemu-ppc@nongnu.org Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 3D47CE0064; Thu, 6 Aug 2015 11:01:41 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay01.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t765RNKA983374; Thu, 6 Aug 2015 10:57:23 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t765RMLt024962; Thu, 6 Aug 2015 10:57:23 +0530 Received: from bharata.in.ibm.com ([9.124.35.131]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t765RLsI024829; Thu, 6 Aug 2015 10:57:22 +0530 From: Bharata B Rao To: qemu-devel@nongnu.org Date: Thu, 6 Aug 2015 10:57:16 +0530 Message-Id: <1438838837-28504-11-git-send-email-bharata@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1438838837-28504-1-git-send-email-bharata@linux.vnet.ibm.com> References: <1438838837-28504-1-git-send-email-bharata@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15080605-0025-0000-0000-0000063FB221 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 122.248.162.7 Cc: aik@ozlabs.ru, Bharata B Rao , mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, imammedo@redhat.com, afaerber@suse.de, david@gibson.dropbear.id.au Subject: [Qemu-devel] [RFC PATCH v4 10/11] spapr: CPU hot unplug support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Signed-off-by: Bharata B Rao --- hw/ppc/spapr.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 004a8e1..c05d85b 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2374,11 +2374,83 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, } } +static void spapr_cpu_destroy(PowerPCCPU *cpu) +{ + sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); + + xics_cpu_destroy(spapr->icp, cpu); + qemu_unregister_reset(spapr_cpu_reset, cpu); +} + +static void spapr_cpu_release(DeviceState *dev, void *opaque) +{ + CPUState *cs; + int i; + int id = ppc_get_vcpu_dt_id(POWERPC_CPU(CPU(dev))); + + for (i = id; i < id + smp_threads; i++) { + CPU_FOREACH(cs) { + PowerPCCPU *cpu = POWERPC_CPU(cs); + + if (i == ppc_get_vcpu_dt_id(cpu)) { + spapr_cpu_destroy(cpu); + cpu_remove(cs); + } + } + } +} + +static int spapr_cpu_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, + Error **errp) +{ + CPUState *cs = CPU(dev); + PowerPCCPU *cpu = POWERPC_CPU(cs); + int id = ppc_get_vcpu_dt_id(cpu); + int smt = kvmppc_smt_threads(); + sPAPRDRConnector *drc = + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id); + sPAPRDRConnectorClass *drck; + Error *local_err = NULL; + + /* + * SMT threads return from here, only main thread (core) will + * continue and signal hot unplug event to the guest. + */ + if ((id % smt) != 0) { + return 0; + } + g_assert(drc); + + drck = 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 notification + * interrupt to the guest for coldplugged CPUs started via -device + * option too. + */ + spapr_hotplug_req_remove_event(drc); + + return 0; +} + static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(qdev_get_machine()); + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { error_setg(errp, "Memory hot unplug not supported by sPAPR"); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + if (!smc->dr_cpu_enabled) { + error_setg(errp, "CPU hot unplug not supported on this machine"); + return; + } + spapr_cpu_unplug(hotplug_dev, dev, errp); } }