Skip to contentSkip to conversation

Improve traces on migration failure due to cpreg number mismatch

PATCH Superseded Eric Auger 3 participants 14 messages Feb 26 – Mar 3

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

cover Improve traces on migration failure due to cpreg number mismatch

This series comes as a follow-up of discussions held in [PATCH v6 00/11] Mitigation of "failed to load cpu:cpreg_vmstate_array_len" migration failures
(https://lore.kernel.org/all/[email protected]/)

It only covers the improvement of the traces. Actual mitigations will be handled in a separate series.

When the number of CPU registers received in an incoming migration stream is bigger than the number of CPU registers seen by the destination we currently get the following error:

"failed to load cpu:cpreg_vmstate_array_len"

This series removes this cryptic message and explicitly outputs which spurious registers cause the failures.

Available at:
https://github.com/eauger/qemu/tree/cpreg_vmstate_array_len_traces

Eric Auger (5):
vmstate: Introduce VMSTATE_VARRAY_INT32_ALLOC target/arm/machine: Use VMSTATE_VARRAY_INT32_ALLOC for cpreg arrays target/arm/kvm: Export kvm_print_register_name() target/arm/machine: Trace cpreg names which do not match on migration target/arm/machine: Trace all register mismatches

 include/migration/vmstate.h | 10 +++++++
 target/arm/kvm_arm.h        |  2 ++
 target/arm/helper.c         |  5 ----
 target/arm/kvm-stub.c       |  6 ++++
 target/arm/kvm.c            |  7 +----
 target/arm/machine.c        | 57 +++++++++++++++++++++++++++----------
 target/arm/trace-events     |  3 ++
 7 files changed, 64 insertions(+), 26 deletions(-)
Signature · 1 line
2.53.0
author
#1 lore raw

PATCH 1/5 vmstate: Introduce VMSTATE_VARRAY_INT32_ALLOC

Already existing VMSTATE_VARRAY_INT32 requires an array to be pre-allocated, however there are cases when the size is not known in advance and there is no real need to enforce it.

Introduce VMSTATE_VARRAY_INT32_ALLOC as we currently have for UINT32 and UINT16.

The first user of this variant will be the target/arm/machine.c cpreg indexes/values arrays.

---
 include/migration/vmstate.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/migration/vmstate.h +10 -0
index 89f9f49d20a..62c2abd0c49 100644
@@ -447,6 +447,16 @@ extern const VMStateInfo vmstate_info_qlist;
     .offset     = vmstate_offset_pointer(_state, _field, _type),     \
 }
 
+#define VMSTATE_VARRAY_INT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\
+    .name       = (stringify(_field)),                               \
+    .version_id = (_version),                                        \
+    .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \
+    .info       = &(_info),                                          \
+    .size       = sizeof(_type),                                     \
+    .flags      = VMS_VARRAY_INT32 | VMS_POINTER | VMS_ALLOC,        \
+    .offset     = vmstate_offset_pointer(_state, _field, _type),     \
+}
+
 #define VMSTATE_VARRAY_UINT32_ALLOC(_field, _state, _field_num, _version, _info, _type) {\
     .name       = (stringify(_field)),                               \
     .version_id = (_version),                                        \
Signature · 1 line
2.53.0
author
#7 lore raw

PATCH 3/5 target/arm/kvm: Export kvm_print_register_name()

In reply to Eric Auger

We want to use kvm_print_register_name() in machine.c so let's export the helper and implement a stub when kvm is not enabled.

---
 target/arm/kvm_arm.h  | 2 ++
 target/arm/kvm-stub.c | 6 ++++++
 target/arm/kvm.c      | 2 +-
 3 files changed, 9 insertions(+), 1 deletion(-)
target/arm/kvm_arm.h +2 -0
index cc0b374254e..b6980e4957a 100644
@@ -266,4 +266,6 @@ void arm_cpu_kvm_set_irq(void *arm_cpu, int irq, int level);
 
 void arm_gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3);
 
