Improve traces on migration failure due to cpreg number mismatch
v3 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 are handled in a follow-up series:
Mitigation of "failed to load cpu:cpreg_vmstate_array_len" (v8)
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_v3_mitig_v2
v2 -> v3:
- clear the vmstate array pointers on post_save()
- improve the print_register_name comment
- Collecting remaining R-b's
v1 -> v2:
- Tool all comments from Peter on v1. See individual history logs
- Also added last patch which was previously included in the follow-up mitigation series ([PATCH v7 0/7] Mitigation of "failed to load cpu:cpreg_vmstate_array_len" migration failures) but actually belongs to those functional changes.
Eric Auger (7):
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/kvm: Tweak print_register_name() for arm64 system register target/arm/machine: Trace cpreg names which do not match on migration target/arm/machine: Trace all register mismatches target/arm/machine: Fix detection of unknown incoming cpregs
include/migration/vmstate.h | 10 ++++ target/arm/kvm_arm.h | 9 +++ target/arm/helper.c | 5 -- target/arm/kvm-stub.c | 5 ++ target/arm/kvm.c | 9 +-- target/arm/machine.c | 115 ++++++++++++++++++++++++++++++------ target/arm/whpx/whpx-all.c | 7 --- target/arm/trace-events | 3 + 8 files changed, 127 insertions(+), 36 deletions(-)
Signature · 1 line
2.53.0
PATCH v3 1/7 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
@@ -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
PATCH v3 2/7 target/arm/machine: Use VMSTATE_VARRAY_INT32_ALLOC for cpreg arrays
In reply to Eric AugerThis 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.
---
v1 -> v2:
- also modifies the allocation of cpureg_vmstate_* in target/arm/whpx/whpx-all.c
- added Peter's suggested comment on cpu_pre_save()
- free the the vmstate arrays on post_load
- add assert on pre_load
- fix comment aboy length check in machine.c
v2 -> v3:
- clear the pointers also in post_save()
--- target/arm/helper.c | 5 ----- target/arm/kvm.c | 5 ----- target/arm/machine.c | 45 +++++++++++++++++++++++++++----------- target/arm/whpx/whpx-all.c | 7 ------ target/arm/trace-events | 3 +++ 5 files changed, 35 insertions(+), 30 deletions(-)
target/arm/helper.c +0 -5
@@ -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
@@ -864,12 +864,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 +32 -13
88 lines not on this page · raw message
target/arm/whpx/whpx-all.c +0 -7
@@ -783,12 +783,6 @@ int whpx_init_vcpu(CPUState *cpu) sregs_match_len); arm_cpu->cpreg_values =g_renew (uint64_t, arm_cpu->cpreg_values, sregs_match_len); - arm_cpu->cpreg_vmstate_indexes =g_renew (uint64_t, - arm_cpu->cpreg_vmstate_indexes, - sregs_match_len); - arm_cpu->cpreg_vmstate_values =g_renew (uint64_t, - arm_cpu->cpreg_vmstate_values, - sregs_match_len);memset (arm_cpu->cpreg_values,0 , sregs_match_len *sizeof (uint64_t ));
@@ -807,7 +801,6 @@ int whpx_init_vcpu(CPUState *cpu) } } arm_cpu->cpreg_array_len = sregs_cnt; - arm_cpu->cpreg_vmstate_array_len = sregs_cnt;assert (write_cpustate_to_list (arm_cpu, false));
target/arm/trace-events +3 -0
@@ -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
PATCH v3 3/7 target/arm/kvm: Export kvm_print_register_name()
In reply to Eric AugerWe 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.
---
v2 -> v3:
- added "The caller must free the string with g_free()."
v1 -> v2:
- add doc comment
- no code after g_assert_not_reached()
- use char * instead of gchar
--- target/arm/kvm_arm.h | 9 +++++++++ target/arm/kvm-stub.c | 5 +++++ target/arm/kvm.c | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-)
target/arm/kvm_arm.h +9 -0
@@ -231,4 +231,13 @@ void arm_cpu_kvm_set_irq(void *arm_cpu, int irq, int level);void arm_gic_cap_kvm_probe (GICCapability *v2,GICCapability *v3); +/* +* kvm_print_register_name: +* @regidx: register KVM index +* +* Returns a human-readable string representing this register +* The caller must free the string with g_free(). +*/ +char *kvm_print_register_name (uint64_t regidx); +#endif
target/arm/kvm-stub.c +5 -0
@@ -114,3 +114,8 @@ void arm_gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3) {g_assert_not_reached (); } + +char *kvm_print_register_name (uint64_t regidx) +{ +g_assert_not_reached (); +}
target/arm/kvm.c +1 -1
@@ -970,7 +970,7 @@ static gchar *kvm_print_sve_register_name(uint64_t regidx) } } -static gchar *kvm_print_register_name (uint64_t regidx) +char *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
PATCH v3 4/7 target/arm/kvm: Tweak print_register_name() for arm64 system register
In reply to Eric AugerAs opposed to other register types, arm64 system register decoding is not introduced by any 'register' mention which can lead to unfriendly user-facing traces. Let's add "system register"
--- target/arm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/kvm.c +1 -1
@@ -978,7 +978,7 @@ char *kvm_print_register_name(uint64_t regidx)case KVM_REG_ARM_DEMUX :return g_strdup_printf ("demuxed reg %" PRIx64, regidx);case KVM_REG_ARM64_SYSREG : - return g_strdup_printf("op0:%d op1:%d crn:%d crm:%d op2:%d", + return g_strdup_printf("system register op0:%d op1:%d crn:%d crm:%d op2:%d", CP_REG_ARM64_SYSREG_OP(regidx, OP0), CP_REG_ARM64_SYSREG_OP(regidx, OP1), CP_REG_ARM64_SYSREG_OP(regidx, CRN),
Signature · 1 line
2.53.0
PATCH v3 5/7 target/arm/machine: Trace cpreg names which do not match on migration
In reply to Eric AugerWhenever 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: system register op0:3 op1:0 crn:2 crm:0 op2:3 in the incoming stream but unknown on the destination, fail migration
---
v1 -> v2:
- replaced ',' by ':' in the traces
- added system register in print_register_name when kvm is not enabled
--- target/arm/machine.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
target/arm/machine.c +19 -2
@@ -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"
@@ -1047,6 +1048,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 ("system register 0x%x" ,kvm_to_cpreg_id (kvm_regidx)); + } +} +static int cpu_post_load (void *opaque,int version_id) {ARMCPU *cpu = opaque;
@@ -1085,11 +1095,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
PATCH v3 6/7 target/arm/machine: Trace all register mismatches
In reply to Eric AugerAt the moment, cpu_post_load() exits 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
@@ -1061,6 +1061,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,
@@ -1093,13 +1094,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]) {
@@ -1107,12 +1109,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
PATCH v3 7/7 target/arm/machine: Fix detection of unknown incoming cpregs
In reply to Eric AugerCurrently the check of cpreg index matches fail to detect
a situation where the length of both arrays is same but
- destination has an extra register not found in the incoming stream (idx1)
- source has an extra register not found in the destination (idx2) where idx1 < = idx2
Normally this should fail but it does not.
Fix the logic to scan all indexes.
--- target/arm/machine.c | 61 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 12 deletions(-)
target/arm/machine.c +49 -12
@@ -1057,6 +1057,35 @@ static gchar *print_register_name(uint64_t kvm_regidx) } } +/* +* Handle the situation where @kvmidx is on destination but not +* in the incoming stream. This never fails the migration. +*/ +static void handle_cpreg_missing_in_incoming_stream (ARMCPU *cpu,uint64_t kvmidx) +{ + g_autofree gchar *name = print_register_name(kvmidx); + +warn_report ("%s: %s " +"expected by the destination but not in the incoming stream: " +"skip it" , __func__, name); +} + +/* +* Handle the situation where @kvmidx is in the incoming stream +* but not on destination. This currently fails the migration but +* we plan to accomodate some exceptions, hence the boolean returned value. +*/ +static bool handle_cpreg_only_in_incoming_stream (ARMCPU *cpu,uint64_t kvmidx) +{ + g_autofree gchar *name = print_register_name(kvmidx); +bool fail = true; + +error_report ("%s: %s in the incoming stream but unknown on the " +"destination: fail migration" , __func__, name); + +return fail; +} +static int cpu_post_load (void *opaque,int version_id) {ARMCPU *cpu = opaque;
@@ -1096,21 +1125,12 @@ 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;) {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++; +handle_cpreg_missing_in_incoming_stream (cpu, cpu->cpreg_indexes[i++]);continue ; }if (cpu->cpreg_vmstate_indexes[v] < cpu->cpreg_indexes[i]) { - 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); - v++; - fail = true; + fail =handle_cpreg_only_in_incoming_stream (cpu, + cpu->cpreg_vmstate_indexes[v++]);continue ; }/* matching register, copy the value over */
@@ -1118,6 +1138,23 @@ static int cpu_post_load(void *opaque, int version_id) i++; v++; } + +/* +* if we have reached the end of the incoming array but there are +* still regs in cpreg, continue parsing the regs which are missing +* in the input stream +*/ +for ( ; i < cpu->cpreg_array_len; i++) { +handle_cpreg_missing_in_incoming_stream (cpu, cpu->cpreg_indexes[i]); + } +/* +* if we have reached the end of the cpreg array but there are +* still regs in the input stream, continue parsing the vmstate array +*/ +for ( ; v < cpu->cpreg_vmstate_array_len; v++) { + fail =handle_cpreg_only_in_incoming_stream (cpu, + cpu->cpreg_vmstate_indexes[v]); + }if (fail) {return -1 ; }
Signature · 1 line
2.53.0
Peter Maydell
AppliedQuoted 14 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 are handled in a follow-up series:
Mitigation of "failed to load cpu:cpreg_vmstate_array_len" (v8)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:
Quoted 6 lines
"failed to load cpu:cpreg_vmstate_array_len"
This series removes this cryptic message and explicitly outputs which spurious registers cause the failures.
---
Applied to target-arm.next, thanks.
-- PMM