Skip to contentSkip to conversation

target-sparc: Update to use VMStateDescription

PATCH In review Peter Maydell 2 participants 12 messages Jan 11, 2016 – Jan 15, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover target-sparc: Update to use VMStateDescription

This patchset updates target-sparc to use VMStateDescription rather than hand-written save/load functions. (SPARC is the very last target still using the old approach. Once this patchset gets in via the sparc tree I'll send out the patches to clean up the core QOM CPU code to remove the unused support for hand-written save/load.)

It's based on some patches from back in 2012 by Juan which I've updated, rebased and made some tweaks to.

The major change here from v1 (sent back in August last year) is that we retain migration format compatibility for SPARC32. SPARC64 compat is broken, but SPARC64 migration doesn't work at the moment for any of our machines so that's OK.

Also new since v1 is the final patch, which fixes a bug spotted by Paolo where we weren't migrating env->cwp or env->psrpil for SPARC64. This bug fix means that sparc64 migration of a system that's sat at the boot prompt now works at least to the extent that the system will respond to key presses after the restore.

NB that the 'split cpu_put_psr' patch seems to me to be a bugfix in and of itself, since currently we might try to call cpu_check_irqs() and deliver interrupts while we're halfway through updating a PSR value...

Juan Quintela (4):
vmstate: introduce CPU_DoubleU arrays
vmstate: Introduce VMSTATE_VARRAY_MULTPLY
vmstate: define vmstate_info_uinttl
target-sparc: Convert to VMStateDescription

Peter Maydell (4):
target-sparc: Split cpu_put_psr into side-effect and no-side-effect
parts
target-sparc: Don't flush TLB in cpu_load function
target-sparc: Use VMState arrays for SPARC64 TLB/MMU state
target-sparc: Migrate CWP and PIL for SPARC64

 hw/sparc64/sun4u.c          |  24 ---
 include/hw/hw.h             |   2 +
 include/migration/vmstate.h |  18 +++
 migration/vmstate.c         |  27 ++++
 target-sparc/cpu-qom.h      |   4 +
 target-sparc/cpu.c          |   1 +
 target-sparc/cpu.h          |   7 +-
 target-sparc/machine.c      | 370 ++++++++++++++++++++------------------------
 target-sparc/win_helper.c   |  19 ++-
 9 files changed, 236 insertions(+), 236 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/8 vmstate: introduce CPU_DoubleU arrays

From: Juan Quintela <[email protected]>

Add vmstate support for migrating arrays of CPU_DoubleU via VMSTATE_CPUDOUBLE_ARRAY.

[PMM: rebased, since files have all moved since 2012;
added VMSTATE_CPUDOUBLE_ARRAY_V for consistency with FLOAT64]

---
 include/migration/vmstate.h |  7 +++++++
 migration/vmstate.c         | 23 +++++++++++++++++++++++
 2 files changed, 30 insertions(+)
include/migration/vmstate.h +7 -0
index 7267e38..a389bdc 100644
@@ -156,6 +156,7 @@ extern const VMStateInfo vmstate_info_uint32;
 extern const VMStateInfo vmstate_info_uint64;
 
 extern const VMStateInfo vmstate_info_float64;
+extern const VMStateInfo vmstate_info_cpudouble;
 
 extern const VMStateInfo vmstate_info_timer;
 extern const VMStateInfo vmstate_info_buffer;
@@ -768,6 +769,12 @@ extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_FLOAT64_ARRAY(_f, _s, _n)                             \
     VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0)
 
+#define VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, _v)                     \
+    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_cpudouble, CPU_DoubleU)
+
+#define VMSTATE_CPUDOUBLE_ARRAY(_f, _s, _n)                           \
+    VMSTATE_CPUDOUBLE_ARRAY_V(_f, _s, _n, 0)
+
 #define VMSTATE_BUFFER_V(_f, _s, _v)                                  \
     VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
 
migration/vmstate.c +23 -0
index e8ccf22..f70fe59 100644
@@ -794,6 +794,29 @@ const VMStateInfo vmstate_info_float64 = {
     .put  = put_float64,
 };
 