+gchar *kvm_print_register_name(uint64_t regidx);
+
 #endif
target/arm/kvm-stub.c +6 -0
index ea67deea520..b13bb055e0e 100644
@@ -129,3 +129,9 @@ void arm_gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3)
 {
     g_assert_not_reached();
 }
+
+gchar *kvm_print_register_name(uint64_t regidx)
+{
+    g_assert_not_reached();
+    return NULL;
+}
target/arm/kvm.c +1 -1
index 12a75f42e07..69efa3e8137 100644
@@ -913,7 +913,7 @@ static gchar *kvm_print_sve_register_name(uint64_t regidx)
     }
 }
 
-static gchar *kvm_print_register_name(uint64_t regidx)
+gchar *kvm_print_register_name(uint64_t regidx)
 {
         switch ((regidx & KVM_REG_ARM_COPROC_MASK)) {
         case KVM_REG_ARM_CORE:
Signature · 1 line
2.53.0
author
#9 lore raw

PATCH 4/5 target/arm/machine: Trace cpreg names which do not match on migration

In reply to Eric Auger

Whenever there is a mismatch between cpreg indexes in the incoming stream and cpregs exposed by the destination output the name of the register. We use a print_register_name() wrapper helper. At the moment we are only able to do a nice decoding of the index for KVM regs.

Without this patch, the error would be:
qemu-system-aarch64: load of migration failed: Operation not permitted:
error while loading state for instance 0x0 of device 'cpu': post load hook failed for: cpu, version_id: 22, minimum_version: 22, ret: -1 which is not helpful for the end user to understand the actual issue.

This patch adds the actual information about the probme:
qemu-system-aarch64: cpu_post_load: op0:3 op1:0 crn:2 crm:0 op2:3 in the incoming stream but unknown on the destination, fail migration

---
 target/arm/machine.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
target/arm/machine.c +19 -2
index 214087111bc..ee68e752ea9 100644
@@ -1,5 +1,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
+#include "cpregs.h"
 #include "trace.h"
 #include "qemu/error-report.h"
 #include "system/kvm.h"
@@ -1036,6 +1037,15 @@ static int cpu_pre_load(void *opaque)
     return 0;
 }
 
+static gchar *print_register_name(uint64_t kvm_regidx)
+{
+    if (kvm_enabled()) {
+        return kvm_print_register_name(kvm_regidx);
+    } else {
+        return g_strdup_printf("0x%x", kvm_to_cpreg_id(kvm_regidx));
+    }
+}
+
 static int cpu_post_load(void *opaque, int version_id)
 {
     ARMCPU *cpu = opaque;
@@ -1074,11 +1084,18 @@ static int cpu_post_load(void *opaque, int version_id)
     for (i = 0, v = 0; i < cpu->cpreg_array_len
              && v < cpu->cpreg_vmstate_array_len; i++) {
         if (cpu->cpreg_vmstate_indexes[v] > cpu->cpreg_indexes[i]) {
-            /* register in our list but not incoming : skip it */
+            g_autofree gchar *name = print_register_name(cpu->cpreg_indexes[i]);
+
+            warn_report("%s: %s "
+                        "expected by the destination but not in the incoming stream, "
+                        "skip it", __func__, name);
             continue;
         }
         if (cpu->cpreg_vmstate_indexes[v] < cpu->cpreg_indexes[i]) {
-            /* register in their list but not ours: fail migration */
+            g_autofree gchar *name = print_register_name(cpu->cpreg_vmstate_indexes[v]);
+
+            error_report("%s: %s in the incoming stream but unknown on the destination, "
+                         "fail migration", __func__, name);
             return -1;
         }
         /* matching register, copy the value over */
Signature · 1 line
2.53.0
author
#5 lore raw

PATCH 2/5 target/arm/machine: Use VMSTATE_VARRAY_INT32_ALLOC for cpreg arrays

In reply to Eric Auger

This removes the need for explicitly allocating cpreg_vmstate arrays. On post save we simply point to cpreg arrays and set the length accordingly.

Remove VMSTATE_VARRAY_INT32 for cpreg_vmstate_array_len as now the array is dynamically allocated.

Also add a trace point on post_load to trace potential mismatch between the number of incoming cpregs versus current ones.

---
 target/arm/helper.c     |  5 -----
 target/arm/kvm.c        |  5 -----
 target/arm/machine.c    | 24 +++++++++++++-----------
 target/arm/trace-events |  3 +++
 4 files changed, 16 insertions(+), 21 deletions(-)
target/arm/helper.c +0 -5
index 6bfab90981c..7389f2988c4 100644
@@ -265,15 +265,10 @@ void arm_init_cpreg_list(ARMCPU *cpu)
     if (arraylen) {
         cpu->cpreg_indexes = g_new(uint64_t, arraylen);
         cpu->cpreg_values = g_new(uint64_t, arraylen);
-        cpu->cpreg_vmstate_indexes = g_new(uint64_t, arraylen);
-        cpu->cpreg_vmstate_values = g_new(uint64_t, arraylen);
     } else {
         cpu->cpreg_indexes = NULL;
         cpu->cpreg_values = NULL;
-        cpu->cpreg_vmstate_indexes = NULL;
-        cpu->cpreg_vmstate_values = NULL;
     }
-    cpu->cpreg_vmstate_array_len = arraylen;
     cpu->cpreg_array_len = 0;
 
     g_hash_table_foreach(cpu->cp_regs, add_cpreg_to_list, cpu);
target/arm/kvm.c +0 -5
index ded582e0da0..12a75f42e07 100644
@@ -807,12 +807,7 @@ static int kvm_arm_init_cpreg_list(ARMCPU *cpu)
 
     cpu->cpreg_indexes = g_renew(uint64_t, cpu->cpreg_indexes, arraylen);
     cpu->cpreg_values = g_renew(uint64_t, cpu->cpreg_values, arraylen);
-    cpu->cpreg_vmstate_indexes = g_renew(uint64_t, cpu->cpreg_vmstate_indexes,
-                                         arraylen);
-    cpu->cpreg_vmstate_values = g_renew(uint64_t, cpu->cpreg_vmstate_values,
-                                        arraylen);
     cpu->cpreg_array_len = arraylen;
-    cpu->cpreg_vmstate_array_len = arraylen;
 
     for (i = 0, arraylen = 0; i < rlp->n; i++) {
         uint64_t regidx = rlp->reg[i];
target/arm/machine.c +13 -11
index bbaae344492..214087111bc 100644
@@ -1,5 +1,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
+#include "trace.h"
 #include "qemu/error-report.h"
 #include "system/kvm.h"
 #include "system/tcg.h"
@@ -984,11 +985,9 @@ static int cpu_pre_save(void *opaque)
         }
     }
 
+    cpu->cpreg_vmstate_indexes = cpu->cpreg_indexes;
+    cpu->cpreg_vmstate_values = cpu->cpreg_values;
     cpu->cpreg_vmstate_array_len = cpu->cpreg_array_len;
-    memcpy(cpu->cpreg_vmstate_indexes, cpu->cpreg_indexes,
-           cpu->cpreg_array_len * sizeof(uint64_t));
-    memcpy(cpu->cpreg_vmstate_values, cpu->cpreg_values,
-           cpu->cpreg_array_len * sizeof(uint64_t));
 
     return 0;
 }
@@ -1043,6 +1042,9 @@ static int cpu_post_load(void *opaque, int version_id)
     CPUARMState *env = &cpu->env;
     int i, v;
 
+    trace_cpu_post_load(cpu->cpreg_vmstate_array_len,
+                        cpu->cpreg_array_len);
+
     /*
      * Handle migration compatibility from old QEMU which didn't
      * send the irq-line-state subsection. A QEMU without it did not
@@ -1170,13 +1172,13 @@ const VMStateDescription vmstate_arm_cpu = {
         /* The length-check must come before the arrays to avoid
          * incoming data possibly overflowing the array.
          */
-        VMSTATE_INT32_POSITIVE_LE(cpreg_vmstate_array_len, ARMCPU),
-        VMSTATE_VARRAY_INT32(cpreg_vmstate_indexes, ARMCPU,
-                             cpreg_vmstate_array_len,
-                             0, vmstate_info_uint64, uint64_t),
-        VMSTATE_VARRAY_INT32(cpreg_vmstate_values, ARMCPU,
-                             cpreg_vmstate_array_len,
-                             0, vmstate_info_uint64, uint64_t),
+        VMSTATE_INT32(cpreg_vmstate_array_len, ARMCPU),
+        VMSTATE_VARRAY_INT32_ALLOC(cpreg_vmstate_indexes, ARMCPU,
+                                   cpreg_vmstate_array_len,
+                                   0, vmstate_info_uint64, uint64_t),
+        VMSTATE_VARRAY_INT32_ALLOC(cpreg_vmstate_values, ARMCPU,
+                                   cpreg_vmstate_array_len,
+                                   0, vmstate_info_uint64, uint64_t),
         VMSTATE_UINT64(env.exclusive_addr, ARMCPU),
         VMSTATE_UINT64(env.exclusive_val, ARMCPU),
         VMSTATE_UINT64(env.exclusive_high, ARMCPU),
target/arm/trace-events +3 -0
index 676d29fe516..2de0406f784 100644
@@ -26,3 +26,6 @@ arm_powerctl_reset_cpu(uint64_t mp_aff) "cpu %" PRIu64
 
 # tcg/psci.c and hvf/hvf.c
 arm_psci_call(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3, uint32_t cpuid) "PSCI Call x0=0x%016"PRIx64" x1=0x%016"PRIx64" x2=0x%016"PRIx64" x3=0x%016"PRIx64" cpuid=0x%x"
+
+# machine.c
+cpu_post_load(uint32_t cpreg_vmstate_array_len, uint32_t cpreg_array_len) "cpreg_vmstate_array_len=%d cpreg_array_len=%d"
Signature · 1 line
2.53.0
author
#11 lore raw

PATCH 5/5 target/arm/machine: Trace all register mismatches

In reply to Eric Auger

At the moment, cpu_post_load() exists with error on the first catch of unexpected register in the incoming stream. Let the code go further and trace all the issues before exiting.

---
 target/arm/machine.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
target/arm/machine.c +10 -2
index ee68e752ea9..7a3b5a87932 100644
@@ -1050,6 +1050,7 @@ static int cpu_post_load(void *opaque, int version_id)
 {
     ARMCPU *cpu = opaque;
     CPUARMState *env = &cpu->env;
+    bool fail = false;
     int i, v;
 
     trace_cpu_post_load(cpu->cpreg_vmstate_array_len,
@@ -1082,13 +1083,14 @@ static int cpu_post_load(void *opaque, int version_id)
      */
 
     for (i = 0, v = 0; i < cpu->cpreg_array_len
-             && v < cpu->cpreg_vmstate_array_len; i++) {
+             && v < cpu->cpreg_vmstate_array_len;) {
         if (cpu->cpreg_vmstate_indexes[v] > cpu->cpreg_indexes[i]) {
             g_autofree gchar *name = print_register_name(cpu->cpreg_indexes[i]);
 
             warn_report("%s: %s "
                         "expected by the destination but not in the incoming stream, "
                         "skip it", __func__, name);
+            i++;
             continue;
         }
         if (cpu->cpreg_vmstate_indexes[v] < cpu->cpreg_indexes[i]) {
@@ -1096,12 +1098,18 @@ static int cpu_post_load(void *opaque, int version_id)
 
             error_report("%s: %s in the incoming stream but unknown on the destination, "
                          "fail migration", __func__, name);
-            return -1;
+            v++;
+            fail = true;
+            continue;
         }
         /* matching register, copy the value over */
         cpu->cpreg_values[i] = cpu->cpreg_vmstate_values[v];
+        i++;
         v++;
     }
+    if (fail) {
+        return -1;
+    }
 
     if (kvm_enabled()) {
         if (!kvm_arm_cpu_post_load(cpu)) {
Signature · 1 line
2.53.0
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] vmstate: Introduce VMSTATE_VARRAY_INT32_ALLOC

In reply to Eric Auger
Quoted 5 lines · Eric Auger

Already existing VMSTATE_VARRAY_INT32 requires an array to be pre-allocated, however there are cases when the size is not known in advance and there is no real need to enforce it.

Quoted 8 lines

Introduce VMSTATE_VARRAY_INT32_ALLOC as we currently have for UINT32 and UINT16.

The first user of this variant will be the target/arm/machine.c cpreg indexes/values arrays.

thanks
-- PMM

#6 lore raw

Re: [PATCH 2/5] target/arm/machine: Use VMSTATE_VARRAY_INT32_ALLOC for cpreg arrays

In reply to Eric Auger
Quoted 11 lines · Eric Auger

This removes the need for explicitly allocating cpreg_vmstate arrays. On post save we simply point to cpreg arrays and set the length accordingly.

Remove VMSTATE_VARRAY_INT32 for cpreg_vmstate_array_len as now the array is dynamically allocated.

Also add a trace point on post_load to trace potential mismatch between the number of incoming cpregs versus current ones.

Quoted 7 lines
---
 target/arm/helper.c     |  5 -----
 target/arm/kvm.c        |  5 -----
 target/arm/machine.c    | 24 +++++++++++++-----------
 target/arm/trace-events |  3 +++

target/arm/whpx/whpx-all.c also has the code to initialize cpureg_vmstate_{indexes,values,array_len} that needs to be updated like the TCG and KVM code.

Quoted 51 lines
 4 files changed, 16 insertions(+), 21 deletions(-)
target/arm/helper.c +0 -5
index 6bfab90981c..7389f2988c4 100644
@@ -265,15 +265,10 @@ void arm_init_cpreg_list(ARMCPU *cpu)
     if (arraylen) {
         cpu->cpreg_indexes = g_new(uint64_t, arraylen);
         cpu->cpreg_values = g_new(uint64_t, arraylen);
-        cpu->cpreg_vmstate_indexes = g_new(uint64_t, arraylen);
-        cpu->cpreg_vmstate_values = g_new(uint64_t, arraylen);
     } else {
         cpu->cpreg_indexes = NULL;
         cpu->cpreg_values = NULL;
-        cpu->cpreg_vmstate_indexes = NULL;
-        cpu->cpreg_vmstate_values = NULL;
     }
-    cpu->cpreg_vmstate_array_len = arraylen;
     cpu->cpreg_array_len = 0;
 
     g_hash_table_foreach(cpu->cp_regs, add_cpreg_to_list, cpu);
target/arm/kvm.c +0 -5
index ded582e0da0..12a75f42e07 100644
@@ -807,12 +807,7 @@ static int kvm_arm_init_cpreg_list(ARMCPU *cpu)
 
     cpu->cpreg_indexes = g_renew(uint64_t, cpu->cpreg_indexes, arraylen);
     cpu->cpreg_values = g_renew(uint64_t, cpu->cpreg_values, arraylen);
-    cpu->cpreg_vmstate_indexes = g_renew(uint64_t, cpu->cpreg_vmstate_indexes,
-                                         arraylen);
-    cpu->cpreg_vmstate_values = g_renew(uint64_t, cpu->cpreg_vmstate_values,
-                                        arraylen);
     cpu->cpreg_array_len = arraylen;
-    cpu->cpreg_vmstate_array_len = arraylen;
 
     for (i = 0, arraylen = 0; i < rlp->n; i++) {
         uint64_t regidx = rlp->reg[i];
target/arm/machine.c +1 -0
index bbaae344492..214087111bc 100644
@@ -1,5 +1,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
+#include "trace.h"
 #include "qemu/error-report.h"
 #include "system/kvm.h"
 #include "system/tcg.h"

target/arm/machine.c static int cpu_pre_save(void *opaque) · line 991

Quoted 10 lines
target/arm/machine.c +2 -4
@@ -984,11 +985,9 @@ static int cpu_pre_save(void *opaque)
         }
     }
 
+    cpu->cpreg_vmstate_indexes = cpu->cpreg_indexes;
+    cpu->cpreg_vmstate_values = cpu->cpreg_values;
     cpu->cpreg_vmstate_array_len = cpu->cpreg_array_len;
-    memcpy(cpu->cpreg_vmstate_indexes, cpu->cpreg_indexes,
-           cpu->cpreg_array_len * sizeof(uint64_t));
-    memcpy(cpu->cpreg_vmstate_values, cpu->cpreg_values,
-           cpu->cpreg_array_len * sizeof(uint64_t));

This is OK for pre-save, but it could use a comment, maybe something like:

/*
* On outbound migration, send the data in our cpreg_{values,indexes}
* arrays. The migration code will not allocate anything, but just
* reads the data pointed to by the VMSTATE_VARRAY_INT32_ALLOC() fields. */

target/arm/machine.c static int cpu_post_load(void *opaque, int version_id) · line 1050

Quoted 13 lines
target/arm/machine.c +3 -0
     return 0;
 }
@@ -1043,6 +1042,9 @@ static int cpu_post_load(void *opaque, int version_id)
     CPUARMState *env = &cpu->env;
     int i, v;
 
+    trace_cpu_post_load(cpu->cpreg_vmstate_array_len,
+                        cpu->cpreg_array_len);
+
     /*
      * Handle migration compatibility from old QEMU which didn't
      * send the irq-line-state subsection. A QEMU without it did not

On post-load, something seems to be missing. The migration core code will have allocated (with g_malloc()) the memory for the arrays. When the post-load hook has finished checking and copying the data out of there it needs to free that memory (and probably set the pointers back to NULL to make accidental use-after-free easier to spot). Otherwise we will leak the memory if we do an incoming migration followed by an outbound migration.

Maybe we should enforce that these fields are always NULL/0 except during a migration, by having:
pre_save points them to the cpreg_indexes/cpreg_values arrays post_save sets them to NULL/0
pre_load (maybe) asserts them as NULL?
post_load uses the data and then frees it and sets them to NULL/0

and note that in the comment in cpu.h on the fields.

target/arm/machine.c const VMStateDescription vmstate_arm_cpu = { · line 1174

Quoted 4 lines
target/arm/machine.c +0 -0
@@ -1170,13 +1172,13 @@ const VMStateDescription vmstate_arm_cpu = {
         /* The length-check must come before the arrays to avoid
          * incoming data possibly overflowing the array.
          */

This comment needs to be updated -- we still need the length first, but it's no longer a length-check, and the reason is different:
we need to receive the length first so we can allocate the arrays before their data arrives.

Quoted 29 lines
target/arm/machine.c +7 -7
-        VMSTATE_INT32_POSITIVE_LE(cpreg_vmstate_array_len, ARMCPU),
-        VMSTATE_VARRAY_INT32(cpreg_vmstate_indexes, ARMCPU,
-                             cpreg_vmstate_array_len,
-                             0, vmstate_info_uint64, uint64_t),
-        VMSTATE_VARRAY_INT32(cpreg_vmstate_values, ARMCPU,
-                             cpreg_vmstate_array_len,
-                             0, vmstate_info_uint64, uint64_t),
+        VMSTATE_INT32(cpreg_vmstate_array_len, ARMCPU),
+        VMSTATE_VARRAY_INT32_ALLOC(cpreg_vmstate_indexes, ARMCPU,
+                                   cpreg_vmstate_array_len,
+                                   0, vmstate_info_uint64, uint64_t),
+        VMSTATE_VARRAY_INT32_ALLOC(cpreg_vmstate_values, ARMCPU,
+                                   cpreg_vmstate_array_len,
+                                   0, vmstate_info_uint64, uint64_t),
         VMSTATE_UINT64(env.exclusive_addr, ARMCPU),
         VMSTATE_UINT64(env.exclusive_val, ARMCPU),
         VMSTATE_UINT64(env.exclusive_high, ARMCPU),
target/arm/trace-events +3 -1
index 676d29fe516..2de0406f784 100644
@@ -26,3 +26,6 @@ arm_powerctl_reset_cpu(uint64_t mp_aff) "cpu %" PRIu64
 
 # tcg/psci.c and hvf/hvf.c
 arm_psci_call(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3, uint32_t cpuid) "PSCI Call x0=0x%016"PRIx64" x1=0x%016"PRIx64" x2=0x%016"PRIx64" x3=0x%016"PRIx64" cpuid=0x%x"
+
+# machine.c
+cpu_post_load(uint32_t cpreg_vmstate_array_len, uint32_t cpreg_array_len) "cpreg_vmstate_array_len=%d cpreg_array_len=%d"
--
Quoted 1 line

2.53.0

thanks
-- PMM

#8 lore raw

Re: [PATCH 3/5] target/arm/kvm: Export kvm_print_register_name()

In reply to Eric Auger
Quoted 17 lines · Eric Auger

We want to use kvm_print_register_name() in machine.c so let's export the helper and implement a stub when kvm is not enabled.

---
 target/arm/kvm_arm.h  | 2 ++
 target/arm/kvm-stub.c | 6 ++++++
 target/arm/kvm.c      | 2 +-
 3 files changed, 9 insertions(+), 1 deletion(-)
target/arm/kvm_arm.h +0 -0
index cc0b374254e..b6980e4957a 100644

target/arm/kvm_arm.h void arm_cpu_kvm_set_irq(void *arm_cpu, int irq, int level); · line 270

Quoted 5 lines
target/arm/kvm_arm.h +2 -0
@@ -266,4 +266,6 @@ void arm_cpu_kvm_set_irq(void *arm_cpu, int irq, int level);
 
 void arm_gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3);
 
+gchar *kvm_print_register_name(uint64_t regidx);
+

If this is going to be wider usage than just inside one file, then I think we should be a bit pickier about it:

* brief doc comment in the header file
* use the standard type "char *", not the glib funny typedef

Quoted 6 lines
target/arm/kvm_arm.h +0 -0
 #endif
target/arm/kvm-stub.c +0 -0
index ea67deea520..b13bb055e0e 100644

target/arm/kvm-stub.c void arm_gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3) · line 136

