Mitigation of "failed to load cpu:cpreg_vmstate_array_len" migration failures
v7 cover Mitigation of "failed to load cpu:cpreg_vmstate_array_len" migration failures
This series applies on top of
[PATCH 0/5] Improve traces on migration failure due to cpreg number mismatch
https://lore.kernel.org/all/[email protected]/
It introduces an infrastructure to explicitly tolerate some mismatches between cpu cpreg indexes/values on migration.
We especially handle failures due to an attempt to migrate more registers than exposed on the destination.
Once the infrastructure is in place we can handle the following known issues:
KVM:
- removal of unconditionnal exposure of TCR2_EL1, PIRE0_EL1, PIR_EL1 from v6.13 onwards. Causes forward migration failure.
- unconditionnal exposure of KVM_REG_ARM_VENDOR_HYP_BMAP_2 FW pseudo register from v6.16 onwards. Causes backward migration failure.
TCG:
- We can eventually remove AArch32 DBGDTRTX register which was erroneously defined.
Both series are available at:
https://github.com/eauger/qemu/tree/cpreg_vmstate_array_len_traces_mitig
History:
v6 -> v7
- complete rework after Peter's comments in
(https://lore.kernel.org/all/[email protected]/)
Especially it does not use properties at all. Do not feature hidden regs Also the initial series was split into 2.
Eric Auger (7):
target/arm/machine: Fix detection of unknown incoming cpregs target/arm/cpu: Introduce the infrastructure for cpreg migration
tolerances
target/arm/machine: Take account cpreg mig tolerances in case of
mismatch
target/arm/cpu64: Mitigate migration failures due to spurious TCR_EL1,
PIRE0_EL1 and PIR_EL1
target/arm/cpu64: Define cpreg migration tolerance for
KVM_REG_ARM_VENDOR_HYP_BMAP_2
target/arm/helper: Define cpreg migration tolerance for DGBDTR_EL0 Revert "target/arm: Reinstate bogus AArch32 DBGDTRTX register for
migration compat"
target/arm/cpu.h | 32 +++++++++++++++++ target/arm/cpu.c | 75 +++++++++++++++++++++++++++++++++++++++ target/arm/cpu64.c | 34 ++++++++++++++++++ target/arm/debug_helper.c | 29 --------------- target/arm/helper.c | 5 +++ target/arm/machine.c | 70 +++++++++++++++++++++++++++++------- target/arm/trace-events | 2 ++ 7 files changed, 206 insertions(+), 41 deletions(-)
Signature · 1 line
2.53.0
PATCH v7 1/7 target/arm/machine: Fix detection of unknown incoming cpregs
Currently 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
target/arm/machine.c +23 -0
@@ -1107,6 +1107,29 @@ 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++) { + 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); + } +/* +* 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++) { + 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); + fail = true; + }if (fail) {return -1 ; }
Signature · 1 line
2.53.0
Re: [PATCH v7 1/7] target/arm/machine: Fix detection of unknown incoming cpregs
Quoted 11 lines · Eric Auger
Currently 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.
Signed-off-by Eric Auger <[email protected]>Fixes 721fae12536 ("target-arm: Convert TCG to using (index,value) list for cp migration")
PATCH v7 2/7 target/arm/cpu: Introduce the infrastructure for cpreg migration tolerances
In reply to Eric AugerWe introduce a datatype for a tolerance with respect to a given cpreg migration issue. The tolerance applies to a given cpreg kvm index, and can be of different types:
- ToleranceNotOnBothEnds (cpreg index is allowed to be only on one end)
- ToleranceDiffInMask (value differences are allowed only within a mask)
- ToleranceFieldLT (incoming field value must be less than a given value)
- ToleranceFieldGT (incoming field value must be greater than a given value)
A QLIST of such tolerances can be populated using a new helper:arm_register_cpreg_mig_tolerance() and arm_cpu_cpreg_has_mig_tolerance() allows to check whether a tolerance exists for a given kvm index.
callers for those helpers will be introduced in subsequent patches.
--- target/arm/cpu.h | 32 +++++++++++++++++++++ target/arm/cpu.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+)
target/arm/cpu.h +32 -0
@@ -843,6 +843,21 @@ struct ARMELChangeHook {QLIST_ENTRY (ARMELChangeHook) node; }; +typedef enum { + ToleranceNotOnBothEnds, + ToleranceDiffInMask, + ToleranceFieldLT, + ToleranceFieldGT, +}ARMCPUCPREGMigToleranceType ; + +typedef struct ARMCPUCPREGMigTolerance { +uint64_t kvmidx; +uint64_t mask; +uint64_t value; +ARMCPUCPREGMigToleranceType type; +QLIST_ENTRY (ARMCPUCPREGMigTolerance) node; +}ARMCPUCPREGMigTolerance ; +/* These values map onto the return values for * QEMU_PSCI_0_2_FN_AFFINITY_INFO */ typedef enum ARMPSCIState {
@@ -1139,6 +1154,7 @@ struct ArchCPU { QLIST_HEAD(, ARMELChangeHook) pre_el_change_hooks; QLIST_HEAD(, ARMELChangeHook) el_change_hooks; + QLIST_HEAD(, ARMCPUCPREGMigTolerance) cpreg_mig_tolerances;int32_t node_id;/* NUMA node this CPU belongs to */
@@ -2632,6 +2648,22 @@ void arm_register_pre_el_change_hook(ARMCPU *cpu, ARMELChangeHookFn *hook,void arm_register_el_change_hook (ARMCPU *cpu,ARMELChangeHookFn *hook,void *opaque); +/** +* arm_register_cpreg_mig_tolerance: +* Register a migration tolerance wrt one given cpreg identified by its +* @kvmidx. Only one tolerance can be registered by kvm reg idx. +*/ +void arm_register_cpreg_mig_tolerance (ARMCPU *cpu,uint64_t kvmidx, +uint64_t mask,uint64_t value, +ARMCPUCPREGMigToleranceType type); + +/** +* arm_cpu_cpreg_has_mig_tolerance: +* Check whether a tolerance of type @type exists for a given @kvmidx +*/ +bool arm_cpu_cpreg_has_mig_tolerance (ARMCPU *cpu,uint64_t kvmidx, +uint64_t vmstate_value,uint64_t local_value, +ARMCPUCPREGMigToleranceType type);/** * arm_rebuild_hflags: * Rebuild the cached TBFLAGS for arbitrary changed processor state.
target/arm/cpu.c +75 -0
99 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v7 3/7 target/arm/machine: Take account cpreg mig tolerances in case of mismatch
In reply to Eric AugerIf there is a mismatch between the cpreg indexes found on both ends, check whether a tolerance was registered for the given kvmidx. If any, silence warning/errors.
Create dedicated helper functions that print the name of the culprit reg and analyze whether a tolerance is set. According set the level of traces and analyze whether the migration must eventually fail.
--- target/arm/machine.c | 67 +++++++++++++++++++++++++++-------------- target/arm/trace-events | 2 ++ 2 files changed, 47 insertions(+), 22 deletions(-)
target/arm/machine.c +45 -22
@@ -1046,6 +1046,45 @@ 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); + +if (!arm_cpu_cpreg_has_mig_tolerance (cpu, kvmidx, +0 ,0 , ToleranceNotOnBothEnds)) { +warn_report ("%s: %s " +"expected by the destination but not in the incoming stream, " +"skip it" , __func__, name); + }else { +trace_tolerate_cpreg_missing_in_incoming_stream (name); + } +} + +/* +* Handle the situation where @kvmidx is in the incoming +* stream but not on destination. This fails the migration if +* no cpreg mig tolerance is set for this @kvmidx +*/ +static bool handle_cpreg_only_in_incoming_stream (ARMCPU *cpu,uint64_t kvmidx) +{ + g_autofree gchar *name = print_register_name(kvmidx); +bool fail = false; + +if (!arm_cpu_cpreg_has_mig_tolerance (cpu, kvmidx, +0 ,0 , ToleranceNotOnBothEnds)) { +error_report ("%s: %s in the incoming stream but unknown on the " +"destination, fail migration" , __func__, name); + fail = true; + }else { +trace_tolerate_cpreg_only_in_incoming_stream (name); + } +return fail; +} +static int cpu_post_load (void *opaque,int version_id) {ARMCPU *cpu = opaque;
@@ -1085,21 +1124,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 */
@@ -1113,22 +1143,15 @@ static int cpu_post_load(void *opaque, int version_id)* in the input stream */ for ( ; i < cpu->cpreg_array_len; 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); +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++) { - 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); - fail = true; + fail =handle_cpreg_only_in_incoming_stream (cpu, + cpu->cpreg_vmstate_indexes[v]); }if (fail) {return -1 ;
target/arm/trace-events +2 -0
@@ -29,3 +29,5 @@ arm_psci_call(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3, uint32_t cpuid # 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" +tolerate_cpreg_missing_in_incoming_stream(char *name) "cpreg %s is missing in incoming stream but this is explicitly tolerated" +tolerate_cpreg_only_in_incoming_stream(char *name) "cpreg %s is in incoming stream but not on destination but this is explicitly tolerated"
Signature · 1 line
2.53.0
PATCH v7 4/7 target/arm/cpu64: Mitigate migration failures due to spurious TCR_EL1, PIRE0_EL1 and PIR_EL1
In reply to Eric AugerBefore linux v6.13 those registers were erroneously unconditionally exposed and this was fixed by commits:
- 0fcb4eea5345 ("KVM: arm64: Hide TCR2_EL1 from userspace when disabled for guests")
- a68cddbe47ef ("KVM: arm64: Hide S1PIE registers from userspace when disabled for guests")
in v6.13.
This means if we migrate from an old kernel host to a >= 6.13 kernel host, migration currently fails.
Declare cpreg migration tolerance for those registers.
--- target/arm/cpu64.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
target/arm/cpu64.c +26 -0
@@ -794,10 +794,36 @@ static void aarch64_a53_initfn(Object *obj)define_cortex_a72_a57_a53_cp_reginfo (cpu); } +static void kvm_arm_set_cpreg_mig_tolerances (ARMCPU *cpu) +{ +/* +* Registers that may be in the incoming stream and not exposed +* on the destination +*/ + +/* +* TCR_EL1 was erroneously unconditionnally exposed before linux v6.13. +* See commit 0fcb4eea5345 ("KVM: arm64: Hide TCR2_EL1 from userspace +* when disabled for guests") +*/ +arm_register_cpreg_mig_tolerance (cpu,ARM64_SYS_REG (3 ,0 ,2 ,0 ,3 ), +0 ,0 , ToleranceNotOnBothEnds); +/* +* PIRE0_EL1 and PIR_EL1 were erroneously unconditionnally exposed +* before linux v6.13. See commit a68cddbe47ef ("KVM: arm64: Hide +* S1PIE registers from userspace when disabled for guests") +*/ +arm_register_cpreg_mig_tolerance (cpu,ARM64_SYS_REG (3 ,0 ,10 ,2 ,2 ), +0 ,0 , ToleranceNotOnBothEnds); +arm_register_cpreg_mig_tolerance (cpu,ARM64_SYS_REG (3 ,0 ,10 ,2 ,3 ), +0 ,0 , ToleranceNotOnBothEnds); +} +static void aarch64_host_initfn (Object *obj) {ARMCPU *cpu =ARM_CPU (obj);#if defined(CONFIG_KVM ) +kvm_arm_set_cpreg_mig_tolerances (cpu);kvm_arm_set_cpu_features_from_host (cpu);if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) {aarch64_add_sve_properties (obj);
Signature · 1 line
2.53.0
PATCH v7 5/7 target/arm/cpu64: Define cpreg migration tolerance for KVM_REG_ARM_VENDOR_HYP_BMAP_2
In reply to Eric AugerKVM_REG_ARM_VENDOR_HYP_BMAP_2 pseudo FW register is exposed from v6.15 onwards. Backward migration from a >= v6.15 to an older kernel would fail without cpreg migration tolerance definition for this register.
--- target/arm/cpu64.c | 8 ++++++++ 1 file changed, 8 insertions(+)
target/arm/cpu64.c +8 -0
@@ -817,6 +817,14 @@ static void kvm_arm_set_cpreg_mig_tolerances(ARMCPU *cpu) 0, 0, ToleranceNotOnBothEnds);arm_register_cpreg_mig_tolerance (cpu,ARM64_SYS_REG (3 ,0 ,10 ,2 ,3 ),0 ,0 , ToleranceNotOnBothEnds); + +/* +* KVM_REG_ARM_VENDOR_HYP_BMAP_2 pseudo FW register is exposed +* from v6.15 onwards. Backward migration from a >= v6.15 to an older +* kernel would fail without cpreg migration tolerance definition +*/ +arm_register_cpreg_mig_tolerance (cpu,KVM_REG_ARM_FW_FEAT_BMAP_REG (3 ), +0 ,0 , ToleranceNotOnBothEnds); }static void aarch64_host_initfn (Object *obj)
Signature · 1 line
2.53.0
PATCH v7 6/7 target/arm/helper: Define cpreg migration tolerance for DGBDTR_EL0
In reply to Eric AugerWe want to remove AArch32 DBGDTRTX which was erroneously exposed. This was attempted by 655659a74a36b ("target/arm: Correct encoding of Debug Communications Channel registers") but it was discovered that the removal of this debug register broke forward migration on TCG. Now we have the cpreg migration tolerance infrastructure, we can declare one for the DBGDTRTX. This allow to revert the reinstate patch.
--- target/arm/helper.c | 5 +++++ 1 file changed, 5 insertions(+)
target/arm/helper.c +5 -0
@@ -6426,9 +6426,14 @@ void register_cp_regs_for_features(ARMCPU *cpu) .fgt = FGT_CLIDR_EL1, .resetvalue = GET_IDREG(isar, CLIDR) }; +uint64_t dbgtr_el0_kvmidx = +cpreg_to_kvm_id (ENCODE_CP_REG (14 ,0 ,1 ,0 ,5 ,3 ,0 )); +define_one_arm_cp_reg (cpu, &clidr);define_arm_cp_regs (cpu, v7_cp_reginfo);define_debug_regs (cpu); +arm_register_cpreg_mig_tolerance (cpu, dbgtr_el0_kvmidx, +0 ,0 , ToleranceNotOnBothEnds); }else {define_arm_cp_regs (cpu, not_v7_cp_reginfo); }
Signature · 1 line
2.53.0
PATCH v7 7/7 Revert "target/arm: Reinstate bogus AArch32 DBGDTRTX register for migration compat"
In reply to Eric AugerThis reverts commit 4f2b82f60431 ("target/arm: Reinstate bogus AArch32 DBGDTRTX register for migration compat). We don't need that commit anymore as the AArch32 DBGDTRTX register is declared to
be safe to ignore in the incoming migration stream.
--- target/arm/debug_helper.c | 29 ----------------------------- 1 file changed, 29 deletions(-)
target/arm/debug_helper.c +0 -29
@@ -171,13 +171,6 @@ static void dbgclaimclr_write(CPUARMState *env, const ARMCPRegInfo *ri, env->cp15.dbgclaim &= ~(value &0xFF ); } -static CPAccessResult access_bogus (CPUARMState *env,const ARMCPRegInfo *ri, -bool isread) -{ -/* Always UNDEF, as if this cpreg didn't exist */ -return CP_ACCESS_UNDEFINED ; -} -static const ARMCPRegInfo debug_cp_reginfo[] = {/* * DBGDRAR, DBGDSAR: always RAZ since we don't implement memory mapped
@@ -240,28 +233,6 @@ static const ARMCPRegInfo debug_cp_reginfo[] = { .opc0 = 2, .opc1 = 3, .crn = 0, .crm = 4, .opc2 = 0, .access = PL0_RW, .accessfn = access_tdcc, .type = ARM_CP_CONST, .resetvalue = 0 }, -/* -* This is not a real AArch32 register. We used to incorrectly expose -* this due to a QEMU bug; to avoid breaking migration compatibility we -* need to continue to provide it so that we don't fail the inbound -* migration when it tells us about a sysreg that we don't have. -* We set an always-fails .accessfn, which means that the guest doesn't -* actually see this register (it will always UNDEF, identically to if -* there were no cpreg definition for it other than that we won't print -* a LOG_UNIMP message about it), and we set the ARM_CP_NO_GDB flag so the -* gdbstub won't see it either. -* (We can't just set .access = 0, because add_cpreg_to_hashtable() -* helpfully ignores cpregs which aren't accessible to the highest -* implemented EL.) -* -* TODO: implement a system for being able to describe "this register -* can be ignored if it appears in the inbound stream"; then we can -* remove this temporary hack. -*/ - { .name = "BOGUS_DBGDTR_EL0", .state = ARM_CP_STATE_AA32, - .cp = 14, .opc1 = 3, .crn = 0, .crm = 5, .opc2 = 0, - .access = PL0_RW, .accessfn = access_bogus, - .type = ARM_CP_CONST | ARM_CP_NO_GDB, .resetvalue = 0 },/* * OSECCR_EL1 provides a mechanism for an operating system * to access the contents of EDECCR. EDECCR is not implemented though,
Signature · 1 line
2.53.0