+/* CPU_DoubleU type */
+
+static int get_cpudouble(QEMUFile *f, void *pv, size_t size)
+{
+    CPU_DoubleU *v = pv;
+    qemu_get_be32s(f, &v->l.upper);
+    qemu_get_be32s(f, &v->l.lower);
+    return 0;
+}
+
+static void put_cpudouble(QEMUFile *f, void *pv, size_t size)
+{
+    CPU_DoubleU *v = pv;
+    qemu_put_be32s(f, &v->l.upper);
+    qemu_put_be32s(f, &v->l.lower);
+}
+
+const VMStateInfo vmstate_info_cpudouble = {
+    .name = "CPU_Double_U",
+    .get  = get_cpudouble,
+    .put  = put_cpudouble,
+};
+
 /* uint8_t buffers */
 
 static int get_buffer(QEMUFile *f, void *pv, size_t size)
Signature · 1 line
1.9.1
#2 lore raw

PATCH v2 2/8 vmstate: Introduce VMSTATE_VARRAY_MULTPLY

In reply to Peter Maydell

From: Juan Quintela <[email protected]>

This allows to send a partial array where the size is another structure field multiplied by a constant.

[PMM: updated to current master]
---
 include/migration/vmstate.h | 11 +++++++++++
 migration/vmstate.c         |  4 ++++
 2 files changed, 15 insertions(+)
include/migration/vmstate.h +11 -0
index a389bdc..4e8495d 100644
@@ -102,6 +102,7 @@ enum VMStateFlags {
     VMS_VARRAY_UINT32    = 0x800,  /* Array with size in uint32_t field*/
     VMS_MUST_EXIST       = 0x1000, /* Field must exist in input */
     VMS_ALLOC            = 0x2000, /* Alloc a buffer on the destination */
+    VMS_MULTIPLY_ELEMENTS = 0x4000, /* multiply varray size by field->num */
 };
 
 typedef struct {
@@ -246,6 +247,16 @@ extern const VMStateInfo vmstate_info_bitmap;
     .offset     = vmstate_offset_2darray(_state, _field, _type, _n1, _n2),  \
 }
 
+#define VMSTATE_VARRAY_MULTIPLY(_field, _state, _field_num, _multiply, _info, _type) { \
+    .name       = (stringify(_field)),                               \
+    .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\
+    .num        = (_multiply),                                       \
+    .info       = &(_info),                                          \
+    .size       = sizeof(_type),                                     \
+    .flags      = VMS_VARRAY_UINT32|VMS_MULTIPLY_ELEMENTS,           \
+    .offset     = offsetof(_state, _field),                          \
+}
+
 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
     .name         = (stringify(_field)),                              \
     .field_exists = (_test),                                          \
migration/vmstate.c +4 -0
index f70fe59..a7ad7f2 100644
@@ -28,6 +28,10 @@ static int vmstate_n_elems(void *opaque, VMStateField *field)
         n_elems = *(uint8_t *)(opaque+field->num_offset);
     }
 
+    if (field->flags & VMS_MULTIPLY_ELEMENTS) {
+        n_elems *= field->num;
+    }
+
     return n_elems;
 }
 
Signature · 1 line
1.9.1
#3 lore raw

PATCH v2 3/8 vmstate: define vmstate_info_uinttl

In reply to Peter Maydell

From: Juan Quintela <[email protected]>

We are going to define arrays of this type, so we need the integer type.

[PMM: updated to apply on current QEMU; renamed to 'uinttl'
rather than 'uinttls' to match other vmstate naming]

---
 include/hw/hw.h | 2 ++
 1 file changed, 2 insertions(+)
include/hw/hw.h +2 -0
index c78adae..cd3d410 100644
@@ -49,6 +49,7 @@ void qemu_unregister_reset(QEMUResetHandler *func, void *opaque);
     VMSTATE_UINT64_EQUAL_V(_f, _s, _v)
 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
     VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
+#define vmstate_info_uinttl vmstate_info_uint64
 #else
 #define VMSTATE_UINTTL_V(_f, _s, _v)                                  \
     VMSTATE_UINT32_V(_f, _s, _v)
