qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Rosato <mjrosato@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: agraf@suse.de, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com,
	pbonzini@redhat.com, afaerber@suse.de, rth@twiddle.net
Subject: [Qemu-devel] [PATCH v2 8/9] s390/virtio-ccw: Add hotplug handler and prepare for unplug
Date: Thu, 19 Nov 2015 10:10:13 -0500	[thread overview]
Message-ID: <1447945814-15765-9-git-send-email-mjrosato@linux.vnet.ibm.com> (raw)
In-Reply-To: <1447945814-15765-1-git-send-email-mjrosato@linux.vnet.ibm.com>

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 <mjrosato@linux.vnet.ibm.com>
---
 hw/s390x/s390-virtio-ccw.c | 28 ++++++++++++++++++++++++++++
 target-s390x/cpu.c         | 32 +++++++++++++++++++++++++++++++-
 target-s390x/cpu.h         |  2 ++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 4f6ed57..ba0a90d 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 060a3cc..4b83a09 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;
@@ -282,6 +281,37 @@ 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(cs);
+}
+
+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 524a7e4..81554b5 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

  parent reply	other threads:[~2015-11-19 15:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-19 15:10 [Qemu-devel] [PATCH v2 0/9] s390: Allow hotplug of s390 CPUs Matthew Rosato
2015-11-19 15:10 ` [Qemu-devel] [PATCH v2 1/9] cpus: Reclaim vCPU objects Matthew Rosato
2015-11-20  2:33   ` Bharata B Rao
2015-11-20 13:37     ` Matthew Rosato
2015-11-19 15:10 ` [Qemu-devel] [PATCH v2 2/9] cpus: Add a sync version of cpu_remove() Matthew Rosato
2015-11-19 15:25   ` Paolo Bonzini
2015-11-19 15:36     ` Matthew Rosato
2015-11-19 15:10 ` [Qemu-devel] [PATCH v2 3/9] s390x/cpu: Cleanup init in preparation for hotplug Matthew Rosato
2015-11-19 15:10 ` [Qemu-devel] [PATCH v2 4/9] s390x/cpu: Set initial CPU state in common routine Matthew Rosato
2015-11-19 15:10 ` [Qemu-devel] [PATCH v2 5/9] s390x/cpu: Move some CPU initialization into realize Matthew Rosato
2015-11-19 15:10 ` [Qemu-devel] [PATCH v2 6/9] s390x/cpu: Add functions to (un)register CPU state Matthew Rosato
2015-11-19 15:10 ` [Qemu-devel] [PATCH v2 7/9] s390x/cpu: Extra cleanup during CPU finalize Matthew Rosato
2015-11-19 15:10 ` Matthew Rosato [this message]
2015-11-19 15:10 ` [Qemu-devel] [PATCH v2 9/9] s390x/cpu: Allow hot plug/unplug of CPUs Matthew Rosato

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447945814-15765-9-git-send-email-mjrosato@linux.vnet.ibm.com \
    --to=mjrosato@linux.vnet.ibm.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=borntraeger@de.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).