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 <mjros...@linux.vnet.ibm.com> --- 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