@@ -56,6 +57,7 @@ void qemu_unregister_reset(QEMUResetHandler *func, void *opaque);
     VMSTATE_UINT32_EQUAL_V(_f, _s, _v)
 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
+#define vmstate_info_uinttl vmstate_info_uint32
 #endif
 #define VMSTATE_UINTTL(_f, _s)                                        \
     VMSTATE_UINTTL_V(_f, _s, 0)
Signature · 1 line
1.9.1
#4 lore raw

PATCH v2 4/8 target-sparc: Split cpu_put_psr into side-effect and no-side-effect parts

In reply to Peter Maydell

For inbound migration we really want to be able to set the PSR without having any side effects, but cpu_put_psr() calls cpu_check_irqs() which might try to deliver CPU interrupts. Split cpu_put_psr() into the no-side-effect and side-effect parts.

This includes reordering the cpu_check_irqs() to the end of cpu_put_psr(), because that function may actually end up calling cpu_interrupt(), which does not seem like a good thing to happen in the middle of updating the PSR.

---
 target-sparc/cpu.h        |  1 +
 target-sparc/win_helper.c | 19 ++++++++++++-------
 2 files changed, 13 insertions(+), 7 deletions(-)
target-sparc/cpu.h +1 -0
index 4aa689e..d963507 100644
@@ -539,6 +539,7 @@ int cpu_sparc_exec(CPUState *cpu);
 /* win_helper.c */
 target_ulong cpu_get_psr(CPUSPARCState *env1);
 void cpu_put_psr(CPUSPARCState *env1, target_ulong val);
+void cpu_put_psr_raw(CPUSPARCState *env1, target_ulong val);
 #ifdef TARGET_SPARC64
 target_ulong cpu_get_ccr(CPUSPARCState *env1);
 void cpu_put_ccr(CPUSPARCState *env1, target_ulong val);
target-sparc/win_helper.c +12 -7
index f01ae08..5b6d7b5 100644
@@ -64,23 +64,28 @@ target_ulong cpu_get_psr(CPUSPARCState *env)
 #endif
 }
 
-void cpu_put_psr(CPUSPARCState *env, target_ulong val)
+void cpu_put_psr_raw(CPUSPARCState *env, target_ulong val)
 {
     env->psr = val & PSR_ICC;
 #if !defined(TARGET_SPARC64)
     env->psref = (val & PSR_EF) ? 1 : 0;
     env->psrpil = (val & PSR_PIL) >> 8;
-#endif
-#if ((!defined(TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY))
-    cpu_check_irqs(env);
-#endif
-#if !defined(TARGET_SPARC64)
     env->psrs = (val & PSR_S) ? 1 : 0;
     env->psrps = (val & PSR_PS) ? 1 : 0;
     env->psret = (val & PSR_ET) ? 1 : 0;
-    cpu_set_cwp(env, val & PSR_CWP);
 #endif
     env->cc_op = CC_OP_FLAGS;
+#if !defined(TARGET_SPARC64)
+    cpu_set_cwp(env, val & PSR_CWP);
+#endif
+}
+
+void cpu_put_psr(CPUSPARCState *env, target_ulong val)
+{
+    cpu_put_psr_raw(env, val);
+#if ((!defined(TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY))
+    cpu_check_irqs(env);
+#endif
 }
 
 int cpu_cwp_inc(CPUSPARCState *env, int cwp)
Signature · 1 line
1.9.1
#5 lore raw

PATCH v2 5/8 target-sparc: Don't flush TLB in cpu_load function

In reply to Peter Maydell

There's no need to flush the TLB in the SPARC cpu_load function: we're guaranteed to be loading state into a fresh clean configuration.

---
 target-sparc/machine.c | 2 --
 1 file changed, 2 deletions(-)