Quoted 8 lines
target/arm/kvm-stub.c +5 -0
@@ -129,3 +129,9 @@ void arm_gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3)
 {
     g_assert_not_reached();
 }
+
+gchar *kvm_print_register_name(uint64_t regidx)
+{
+    g_assert_not_reached();
+    return NULL;

Don't put code after a g_assert_not_reached().

target/arm/kvm-stub.c void arm_gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3) · line 137

Quoted 1 line
target/arm/kvm-stub.c +1 -0
+}

thanks
-- PMM

Reviewed-by on v1 4/5
#10 lore raw

Re: [PATCH 4/5] target/arm/machine: Trace cpreg names which do not match on migration

In reply to Eric Auger
Quoted 14 lines · Eric Auger

Whenever there is a mismatch between cpreg indexes in the incoming stream and cpregs exposed by the destination output the name of the register. We use a print_register_name() wrapper helper. At the moment we are only able to do a nice decoding of the index for KVM regs.

Without this patch, the error would be:
qemu-system-aarch64: load of migration failed: Operation not permitted:
error while loading state for instance 0x0 of device 'cpu': post load hook failed for: cpu, version_id: 22, minimum_version: 22, ret: -1 which is not helpful for the end user to understand the actual issue.

Quoted 3 lines

This patch adds the actual information about the probme:
qemu-system-aarch64: cpu_post_load: op0:3 op1:0 crn:2 crm:0 op2:3 in the incoming stream but unknown on the destination, fail migration

