From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOTLs-0006mo-Bv for qemu-devel@nongnu.org; Wed, 27 Jan 2016 11:53:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOTLo-0003gr-1z for qemu-devel@nongnu.org; Wed, 27 Jan 2016 11:53:52 -0500 Received: from e19.ny.us.ibm.com ([129.33.205.209]:40583) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOTLn-0003gd-TY for qemu-devel@nongnu.org; Wed, 27 Jan 2016 11:53:47 -0500 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 27 Jan 2016 11:53:47 -0500 Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id BED21C90048 for ; Wed, 27 Jan 2016 11:53:43 -0500 (EST) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0RGrj4M18612308 for ; Wed, 27 Jan 2016 16:53:45 GMT Received: from d01av01.pok.ibm.com (localhost [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u0RGriKw003339 for ; Wed, 27 Jan 2016 11:53:45 -0500 From: Matthew Rosato Date: Wed, 27 Jan 2016 11:53:40 -0500 Message-Id: <1453913621-20961-10-git-send-email-mjrosato@linux.vnet.ibm.com> In-Reply-To: <1453913621-20961-1-git-send-email-mjrosato@linux.vnet.ibm.com> References: <1453913621-20961-1-git-send-email-mjrosato@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v3 09/10] s390/virtio-ccw: Add hotplug handler and prepare for unplug List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: agraf@suse.de, borntraeger@de.ibm.com, bharata@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, pbonzini@redhat.com, afaerber@suse.de, rth@twiddle.net Prepare for hotplug and unplug of s390-cpu. In the case of unplug, s390 does not have a safe way of communicating the loss of CPU to a guest, so a full system reset will be performed on the guest. Signed-off-by: Matthew Rosato --- hw/s390x/s390-virtio-ccw.c | 28 ++++++++++++++++++++++++++++ target-s390x/cpu.c | 33 ++++++++++++++++++++++++++++++++- target-s390x/cpu.h | 2 ++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 909c42f..547e070 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -155,10 +155,34 @@ static void ccw_init(MachineState *machine) gtod_save, gtod_load, kvm_state); } +static void s390_machine_device_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + +} + +static void s390_machine_device_unplug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + s390_cpu_unplug(hotplug_dev, dev, errp); + } +} + +static HotplugHandler *s390_get_hotplug_handler(MachineState *machine, + DeviceState *dev) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + return HOTPLUG_HANDLER(machine); + } + return NULL; +} + static void ccw_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); NMIClass *nc = NMI_CLASS(oc); + HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); mc->init = ccw_init; mc->reset = s390_machine_reset; @@ -170,6 +194,9 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) mc->no_sdcard = 1; mc->use_sclp = 1; mc->max_cpus = 255; + mc->get_hotplug_handler = s390_get_hotplug_handler; + hc->plug = s390_machine_device_plug; + hc->unplug = s390_machine_device_unplug; nc->nmi_monitor_handler = s390_nmi; } @@ -231,6 +258,7 @@ static const TypeInfo ccw_machine_info = { .class_init = ccw_machine_class_init, .interfaces = (InterfaceInfo[]) { { TYPE_NMI }, + { TYPE_HOTPLUG_HANDLER}, { } }, }; diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c index 0a669ac..46b1115 100644 --- a/target-s390x/cpu.c +++ b/target-s390x/cpu.c @@ -236,7 +236,6 @@ static void s390_cpu_initfn(Object *obj) #if !defined(CONFIG_USER_ONLY) struct tm tm; #endif - cs->env_ptr = env; cs->halted = 1; cs->exception_index = EXCP_HLT; @@ -268,6 +267,38 @@ static void s390_cpu_finalize(Object *obj) } #if !defined(CONFIG_USER_ONLY) +static void s390_cpu_destroy(S390CPU *cpu) +{ + CPUS390XState *env = &cpu->env; + s390_unregister_cpustate(env->cpu_num); +} + +static void s390_cpu_release(DeviceState *dev, void *opaque) +{ + CPUState *cs = CPU(dev); + + s390_cpu_destroy(S390_CPU(cs)); + cpu_remove_sync(cs); + object_unparent(OBJECT(dev)); +} + +int s390_cpu_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, + Error **errp) +{ + S390CPU *cpu = S390_CPU(dev); + CPUS390XState *env = &cpu->env; + + if (next_cpu_id > env->cpu_num) { + next_cpu_id = env->cpu_num; + } + s390_cpu_release(dev, NULL); + + /* Perform a full system reset */ + qemu_system_reset_request(); + + return 0; +} + static bool disabled_wait(CPUState *cpu) { return cpu->halted && !(S390_CPU(cpu)->env.psw.mask & diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index ae36fcc..c68c405 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -543,6 +543,8 @@ static inline uint8_t s390_cpu_get_state(S390CPU *cpu) void gtod_save(QEMUFile *f, void *opaque); int gtod_load(QEMUFile *f, void *opaque, int version_id); +int s390_cpu_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, + Error **errp); /* service interrupts are floating therefore we must not pass an cpustate */ void s390_sclp_extint(uint32_t parm); -- 1.9.1