target-sparc/machine.c +0 -2
index 3f3de4c..9d221ec 100644
@@ -112,7 +112,6 @@ void cpu_save(QEMUFile *f, void *opaque)
 int cpu_load(QEMUFile *f, void *opaque, int version_id)
 {
     CPUSPARCState *env = opaque;
-    SPARCCPU *cpu = sparc_env_get_cpu(env);
     int i;
     uint32_t tmp;
 
@@ -213,6 +212,5 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
     qemu_get_be64s(f, &env->ssr);
     cpu_get_timer(f, env->hstick);
 #endif
-    tlb_flush(CPU(cpu), 1);
     return 0;
 }
Signature · 1 line
1.9.1
#6 lore raw

PATCH v2 6/8 target-sparc: Convert to VMStateDescription

In reply to Peter Maydell

From: Juan Quintela <[email protected]>

Convert the SPARC CPU from cpu_load/save functions to VMStateDescription. We preserve migration compatibility with the previous version (required for SPARC32 but not necessarily for SPARC64).

[PMM:
* Rebase and update to apply to master
* VMSTATE_STRUCT_POINTER now takes type, not pointer-to-type
* QEMUTimer* are migrated via VMSTATE_TIMER_PTR
* Put CPUTimer vmstate struct inside TARGET_SPARC64 ifdef
* Convert handling of PSR to use a vmstate_psr, like Alpha and ARM
]

---
 hw/sparc64/sun4u.c     |  24 --
 target-sparc/cpu-qom.h |   4 +
 target-sparc/cpu.c     |   1 +
 target-sparc/cpu.h     |   6 -
 target-sparc/machine.c | 641 ++++++++++++++++++++++++++++++++++---------------
 5 files changed, 449 insertions(+), 227 deletions(-)
hw/sparc64/sun4u.c +0 -24
index 7a433d3..febbe89 100644
@@ -358,30 +358,6 @@ typedef struct ResetData {
     uint64_t prom_addr;
 } ResetData;
 
-void cpu_put_timer(QEMUFile *f, CPUTimer *s)
-{
-    qemu_put_be32s(f, &s->frequency);
-    qemu_put_be32s(f, &s->disabled);
-    qemu_put_be64s(f, &s->disabled_mask);
-    qemu_put_be32s(f, &s->npt);
-    qemu_put_be64s(f, &s->npt_mask);
-    qemu_put_sbe64s(f, &s->clock_offset);
-
-    timer_put(f, s->qtimer);
-}
-
-void cpu_get_timer(QEMUFile *f, CPUTimer *s)
-{
-    qemu_get_be32s(f, &s->frequency);
-    qemu_get_be32s(f, &s->disabled);
-    qemu_get_be64s(f, &s->disabled_mask);
-    qemu_get_be32s(f, &s->npt);
-    qemu_get_be64s(f, &s->npt_mask);
-    qemu_get_sbe64s(f, &s->clock_offset);
-
-    timer_get(f, s->qtimer);
-}
-
 static CPUTimer *cpu_timer_create(const char *name, SPARCCPU *cpu,
                                   QEMUBHFunc *cb, uint32_t frequency,
                                   uint64_t disabled_mask, uint64_t npt_mask)
target-sparc/cpu-qom.h +4 -0
index 477c4d5..5096b10 100644
@@ -75,6 +75,10 @@ static inline SPARCCPU *sparc_env_get_cpu(CPUSPARCState *env)
 
 #define ENV_OFFSET offsetof(SPARCCPU, env)
 
+#ifndef CONFIG_USER_ONLY
+extern const struct VMStateDescription vmstate_sparc_cpu;
+#endif
+
 void sparc_cpu_do_interrupt(CPUState *cpu);
 void sparc_cpu_dump_state(CPUState *cpu, FILE *f,
                           fprintf_function cpu_fprintf, int flags);
target-sparc/cpu.c +1 -0
index d98682b..c197a0f 100644
@@ -855,6 +855,7 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data)
     cc->do_unassigned_access = sparc_cpu_unassigned_access;
     cc->do_unaligned_access = sparc_cpu_do_unaligned_access;
     cc->get_phys_page_debug = sparc_cpu_get_phys_page_debug;
+    cc->vmsd = &vmstate_sparc_cpu;
 #endif
     cc->disas_set_info = cpu_sparc_disas_set_info;
 