I think it would be helpful to be slightly more specific in both these messages by saying "system register", so in this example

qemu-system-aarch64: cpu_post_load: system register op0:3 op1:0 crn:2 crm:0 op2:3 in the
incoming stream but unknown on the destination: fail migration

and we should use ":" rather than "," at the end between the error and the bit about what we're going to do.

Otherwise

thanks
-- PMM

Reviewed-by on v1 5/5
#12 lore raw

Re: [PATCH 5/5] target/arm/machine: Trace all register mismatches

In reply to Eric Auger
Quoted 10 lines · Eric Auger

At the moment, cpu_post_load() exists with error on the first catch of unexpected register in the incoming stream. Let the code go further and trace all the issues before exiting.

---
 target/arm/machine.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

thanks
-- PMM

Reviewed-by on v1 1/5
#3 lore raw

Re: [PATCH 1/5] vmstate: Introduce VMSTATE_VARRAY_INT32_ALLOC

In reply to Eric Auger
Quoted 4 lines · Eric Auger

Already existing VMSTATE_VARRAY_INT32 requires an array to be pre-allocated, however there are cases when the size is not known in advance and there is no real need to enforce it.

Quoted 8 lines

Introduce VMSTATE_VARRAY_INT32_ALLOC as we currently have for UINT32 and UINT16.

