qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
To: qemu-ppc@nongnu.org
Cc: qemu-devel@nongnu.org, david@gibson.dropbear.id.au,
	agraf@suse.de, Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Subject: [Qemu-devel] [PATCH 3/5] target/ppc: Implement migration support for large decrementer
Date: Thu,  8 Jun 2017 17:03:49 +1000	[thread overview]
Message-ID: <20170608070351.1434-4-sjitindarsingh@gmail.com> (raw)
In-Reply-To: <20170608070351.1434-1-sjitindarsingh@gmail.com>

Implement support to migrate a guest which is using the large
decrementer.

We need to save the decrementer width to the migration stream.
On incoming migration we then need to check that the hypervisor is
capable of letting the guest use the large decrementer and that the
decrementer width is the same on the receiving side. Since there is no
way to tell the guest when the width of the decrementer changes we have
to terminate if the decrementer width is not what the guest expects.
If we can use the large decrementer then we have to tell the hypervisor
to enable it.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
---
 hw/ppc/spapr.c         | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h |  1 +
 2 files changed, 64 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 5d10366..6ba869a 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1420,6 +1420,45 @@ static bool spapr_vga_init(PCIBus *pci_bus, Error **errp)
     }
 }
 
+static int spapr_import_large_decr_bits(sPAPRMachineState *spapr)
+{
+    /*
+     * If the guest uses the large decrementer then this hypervisor must also
+     * support it and have the exact same width. We must also enable the large
+     * decrementer because we have no way to tell the guest to stop using it.
+     */
+    if (spapr->large_decr_bits) {
+        uint32_t dec_bits = 32;
+        PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
+        CPUState *cs = CPU(cpu);
+        PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs);
+
+        if (kvm_enabled()) {
+            if (!kvmppc_has_cap_large_decr()) {
+                error_report("Host doesn't support large decrementer and guest requires it");
+                return -EINVAL;
+            }
+            dec_bits = kvmppc_get_dec_bits();
+        } else {
+            dec_bits = pcc->large_decr_bits;
+        }
+
+        if (spapr->large_decr_bits != dec_bits) {
+            error_report("Host large decrementer size [%u] doesn't match what guest expects [%u]",
+                         dec_bits, spapr->large_decr_bits);
+            return -EINVAL;
+        }
+
+        if (kvm_enabled()) {
+            CPU_FOREACH(cs) {
+                kvmppc_configure_large_decrementer(cs, true);
+            }
+        }
+    }
+
+    return 0;
+}
+
 static int spapr_post_load(void *opaque, int version_id)
 {
     sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
@@ -1439,8 +1478,13 @@ static int spapr_post_load(void *opaque, int version_id)
      * value into the RTC device */
     if (version_id < 3) {
         err = spapr_rtc_import_offset(&spapr->rtc, spapr->rtc_offset);
+        if (err) {
+            return err;
+        }
     }
 
+    err = spapr_import_large_decr_bits(spapr);
+
     return err;
 }
 
@@ -1529,6 +1573,24 @@ static const VMStateDescription vmstate_spapr_patb_entry = {
     },
 };
 
+static bool spapr_large_decr_entry_needed(void *opaque)
+{
+    sPAPRMachineState *spapr = opaque;
+
+    return !!spapr->large_decr_bits;
+}
+
+static const VMStateDescription vmstate_spapr_large_decr_entry = {
+    .name = "spapr_large_decr_entry",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = spapr_large_decr_entry_needed,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32(large_decr_bits, sPAPRMachineState),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
 static const VMStateDescription vmstate_spapr = {
     .name = "spapr",
     .version_id = 3,
@@ -1547,6 +1609,7 @@ static const VMStateDescription vmstate_spapr = {
     .subsections = (const VMStateDescription*[]) {
         &vmstate_spapr_ov5_cas,
         &vmstate_spapr_patb_entry,
+        &vmstate_spapr_large_decr_entry,
         NULL
     }
 };
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 98fb78b..4ba9b89 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -91,6 +91,7 @@ struct sPAPRMachineState {
     sPAPROptionVector *ov5_cas;     /* negotiated (via CAS) option vectors */
     bool cas_reboot;
     bool cas_legacy_guest_workaround;
+    uint32_t large_decr_bits; /* Large decrementer width (0 -> not in use) */
 
     Notifier epow_notifier;
     QTAILQ_HEAD(, sPAPREventLogEntry) pending_events;
-- 
2.9.4

  parent reply	other threads:[~2017-06-08  7:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-08  7:03 [Qemu-devel] [PATCH 0/5] target/ppc: Implement support for the Large Decrementer Suraj Jitindar Singh
2017-06-08  7:03 ` [Qemu-devel] [PATCH 1/5] target/ppc: Implement large decrementer support for TCG Suraj Jitindar Singh
2017-06-13  7:50   ` David Gibson
2017-06-08  7:03 ` [Qemu-devel] [PATCH 2/5] target/ppc: Implement large decrementer support for KVM Suraj Jitindar Singh
2017-06-13  8:15   ` David Gibson
2017-06-08  7:03 ` Suraj Jitindar Singh [this message]
2017-06-13  8:20   ` [Qemu-devel] [PATCH 3/5] target/ppc: Implement migration support for large decrementer David Gibson
2017-06-08  7:03 ` [Qemu-devel] [PATCH 4/5] target/ppc: Enable the large decrementer for TCG and KVM guests Suraj Jitindar Singh
2017-06-08  7:03 ` [Qemu-devel] [PATCH 5/5] target/ppc: Add cmd line option to disable the large decrementer Suraj Jitindar Singh

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=20170608070351.1434-4-sjitindarsingh@gmail.com \
    --to=sjitindarsingh@gmail.com \
    --cc=agraf@suse.de \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /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).