target-sparc/cpu.h +0 -6
index d963507..58ff474 100644
@@ -374,10 +374,6 @@ struct CPUTimer
 
 typedef struct CPUTimer CPUTimer;
 
-struct QEMUFile;
-void cpu_put_timer(struct QEMUFile *f, CPUTimer *s);
-void cpu_get_timer(struct QEMUFile *f, CPUTimer *s);
-
 typedef struct CPUSPARCState CPUSPARCState;
 
 struct CPUSPARCState {
@@ -599,8 +595,6 @@ int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
 #define cpu_signal_handler cpu_sparc_signal_handler
 #define cpu_list sparc_cpu_list
 
-#define CPU_SAVE_VERSION 7
-
 /* MMU modes definitions */
 #if defined (TARGET_SPARC64)
 #define MMU_USER_IDX   0
target-sparc/machine.c +444 -197

657 lines not on this page · raw message

Signature · 1 line
1.9.1
#7 lore raw

PATCH v2 7/8 target-sparc: Use VMState arrays for SPARC64 TLB/MMU state

In reply to Peter Maydell

Use VMState arrays for SPARC64 TLB/MMU state. This is a migration-break for SPARC64 (but not for SPARC32), which is acceptable because currently migration does not work for any SPARC64 machines due to the lack of any migration of interrupt controller state.

---
This patch is optional but I think that the cleanup is worth it while we are still in a position to break sparc64 compat (and in any case we're going to bump the SPARC64 migration version to add env.tbr and env.cwp in the next patch.)

---
 target-sparc/machine.c | 314 +++----------------------------------------------
 1 file changed, 19 insertions(+), 295 deletions(-)
target-sparc/machine.c +19 -295
index bb9e44c..f8eebdd 100644
@@ -93,11 +93,21 @@ static void cpu_pre_save(void *opaque)
     cpu_set_cwp(env, env->cwp);
 }
 
+/* 32-bit SPARC retains migration compatibility with older versions
+ * of QEMU; 64-bit SPARC has had a migration break since then, so the
+ * versions are different.
+ */
+#ifndef TARGET_SPARC64
+#define SPARC_VMSTATE_VER 7
+#else
+#define SPARC_VMSTATE_VER 8
+#endif
+
 const VMStateDescription vmstate_sparc_cpu = {
     .name = "cpu",
-    .version_id = 7,
-    .minimum_version_id = 7,
-    .minimum_version_id_old = 7,
+    .version_id = SPARC_VMSTATE_VER,
+    .minimum_version_id = SPARC_VMSTATE_VER,
+    .minimum_version_id_old = SPARC_VMSTATE_VER,
     .pre_save = cpu_pre_save,
     .fields = (VMStateField[]) {
         VMSTATE_UINTTL_ARRAY(env.gregs, SPARCCPU, 8),
@@ -134,298 +144,12 @@ const VMStateDescription vmstate_sparc_cpu = {
         VMSTATE_UINT64_ARRAY(env.mmubpregs, SPARCCPU, 4),
 #else
         VMSTATE_UINT64(env.lsu, SPARCCPU),
-        /* Unfortunately we cannot use vmstate arrays for these because
-         * the pre-VMState migration code sent the contents on the wire
-         * interleaved rather than one array at a time.
-         */
-        VMSTATE_UINT64(env.immuregs[0], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[0], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[1], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[1], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[2], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[2], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[3], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[3], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[4], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[4], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[5], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[5], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[6], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[6], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[7], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[7], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[8], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[8], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[9], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[9], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[10], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[10], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[11], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[11], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[12], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[12], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[13], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[13], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[14], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[14], SPARCCPU),
-        VMSTATE_UINT64(env.immuregs[15], SPARCCPU),
-        VMSTATE_UINT64(env.dmmuregs[15], SPARCCPU),
-        VMSTATE_STRUCT(env.itlb[0], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[0], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[1], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[1], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[2], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[2], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[3], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[3], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[4], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[4], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[5], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[5], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[6], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[6], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[7], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[7], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[8], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[8], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[9], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[9], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[10], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[10], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[11], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[11], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[12], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[12], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[13], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[13], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[14], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[14], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[15], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[15], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[16], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[16], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[17], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[17], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[18], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[18], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[19], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[19], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[20], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[20], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[21], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[21], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[22], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[22], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[23], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[23], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[24], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[24], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[25], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[25], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[26], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[26], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[27], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[27], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[28], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[28], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[29], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[29], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[30], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[30], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[31], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[31], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[32], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[32], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[33], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[33], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[34], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[34], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[35], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[35], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[36], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[36], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[37], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[37], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[38], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[38], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[39], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[39], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[40], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[40], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[41], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[41], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[42], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[42], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[43], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[43], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[44], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[44], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[45], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[45], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[46], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[46], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[47], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[47], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[48], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[48], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[49], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[49], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[50], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[50], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[51], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[51], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[52], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[52], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[53], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[53], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[54], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[54], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[55], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[55], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[56], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[56], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[57], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[57], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[58], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[58], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[59], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[59], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[60], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[60], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[61], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[61], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[62], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[62], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.itlb[63], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
-        VMSTATE_STRUCT(env.dtlb[63], SPARCCPU, 0, vmstate_tlb_entry,
-                       SparcTLBEntry),
+        VMSTATE_UINT64_ARRAY(env.immuregs, SPARCCPU, 16),
+        VMSTATE_UINT64_ARRAY(env.dmmuregs, SPARCCPU, 16),
+        VMSTATE_STRUCT_ARRAY(env.itlb, SPARCCPU, 64, 0,
+                             vmstate_tlb_entry, SparcTLBEntry),
+        VMSTATE_STRUCT_ARRAY(env.dtlb, SPARCCPU, 64, 0,
+                             vmstate_tlb_entry, SparcTLBEntry),
         VMSTATE_UINT32(env.mmu_version, SPARCCPU),
         VMSTATE_STRUCT_ARRAY(env.ts, SPARCCPU, MAXTL_MAX, 0,
                              vmstate_trap_state, trap_state),
Signature · 1 line
1.9.1
#8 lore raw

PATCH v2 8/8 target-sparc: Migrate CWP and PIL for SPARC64

In reply to Peter Maydell

In SPARC32 the env->cwp and env->psrpil state is part of the PSR register, and gets migrated as part of that register. In SPARC64 this state is in separate CWP and PIL registers, but we were not doing anything to migrate those.

Add the missing fields to the migration vmstate (which is a migration break, but without these fields migration is completely broken anyway).

This change means that trying a save/load of a SPARC64 target at the boot rom prompt now produces a system which at least responds to keyboard input after the restore.

---
 target-sparc/machine.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target-sparc/machine.c +4 -1
index f8eebdd..aecbe2c 100644
@@ -100,7 +100,7 @@ static void cpu_pre_save(void *opaque)
 #ifndef TARGET_SPARC64
 #define SPARC_VMSTATE_VER 7
 #else
-#define SPARC_VMSTATE_VER 8
+#define SPARC_VMSTATE_VER 9
 #endif
 
 const VMStateDescription vmstate_sparc_cpu = {
@@ -181,6 +181,9 @@ const VMStateDescription vmstate_sparc_cpu = {
         VMSTATE_UINT64(env.hstick_cmpr, SPARCCPU),
         VMSTATE_UINT64(env.ssr, SPARCCPU),
         VMSTATE_CPU_TIMER(env.hstick, SPARCCPU),
+        /* On SPARC32 env.psrpil and env.cwp are migrated as part of the PSR */
+        VMSTATE_UINT32(env.psrpil, SPARCCPU),
+        VMSTATE_UINT32(env.cwp, SPARCCPU),
 #endif
         VMSTATE_END_OF_LIST()
     },
Signature · 1 line
1.9.1
Tested-by on the v2 series
#9 lore raw
In reply to Peter Maydell
Quoted 39 lines · Peter Maydell

This patchset updates target-sparc to use VMStateDescription rather than hand-written save/load functions. (SPARC is the very last target still using the old approach. Once this patchset gets in via the sparc tree I'll send out the patches to clean up the core QOM CPU code to remove the unused support for hand-written save/load.)

It's based on some patches from back in 2012 by Juan which I've updated, rebased and made some tweaks to.

The major change here from v1 (sent back in August last year) is that we retain migration format compatibility for SPARC32. SPARC64 compat is broken, but SPARC64 migration doesn't work at the moment for any of our machines so that's OK.

Also new since v1 is the final patch, which fixes a bug spotted by Paolo where we weren't migrating env->cwp or env->psrpil for SPARC64. This bug fix means that sparc64 migration of a system that's sat at the boot prompt now works at least to the extent that the system will respond to key presses after the restore.

NB that the 'split cpu_put_psr' patch seems to me to be a bugfix in and of itself, since currently we might try to call cpu_check_irqs() and deliver interrupts while we're halfway through updating a PSR value...

Juan Quintela (4):
vmstate: introduce CPU_DoubleU arrays
vmstate: Introduce VMSTATE_VARRAY_MULTPLY
vmstate: define vmstate_info_uinttl
target-sparc: Convert to VMStateDescription

Peter Maydell (4):
target-sparc: Split cpu_put_psr into side-effect and no-side-effect
parts
target-sparc: Don't flush TLB in cpu_load function
target-sparc: Use VMState arrays for SPARC64 TLB/MMU state
target-sparc: Migrate CWP and PIL for SPARC64

Quoted 10 lines
 hw/sparc64/sun4u.c          |  24 ---
 include/hw/hw.h             |   2 +
 include/migration/vmstate.h |  18 +++
 migration/vmstate.c         |  27 ++++
 target-sparc/cpu-qom.h      |   4 +
 target-sparc/cpu.c          |   1 +
 target-sparc/cpu.h          |   7 +-
 target-sparc/machine.c      | 370 ++++++++++++++++++++------------------------
 target-sparc/win_helper.c   |  19 ++-
 9 files changed, 236 insertions(+), 236 deletions(-)

Hi Peter,

Thanks for doing this! It's one of those things that has been on my list of things to do but never seems to get to the the top...

I've just run through some SPARC32 tests with this patchset applied - testing a savevm/loadvm pair pre-patch and post-patch, and then a few random tests with various OSs at random points during boot and no regressions here, so:

The only minor nit I could see during review was that both patches 7 and 8 bump the VMState revision for SPARC64, and given that before the last patch in the set nothing works then is it just worth bumping once to version 8 in patch 7 and let that be it?

ATB,

Mark.

#10 lore raw
Quoted 6 lines · Mark Cave-Ayland

I've just run through some SPARC32 tests with this patchset applied - testing a savevm/loadvm pair pre-patch and post-patch, and then a few random tests with various OSs at random points during boot and no regressions here, so:

Thanks.

Quoted 4 lines

The only minor nit I could see during review was that both patches 7 and 8 bump the VMState revision for SPARC64, and given that before the last patch in the set nothing works then is it just worth bumping once to version 8 in patch 7 and let that be it?

My general feeling is that there isn't a significant shortage of positive integers that would lead us to want to conserve them :-) If you prefer only bumping once you can do that when you apply the patches to your target-sparc queue if you like.

thanks
-- PMM

#11 lore raw
Quoted 16 lines · Peter Maydell
Quoted 6 lines · Mark Cave-Ayland

I've just run through some SPARC32 tests with this patchset applied - testing a savevm/loadvm pair pre-patch and post-patch, and then a few random tests with various OSs at random points during boot and no regressions here, so:

Thanks.

Quoted 4 lines

The only minor nit I could see during review was that both patches 7 and 8 bump the VMState revision for SPARC64, and given that before the last patch in the set nothing works then is it just worth bumping once to version 8 in patch 7 and let that be it?

Quoted 4 lines

My general feeling is that there isn't a significant shortage of positive integers that would lead us to want to conserve them :-) If you prefer only bumping once you can do that when you apply the patches to your target-sparc queue if you like.

Ha well if no-one minds too much then I'm not too worried either :)

Quoted 1 line

From the cover letter it sounds like you've got some further QOM

clean-ups waiting on this, so I'll get it merged and queued shortly.

ATB,

Mark.