The first user of this variant will be the target/arm/machine.c cpreg indexes/values arrays.

Signature · 1 line
Peter Xu
author
#13 lore raw
In reply to Eric Auger

Hi Peter,

Quoted 8 lines · Eric Auger

This series comes as a follow-up of discussions held in [PATCH v6 00/11] Mitigation of "failed to load cpu:cpreg_vmstate_array_len" migration failures
(https://lore.kernel.org/all/[email protected]/)

It only covers the improvement of the traces. Actual mitigations will be handled in a separate series.

Quoted 8 lines

When the number of CPU registers received in an incoming migration stream is bigger than the number of CPU registers seen by the destination we currently get the following error:

"failed to load cpu:cpreg_vmstate_array_len"

This series removes this cryptic message and explicitly outputs which spurious registers cause the failures.

Thank you for the diligent review! Hopefully I have taken into account all your comments in the v2 I've just sent.

Eric

Quoted 20 lines

Available at:
https://github.com/eauger/qemu/tree/cpreg_vmstate_array_len_traces

Eric Auger (5):
vmstate: Introduce VMSTATE_VARRAY_INT32_ALLOC target/arm/machine: Use VMSTATE_VARRAY_INT32_ALLOC for cpreg arrays target/arm/kvm: Export kvm_print_register_name() target/arm/machine: Trace cpreg names which do not match on migration target/arm/machine: Trace all register mismatches

 include/migration/vmstate.h | 10 +++++++
 target/arm/kvm_arm.h        |  2 ++
 target/arm/helper.c         |  5 ----
 target/arm/kvm-stub.c       |  6 ++++
 target/arm/kvm.c            |  7 +----
 target/arm/machine.c        | 57 +++++++++++++++++++++++++++----------
 target/arm/trace-events     |  3 ++
 7 files changed, 64 insertions(+), 26 deletions(-)
author
#4 lore raw

Re: [PATCH 1/5] vmstate: Introduce VMSTATE_VARRAY_INT32_ALLOC

In reply to Peter Xu
Quoted 8 lines · Peter Xu
Quoted 7 lines · Eric Auger

Already existing VMSTATE_VARRAY_INT32 requires an array to be pre-allocated, however there are cases when the size is not known in advance and there is no real need to enforce it.

Introduce VMSTATE_VARRAY_INT32_ALLOC as we currently have for UINT32 and UINT16.

Quoted 6 lines
Quoted 5 lines

The first user of this variant will be the target/arm/machine.c cpreg indexes/values arrays.

Thanks!

Eric

Quoted 1 line