qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alvise Rigo <a.rigo@virtualopensystems.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	tech@virtualopensystems.com,
	Alvise Rigo <a.rigo@virtualopensystems.com>
Subject: [Qemu-devel]  [PATCH v2 3/7] target-arm: Add a way to mask some
Date: Tue, 18 Mar 2014 10:19:45 +0100	[thread overview]
Message-ID: <1395134389-25778-4-git-send-email-a.rigo@virtualopensystems.com> (raw)
In-Reply-To: <1395134389-25778-1-git-send-email-a.rigo@virtualopensystems.com>

One of the issues blocking the migration from KVM to TCG is that the
former processor reads the coprocessors values directly from the
underlying hardware. TCG however, for the way it emulates some
registers, is not able to verify the incoming values, failing the
migration.

Add a mask to the ARMCPRegInfo structure to exclude the bits not supported of
the incoming registers values.
In case of an outgoing migration, the unsupported data is retrieved from the
cpreg_vmstate array.

Signed-off-by: Alvise Rigo <a.rigo@virtualopensystems.com>
---
 target-arm/cpu.h    |  1 +
 target-arm/helper.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 0a7edfe..adcfa42 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -955,6 +955,7 @@ struct ARMCPRegInfo {
      * fieldoffset is 0 then no reset will be done.
      */
     CPResetFn *resetfn;
+    uint64_t attr_mask;
 };
 
 /* Macros which are lvalues for the field in CPUARMState for the
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 2791dac..30973cc 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -166,6 +166,50 @@ static void write_raw_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri,
     }
 }
 
+static bool cpreg_find_vmstate_val(ARMCPU *cpu, uint64_t id,
+                                        const uint64_t *val)
+{
+    int i;
+
+    for (i = 0; i < cpu->cpreg_vmstate_array_len; i++) {
+        if (cpu->cpreg_vmstate_indexes[i] == id) {
+            val = &cpu->cpreg_vmstate_values[i];
+            return true;
+        }
+    }
+
+    return false;
+}
+
+static uint64_t read_incoming_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *ri,
+                                                         uint64_t reg_id)
+{
+    CPUARMState *env = &cpu->env;
+    uint64_t val = read_raw_cp_reg(env, ri);
+    const uint64_t *inc_val = NULL;
+
+    if (cpreg_find_vmstate_val(cpu, reg_id, inc_val) && ri->attr_mask) {
+        val &= ri->attr_mask;
+        val |= (*inc_val & ~ri->attr_mask);
+    }
+
+    return val;
+}
+
+static void write_incoming_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri,
+                             uint64_t *v)
+{
+    if (ri->attr_mask) {
+        *v &= ri->attr_mask;
+        if (ri->type & ARM_CP_CONST) {
+            /* verify equality only of the supported values */
+            *v |= ri->resetvalue & ~ri->attr_mask;
+        }
+    }
+
+    write_raw_cp_reg(env, ri, *v);
+}
+
 bool write_cpustate_to_list(ARMCPU *cpu)
 {
     /* Write the coprocessor state from cpu->env to the (index,value) list. */
@@ -184,7 +228,8 @@ bool write_cpustate_to_list(ARMCPU *cpu)
         if (ri->type & ARM_CP_NO_MIGRATE) {
             continue;
         }
-        cpu->cpreg_values[i] = read_raw_cp_reg(&cpu->env, ri);
+        cpu->cpreg_values[i] = read_incoming_cp_reg(cpu, ri,
+                                     cpu->cpreg_indexes[i]);
     }
     return ok;
 }
@@ -211,7 +256,7 @@ bool write_list_to_cpustate(ARMCPU *cpu)
          * (to catch read-only registers and partially read-only
          * registers where the incoming migration value doesn't match)
          */
-        write_raw_cp_reg(&cpu->env, ri, v);
+        write_incoming_cp_reg(&cpu->env, ri, &v);
         if (read_raw_cp_reg(&cpu->env, ri) != v) {
             ok = false;
         }
-- 
1.8.3.2

  parent reply	other threads:[~2014-03-18  9:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-18  9:19 [Qemu-devel] [PATCH v2 0/7] target-arm: KVM to TCG migration Alvise Rigo
2014-03-18  9:19 ` [Qemu-devel] [PATCH v2 1/7] target-arm: Decouple AArch64 cp registers Alvise Rigo
2014-03-18  9:19 ` [Qemu-devel] [PATCH v2 2/7] target-arm: Migrate CCSIDR registers Alvise Rigo
2014-03-18  9:19 ` Alvise Rigo [this message]
2014-03-18  9:19 ` [Qemu-devel] [PATCH v2 4/7] target-arm: Exclude IC bit from L2CTLR Alvise Rigo
2014-03-18  9:19 ` [Qemu-devel] [PATCH v2 5/7] target-arm: Make TTBR0/1 and TTBRC cp Alvise Rigo
2014-03-18  9:19 ` [Qemu-devel] [PATCH v2 6/7] target-arm: Added ADFSR/AIFSR and REVIDR Alvise Rigo
2014-03-18  9:19 ` [Qemu-devel] [PATCH v2 7/7] target-arm: Minor cp registers changes Alvise Rigo

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=1395134389-25778-4-git-send-email-a.rigo@virtualopensystems.com \
    --to=a.rigo@virtualopensystems.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=tech@virtualopensystems.com \
    /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).